KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/HasRecordsTag.java,v 1.4 2005/02/19 21:26:32 hkollmann Exp $
3  * $Revision: 1.4 $
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 import org.dbforms.config.ResultSetVector;
28
29 import org.dbforms.util.Util;
30
31 import java.io.IOException JavaDoc;
32
33 import javax.servlet.jsp.JspException JavaDoc;
34 import javax.servlet.jsp.JspWriter JavaDoc;
35
36
37
38 /**
39  * DOCUMENT ME!
40  *
41  * @author $author$
42  * @version $Revision: 1.4 $
43  */

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

54    public void setMessage(String JavaDoc message) {
55       this.message = message;
56    }
57
58
59    /**
60     * Gets the message
61     *
62     * @return Returns a String
63     */

64    public String JavaDoc getMessage() {
65       return message;
66    }
67
68
69    /**
70     * DOCUMENT ME!
71     *
72     * @param pageContext DOCUMENT ME!
73     */

74    public void setPageContext(final javax.servlet.jsp.PageContext JavaDoc pageContext) {
75       super.setPageContext(pageContext);
76       this.errors = (DbFormsErrors) pageContext.getServletContext()
77                                                .getAttribute(DbFormsErrors.ERRORS);
78    }
79
80
81    /**
82     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
83     */

84    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
85       throw t;
86    }
87
88
89    /**
90     * DOCUMENT ME!
91     *
92     * @return DOCUMENT ME!
93     *
94     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
95     * @throws JspException DOCUMENT ME!
96     */

97    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
98       // Get result set vector from parent and calculate size
99
try {
100          int rsvSize = getParentForm()
101                           .getResultSetVector()
102                           .size();
103
104          if (rsvSize != 0) {
105             if (bodyContent != null) {
106                bodyContent.writeOut(bodyContent.getEnclosingWriter());
107                bodyContent.clearBody();
108             }
109
110             String JavaDoc pmessage = (errors != null)
111                              ? errors.getXMLErrorMessage(getMessage())
112                              : getMessage();
113
114             if (!Util.isNull(pmessage)) {
115                // Print the results to our output writer
116
JspWriter JavaDoc writer = pageContext.getOut();
117
118                try {
119                   writer.print(pmessage);
120                } catch (IOException JavaDoc e) {
121                   throw new JspException JavaDoc(e.toString());
122                }
123             }
124          }
125       } catch (java.io.IOException JavaDoc e) {
126          throw new JspException JavaDoc("IO Error: " + e.getMessage());
127       }
128
129       return EVAL_PAGE;
130    }
131
132
133    /**
134     * DOCUMENT ME!
135     */

136    public void doFinally() {
137       message = null;
138       errors = null;
139       super.doFinally();
140    }
141
142
143    /**
144     * Render the specified error messages if there are any.
145     *
146     * @return DOCUMENT ME!
147     *
148     * @exception JspException if a JSP exception has occurred
149     */

150    public int doStartTag() throws JspException JavaDoc {
151       if (!ResultSetVector.isNull(getParentForm().getResultSetVector())) {
152          return EVAL_BODY_BUFFERED;
153       } else {
154          return SKIP_BODY;
155       }
156    }
157 }
158
Popular Tags