1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.shared_impl.renderkit.html; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
import org.apache.myfaces.shared_impl.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 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class HtmlImageRendererBase |
40 | |
extends HtmlRenderer |
41 | |
{ |
42 | 0 | private static final Log log = LogFactory.getLog(HtmlImageRendererBase.class); |
43 | |
|
44 | |
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) |
45 | |
throws IOException |
46 | |
{ |
47 | 0 | org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class); |
48 | |
|
49 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
50 | |
|
51 | |
String url; |
52 | 0 | if (uiComponent instanceof HtmlGraphicImage) |
53 | |
{ |
54 | 0 | url = ((HtmlGraphicImage) uiComponent).getUrl(); |
55 | |
} |
56 | |
else |
57 | |
{ |
58 | 0 | url = (String) uiComponent.getAttributes().get(JSFAttr.URL_ATTR); |
59 | |
} |
60 | |
|
61 | 0 | writer.startElement(HTML.IMG_ELEM, uiComponent); |
62 | |
|
63 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext); |
64 | |
|
65 | 0 | if (url != null && url.length() > 0) |
66 | |
{ |
67 | 0 | String src = facesContext.getApplication() |
68 | |
.getViewHandler().getResourceURL(facesContext, url); |
69 | 0 | writer.writeURIAttribute(HTML.SRC_ATTR, |
70 | |
facesContext.getExternalContext().encodeResourceURL(src), |
71 | |
JSFAttr.VALUE_ATTR); |
72 | 0 | } |
73 | |
else |
74 | |
{ |
75 | 0 | if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url)."); |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 0 | if (uiComponent.getAttributes().get(HTML.ALT_ATTR) == null) |
82 | |
{ |
83 | 0 | log.warn("ALT attribute is missing for : " + uiComponent.getId()); |
84 | |
} |
85 | |
|
86 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES); |
87 | |
|
88 | 0 | writer.endElement(org.apache.myfaces.shared_impl.renderkit.html.HTML.IMG_ELEM); |
89 | |
|
90 | 0 | } |
91 | |
|
92 | |
} |