1 16 package org.apache.myfaces.renderkit.html; 17 18 import org.apache.myfaces.renderkit.JSFAttr; 19 import org.apache.myfaces.renderkit.RendererUtils; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import javax.faces.component.UIComponent; 25 import javax.faces.component.UIGraphic; 26 import javax.faces.component.html.HtmlGraphicImage; 27 import javax.faces.context.FacesContext; 28 import javax.faces.context.ResponseWriter; 29 import java.io.IOException ; 30 31 32 47 public class HtmlImageRenderer 48 extends HtmlRenderer 49 { 50 private static final Log log = LogFactory.getLog(HtmlImageRenderer.class); 51 52 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) 53 throws IOException 54 { 55 RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class); 56 57 ResponseWriter writer = facesContext.getResponseWriter(); 58 59 String url; 60 if (uiComponent instanceof HtmlGraphicImage) 61 { 62 url = ((HtmlGraphicImage)uiComponent).getUrl(); 63 } 64 else 65 { 66 url = (String )uiComponent.getAttributes().get(JSFAttr.URL_ATTR); 67 } 68 69 if ((url != null) && (url.length() > 0)) 70 { 71 writer.startElement(HTML.IMG_ELEM, uiComponent); 72 73 writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null); 74 75 String src = facesContext.getApplication() 76 .getViewHandler().getResourceURL(facesContext, url); 77 writer.writeURIAttribute(HTML.SRC_ATTR, 78 facesContext.getExternalContext().encodeResourceURL(src), 79 null); 80 81 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES); 82 83 writer.endElement(HTML.IMG_ELEM); 84 } 85 else 86 { 87 if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url)."); 88 } 89 } 90 } 91 | Popular Tags |