KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > taglib > GridBaseTag


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: GridBaseTag.java,v 1.4 2004/03/26 16:16:12 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.taglib;
28
29 import java.io.IOException JavaDoc;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32 import javax.servlet.jsp.JspWriter JavaDoc;
33
34 import org.apache.struts.taglib.html.BaseHandlerTag;
35
36 abstract public class GridBaseTag extends BaseHandlerTag {
37
38 // ----------------------------------------------------- Protected Constants
39

40     protected final static String JavaDoc QUOTE = "\"";
41
42 // ----------------------------------------------------- Instance Variables
43

44     protected String JavaDoc ms_BodyText = null;
45
46 // ----------------------------------------------------- Public Methods
47

48     /**
49      * Start of Tag processing
50      *
51      * @exception JspException if a JSP exception occurs
52      */

53     public int doStartTag()
54         throws JspException JavaDoc {
55         ms_BodyText = null;
56         // Continue processing this page
57
return (EVAL_BODY_BUFFERED);
58     }
59
60     public int doAfterBody()
61         throws JspException JavaDoc {
62         if (bodyContent != null) {
63             String JavaDoc value = bodyContent.getString().trim();
64             if (value.length() > 0) {
65                 ms_BodyText = value;
66             }
67         }
68         return (SKIP_BODY);
69     }
70
71     /**
72      * End of Tag Processing
73      *
74      * @exception JspException if a JSP exception occurs
75      */

76     public int doEndTag()
77         throws JspException JavaDoc {
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
79         // Before Tag option
80
sb.append(prepareBeforeTag());
81
82         // Create a ELEMENT element based on the parameters
83
sb.append("<");
84         sb.append(getHtmlElement());
85         // Prepare this HTML elements attributes
86
sb.append(prepareAttributes());
87         sb.append(">");
88
89         // Before Body Content option
90
sb.append(prepareBeforeBody());
91         // Add Body Content
92
if (ms_BodyText != null) {
93             sb.append(ms_BodyText);
94         }
95         else {
96             sb.append(getDefaultBody());
97         }
98         // Before After Content option
99
sb.append(prepareAfterBody());
100         // End Tag
101
sb.append("</");
102         sb.append(getHtmlElement());
103         sb.append(">");
104
105         // After Tag option
106
sb.append(prepareAfterTag());
107
108         // Render this element to our writer
109
JspWriter JavaDoc out = pageContext.getOut();
110         try {
111             out.print(sb.toString());
112         }
113         catch (IOException JavaDoc e) {
114             throw new JspException JavaDoc("Exception in " + getClass().getName() + " doEndTag():"
115                 + e.toString());
116         }
117         return EVAL_PAGE;
118     }
119
120     /**
121      * Prepare the attributes of the HTML element
122      */

123     protected String JavaDoc prepareAttributes() throws JspException JavaDoc {
124         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
125
126         // Append Event Handler details
127
sb.append(prepareEventHandlers());
128         // Append Style details
129
sb.append(prepareStyles());
130
131         return sb.toString();
132     }
133
134     /**
135      * Format attribute="value" from the specified attribute & value
136      */

137     protected String JavaDoc prepareAttribute(String JavaDoc attribute, String JavaDoc value) {
138         return value == null ? "" : " " + attribute + "=" + QUOTE + value + QUOTE;
139     }
140
141     /**
142      * Format attribute="value" from the specified attribute & value
143      */

144
145     protected String JavaDoc prepareAttribute(String JavaDoc attribute, int value) {
146         return value == -1 ? "" : " " + attribute + "=" + QUOTE + value + QUOTE;
147     }
148
149     /**
150      * Release resources after Tag processing has finished.
151      */

152     public void release() {
153         super.release();
154         ms_BodyText = null;
155     }
156
157 // ----------------------------------------------------- Protected Methods
158

159     abstract protected String JavaDoc getHtmlElement();
160
161     protected String JavaDoc prepareBeforeTag() {
162         return "";
163     }
164
165     protected String JavaDoc prepareAfterTag() {
166         return "";
167     }
168
169     protected String JavaDoc prepareBeforeBody() {
170         return "";
171     }
172
173     protected String JavaDoc prepareAfterBody() {
174         return "";
175     }
176
177     protected String JavaDoc getDefaultBody() {
178         return "";
179     }
180 }
Popular Tags