1 17 package org.alfresco.web.ui.common.renderer; 18 19 import java.io.IOException ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import javax.faces.component.UIComponent; 25 import javax.faces.component.UIParameter; 26 import javax.faces.context.FacesContext; 27 import javax.faces.context.ResponseWriter; 28 import javax.faces.render.Renderer; 29 30 35 public abstract class BaseRenderer extends Renderer 36 { 37 46 protected static void outputAttribute(ResponseWriter out, Object attr, String mapping) 47 throws IOException 48 { 49 if (attr != null) 50 { 51 out.write(' '); 52 out.write(mapping); 53 out.write("=\""); 54 out.write(attr.toString()); 55 out.write('"'); 56 } 57 } 58 59 66 protected static void assertParmeters(FacesContext ctx, UIComponent component) 67 { 68 if (ctx == null) 69 { 70 throw new IllegalStateException ("context can not be null"); 71 } 72 73 if (component == null) 74 { 75 throw new IllegalStateException ("component can not be null"); 76 } 77 } 78 79 86 protected static Map <String , String > getParameterMap(UIComponent component) 87 { 88 Map <String , String > params = null; 89 90 if (component.getChildCount() != 0) 91 { 92 params = new HashMap <String , String >(3, 1.0f); 93 for (Iterator i=component.getChildren().iterator(); i.hasNext(); ) 94 { 95 UIComponent child = (UIComponent)i.next(); 96 if (child instanceof UIParameter) 97 { 98 UIParameter param = (UIParameter)child; 99 params.put(param.getName(), (String )param.getValue()); 100 } 101 } 102 } 103 104 return params; 105 } 106 } 107 | Popular Tags |