1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 26 import nu.xom.Builder; 27 import nu.xom.Element; 28 import nu.xom.Attribute; 29 import nu.xom.Nodes; 30 import nu.xom.NodeFactory; 31 import nu.xom.ParsingException; 32 33 34 45 public class StreamingTypeCounter extends NodeFactory{ 46 47 private int CDATA = 0; 48 private int ID = 0; 49 private int IDREF = 0; 50 private int IDREFS = 0; 51 private int NMTOKEN = 0; 52 private int NMTOKENS = 0; 53 private int ENTITY = 0; 54 private int ENTITIES = 0; 55 private int NOTATION = 0; 56 57 private Nodes empty = new Nodes(); 58 59 public void printCount() { 60 System.out.println("CDATA type attributes: " + CDATA); 61 System.out.println("ID type attributes: " + ID ); 62 System.out.println("IDREF type attributes: " + IDREF ); 63 System.out.println("IDREFS type attributes: " + IDREFS ); 64 System.out.println("NMTOKEN type attributes: " + NMTOKEN ); 65 System.out.println("NMTOKENS type attributes: " + NMTOKENS ); 66 System.out.println("ENTITY type attributes: " + ENTITY ); 67 System.out.println("ENTITIES type attributes: " + ENTITIES ); 68 System.out.println("NOTATION type attributes: " + NOTATION ); 69 } 70 71 public static void main(String [] args) { 72 73 if (args.length == 0) { 74 System.out.println( 75 "Usage: java nu.xom.samples.StreamingTypeCounter URL" 76 ); 77 return; 78 } 79 80 StreamingTypeCounter counter = new StreamingTypeCounter(); 81 Builder builder = new Builder(counter); 82 83 try { 84 builder.build(args[0]); 85 counter.printCount(); 86 } 87 catch (ParsingException ex) { 89 System.out.println(args[0] + " is not well-formed."); 90 System.out.println(ex.getMessage()); 91 } 92 catch (IOException ex) { 93 System.out.println(ex); 94 } 95 96 } 97 98 public Nodes makeComment(String data) { 100 return empty; 101 } 102 103 public Nodes makeText(String data) { 105 return empty; 106 } 107 108 public Element startMakingElement(String name, String namespace) { 109 return null; 111 } 112 113 public Nodes makeAttribute(String name, String URI, 114 String value, Attribute.Type type) { 115 if (type.equals(Attribute.Type.CDATA)) CDATA++; 116 else if (type.equals(Attribute.Type.UNDECLARED)) CDATA++; 117 else if (type.equals(Attribute.Type.ID)) ID++; 118 else if (type.equals(Attribute.Type.IDREF)) IDREF++; 119 else if (type.equals(Attribute.Type.IDREFS)) IDREFS++; 120 else if (type.equals(Attribute.Type.NMTOKEN)) NMTOKEN++; 121 else if (type.equals(Attribute.Type.NMTOKENS)) NMTOKENS++; 122 else if (type.equals(Attribute.Type.ENTITY)) ENTITY++; 123 else if (type.equals(Attribute.Type.ENTITIES)) ENTITIES++; 124 else if (type.equals(Attribute.Type.NOTATION)) NOTATION++; 125 return empty; 126 } 127 128 public Nodes makeDocType(String rootElementName, 129 String publicID, String systemID) { 130 return empty; 131 } 132 133 public Nodes makeProcessingInstruction( 134 String target, String data) { 135 return empty; 136 } 137 138 } 139 | Popular Tags |