001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.html;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.faces.*;
035: import javax.faces.component.*;
036: import javax.faces.component.html.*;
037: import javax.faces.context.*;
038: import javax.faces.render.*;
039:
040: /**
041: * The HTML text renderer
042: */
043: class HtmlOutputTextRenderer extends HtmlRenderer {
044: public static final Renderer RENDERER = new HtmlOutputTextRenderer();
045:
046: /**
047: * True if the renderer is responsible for rendering the children.
048: */
049: @Override
050: public boolean getRendersChildren() {
051: return true;
052: }
053:
054: /**
055: * Renders the open tag for the text.
056: */
057: @Override
058: public void encodeBegin(FacesContext context, UIComponent component)
059: throws IOException {
060: ResponseWriter out = context.getResponseWriter();
061:
062: String id = component.getId();
063: String dir;
064: String lang;
065: String style;
066: String styleClass;
067: String title;
068: boolean escape;
069: Object value;
070:
071: if (component instanceof HtmlOutputText) {
072: HtmlOutputText htmlOutput = (HtmlOutputText) component;
073:
074: dir = htmlOutput.getDir();
075: lang = htmlOutput.getLang();
076: style = htmlOutput.getStyle();
077: styleClass = htmlOutput.getStyleClass();
078: title = htmlOutput.getTitle();
079:
080: escape = htmlOutput.isEscape();
081: value = htmlOutput.getValue();
082: } else {
083: Map<String, Object> attrMap = component.getAttributes();
084:
085: dir = (String) attrMap.get("dir");
086: lang = (String) attrMap.get("lang");
087: style = (String) attrMap.get("style");
088: styleClass = (String) attrMap.get("styleClass");
089: title = (String) attrMap.get("title");
090:
091: Boolean escapeValue = (Boolean) attrMap.get("escape");
092:
093: if (escapeValue != null)
094: escape = escapeValue;
095: else
096: escape = true;
097:
098: value = attrMap.get("value");
099: }
100:
101: boolean hasSpan = false;
102:
103: if (dir != null
104: || lang != null
105: || style != null
106: || styleClass != null
107: || (id != null && !id
108: .startsWith(UIViewRoot.UNIQUE_ID_PREFIX))) {
109: hasSpan = true;
110:
111: out.startElement("span", component);
112:
113: if (id != null
114: && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
115: out.writeAttribute("id",
116: component.getClientId(context), "id");
117:
118: if (dir != null)
119: out.writeAttribute("dir", dir, "dir");
120:
121: if (lang != null)
122: out.writeAttribute("lang", lang, "dir");
123:
124: if (style != null)
125: out.writeAttribute("style", style, "style");
126:
127: if (styleClass != null)
128: out.writeAttribute("class", styleClass, "class");
129:
130: if (title != null)
131: out.writeAttribute("title", title, "title");
132: }
133:
134: String string = toString(context, component, value);
135:
136: if (escape)
137: escapeText(out, string, "value");
138: else
139: out.writeText(string, "value");
140:
141: if (hasSpan)
142: out.endElement("span");
143: }
144:
145: public String toString() {
146: return "HtmlOutputTextRenderer[]";
147: }
148: }
|