1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.renderkit.html;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.myfaces.shared.renderkit.JSFAttr;
24
25 import javax.faces.component.UIComponent;
26 import javax.faces.component.UIGraphic;
27 import javax.faces.component.html.HtmlGraphicImage;
28 import javax.faces.context.FacesContext;
29 import javax.faces.context.ResponseWriter;
30 import java.io.IOException;
31
32
33 /***
34 * @author Manfred Geiler (latest modification by $Author: grantsmith $)
35 * @author Thomas Spiegl
36 * @author Anton Koinov
37 * @version $Revision$ $Date: 2005-05-11 18:45:06 +0200 (Wed, 11 May 2005) $
38 */
39 public class HtmlImageRendererBase
40 extends HtmlRenderer
41 {
42 private static final Log log = LogFactory.getLog(HtmlImageRendererBase.class);
43
44 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
45 throws IOException
46 {
47 org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
48
49 ResponseWriter writer = facesContext.getResponseWriter();
50
51 String url;
52 if (uiComponent instanceof HtmlGraphicImage)
53 {
54 url = ((HtmlGraphicImage) uiComponent).getUrl();
55 }
56 else
57 {
58 url = (String) uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
59 }
60
61 writer.startElement(HTML.IMG_ELEM, uiComponent);
62
63 HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
64
65 if (url != null && url.length() > 0)
66 {
67 String src = facesContext.getApplication()
68 .getViewHandler().getResourceURL(facesContext, url);
69 writer.writeURIAttribute(HTML.SRC_ATTR,
70 facesContext.getExternalContext().encodeResourceURL(src),
71 JSFAttr.VALUE_ATTR);
72 }
73 else
74 {
75 if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url).");
76 }
77
78
79
80
81 if (uiComponent.getAttributes().get(HTML.ALT_ATTR) == null)
82 {
83 log.warn("ALT attribute is missing for : " + uiComponent.getId());
84 }
85
86 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
87
88 writer.endElement(org.apache.myfaces.shared.renderkit.html.HTML.IMG_ELEM);
89
90 }
91
92 }