1 4 5 42 43 45 package org.apache.cocoon.faces.samples.components.renderkit; 46 47 import javax.faces.FactoryFinder; 48 import javax.faces.application.Application; 49 import javax.faces.application.ApplicationFactory; 50 import javax.faces.component.UIComponent; 51 import javax.faces.context.FacesContext; 52 import javax.faces.el.MethodBinding; 53 import javax.faces.el.ValueBinding; 54 55 61 62 public class Util extends Object { 63 64 68 72 79 80 private static String booleanPassthruAttributes[] = { 81 "disabled", 82 "readonly", 83 "ismap" 84 }; 85 86 95 private static String passthruAttributes[] = { 96 "accesskey", 97 "alt", 98 "cols", 99 "height", 100 "lang", 101 "longdesc", 102 "maxlength", 103 "onblur", 104 "onchange", 105 "onclick", 106 "ondblclick", 107 "onfocus", 108 "onkeydown", 109 "onkeypress", 110 "onkeyup", 111 "onload", 112 "onmousedown", 113 "onmousemove", 114 "onmouseout", 115 "onmouseover", 116 "onmouseup", 117 "onreset", 118 "onselect", 119 "onsubmit", 120 "onunload", 121 "rows", 122 "size", 123 "tabindex", 124 "title", 126 "style", 127 "width", 128 "dir", 129 "rules", 130 "frame", 131 "border", 132 "cellspacing", 133 "cellpadding", 134 "summary", 135 "bgcolor", 136 "usemap", 137 "enctype", 138 "accept-charset", 139 "accept", 140 "target", 141 "onsubmit", 142 "onreset" 143 }; 144 145 private static long id = 0; 146 147 148 152 154 156 160 private Util() { 161 throw new IllegalStateException (); 162 } 163 164 public static Class loadClass(String name) throws ClassNotFoundException { 168 ClassLoader loader = 169 Thread.currentThread().getContextClassLoader(); 170 if (loader == null) { 171 return Class.forName(name); 172 } else { 173 return loader.loadClass(name); 174 } 175 } 176 177 178 182 public static synchronized String generateId() { 183 if (id == Long.MAX_VALUE) { 184 id = 0; 185 } else { 186 id++; 187 } 188 return Long.toHexString(id); 189 } 190 191 192 251 252 253 259 260 public static String renderBooleanPassthruAttributes(FacesContext context, 261 UIComponent component) { 262 int i = 0, len = booleanPassthruAttributes.length; 263 String value; 264 boolean thisIsTheFirstAppend = true; 265 StringBuffer renderedText = new StringBuffer (); 266 267 for (i = 0; i < len; i++) { 268 if (null != (value = (String ) 269 component.getAttributes().get(booleanPassthruAttributes[i]))) { 270 if (thisIsTheFirstAppend) { 271 renderedText.append(' '); 273 thisIsTheFirstAppend = false; 274 } 275 if (Boolean.valueOf(value).booleanValue()) { 276 renderedText.append(booleanPassthruAttributes[i] + ' '); 277 } 278 } 279 } 280 281 return renderedText.toString(); 282 } 283 284 285 297 298 public static String renderPassthruAttributes(FacesContext context, 299 UIComponent component) { 300 int i = 0, len = passthruAttributes.length; 301 String value; 302 boolean thisIsTheFirstAppend = true; 303 StringBuffer renderedText = new StringBuffer (); 304 305 for (i = 0; i < len; i++) { 306 if (null != (value = (String ) 307 component.getAttributes().get(passthruAttributes[i]))) { 308 if (thisIsTheFirstAppend) { 309 renderedText.append(' '); 311 thisIsTheFirstAppend = false; 312 } 313 renderedText.append(passthruAttributes[i] + "=\"" + value + 314 "\" "); 315 } 316 } 317 318 return renderedText.toString(); 319 } 320 321 322 public static ValueBinding getValueBinding(String valueRef) { 323 ApplicationFactory af = (ApplicationFactory) 324 FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); 325 Application a = af.getApplication(); 326 return (a.createValueBinding(valueRef)); 327 } 328 329 330 public static MethodBinding createConstantMethodBinding(String outcome) { 331 return new ConstantMethodBinding(outcome); 332 } 333 334 338 } | Popular Tags |