| 1 5 package fr.improve.struts.taglib.layout.test; 6 7 import java.beans.IntrospectionException ; 8 import java.beans.PropertyDescriptor ; 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.util.HashMap ; 12 13 import org.apache.commons.digester.Digester; 14 import org.xml.sax.SAXException ; 15 16 21 public class TLDTest { 22 private Class tagClass; 23 private HashMap attributes; 24 25 public TLDTest() { 26 attributes = new HashMap (); 27 } 28 29 public static void main(String [] args) { 30 File lc_file = new File ("c:\\java\\eclipse\\workspace\\Improve Struts-Layout\\src\\library\\struts-layout.tld"); 31 Digester lc_digester = new Digester(); 32 lc_digester.addObjectCreate("taglib/tag", "fr.improve.struts.taglib.layout.test.TLDTest"); 33 lc_digester.addCallMethod("taglib/tag/tagclass", "setTagClassName", 0); 34 lc_digester.addCallMethod("taglib/tag/attribute/name","setAttribute",0); 35 try { 36 lc_digester.parse(lc_file); 37 } catch (IOException e) { 38 System.err.println(e); 39 } catch (SAXException e) { 40 System.err.println(e); 41 } 42 } 43 44 public void setTagClassName(String in_name) { 45 try { 46 tagClass = Class.forName(in_name); 47 } catch (ClassNotFoundException cnfe) { 48 System.err.println("Class not found: " + in_name); 49 System.exit(1); 50 } 51 attributes.clear(); 52 } 53 54 public void setAttribute(String in_attribute) { 55 String lc_attribute = (String ) attributes.get(in_attribute); 57 if (lc_attribute != null) { 58 System.err.println( 59 "The attribute " 60 + in_attribute 61 + " is defined more than once for the class " 62 + tagClass.getName()); 63 } else 64 try { 65 PropertyDescriptor lc_propertyDescriptor = 67 new PropertyDescriptor (in_attribute, tagClass); 68 if (lc_propertyDescriptor.getWriteMethod() == null) { 69 System.err.println( 70 "The setter mothod of the attribute " 71 + in_attribute 72 + " in the class " 73 + tagClass.getName() 74 + " is not implemented."); 75 } 76 } catch (IntrospectionException ie) { 77 System.err.println( 78 "Introspection exception looking for the attribute " 79 + in_attribute 80 + " in the class " 81 + tagClass.getName() + ie.getMessage()); 82 } 83 } 84 } | Popular Tags |