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.AbstractSimpleTag;
022: import org.apache.beehive.netui.util.Bundle;
023: import org.apache.beehive.netui.util.logging.Logger;
024:
025: import javax.servlet.jsp.JspException;
026:
027: /**
028: * The Content tag is used to display text, or the result of an expression, to the page.
029: * @jsptagref.tagdescription Displays text or the result of an expression.
030: * Note that <netui:content> is similar to {@link Span}, except for the way
031: * it processes HTML-sensitive text. The <netui:content> tag does not escape
032: * HTML-sensitive characters, but the <netui:span> tag filters the input
033: * string for characters that are senstive to
034: * HTML interpreters and replaces these characters
035: * with the corresponding entity strings. For example, if you pass the
036: * string '&amp;' to a <netui:span> tag, the string '&amp;amp;' will be written to
037: * the HTML source file, and the following will be displayed
038: * in the browser: '&amp;'.
039: *
040: * <p>The following table shows how the <netui:span> and <netui:content> tags treat HTML-sensitive characters.
041: * <blockquote>
042: * <table border="1">
043: * <tr>
044: * <td width="30%"><b>tag</b></td>
045: * <td width="30%"><b>generated HTML source</b></td>
046: * <td width="30%"><b>displayed in browser</b></td>
047: * </tr>
048: * <tr>
049: * <td><netui:content value="&amp;"/></td>
050: * <td>&amp;</td>
051: * <td>&</td>
052: * </tr>
053: * <tr>
054: * <td><netui:span value="&amp;"/></td>
055: * <td>&amp;amp;</td>
056: * <td>&amp;</td>
057: * </tr>
058: * </table>
059: * </blockquote>
060: * @example In this sample, the Content tag displays a Form Bean's <code>lastName</code> property.
061: * <pre>
062: * <netui:content value="${actionForm.lastName}"/>
063: * </pre>
064: * @netui:tag name="content" body-content="empty" description="Used to display text or the result of an expression to the page."
065: */
066: public class Content extends AbstractSimpleTag {
067: private static final Logger logger = Logger
068: .getInstance(Content.class);
069:
070: private static final String DEFAULT_NULL_TEXT = "";
071: private String _defaultValue = null;
072: private Object _value = null; // The value for this content.
073:
074: /**
075: * Return the name of the Tag.
076: */
077: public String getTagName() {
078: return "Content";
079: }
080:
081: /**
082: * Set the default value of this Content.
083: * @param defaultValue the default value
084: * @jsptagref.attributedescription The String literal or expression to be used as the default output.
085: * @jsptagref.databindable Read Only
086: * @jsptagref.attributesyntaxvalue <i>string_or_expression_defaultOutput</i>
087: * @netui:attribute required="false" rtexprvalue="true"
088: * description="The String literal or expression to be used as the default output."
089: */
090: public void setDefaultValue(String defaultValue)
091: throws JspException {
092: _defaultValue = setRequiredValueAttribute(defaultValue,
093: "defaultValue");
094: }
095:
096: /**
097: * Set the value of this Content.
098: * @param value the Content value
099: * @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 value) {
106: _value = value;
107: }
108:
109: /**
110: * Render the content.
111: * @throws JspException if a JSP exception has occurred
112: */
113: public void doTag() throws JspException {
114: // report any errors...
115: if (hasErrors()) {
116: reportErrors();
117: return;
118: }
119:
120: // calculate the output value...
121: String text;
122: if (_value != null) {
123: text = _value.toString();
124: } else {
125: if (_defaultValue != null) {
126: text = _defaultValue;
127: } else {
128: logger.warn(Bundle.getString(
129: "Tags_ContentExpressionNull", _value));
130: text = DEFAULT_NULL_TEXT;
131: }
132: }
133:
134: write(text);
135: }
136: }
|