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.application.*;
036: import javax.faces.component.*;
037: import javax.faces.component.html.*;
038: import javax.faces.context.*;
039: import javax.faces.render.*;
040:
041: /**
042: * The HTML graphic/image renderer
043: */
044: class HtmlGraphicImageRenderer extends Renderer {
045: public static final Renderer RENDERER = new HtmlGraphicImageRenderer();
046:
047: /**
048: * True if the renderer is responsible for rendering the children.
049: */
050: @Override
051: public boolean getRendersChildren() {
052: return true;
053: }
054:
055: /**
056: * Renders the open tag for the text.
057: */
058: @Override
059: public void encodeBegin(FacesContext context, UIComponent component)
060: throws IOException {
061: ResponseWriter out = context.getResponseWriter();
062:
063: String id = component.getId();
064:
065: String alt;
066: String dir;
067: String height;
068: boolean ismap = false;
069: String lang;
070: String longdesc;
071:
072: String onclick;
073: String ondblclick;
074:
075: String onkeydown;
076: String onkeypress;
077: String onkeyup;
078:
079: String onmousedown;
080: String onmousemove;
081: String onmouseout;
082: String onmouseover;
083: String onmouseup;
084:
085: String style;
086: String styleClass;
087: String title;
088: String usemap;
089: String width;
090:
091: Object value;
092:
093: if (component instanceof HtmlGraphicImage) {
094: HtmlGraphicImage html = (HtmlGraphicImage) component;
095:
096: alt = html.getAlt();
097: dir = html.getDir();
098: height = html.getHeight();
099: ismap = html.isIsmap();
100: lang = html.getLang();
101: longdesc = html.getLongdesc();
102:
103: onclick = html.getOnclick();
104: ondblclick = html.getOndblclick();
105:
106: onkeydown = html.getOnkeydown();
107: onkeypress = html.getOnkeypress();
108: onkeyup = html.getOnkeyup();
109:
110: onmousedown = html.getOnmousedown();
111: onmousemove = html.getOnmousemove();
112: onmouseout = html.getOnmouseout();
113: onmouseover = html.getOnmouseover();
114: onmouseup = html.getOnmouseup();
115:
116: style = html.getStyle();
117: styleClass = html.getStyleClass();
118: title = html.getTitle();
119: usemap = html.getUsemap();
120: width = html.getWidth();
121:
122: value = html.getValue();
123: } else {
124: Map<String, Object> attrMap = component.getAttributes();
125:
126: alt = (String) attrMap.get("alt");
127: dir = (String) attrMap.get("dir");
128: height = (String) attrMap.get("height");
129: Boolean bValue = (Boolean) attrMap.get("ismap");
130: if (bValue != null)
131: ismap = bValue;
132: lang = (String) attrMap.get("lang");
133: longdesc = (String) attrMap.get("longdesc");
134:
135: onclick = (String) attrMap.get("onclick");
136: ondblclick = (String) attrMap.get("ondblclick");
137:
138: onkeydown = (String) attrMap.get("onkeydown");
139: onkeypress = (String) attrMap.get("onkeypress");
140: onkeyup = (String) attrMap.get("onkeyup");
141:
142: onmousedown = (String) attrMap.get("onmousedown");
143: onmousemove = (String) attrMap.get("onmousemove");
144: onmouseout = (String) attrMap.get("onmouseout");
145: onmouseover = (String) attrMap.get("onmouseover");
146: onmouseup = (String) attrMap.get("onmouseup");
147:
148: style = (String) attrMap.get("style");
149: styleClass = (String) attrMap.get("styleClass");
150: title = (String) attrMap.get("title");
151: usemap = (String) attrMap.get("usemap");
152: width = (String) attrMap.get("width");
153:
154: value = attrMap.get("value");
155: }
156:
157: out.startElement("img", component);
158:
159: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
160: out.writeAttribute("id", component.getClientId(context),
161: "id");
162:
163: String src;
164: if (value == null)
165: src = "";
166: else
167: src = String.valueOf(value);
168:
169: ViewHandler view = context.getApplication().getViewHandler();
170: ExternalContext extContext = context.getExternalContext();
171:
172: src = extContext.encodeResourceURL(view.getResourceURL(context,
173: src));
174:
175: out.writeAttribute("src", src, "src");
176:
177: if (alt != null)
178: out.writeAttribute("alt", alt, "alt");
179:
180: if (dir != null)
181: out.writeAttribute("dir", dir, "dir");
182:
183: if (height != null)
184: out.writeAttribute("height", height, "height");
185:
186: if (ismap)
187: out.writeAttribute("ismap", "ismap", "ismap");
188:
189: if (lang != null)
190: out.writeAttribute("lang", lang, "lang");
191:
192: if (longdesc != null)
193: out.writeAttribute("longdesc", longdesc, "longdesc");
194:
195: if (onclick != null)
196: out.writeAttribute("onclick", onclick, "onclick");
197:
198: if (ondblclick != null)
199: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
200:
201: if (onkeydown != null)
202: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
203:
204: if (onkeypress != null)
205: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
206:
207: if (onkeyup != null)
208: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
209:
210: if (onmousedown != null)
211: out.writeAttribute("onmousedown", onmousedown,
212: "onmousedown");
213:
214: if (onmousemove != null)
215: out.writeAttribute("onmousemove", onmousemove,
216: "onmousemove");
217:
218: if (onmouseout != null)
219: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
220:
221: if (onmouseover != null)
222: out.writeAttribute("onmouseover", onmouseover,
223: "onmouseover");
224:
225: if (onmouseup != null)
226: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
227:
228: if (style != null)
229: out.writeAttribute("style", style, "style");
230:
231: if (styleClass != null)
232: out.writeAttribute("class", styleClass, "class");
233:
234: if (title != null)
235: out.writeAttribute("title", title, "title");
236:
237: if (usemap != null)
238: out.writeAttribute("usemap", usemap, "usemap");
239:
240: if (width != null)
241: out.writeAttribute("width", width, "width");
242:
243: out.endElement("img");
244: }
245:
246: /**
247: * Renders the content for the component.
248: */
249: @Override
250: public void encodeChildren(FacesContext context,
251: UIComponent component) throws IOException {
252: }
253:
254: /**
255: * Renders the closing tag for the component.
256: */
257: @Override
258: public void encodeEnd(FacesContext context, UIComponent component)
259: throws IOException {
260: ResponseWriter out = context.getResponseWriter();
261: }
262:
263: public String toString() {
264: return "HtmlGraphicImageRenderer[]";
265: }
266: }
|