KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractSimpleTag;
21 import org.apache.beehive.netui.util.Bundle;
22 import org.apache.beehive.netui.util.logging.Logger;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 /**
27  * The Content tag is used to display text, or the result of an expression, to the page.
28  * @jsptagref.tagdescription Displays text or the result of an expression.
29  * Note that <netui:content> is similar to {@link Span}, except for the way
30  * it processes HTML-sensitive text. The <netui:content> tag does not escape
31  * HTML-sensitive characters, but the <netui:span> tag filters the input
32  * string for characters that are senstive to
33  * HTML interpreters and replaces these characters
34  * with the corresponding entity strings. For example, if you pass the
35  * string '&' to a <netui:span> tag, the string '&' will be written to
36  * the HTML source file, and the following will be displayed
37  * in the browser: '&'.
38  *
39  * <p>The following table shows how the &lt;netui:span> and &lt;netui:content> tags treat HTML-sensitive characters.
40  * <blockquote>
41  * <table border="1">
42  * <tr>
43  * <td width="30%"><b>tag</b></td>
44  * <td width="30%"><b>generated HTML source</b></td>
45  * <td width="30%"><b>displayed in browser</b></td>
46  * </tr>
47  * <tr>
48  * <td>&lt;netui:content value="&amp;amp;"/></td>
49  * <td>&amp;amp;</td>
50  * <td>&</td>
51  * </tr>
52  * <tr>
53  * <td>&lt;netui:span value="&amp;amp;"/></td>
54  * <td>&amp;amp;amp;</td>
55  * <td>&amp;amp;</td>
56  * </tr>
57  * </table>
58  * </blockquote>
59  * @example In this sample, the Content tag displays a Form Bean's <code>lastName</code> property.
60  * <pre>
61  * &lt;netui:content value="${actionForm.lastName}"/>
62  * </pre>
63  * @netui:tag name="content" body-content="empty" description="Used to display text or the result of an expression to the page."
64  */

65 public class Content extends AbstractSimpleTag
66 {
67     private static final Logger logger = Logger.getInstance(Content.class);
68
69     private static final String JavaDoc DEFAULT_NULL_TEXT = "";
70     private String JavaDoc _defaultValue = null;
71     private Object JavaDoc _value = null; // The value for this content.
72

73     /**
74      * Return the name of the Tag.
75      */

76     public String JavaDoc getTagName()
77     {
78         return "Content";
79     }
80
81     /**
82      * Set the default value of this Content.
83      * @param defaultValue the default value
84      * @jsptagref.attributedescription The String literal or expression to be used as the default output.
85      * @jsptagref.databindable Read Only
86      * @jsptagref.attributesyntaxvalue <i>string_or_expression_defaultOutput</i>
87      * @netui:attribute required="false" rtexprvalue="true"
88      * description="The String literal or expression to be used as the default output."
89      */

90     public void setDefaultValue(String JavaDoc defaultValue)
91             throws JspException JavaDoc
92     {
93         _defaultValue = setRequiredValueAttribute(defaultValue, "defaultValue");
94     }
95
96     /**
97      * Set the value of this Content.
98      * @param value the Content value
99      * @jsptagref.attributedescription The String literal or expression used to output the content.
100      * @jsptagref.databindable Read Only
101      * @jsptagref.attributesyntaxvalue <i>string_or_expression_output</i>
102      * @netui:attribute required="true" rtexprvalue="true" type="java.lang.Object"
103      * description="The String literal or expression used to output the content."
104      */

105     public void setValue(Object JavaDoc value)
106     {
107         _value = value;
108     }
109
110     /**
111      * Render the content.
112      * @throws JspException if a JSP exception has occurred
113      */

114     public void doTag()
115             throws JspException JavaDoc
116     {
117         // report any errors...
118
if (hasErrors()) {
119             reportErrors();
120             return;
121         }
122
123         // calculate the output value...
124
String JavaDoc text;
125         if (_value != null) {
126             text = _value.toString();
127         }
128         else {
129             if (_defaultValue != null) {
130                 text = _defaultValue;
131             }
132             else {
133                 logger.warn(Bundle.getString("Tags_ContentExpressionNull", _value));
134                 text = DEFAULT_NULL_TEXT;
135             }
136         }
137
138         write(text);
139     }
140 }
141
Popular Tags