View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/HasMoreRecordsTag.java,v 1.15 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.15 $
4    * $Date: 2006/01/13 13:38:51 $
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;
31  
32  import javax.servlet.jsp.JspException;
33  import javax.servlet.jsp.JspWriter;
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 AbstractDbBaseHandlerTag
42     implements javax.servlet.jsp.tagext.TryCatchFinally {
43     private transient DbFormsErrors errors;
44     private String                  count   = null;
45     private String                  message = null;
46  
47     /***
48      * Sets the count
49      *
50      * @param count The count to set
51      */
52     public void setCount(String count) {
53        this.count = count;
54     }
55  
56  
57     /***
58      * Gets the count
59      *
60      * @return Returns a String
61      */
62     public String 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 message) {
83        this.message = message;
84     }
85  
86  
87     /***
88      * Gets the message
89      *
90      * @return Returns a String
91      */
92     public String 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 pageContext) {
103       super.setPageContext(pageContext);
104       this.errors = (DbFormsErrors) pageContext.getServletContext()
105                                                .getAttribute(DbFormsErrors.ERRORS);
106    }
107 
108    /***
109     * DOCUMENT ME!
110     *
111     * @return DOCUMENT ME!
112     *
113     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
114     * @throws JspException DOCUMENT ME!
115     */
116    public int doEndTag() throws javax.servlet.jsp.JspException {
117       // Get result set vector from parent and calculate size
118       try {
119          int rsvSize = getParentForm()
120                           .getResultSetVector()
121                           .size();
122 
123          if (rsvSize >= getCountAsInt()) {
124             if (bodyContent != null) {
125                bodyContent.writeOut(bodyContent.getEnclosingWriter());
126                bodyContent.clearBody();
127             }
128 
129             String pmessage = (errors != null)
130                              ? errors.getXMLErrorMessage(getMessage())
131                              : getMessage();
132 
133             if (!Util.isNull(pmessage)) {
134                // Print the results to our output writer
135                JspWriter writer = pageContext.getOut();
136 
137                try {
138                   writer.print(pmessage);
139                } catch (IOException e) {
140                   throw new JspException(e.toString());
141                }
142             }
143          }
144       } catch (java.io.IOException e) {
145          throw new JspException("IO Error: " + e.getMessage());
146       }
147 
148       return EVAL_PAGE;
149    }
150 
151 
152    /***
153     * DOCUMENT ME!
154     */
155    public void doFinally() {
156       count   = null;
157       message = null;
158       errors  = null;
159       super.doFinally();
160    }
161 
162 
163    /***
164     * Render the specified error messages if there are any.
165     *
166     * @return DOCUMENT ME!
167     *
168     * @exception JspException if a JSP exception has occurred
169     */
170    public int doStartTag() throws JspException {
171       int rsvSize = getParentForm()
172                        .getResultSetVector()
173                        .size();
174 
175       if (rsvSize >= getCountAsInt()) {
176          return EVAL_BODY_BUFFERED;
177       } else {
178          return SKIP_BODY;
179       }
180    }
181 }