KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > HasMoreRecordsTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/HasMoreRecordsTag.java,v 1.13 2005/02/19 21:26:32 hkollmann Exp $
3  * $Revision: 1.13 $
4  * $Date: 2005/02/19 21:26:32 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.config.DbFormsErrors;
27
28 import org.dbforms.util.Util;
29
30 import java.io.IOException JavaDoc;
31
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.JspWriter JavaDoc;
34
35
36
37 /**
38  * Grunikiewicz.philip 2001-12-18 Display a custom message if the developer has
39  * set a limit on the number of rows to display
40  */

41 public class HasMoreRecordsTag extends DbBaseHandlerTag
42    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
43    private transient DbFormsErrors errors;
44    private String JavaDoc count = null;
45    private String JavaDoc message = null;
46
47    /**
48     * Sets the count
49     *
50     * @param count The count to set
51     */

52    public void setCount(String JavaDoc count) {
53       this.count = count;
54    }
55
56
57    /**
58     * Gets the count
59     *
60     * @return Returns a String
61     */

62    public String JavaDoc getCount() {
63       return count;
64    }
65
66
67    /**
68     * Gets the count as int
69     *
70     * @return DOCUMENT ME!
71     */

72    public int getCountAsInt() {
73       return Integer.parseInt(getCount());
74    }
75
76
77    /**
78     * Sets the message
79     *
80     * @param message The message to set
81     */

82    public void setMessage(String JavaDoc message) {
83       this.message = message;
84    }
85
86
87    /**
88     * Gets the message
89     *
90     * @return Returns a String
91     */

92    public String JavaDoc getMessage() {
93       return message;
94    }
95
96
97    /**
98     * DOCUMENT ME!
99     *
100     * @param pageContext DOCUMENT ME!
101     */

102    public void setPageContext(final javax.servlet.jsp.PageContext JavaDoc pageContext) {
103       super.setPageContext(pageContext);
104       this.errors = (DbFormsErrors) pageContext.getServletContext()
105                                                .getAttribute(DbFormsErrors.ERRORS);
106    }
107
108
109    /**
110     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
111     */

112    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
113       throw t;
114    }
115
116
117    /**
118     * DOCUMENT ME!
119     *
120     * @return DOCUMENT ME!
121     *
122     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
123     * @throws JspException DOCUMENT ME!
124     */

125    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
126       // Get result set vector from parent and calculate size
127
try {
128          int rsvSize = getParentForm()
129                           .getResultSetVector()
130                           .size();
131
132          if (rsvSize >= getCountAsInt()) {
133             if (bodyContent != null) {
134                bodyContent.writeOut(bodyContent.getEnclosingWriter());
135                bodyContent.clearBody();
136             }
137
138             String JavaDoc pmessage = (errors != null)
139                              ? errors.getXMLErrorMessage(getMessage())
140                              : getMessage();
141
142             if (!Util.isNull(pmessage)) {
143                // Print the results to our output writer
144
JspWriter JavaDoc writer = pageContext.getOut();
145
146                try {
147                   writer.print(pmessage);
148                } catch (IOException JavaDoc e) {
149                   throw new JspException JavaDoc(e.toString());
150                }
151             }
152          }
153       } catch (java.io.IOException JavaDoc e) {
154          throw new JspException JavaDoc("IO Error: " + e.getMessage());
155       }
156
157       return EVAL_PAGE;
158    }
159
160
161    /**
162     * DOCUMENT ME!
163     */

164    public void doFinally() {
165       count = null;
166       message = null;
167       errors = null;
168       super.doFinally();
169    }
170
171
172    /**
173     * Render the specified error messages if there are any.
174     *
175     * @return DOCUMENT ME!
176     *
177     * @exception JspException if a JSP exception has occurred
178     */

179    public int doStartTag() throws JspException JavaDoc {
180       int rsvSize = getParentForm()
181                        .getResultSetVector()
182                        .size();
183
184       if (rsvSize >= getCountAsInt()) {
185          return EVAL_BODY_BUFFERED;
186       } else {
187          return SKIP_BODY;
188       }
189    }
190 }
191
Popular Tags