1 16 package org.apache.myfaces.wap.renderkit.wml; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.context.FacesContext; 20 import javax.faces.context.ResponseWriter; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.myfaces.wap.component.GraphicImage; 25 import org.apache.myfaces.wap.renderkit.Attributes; 26 import org.apache.myfaces.wap.renderkit.RendererUtils; 27 import org.apache.myfaces.wap.renderkit.WmlRenderer; 28 29 37 public class ImageRenderer extends WmlRenderer { 38 private static Log log = LogFactory.getLog(ImageRenderer.class); 39 40 41 public ImageRenderer() { 42 super(); 43 log.debug("created object " + this.getClass().getName()); 44 } 45 46 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 47 log.debug("encodeBegin(" + component.getId() + ")"); 48 if (context == null || component == null) { 49 throw new NullPointerException (); 50 } 51 } 52 53 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 54 log.debug("encodeChildren(" + component.getId() + ")"); 55 if (context == null || component == null) { 56 throw new NullPointerException (); 57 } 58 } 59 60 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 61 log.debug("encodeEnd(" + component.getId() + ")"); 62 if (context == null || component == null) { 63 throw new NullPointerException (); 64 } 65 if (!component.isRendered()) return; 66 67 GraphicImage comp = (GraphicImage)component; 68 String contextPath = context.getExternalContext().getRequestContextPath(); 69 71 ResponseWriter writer = context.getResponseWriter(); 72 73 writer.startElement(Attributes.IMG, comp); 74 75 RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer); 76 RendererUtils.writeAttribute(Attributes.STYLE_CLASS, comp.getStyleClass(), writer); 77 RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer); 78 RendererUtils.writeAttribute(Attributes.ALT, comp.getAlt(), writer); 79 80 String url = null; 82 if (comp.getValue() != null) url = (String )comp.getValue(); else if (comp.getUrl() != null) url = (String )comp.getUrl(); 84 RendererUtils.writeAttribute(Attributes.SRC, getURL(context, url), writer); 85 86 RendererUtils.writeAttribute(Attributes.LOCAL_SRC, comp.getLocalsrc(), writer); 87 RendererUtils.writeAttribute(Attributes.VSPACE, comp.getVspace(), writer); 88 RendererUtils.writeAttribute(Attributes.HSPACE, comp.getHspace(), writer); 89 RendererUtils.writeAttribute(Attributes.ALIGN, comp.getAlign(), writer); 90 RendererUtils.writeAttribute(Attributes.HEIGHT, comp.getHeight(), writer); 91 RendererUtils.writeAttribute(Attributes.WIDTH, comp.getWidth(), writer); 92 93 writer.endElement(Attributes.IMG); 94 } 95 96 97 public void decode(FacesContext context, UIComponent component) { 98 if (component == null) throw new NullPointerException (); 99 } 100 101 104 private String getURL(FacesContext context, String url) throws java.io.IOException { 105 if (url == null) throw new java.io.WriteAbortedException ("URL parameter in tag graphicImage is null.", new java.lang.NullPointerException ()); 106 url = context.getApplication().getViewHandler().getResourceURL(context, url); 107 url = context.getExternalContext().encodeResourceURL(url); 108 return (url); 109 } 110 111 } 112 113 | Popular Tags |