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.javascript;
020:
021: import org.apache.beehive.netui.tags.AbstractClassicTag;
022: import org.apache.beehive.netui.tags.rendering.ScriptTag;
023: import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
024: import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.jsp.JspException;
028:
029: /**
030: * ScriptHeader will write the <script> and JavaScript includes into the HTML
031: * <head> tag. It can also be used to write the <script> and JavaScript
032: * includes in the body given a JSP fragment that uses the {@link ScriptContainer}.
033: * @jsptagref.tagdescription ScriptHeader will write the <script> and JavaScript
034: * includes into the HTML <head> tag. It can also be used to write the
035: * <script> and JavaScript includes in the body given a JSP fragment that
036: * uses the {@link ScriptContainer}.
037: *
038: * <p>This tag is required to be empty. It is also required when using the
039: * <netui:tree> element with the attribute runAtClient="true".
040: *
041: * <p>The <scriptHeader> tag should have a parent <netui:html> or
042: * <netui:scriptContainer> tag.
043: *
044: * @example In this example the <netui:scriptHeader/> tag has a parent
045: * <netui:html> tag.
046: * <pre> <netui:html>
047: * <head>
048: * <title>Page Title</title>
049: * <netui:scriptHeader/>
050: * </head>
051: * <netui:body>
052: * ...
053: * </pre>
054: *
055: * <p>In this example the <netui:scriptHeader/> tag is enclosed in the
056: * <netui:scriptContainer> tag.
057: * <pre> <netui:body>
058: * <netui:scriptContainer>
059: * <netui:scriptHeader/>
060: * <netui:tree runAtClient="true"
061: * dataSource="pageFlow.root"
062: * selectionAction="postback"
063: * tagId="testTree"/>
064: * ...
065: * </netui:scriptContainer>
066: * </netui:body></pre>
067: * @netui:tag name="scriptHeader" body-content="empty"
068: * description="ScriptHeader will write the <script> and JavaScript includes."
069: */
070: public class ScriptHeader extends AbstractClassicTag {
071: /**
072: * Returns the name of the Tag.
073: */
074: public String getTagName() {
075: return "ScriptHeader";
076: }
077:
078: /**
079: * Process the start of the Button.
080: * @throws javax.servlet.jsp.JspException if a JSP exception has occurred
081: */
082: public int doStartTag() throws JspException {
083: IScriptReporter sr = getScriptReporter();
084: HttpServletRequest req = (HttpServletRequest) pageContext
085: .getRequest();
086: WriteRenderAppender writer = new WriteRenderAppender(
087: pageContext);
088:
089: // write out the include
090: ScriptTag.State state = new ScriptTag.State();
091: TagRenderingBase br = TagRenderingBase.Factory.getRendering(
092: TagRenderingBase.SCRIPT_TAG, pageContext.getRequest());
093:
094: state.src = req.getContextPath()
095: + "/resources/beehive/version1/javascript/netui-tree.js";
096: br.doStartTag(writer, state);
097: br.doEndTag(writer);
098:
099: // write out the dynamic content
100: ScriptRequestState srs = ScriptRequestState
101: .getScriptRequestState(req);
102: srs.writeFeature(sr, writer, CoreScriptFeature.DYNAMIC_INIT,
103: true, false, new Object[] { req.getContextPath() });
104:
105: return EVAL_BODY_INCLUDE;
106: }
107:
108: public int doEndTag() throws JspException {
109: localRelease();
110: return EVAL_PAGE;
111: }
112:
113: protected void localRelease() {
114: super.localRelease();
115: }
116: }
|