001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.html;
020:
021: import org.apache.beehive.netui.tags.ErrorHandling;
022: import org.apache.beehive.netui.tags.javascript.IScriptReporter;
023: import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
024: import org.apache.beehive.netui.tags.rendering.BodyTag;
025: import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
026: import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.jsp.JspException;
030:
031: /**
032: * @jsptagref.tagdescription <p>
033: * Renders an HTML <body> tag with the attributes specified.
034: * </p>
035: * @netui:tag name="body" description="Output the <body> container. This tag allows the NetUI framework to output script and errors before the page is finished rendering."
036: */
037: public class Body extends HtmlBaseTag {
038: private BodyTag.State _state = new BodyTag.State();
039: private TagRenderingBase _br;
040: private WriteRenderAppender _writer;
041: private String _idScript;
042:
043: /**
044: * Return the name of the Tag.
045: */
046: public String getTagName() {
047: return "Body";
048: }
049:
050: /**
051: * This method will return the state associated with the tag. This is used by this
052: * base class to access the individual state objects created by the tags.
053: * @return a subclass of the <code>AbstractHtmlState</code> class.
054: */
055: protected AbstractHtmlState getState() {
056: return _state;
057: }
058:
059: /**
060: * Sets the onLoad javascript event.
061: * @param onload the onLoad event.
062: * @jsptagref.attributedescription The onLoad JavaScript event.
063: * @jsptagref.databindable false
064: * @jsptagref.attributesyntaxvalue <i>string_onLoad</i>
065: * @netui:attribute required="false" rtexprvalue="true"
066: * description="The onLoad JavaScript event."
067: */
068: public void setOnLoad(String onload) {
069: _state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
070: ONLOAD, onload);
071: }
072:
073: /**
074: * Sets the onUnload javascript event.
075: * @param onunload the onUnload event.
076: * @jsptagref.attributedescription The onLoad JavaScript event.
077: * @jsptagref.databindable false
078: * @jsptagref.attributesyntaxvalue <i>string_onUnload</i>
079: * @netui:attribute required="false" rtexprvalue="true"
080: * description="The onLoad JavaScript event."
081: */
082: public void setOnUnload(String onunload) {
083: _state.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT,
084: ONUNLOAD, onunload);
085: }
086:
087: /**
088: * Sets the background image of the page.
089: * @param background the background image of the page.
090: * @jsptagref.attributedescription The background image of the page.
091: * @jsptagref.databindable false
092: * @jsptagref.attributesyntaxvalue <i>string_background</i>
093: * @netui:attribute required="false" rtexprvalue="true"
094: * description="The background image of the page."
095: */
096: public void setBackground(String background) {
097: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
098: BACKGROUND, background);
099: }
100:
101: /**
102: * Sets the bgcolor of the page.
103: * @param bgcolor the background color of the page.
104: * @jsptagref.attributedescription The background color of the page.
105: * @jsptagref.databindable false
106: * @jsptagref.attributesyntaxvalue <i>string_bgcolor</i>
107: * @netui:attribute required="false" rtexprvalue="true"
108: * description="The background color of the page."
109: */
110: public void setBgcolor(String bgcolor) {
111: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
112: BGCOLOR, bgcolor);
113: }
114:
115: /**
116: * Sets the foreground text color of the page.
117: * @param text the foreground text color of the page.
118: * @jsptagref.attributedescription The foreground text color of the page.
119: * @jsptagref.databindable false
120: * @jsptagref.attributesyntaxvalue <i>string_text</i>
121: * @netui:attribute required="false" rtexprvalue="true"
122: * description="The foreground text color of the page."
123: */
124: public void setText(String text) {
125: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TEXT,
126: text);
127: }
128:
129: /**
130: * Sets the the color of text marking unvisited hypertext links.
131: * @param link the color of text marking unvisited hypertext links of the page.
132: * @jsptagref.attributedescription The color of text marking unvisited hypertext links of the page
133: * @jsptagref.databindable false
134: * @jsptagref.attributesyntaxvalue <i>string_link</i>
135: * @netui:attribute required="false" rtexprvalue="true"
136: * description="The color of text marking unvisited hypertext links of the page."
137: */
138: public void setLink(String link) {
139: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, LINK,
140: link);
141: }
142:
143: /**
144: * Sets the the color of text marking visited hypertext links.
145: * @param vlink the color of text marking visited hypertext links of the page.
146: * @jsptagref.attributedescription The color of text marking visited hypertext links of the page
147: * @jsptagref.databindable false
148: * @jsptagref.attributesyntaxvalue <i>string_vlink</i>
149: * @netui:attribute required="false" rtexprvalue="true"
150: * description="The color of text marking visited hypertext links of the page."
151: */
152: public void setVlink(String vlink) {
153: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, VLINK,
154: vlink);
155: }
156:
157: /**
158: * Sets the color of text marking hypertext links when selected by the user.
159: * @param alink the color of text marking hypertext links when selected by the user.
160: * @jsptagref.attributedescription The color of text marking hypertext links when selected by the user
161: * @jsptagref.databindable false
162: * @jsptagref.attributesyntaxvalue <i>string_alink</i>
163: * @netui:attribute required="false" rtexprvalue="true"
164: * description="The color of text marking hypertext links when selected by the user."
165: */
166: public void setAlink(String alink) {
167: _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALINK,
168: alink);
169: }
170:
171: /**
172: * Process the start of the Button.
173: * @throws javax.servlet.jsp.JspException if a JSP exception has occurred
174: */
175: public int doStartTag() throws JspException {
176: // we assume that tagId will over have override id if both are defined.
177: if (_state.id != null) {
178: _idScript = renderNameAndId(
179: (HttpServletRequest) pageContext.getRequest(),
180: _state, null);
181: }
182:
183: // render the header...
184: _writer = new WriteRenderAppender(pageContext);
185: _br = TagRenderingBase.Factory.getRendering(
186: 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 {
197: // if there were errors lets report them.
198: if (hasErrors()) {
199: reportErrors();
200: }
201:
202: // Get the script reporter
203: IScriptReporter sr = getScriptReporter();
204: if (sr != null) {
205: //if (!sr.isInitScriptWritten()) {
206: // String s = Bundle.getString("Tags_ClientReqScriptHeader", null);
207: // registerTagError(s, null);
208: //}
209:
210: // write out any errors
211: ErrorHandling.reportCollectedErrors(pageContext, this );
212:
213: // write out the script before the end tag.
214: sr.writeScript(_writer);
215:
216: if (sr instanceof Html) {
217: Html htmlSr = (Html) sr;
218: if (htmlSr.getIdScope() != null) {
219: htmlSr.endScope(_writer);
220: }
221: }
222: }
223:
224: if (_idScript != null)
225: write(_idScript);
226:
227: _br.doEndTag(_writer);
228:
229: // Evaluate the remainder of this page
230: localRelease();
231: return EVAL_PAGE;
232: }
233:
234: public void localRelease() {
235: super.localRelease();
236: _state.clear();
237: _br = null;
238: _writer = null;
239: }
240: }
|