| 1 4 package gnu.kawa.sax; 5 import gnu.lists.*; 6 import gnu.xml.*; 7 import org.xml.sax.*; 8 import gnu.mapping.Symbol; 9 10 12 13 public class ConsumeSAXHandler implements DocumentHandler, ContentHandler 14 { 15 Consumer out; 16 17 public void setDocumentLocator(Locator locator) 18 { 19 } 21 22 public ConsumeSAXHandler(Consumer out) 23 { 24 this.out = out; 25 } 26 27 public void startDocument() 28 { 29 out.beginDocument(); 30 } 31 32 public void endDocument() 33 { 34 out.endDocument(); 35 } 36 37 public void startElement (String namespaceURI, String localName, 38 String qName, Attributes atts) 39 throws SAXException 40 { 41 out.beginGroup(Symbol.make(namespaceURI, localName)); 42 int numAttributes = atts.getLength(); 43 for (int i = 0; i < numAttributes; i++) 44 { 45 out.beginAttribute(Symbol.make(atts.getURI(i), atts.getLocalName(i))); 46 out.write(atts.getValue(i)); 47 out.endAttribute(); 48 } 49 } 50 51 public void endElement (String namespaceURI, String localName, 52 String qName) 53 throws SAXException 54 { 55 out.endGroup(); 56 } 57 58 public void startElement (String name, AttributeList atts) 59 throws SAXException 60 { 61 name = name.intern(); out.beginGroup(name); int attrLength = atts.getLength(); 64 for (int i = 0; i < attrLength; i++) 65 { 66 name = atts.getName(i); 67 name = name.intern(); String type = atts.getType(i); 69 String value = atts.getValue(i); 70 out.beginAttribute(name); out.write(value); 72 out.endAttribute(); 73 } 74 } 75 76 public void endElement (String name) 77 throws SAXException 78 { 79 out.endGroup(); 80 } 81 82 public void characters (char ch[], int start, int length) 83 throws SAXException 84 { 85 out.write(ch, start, length); 86 } 87 88 public void ignorableWhitespace (char ch[], int start, int length) 89 throws SAXException 90 { 91 out.write(ch, start, length); 93 } 94 95 public void processingInstruction(String target, String data) 96 { 97 } 99 100 public void startPrefixMapping (String prefix, String uri) 101 { 102 } 104 105 public void endPrefixMapping (String prefix) 106 { 107 } 109 110 public void skippedEntity (String name) 111 { 112 } 114 } 115 | Popular Tags |