KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > taglibs > RepeatTag


1 /*
2  * RepeatTag is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/taglibs/RepeatTag.java,v 1.3.2.1 2006/12/11 16:27:38 fxrobin Exp $
21  */

22
23 package org.cofax.taglibs;
24
25 import javax.servlet.jsp.*;
26 import javax.servlet.jsp.tagext.*;
27 import java.io.*;
28
29 /**
30  * RepeatTag is a child tag to ExecuteTag, which in turn is a child tag of
31  * PackageTag. A RepeatTag allows access to each row of a PackageTag's results
32  * in turn. It can display a table row for example. This tag is used in concert
33  * with FooterTag, HeaderTag, and NoRowTag.
34  *
35  * Note that this tag returns SKIP_BODY if no rows are returned from the
36  * PackageTag
37  *
38  */

39 public class RepeatTag extends BodyTagSupport {
40
41     PackageTag parent;
42
43     /**
44      * Verify if the parent packageTag date exist the call doAfterBody() method
45      */

46     public int doStartTag() {
47         parent = (PackageTag) findAncestorWithClass(this, PackageTag.class);
48         // check for existing row
49
if ((parent != null) && (!parent.getNoRows())) {
50             return EVAL_BODY_TAG;
51         } else {
52             return SKIP_BODY;
53         }
54     }
55
56     /**
57      * Display each record from PackageTag glossary
58      */

59     public int doAfterBody() throws JspException {
60
61         BodyContent body = getBodyContent();
62         try {
63             body.writeOut(getPreviousOut());
64             parent.nextRow();
65         } catch (IOException e) {
66             parent.printMessage("Error in IO body repeat" + e);
67         }
68         body.clearBody();
69
70         if (parent.getHasRowData()) {
71             return EVAL_BODY_TAG;
72         } else {
73             return SKIP_BODY;
74         }
75
76     }
77
78     /**
79      * Ends this Tag run.
80      */

81     public int doEndTag() {
82         return EVAL_PAGE;
83     }
84
85 } // end RepeatTag
86

87
Popular Tags