KickJava   Java API By Example, From Geeks To Geeks.

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


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.JspException JavaDoc;
28 import javax.servlet.jsp.JspTagException JavaDoc;
29 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
30 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
31
32 import de.jwi.jgallery.Folder;
33 import de.jwi.jgallery.GalleryException;
34 import de.jwi.jgallery.Image;
35
36 /**
37  * @author Juergen Weber
38  * Source file created on 18.02.2004
39  *
40  * @see http://java.sun.com/products/jsp/tutorial/TagLibraries16.html
41  */

42 public class RowIteratorTag extends BodyTagSupport JavaDoc
43 {
44
45     private int cols;
46
47     private int imagesLeft;
48
49     private int currentImageNum;
50
51     private Folder folder;
52
53     // this is a callback for ColIteratorTag
54
int getColsLeft()
55     {
56         int n = Math.min(imagesLeft, cols);
57         imagesLeft -= n;
58         return n;
59     }
60
61     // this is a callback for ColIteratorTag
62
Image getNextImage()
63     throws GalleryException
64     {
65         return folder.getSubDirOrImage(currentImageNum++);
66     }
67
68     public int doStartTag() throws JspException JavaDoc
69     {
70         folder = (Folder) pageContext.getRequest().getAttribute(
71                 "folder");
72
73         if (null == folder) { throw new JspException JavaDoc(
74                 "no folder Attribute found in request"); }
75
76         imagesLeft = folder.getCurrentImagesPerPage();
77
78         if (imagesLeft > 0)
79         {
80             cols = folder.getColsI();
81             currentImageNum = folder.getImageNumI();
82
83             return (EVAL_BODY_AGAIN);
84         }
85         else
86         {
87             return SKIP_BODY;
88         }
89     }
90
91     public int doAfterBody() throws JspTagException JavaDoc
92     {
93         BodyContent JavaDoc body = getBodyContent();
94         try
95         {
96             body.writeOut(getPreviousOut());
97         }
98         catch (IOException JavaDoc e)
99         {
100             throw new JspTagException JavaDoc("IterationTag: " + e.getMessage());
101         }
102
103         body.clearBody();
104         if (imagesLeft > 0)
105         {
106             return EVAL_BODY_AGAIN;
107         }
108         else
109         {
110             return SKIP_BODY;
111         }
112
113     }
114 }
115
Popular Tags