1 28 29 package com.caucho.xml; 30 31 import org.xml.sax.AttributeList ; 32 import org.xml.sax.Attributes ; 33 import org.xml.sax.ContentHandler ; 34 import org.xml.sax.DocumentHandler ; 35 import org.xml.sax.Locator ; 36 import org.xml.sax.SAXException ; 37 38 42 class ContentHandlerAdapter implements ContentHandler { 43 private DocumentHandler handler; 44 private QAttributeList attributeList; 45 46 ContentHandlerAdapter(DocumentHandler handler) 47 { 48 this.handler = handler; 49 attributeList = new QAttributeList(); 50 } 51 52 public void setDocumentLocator(Locator locator) 53 { 54 handler.setDocumentLocator(locator); 55 } 56 57 public void startDocument() 58 throws SAXException 59 { 60 handler.startDocument(); 61 } 62 63 public void endDocument() 64 throws SAXException 65 { 66 handler.endDocument(); 67 } 68 69 public void startPrefixMapping(String prefix, String uri) 70 throws SAXException 71 { 72 } 73 74 public void endPrefixMapping(String prefix) 75 throws SAXException 76 { 77 } 78 79 public void startElement(String namespaceURI, String localName, 80 String qName, Attributes attrs) 81 throws SAXException 82 { 83 attributeList.init((QAttributes) attrs); 84 85 handler.startElement(qName, attributeList); 86 } 87 88 public void endElement (String namespaceURI, String localName, String qName) 89 throws SAXException 90 { 91 handler.endElement(qName); 92 } 93 94 public void characters(char ch[], int start, int length) 95 throws SAXException 96 { 97 handler.characters(ch, start, length); 98 } 99 100 public void ignorableWhitespace(char ch[], int start, int length) 101 throws SAXException 102 { 103 handler.ignorableWhitespace(ch, start, length); 104 } 105 106 public void processingInstruction (String target, String data) 107 throws SAXException 108 { 109 handler.processingInstruction(target, data); 110 } 111 112 public void skippedEntity(String name) 113 throws SAXException 114 { 115 } 116 117 static class QAttributeList implements AttributeList { 118 private QAttributes attributes; 119 120 void init(QAttributes attributes) 121 { 122 this.attributes = attributes; 123 } 124 125 public int getLength() 126 { 127 return attributes.getLength(); 128 } 129 130 public String getName(int i) 131 { 132 return attributes.getQName(i); 133 } 134 135 public String getValue(int i) 136 { 137 return attributes.getValue(i); 138 } 139 140 public String getValue(String qName) 141 { 142 return attributes.getValue(qName); 143 } 144 145 public String getType(int i) 146 { 147 return attributes.getType(i); 148 } 149 150 public String getType(String qName) 151 { 152 return attributes.getType(qName); 153 } 154 } 155 } 156 | Popular Tags |