1 16 package org.apache.myfaces.wap.renderkit.wml; 17 18 import java.util.List ; 19 20 import javax.faces.component.UIComponent; 21 import javax.faces.component.UIParameter; 22 import javax.faces.context.FacesContext; 23 import javax.faces.context.ResponseWriter; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.myfaces.wap.component.OutputLink; 28 import org.apache.myfaces.wap.renderkit.Attributes; 29 import org.apache.myfaces.wap.renderkit.RendererUtils; 30 import org.apache.myfaces.wap.renderkit.WmlRenderer; 31 32 33 41 public class OutputLinkRenderer extends WmlRenderer { 42 private static Log log = LogFactory.getLog(OutputLinkRenderer.class); 43 44 45 public OutputLinkRenderer() { 46 super(); 47 log.debug("created object " + this.getClass().getName()); 48 } 49 50 public boolean getRendersChildren(){ 51 return(true); 52 } 53 54 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 55 log.debug("encodeBegin(" + component.getId() + ")"); 56 57 if (context == null || component == null) { 58 throw new NullPointerException (); 59 } 60 if (!component.isRendered()) return; 61 62 ResponseWriter writer = context.getResponseWriter(); 63 OutputLink comp = (OutputLink)component; 64 65 String href = RendererUtils.convertToString(context, component); 66 67 List child = component.getChildren(); 68 for (int i = 0; i < child.size(); i++){ if (child.get(i) instanceof UIParameter){ 70 href = insertParam(href, (UIParameter)child.get(i), writer.getCharacterEncoding()); 71 } 72 } 73 href = context.getExternalContext().encodeResourceURL(href); 74 75 writer.startElement(Attributes.A, component); 76 RendererUtils.writeAttribute(Attributes.HREF, href, writer); 77 RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer); 78 RendererUtils.writeAttribute(Attributes.CLASS, comp.getStyleClass(), writer); 79 RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer); 80 RendererUtils.writeAttribute(Attributes.TITLE, comp.getTitle(), writer); 81 writer.flush(); 82 } 83 84 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 85 log.debug("encodeChildren(" + component.getId() + ")"); 86 if (context == null || component == null) { 87 throw new NullPointerException (); 88 } 89 if (!component.isRendered()) return; 90 91 RendererUtils.renderChildren(context, component); 92 } 93 94 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 95 log.debug("encodeEnd(" + component.getId() + ")"); 96 if (context == null || component == null) { 97 throw new NullPointerException (); 98 } 99 if (!component.isRendered()) return; 100 101 ResponseWriter writer = context.getResponseWriter(); 102 writer.endElement(Attributes.A); 103 } 104 105 public void decode(FacesContext context, UIComponent component) { 106 if (component == null ) throw new NullPointerException (); 107 } 108 109 private String insertParam(String href, UIParameter param, String encoding) throws java.io.IOException { 110 String name = (String )param.getName(); 111 String value = (String )param.getValue(); 112 113 return(RendererUtils.insertGetParam(href, name, value, encoding)); 114 } 115 116 117 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws javax.faces.convert.ConverterException { 118 return(RendererUtils.convertToObject(context, component)); 119 } 120 } 121 122 | Popular Tags |