1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.render.html; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
|
20 | |
import javax.faces.component.UIComponent; |
21 | |
import javax.faces.component.UIGraphic; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
import javax.faces.context.ResponseWriter; |
24 | |
import javax.faces.internal.IgnoreAttribute; |
25 | |
|
26 | |
import org.seasar.teeda.core.JsfConstants; |
27 | |
import org.seasar.teeda.core.render.AbstractRenderer; |
28 | |
import org.seasar.teeda.core.util.FacesContextUtil; |
29 | |
import org.seasar.teeda.core.util.RendererUtil; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 34 | public class HtmlGraphicImageRenderer extends AbstractRenderer { |
35 | |
|
36 | |
public static final String COMPONENT_FAMILY = "javax.faces.Graphic"; |
37 | |
|
38 | |
public static final String RENDERER_TYPE = "javax.faces.Image"; |
39 | |
|
40 | 34 | private final IgnoreAttribute ignoreComponent = new IgnoreAttribute(); |
41 | |
{ |
42 | 34 | ignoreComponent.addAttributeName(JsfConstants.ID_ATTR); |
43 | 34 | ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR); |
44 | 34 | ignoreComponent.addAttributeName(JsfConstants.URL_ATTR); |
45 | 34 | } |
46 | |
|
47 | |
public void encodeEnd(FacesContext context, UIComponent component) |
48 | |
throws IOException { |
49 | 11 | assertNotNull(context, component); |
50 | 9 | if (!component.isRendered()) { |
51 | 1 | return; |
52 | |
} |
53 | 8 | encodeHtmlGraphicImageEnd(context, (UIGraphic) component); |
54 | 8 | } |
55 | |
|
56 | |
protected void encodeHtmlGraphicImageEnd(FacesContext context, |
57 | |
UIGraphic graphic) throws IOException { |
58 | 8 | ResponseWriter writer = context.getResponseWriter(); |
59 | 8 | writer.startElement(JsfConstants.IMG_ELEM, graphic); |
60 | 8 | RendererUtil.renderIdAttributeIfNecessary(writer, graphic, |
61 | |
getIdForRender(context, graphic)); |
62 | 8 | final String url = getUrl(context, graphic); |
63 | 8 | writer.writeURIAttribute(JsfConstants.SRC_ATTR, url, null); |
64 | 8 | renderRemainAttributes(graphic, writer, ignoreComponent); |
65 | 8 | writer.endElement(JsfConstants.IMG_ELEM); |
66 | 8 | } |
67 | |
|
68 | |
protected String getUrl(FacesContext context, UIGraphic htmlGraphicImage) { |
69 | 8 | String url = htmlGraphicImage.getUrl(); |
70 | 8 | if (url == null) { |
71 | 4 | url = ""; |
72 | |
} |
73 | 8 | url = FacesContextUtil.getViewHandler(context).getResourceURL(context, |
74 | |
url); |
75 | 8 | url = context.getExternalContext().encodeResourceURL(url); |
76 | 8 | return url; |
77 | |
} |
78 | |
|
79 | |
protected void addIgnoreAttributeName(final String attr) { |
80 | 0 | ignoreComponent.addAttributeName(attr); |
81 | 0 | } |
82 | |
|
83 | |
} |