KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jgallery > tags > ColIteratorTag


1 package de.jwi.jgallery.tags;
2
3 /*
4  * jGallery - Java web application to display image galleries
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jGallery.
9  *
10  * jGallery is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jGallery is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jGallery; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25 import java.io.IOException JavaDoc;
26
27 import javax.servlet.jsp.JspTagException JavaDoc;
28 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
29 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
30 import javax.servlet.jsp.tagext.Tag JavaDoc;
31
32 import de.jwi.jgallery.GalleryException;
33 import de.jwi.jgallery.Image;
34
35 /**
36  * @author Juergen Weber
37  * Source file created on 18.02.2004
38  *
39  */

40 public class ColIteratorTag extends BodyTagSupport JavaDoc
41 {
42
43     public static final String JavaDoc CURRENTIMAGE = "image";
44
45     private int colsLeft;
46
47     private RowIteratorTag rowIteratorTag;
48
49     public int doStartTag() throws JspTagException JavaDoc
50     {
51         Tag JavaDoc parent = getParent();
52
53         if ((null == parent) || (!(parent instanceof RowIteratorTag))) { throw new JspTagException JavaDoc(
54                 "colIterator tag not within rowIterator tag"); }
55         rowIteratorTag = (RowIteratorTag) parent;
56         colsLeft = rowIteratorTag.getColsLeft();
57         if (colsLeft > 0)
58         {
59             Image currentImage = null;
60             colsLeft--;
61
62             try
63             {
64                 currentImage = rowIteratorTag.getNextImage();
65                 pageContext.getRequest().setAttribute(CURRENTIMAGE, currentImage);
66             }
67             catch (GalleryException e)
68             {
69                 throw new JspTagException JavaDoc(e.getMessage());
70             }
71
72             return (EVAL_BODY_AGAIN);
73         }
74         else
75         {
76             return SKIP_BODY;
77         }
78     }
79
80     public int doAfterBody() throws JspTagException JavaDoc
81     {
82         BodyContent JavaDoc body = getBodyContent();
83         try
84         {
85             body.writeOut(getPreviousOut());
86         }
87         catch (IOException JavaDoc e)
88         {
89             throw new JspTagException JavaDoc("IterationTag: " + e.getMessage());
90         }
91
92         // clear up so the next time the body content is empty
93
body.clearBody();
94         if (colsLeft > 0)
95         {
96             colsLeft--;
97             try
98             {
99                 Image currentImage = rowIteratorTag.getNextImage();
100                 pageContext.getRequest().setAttribute(CURRENTIMAGE,
101                         currentImage);
102             }
103             catch (GalleryException e)
104             {
105                 throw new JspTagException JavaDoc(e.getMessage());
106             }
107             return (EVAL_BODY_AGAIN);
108         }
109         else
110         {
111             return SKIP_BODY;
112         }
113     }
114 }
115
Popular Tags