KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > html > Body


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.html;
19
20 import org.apache.beehive.netui.tags.ErrorHandling;
21 import org.apache.beehive.netui.tags.javascript.IScriptReporter;
22 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
23 import org.apache.beehive.netui.tags.rendering.BodyTag;
24 import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
25 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.jsp.JspException JavaDoc;
29
30 /**
31  * @jsptagref.tagdescription <p>
32  * Renders an HTML &lt;body> tag with the attributes specified.
33  * </p>
34  * @netui:tag name="body" description="Output the &lt;body> container. This tag allows the NetUI framework to output script and errors before the page is finished rendering."
35  */

36 public class Body extends HtmlBaseTag
37 {
38     private BodyTag.State _state = new BodyTag.State();
39     private TagRenderingBase _br;
40     private WriteRenderAppender _writer;
41     private String JavaDoc _idScript;
42
43     /**
44      * Return the name of the Tag.
45      */

46     public String JavaDoc getTagName()
47     {
48         return "Body";
49     }
50
51     /**
52      * This method will return the state associated with the tag. This is used by this
53      * base class to access the individual state objects created by the tags.
54      * @return a subclass of the <code>AbstractHtmlState</code> class.
55      */

56     protected AbstractHtmlState getState()
57     {
58         return _state;
59     }
60
61     /**
62      * Sets the onLoad javascript event.
63      * @param onload the onLoad event.
64      * @jsptagref.attributedescription The onLoad JavaScript event.
65      * @jsptagref.databindable false
66      * @jsptagref.attributesyntaxvalue <i>string_onLoad</i>
67      * @netui:attribute required="false" rtexprvalue="true"
68      * description="The onLoad JavaScript event."
69      */

70     public void setOnLoad(String JavaDoc onload)
71     {
72         _state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONLOAD, onload);
73     }
74
75     /**
76      * Sets the onUnload javascript event.
77      * @param onunload the onUnload event.
78      * @jsptagref.attributedescription The onLoad JavaScript event.
79      * @jsptagref.databindable false
80      * @jsptagref.attributesyntaxvalue <i>string_onUnload</i>
81      * @netui:attribute required="false" rtexprvalue="true"
82      * description="The onLoad JavaScript event."
83      */

84     public void setOnUnload(String JavaDoc onunload)
85     {
86         _state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONUNLOAD, onunload);
87     }
88
89     /**
90      * Sets the background image of the page.
91      * @param background the background image of the page.
92      * @jsptagref.attributedescription The background image of the page.
93      * @jsptagref.databindable false
94      * @jsptagref.attributesyntaxvalue <i>string_background</i>
95      * @netui:attribute required="false" rtexprvalue="true"
96      * description="The background image of the page."
97      */

98     public void setBackground(String JavaDoc background)
99     {
100         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BACKGROUND, background);
101     }
102
103     /**
104      * Sets the bgcolor of the page.
105      * @param bgcolor the background color of the page.
106      * @jsptagref.attributedescription The background color of the page.
107      * @jsptagref.databindable false
108      * @jsptagref.attributesyntaxvalue <i>string_bgcolor</i>
109      * @netui:attribute required="false" rtexprvalue="true"
110      * description="The background color of the page."
111      */

112     public void setBgcolor(String JavaDoc bgcolor)
113     {
114         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BGCOLOR, bgcolor);
115     }
116
117     /**
118      * Sets the foreground text color of the page.
119      * @param text the foreground text color of the page.
120      * @jsptagref.attributedescription The foreground text color of the page.
121      * @jsptagref.databindable false
122      * @jsptagref.attributesyntaxvalue <i>string_text</i>
123      * @netui:attribute required="false" rtexprvalue="true"
124      * description="The foreground text color of the page."
125      */

126     public void setText(String JavaDoc text)
127     {
128         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TEXT, text);
129     }
130
131     /**
132      * Sets the the color of text marking unvisited hypertext links.
133      * @param link the color of text marking unvisited hypertext links of the page.
134      * @jsptagref.attributedescription The color of text marking unvisited hypertext links of the page
135      * @jsptagref.databindable false
136      * @jsptagref.attributesyntaxvalue <i>string_link</i>
137      * @netui:attribute required="false" rtexprvalue="true"
138      * description="The color of text marking unvisited hypertext links of the page."
139      */

140     public void setLink(String JavaDoc link)
141     {
142         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, LINK, link);
143     }
144
145     /**
146      * Sets the the color of text marking visited hypertext links.
147      * @param vlink the color of text marking visited hypertext links of the page.
148      * @jsptagref.attributedescription The color of text marking visited hypertext links of the page
149      * @jsptagref.databindable false
150      * @jsptagref.attributesyntaxvalue <i>string_vlink</i>
151      * @netui:attribute required="false" rtexprvalue="true"
152      * description="The color of text marking visited hypertext links of the page."
153      */

154     public void setVlink(String JavaDoc vlink)
155     {
156         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, VLINK, vlink);
157     }
158
159     /**
160      * Sets the color of text marking hypertext links when selected by the user.
161      * @param alink the color of text marking hypertext links when selected by the user.
162      * @jsptagref.attributedescription The color of text marking hypertext links when selected by the user
163      * @jsptagref.databindable false
164      * @jsptagref.attributesyntaxvalue <i>string_alink</i>
165      * @netui:attribute required="false" rtexprvalue="true"
166      * description="The color of text marking hypertext links when selected by the user."
167      */

168     public void setAlink(String JavaDoc alink)
169     {
170         _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALINK, alink);
171     }
172
173     /**
174      * Process the start of the Button.
175      * @throws javax.servlet.jsp.JspException if a JSP exception has occurred
176      */

177     public int doStartTag() throws JspException JavaDoc
178     {
179         // we assume that tagId will over have override id if both are defined.
180
if (_state.id != null) {
181             _idScript = renderNameAndId((HttpServletRequest JavaDoc) pageContext.getRequest(), _state, null);
182         }
183
184         // render the header...
185
_writer = new WriteRenderAppender(pageContext);
186         _br = TagRenderingBase.Factory.getRendering(TagRenderingBase.BODY_TAG, pageContext.getRequest());
187         _br.doStartTag(_writer, _state);
188
189         return EVAL_BODY_INCLUDE;
190     }
191
192     /**
193      * Render the button.
194      * @throws JspException if a JSP exception has occurred
195      */

196     public int doEndTag() throws JspException JavaDoc
197     {
198         // if there were errors lets report them.
199
if (hasErrors()) {
200             reportErrors();
201         }
202
203         // Get the script reporter
204
IScriptReporter sr = getScriptReporter();
205         if (sr != null) {
206             //if (!sr.isInitScriptWritten()) {
207
// String s = Bundle.getString("Tags_ClientReqScriptHeader", null);
208
// registerTagError(s, null);
209
//}
210

211             // write out any errors
212
ErrorHandling.reportCollectedErrors(pageContext, this);
213
214             // write out the script before the end tag.
215
sr.writeScript(_writer);
216
217             if (sr instanceof Html) {
218                 Html htmlSr = (Html) sr;
219                 if (htmlSr.getIdScope() != null) {
220                     htmlSr.endScope(_writer);
221                 }
222             }
223         }
224
225         if (_idScript != null)
226             write(_idScript);
227
228         _br.doEndTag(_writer);
229
230         // Evaluate the remainder of this page
231
localRelease();
232         return EVAL_PAGE;
233     }
234
235     public void localRelease()
236     {
237         super.localRelease();
238         _state.clear();
239         _br = null;
240         _writer = null;
241     }
242 }
243
Popular Tags