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: package com.caucho.jsf.html;
029:
030: import java.io.*;
031:
032: import java.util.*;
033:
034: import javax.faces.component.*;
035: import javax.faces.component.html.*;
036: import javax.faces.context.*;
037: import javax.faces.render.*;
038:
039: class HtmlOutputLabelRenderer extends BaseRenderer {
040: public static final Renderer RENDERER = new HtmlOutputLabelRenderer();
041:
042: /**
043: * True if the renderer is responsible for rendering the children.
044: */
045: @Override
046: public boolean getRendersChildren() {
047: return false;
048: }
049:
050: /**
051: * Renders the open tag for the text.
052: */
053: @Override
054: public void encodeBegin(FacesContext context, UIComponent component)
055: throws IOException {
056: ResponseWriter out = context.getResponseWriter();
057:
058: String id = component.getId();
059: String dir;
060: String lang;
061: String style;
062: String styleClass;
063: String title;
064:
065: String accesskey;
066: String onfocus;
067: String onblur;
068: String onclick;
069: String ondblclick;
070: String onmousedown;
071: String onmouseup;
072: String onmouseover;
073: String onmousemove;
074: String onmouseout;
075: String onkeypress;
076: String onkeydown;
077: String onkeyup;
078:
079: String forValue;
080: String tabindex;
081:
082: Object value;
083:
084: if (component instanceof HtmlOutputLabel) {
085: HtmlOutputLabel htmlOutput = (HtmlOutputLabel) component;
086:
087: dir = htmlOutput.getDir();
088: lang = htmlOutput.getLang();
089: style = htmlOutput.getStyle();
090: styleClass = htmlOutput.getStyleClass();
091: title = htmlOutput.getTitle();
092:
093: forValue = htmlOutput.getFor();
094:
095: tabindex = htmlOutput.getTabindex();
096:
097: accesskey = htmlOutput.getAccesskey();
098: onfocus = htmlOutput.getOnfocus();
099: onblur = htmlOutput.getOnblur();
100: onclick = htmlOutput.getOnclick();
101: ondblclick = htmlOutput.getOndblclick();
102: onmousedown = htmlOutput.getOnmousedown();
103: onmouseup = htmlOutput.getOnmouseup();
104: onmouseover = htmlOutput.getOnmouseover();
105: onmousemove = htmlOutput.getOnmousemove();
106: onmouseout = htmlOutput.getOnmouseout();
107: onkeypress = htmlOutput.getOnkeypress();
108: onkeydown = htmlOutput.getOnkeydown();
109: onkeyup = htmlOutput.getOnkeyup();
110:
111: value = htmlOutput.getValue();
112: } else {
113: Map<String, Object> attrMap = component.getAttributes();
114:
115: dir = (String) attrMap.get("dir");
116: lang = (String) attrMap.get("lang");
117: style = (String) attrMap.get("style");
118: styleClass = (String) attrMap.get("styleClass");
119: title = (String) attrMap.get("title");
120:
121: forValue = (String) attrMap.get("for");
122:
123: tabindex = (String) attrMap.get("tabindex");
124:
125: accesskey = (String) attrMap.get("accesskey");
126: onfocus = (String) attrMap.get("onfocus");
127: onblur = (String) attrMap.get("onblur");
128: onclick = (String) attrMap.get("onclick");
129: ondblclick = (String) attrMap.get("ondblclick");
130: onmousedown = (String) attrMap.get("onmousedown");
131: onmouseup = (String) attrMap.get("onmouseup");
132: onmouseover = (String) attrMap.get("onmouseover");
133: onmousemove = (String) attrMap.get("onmousemove");
134: onmouseout = (String) attrMap.get("onmouseout");
135: onkeypress = (String) attrMap.get("onkeypress");
136: onkeydown = (String) attrMap.get("onkeydown");
137: onkeyup = (String) attrMap.get("onkeyup");
138:
139: value = attrMap.get("value");
140: }
141:
142: out.startElement("label", component);
143:
144: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
145: out.writeAttribute("id", component.getClientId(context),
146: "id");
147:
148: if (dir != null)
149: out.writeAttribute("dir", dir, "dir");
150:
151: if (lang != null)
152: out.writeAttribute("lang", lang, "dir");
153:
154: if (style != null)
155: out.writeAttribute("style", style, "style");
156:
157: if (styleClass != null)
158: out.writeAttribute("class", styleClass, "class");
159:
160: if (title != null)
161: out.writeAttribute("title", title, "title");
162:
163: if (forValue != null) {
164: UIComponent forComponent = component
165: .findComponent(forValue);
166: if (forComponent != null)
167: out.writeAttribute("for", forComponent
168: .getClientId(context), "for");
169: }
170:
171: if (tabindex != null)
172: out.writeAttribute("tabindex", tabindex, "tabindex");
173:
174: if (accesskey != null)
175: out.writeAttribute("accesskey", accesskey, "accesskey");
176:
177: if (onfocus != null)
178: out.writeAttribute("onfocus", onfocus, "onfocus");
179:
180: if (onblur != null)
181: out.writeAttribute("onblur", onblur, "onblur");
182:
183: if (onclick != null)
184: out.writeAttribute("onclick", onclick, "onclick");
185:
186: if (ondblclick != null)
187: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
188:
189: if (onmousedown != null)
190: out.writeAttribute("onmousedown", onmousedown,
191: "onmousedown");
192:
193: if (onmouseup != null)
194: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
195:
196: if (onmouseover != null)
197: out.writeAttribute("onmouseover", onmouseover,
198: "onmouseover");
199:
200: if (onmousemove != null)
201: out.writeAttribute("onmousemove", onmousemove,
202: "onmousemove");
203:
204: if (onmouseout != null)
205: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
206:
207: if (onkeypress != null)
208: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
209:
210: if (onkeydown != null)
211: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
212:
213: if (onkeyup != null)
214: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
215:
216: if (value != null)
217: out.writeText(toString(context, component, value), "value");
218: }
219:
220: /**
221: * Renders the closing tag for the component.
222: */
223: @Override
224: public void encodeEnd(FacesContext context, UIComponent component)
225: throws IOException {
226: ResponseWriter out = context.getResponseWriter();
227: out.endElement("label");
228: }
229:
230: public String toString() {
231: return "HtmlOutputLabelRenderer[]";
232: }
233: }
|