1 2 34 35 package com.icesoft.metadata.generators; 36 37 import com.icesoft.jsfmeta.util.AbstractGenerator; 38 import com.icesoft.jsfmeta.util.InternalConfig; 39 import java.io.BufferedWriter ; 40 import java.io.File ; 41 import java.io.FileWriter ; 42 import java.io.IOException ; 43 import java.io.PrintWriter ; 44 import java.util.HashSet ; 45 import java.util.Iterator ; 46 import java.util.Set ; 47 import java.util.TreeMap ; 48 49 import com.sun.rave.jsfmeta.beans.AttributeBean; 50 import com.sun.rave.jsfmeta.beans.ComponentBean; 51 import com.sun.rave.jsfmeta.beans.DescriptionBean; 52 import com.sun.rave.jsfmeta.beans.PropertyBean; 53 import com.sun.rave.jsfmeta.beans.RendererBean; 54 import java.util.logging.Level ; 55 56 61 public class TLDGenerator extends AbstractGenerator { 62 63 64 private TreeMap attributes; 65 66 private PrintWriter writer; 67 68 private boolean base; 69 70 private static PropertyBean binding; 71 72 private String descriptor; 73 74 private String listeners[]; 75 76 private String prefix; 77 78 private String tagClassPackage; 79 80 private String uri; 81 82 private String validators[]; 83 84 static { 85 binding = new PropertyBean(); 86 binding.setPropertyName("binding"); 87 String db_string = "The value binding expression linking this component to a property in a backing bean"; 88 DescriptionBean dbBean = new DescriptionBean("", db_string); 89 binding.addDescription(dbBean); 90 binding.setRequired(false); 91 } 92 93 public TLDGenerator(InternalConfig internalConfig) { 94 95 super(internalConfig); 96 attributes = new TreeMap (); 97 writer = null; 98 base = false; 99 descriptor = internalConfig.getProperty("project.tld.file"); 100 listeners = null; 101 prefix = internalConfig.getProperty("project.taglib.prefix"); 102 tagClassPackage = internalConfig.getProperty("project.taglib.package"); 103 uri = internalConfig.getProperty("project.taglib.uri"); 104 validators = null; 105 } 106 107 public boolean getBase() { 108 return base; 109 } 110 111 public void setBase(boolean base) { 112 this.base = base; 113 } 114 115 public String getDescriptor() { 116 return descriptor; 117 } 118 119 public void setDescriptor(String descriptor) { 120 this.descriptor = descriptor; 121 } 122 123 public String [] getListeners() { 124 return listeners; 125 } 126 127 public void setListeners(String listeners[]) { 128 this.listeners = listeners; 129 } 130 131 public String getPrefix() { 132 return prefix; 133 } 134 135 public void setPrefix(String prefix) { 136 this.prefix = prefix; 137 } 138 139 public String getTagClassPackage() { 140 return tagClassPackage; 141 } 142 143 public void setTagClassPackage(String tagClassPackage) { 144 this.tagClassPackage = tagClassPackage; 145 } 146 147 public String getURI() { 148 return uri; 149 } 150 151 public void setURI(String uri) { 152 this.uri = uri; 153 } 154 155 public String [] getValidators() { 156 return validators; 157 } 158 159 public void setValidators(String validators[]) { 160 this.validators = validators; 161 } 162 163 public void generate() throws IOException { 164 165 File outputFile = new File (getDest(), getDescriptor()); 166 outputFile.mkdirs(); 167 outputFile.delete(); 168 writer = new PrintWriter (new BufferedWriter (new FileWriter (outputFile))); 169 logger.log(Level.FINEST, "Generate " + outputFile.getAbsoluteFile()); 170 license(); 171 header(); 172 validators(); 173 listeners(); 174 components(); 175 jspTagOnly(); 176 177 footer(); 178 writer.flush(); 179 writer.close(); 180 } 181 182 private void attribute(ComponentBean cb, RendererBean rb, PropertyBean pb) 183 throws IOException { 184 if ("com.icesoft.faces.component.menubar.MenuBar".equals(cb.getComponentClass()) 185 && (pb.getPropertyName().equals("action") || 186 pb.getPropertyName().equals("actionListener"))) { 187 return; 188 } 189 StringBuffer sb = new StringBuffer (); 190 sb.append(" <attribute>\n"); 191 sb.append(" <name>" + pb.getPropertyName() + "</name>\n"); 192 sb.append(" <required>" + pb.isRequired() + "</required>\n"); 193 sb.append(" <rtexprvalue>false</rtexprvalue>\n"); 194 if (isVerbose()) { 195 AttributeBean ab = rb.getAttribute(pb.getPropertyName()); 196 DescriptionBean db = null; 197 if (ab != null && !cb.getComponentType().startsWith("com.icesoft.faces")) 198 db = ab.getDescription(""); 199 else 200 db = pb.getDescription(""); 201 if (db != null) { 202 sb.append(" <description><![CDATA[\n"); 203 sb.append(" " + db.getDescription() + "\n"); 204 sb.append(" ]]></description>\n"); 205 } 206 } 207 sb.append(" </attribute>\n\n"); 208 attributes.put(pb.getPropertyName(), sb.toString()); 209 } 210 211 private void attributes(ComponentBean cb, RendererBean rb) 212 throws IOException { 213 attribute(cb, rb, binding); 214 attributes(cb, rb, ((Set ) (new HashSet ()))); 215 } 216 217 private void attributes(ComponentBean cb, RendererBean rb, Set set) 218 throws IOException { 219 PropertyBean pbs[] = cb.getProperties(); 220 if (pbs == null){ 221 pbs = new PropertyBean[0]; 222 } 223 for (int i = 0; i < pbs.length; i++) { 224 if (set.contains(pbs[i].getPropertyName())) 225 continue; 226 set.add(pbs[i].getPropertyName()); 227 PropertyBean pb = merge(pbs[i], rb.getAttribute(pbs[i] 228 .getPropertyName())); 229 if (!pb.isSuppressed() && pb.isTagAttribute()){ 230 attribute(cb, rb, pb); 231 } 232 } 233 234 String baseComponentType = cb.getBaseComponentType(); 235 if (baseComponentType != null) { 236 ComponentBean bcb = getConfig().getComponent(baseComponentType); 237 if (bcb != null){ 238 attributes(bcb, rb, set); 239 } 240 } 241 } 242 243 private void component(ComponentBean cb) throws IOException { 244 if (cb.isSuppressed()) 245 return; 246 if(cb.getComponentClass().startsWith("javax.faces.component.")){ 247 return; 248 } 249 RendererBean rb = renderer(cb); 250 251 if(cb == null){ 252 logger.log(Level.SEVERE, "component bean is null"); 253 }else{ 254 logger.log(Level.FINEST, "component bean class ="+cb.getClass().getName()+ 255 "RendererBean comp family="+cb.getComponentFamily()+ 256 "componentBean rendertype"+cb.getRendererType()); 257 } 258 259 if (rb == null){ 260 rb = new RendererBean(); 261 } 262 if (rb.getTagName() == null){ 263 return; 264 } 265 writer.println(" <tag>"); 266 writer.println(); 267 writer.println(" <name>" + rb.getTagName() + "</name>"); 268 writer.println(" <tag-class>" + tagClass(cb) + "</tag-class>"); 269 writer.println(" <body-content>JSP</body-content>"); 270 if (isVerbose()) { 271 DescriptionBean db = null; 272 if (rb != null) 273 db = rb.getDescription(""); 274 else 275 db = cb.getDescription(""); 276 if (db != null) { 277 writer.println(" <description><![CDATA["); 278 writer.println(" " + db.getDescription()); 279 writer.println(" ]]></description>"); 280 } 281 } 282 writer.println(); 283 attributes(cb, rb); 284 String name; 285 for (Iterator names = attributes.keySet().iterator(); names.hasNext(); writer 286 .print((String ) attributes.get(name))) 287 name = (String ) names.next(); 288 289 attributes.clear(); 290 writer.println(" </tag>"); 291 writer.println(); 292 writer.println(); 293 } 294 295 private void components() throws IOException { 296 ComponentBean cbs[] = getConfig().getComponents(); 297 for (int i = 0; i < cbs.length; i++) { 298 logger.log(Level.FINEST, "component = "+ cbs[i].getRendererType()); 299 if (generated(cbs[i].getComponentClass())) { 300 301 if (cbs[i] == null) { 302 logger.log(Level.SEVERE, "component is null"); 303 } else { 304 logger.log(Level.FINEST, "component class="+cbs[i].getComponentClass()); 305 component(cbs[i]); 306 } 307 } 308 } 309 310 } 311 312 315 private void jspTagOnly() { 316 317 writer.println(" <tag>"); 318 writer.println(" <name>tabChangeListener</name>"); 319 writer 320 .println(" <tag-class>com.icesoft.faces.component.paneltabset.TabChangeListenerTag</tag-class>"); 321 writer.println(" <body-content>empty</body-content>"); 322 writer.println(" <attribute>"); 323 writer.println(" <name>type</name>"); 324 writer.println(" <required>true</required>"); 325 writer.println(" <rtexprvalue>false</rtexprvalue>"); 326 writer 327 .println(" <description>the name of the class that will be added to the HtmlPanelTabbedPane component as a TabChangeListener</description>"); 328 writer.println(" </attribute>"); 329 writer.println(" </tag>"); 330 writer.println(""); 331 } 332 333 private void footer() throws IOException { 334 writer.println("</taglib>"); 335 } 336 337 private void header() throws IOException { 338 writer.println("<?xml version=\"1.0\"?>"); 339 writer.println("<!DOCTYPE taglib PUBLIC"); 340 writer 341 .println(" \"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN\""); 342 writer 343 .println(" \"http://java.sun.com/dtd//web-jsptaglibrary_1_2.dtd\">"); 344 writer.println(); 345 writer.println("<taglib>"); 346 writer.println(); 347 writer.println(); 348 349 writer.println(" <tlib-version>" + "1.6" + "</tlib-version>"); 351 writer.println(" <jsp-version>1.2</jsp-version>"); 352 writer.println(" <short-name>" + getPrefix() + "</short-name>"); 353 writer.println(" <uri>" + getURI() + "</uri>"); 354 writer.println(" <display-name>" + "ICEfaces Component Suite" + "</display-name>"); 355 writer.println(); 356 } 357 358 private void license() throws IOException { 359 } 360 361 private void listeners() throws IOException { 362 if (listeners == null) 363 return; 364 for (int i = 0; i < listeners.length; i++) { 365 writer.println(" <listener>"); 366 writer.println(" <listener-class>" + listeners[i] 367 + "</listener-class>"); 368 writer.println(" </listener>"); 369 writer.println(); 370 } 371 372 } 373 374 private String stripHtmlName(String s, String word){ 375 376 String tmp = ""; 377 if(!s.startsWith(word)){ 378 tmp = s; 379 }else{ 380 tmp = s.substring(word.length()); 381 } 382 return tmp; 383 } 384 385 private String tagClass(ComponentBean cb) { 386 387 String componentClass = cb.getComponentClass(); 388 if (tagClassPackage != null && componentClass.indexOf(".ext.") >0){ 389 390 return tagClassPackage + "." 391 + stripHtmlName(simpleClassName(cb.getComponentClass()), "Html") + "Tag"; 392 393 }else{ 394 return componentClass + "Tag"; 395 } 396 } 397 398 private void validators() throws IOException { 399 if (validators == null) 400 return; 401 for (int i = 0; i < validators.length; i++) { 402 writer.println(" <validator>"); 403 writer.println(" <validator-class>" + validators[i] 404 + "</validator-class>"); 405 writer.println(" </validator>"); 406 writer.println(); 407 } 408 409 } 410 411 } 412 | Popular Tags |