KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractClassicTag;
21 import org.apache.beehive.netui.tags.TagConfig;
22 import org.apache.beehive.netui.tags.javascript.IScriptReporter;
23 import org.apache.beehive.netui.tags.javascript.ScriptRequestState;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.jsp.JspException JavaDoc;
27
28 /**
29  * Allow a name, typically either an <code>id</code> or <code>name</code> attribute, to participate in URL
30  * rewritting. Some containers rewrite name attributes so they are unique.
31  * This tag will cause the name to be made available from <code>lookupIdByTagId</code>
32  * JavaScript, which is output from the &lt;netui:html&gt; tag.
33  * @jsptagref.tagdescription Allows a name, typically either an <code>id</code> or <code>name</code> attribute,
34  * to participate in URL rewritting. Some containers rewrite name attributes so they are unique.
35  * This tag will cause the name to be made available from the <code>lookupIdByTagId( id, tag )</code>
36  * JavaScript function.
37  * @example In this sample, we are setting the id attribute of the span tag to 'foo'. The
38  * actual value that will be rendered in the HTML may change depending on the
39  * container where the web application resides. For example, a Portal container may
40  * render &lt;span name="scope1_foo"> instead of &lt;span name="foo">.
41  * But the value 'foo' can be passed to <code>lookupIdByTagId( id, tag )</code> to find the rendered
42  * value of the name attribute.
43  *
44  * <pre> &lt;span id="&lt;netui:rewriteName name="foo"/&gt;"&gt;</pre>
45  * @netui:tag name="rewriteName" description="Allows the URL Rewriter to rewrite the name attribute before it is output into the HTML stream."
46  */

47 public class RewriteName
48         extends AbstractClassicTag
49 {
50     private String JavaDoc _name = null;
51     private String JavaDoc _resultId = null;
52
53     /**
54      * Return the name of the Tag.
55      */

56     public String JavaDoc getTagName()
57     {
58         return "RewriteName";
59     }
60
61     /**
62      * Sets the name to be rewritten.
63      * @param name the parameter name.
64      * @jsptagref.attributedescription The name which will be rewritten. This value will be output to the page rendered in the browser and may be looked up using 'name'.
65      * @jsptagref.databindable false
66      * @jsptagref.attributesyntaxvalue <i>string_name</i>
67      * @netui:attribute required="true" rtexprvalue="true"
68      * description="The name which will be rewritten. This value will be output to the page rendered in the browser and may be looked up using 'name'."
69      */

70     public void setName(String JavaDoc name)
71     {
72         _name = name;
73     }
74
75     /**
76      * Sets the resultId which, if non-null, will store the real name
77      * in the page context under the resultId name;
78      * @param resultId the parameter name.
79      * @jsptagref.attributedescription A name that will cause the real name to be stored into the page context under this name.
80      * @jsptagref.databindable false
81      * @jsptagref.attributesyntaxvalue <i>string_resultId</i>
82      * @netui:attribute required="false" rtexprvalue="true"
83      * description="A name that will cause the real name to be stored into the page context under this name."
84      */

85     public void setResultId(String JavaDoc resultId)
86     {
87         _resultId = resultId;
88     }
89
90     /**
91      * Pass the name attribute to the URLRewriter and output the
92      * returned value. Updates the HTML tag to output the mapping.
93      * @throws JspException if a JSP exception has occurred
94      */

95     public int doStartTag() throws JspException JavaDoc
96     {
97         String JavaDoc realName = rewriteName(_name);
98         if (_resultId != null)
99             pageContext.setAttribute(_resultId, realName);
100
101         // @TODO: Is there any way to make this work. Currently if
102
// there is now script container, we will eat the <script> blocks
103
// because we cannot write them out in the middle of the tag being
104
// written
105
IScriptReporter scriptReporter = getScriptReporter();
106         ScriptRequestState srs = ScriptRequestState.getScriptRequestState((HttpServletRequest JavaDoc) pageContext.getRequest());
107         if (TagConfig.isLegacyJavaScript()) {
108             srs.mapLegacyTagId(scriptReporter, _name, realName);
109         }
110         write(realName);
111         localRelease();
112         return SKIP_BODY;
113     }
114
115     /**
116      * Release any acquired resources.
117      */

118     protected void localRelease()
119     {
120         super.localRelease();
121         _name = null;
122         _resultId = null;
123     }
124 }
125
Popular Tags