1 8 package org.apache.avalon.excalibur.xml; 9 10 import org.apache.avalon.excalibur.pool.Recyclable; 11 import org.xml.sax.Attributes ; 12 import org.xml.sax.ContentHandler ; 13 import org.xml.sax.Locator ; 14 import org.xml.sax.SAXException ; 15 import org.xml.sax.ext.LexicalHandler ; 16 17 27 public class ContentHandlerWrapper extends AbstractXMLConsumer implements Recyclable { 28 29 30 protected ContentHandler contentHandler; 31 32 33 protected LexicalHandler lexicalHandler; 34 35 38 public ContentHandlerWrapper() { 39 super(); 40 } 41 42 45 public ContentHandlerWrapper(ContentHandler contentHandler) { 46 this(); 47 this.setContentHandler(contentHandler); 48 } 49 50 53 public ContentHandlerWrapper(ContentHandler contentHandler, 54 LexicalHandler lexicalHandler) { 55 this(); 56 this.setContentHandler(contentHandler); 57 this.setLexicalHandler(lexicalHandler); 58 } 59 60 66 public void setContentHandler(ContentHandler contentHandler) 67 throws IllegalStateException { 68 if (this.contentHandler!=null) throw new IllegalStateException (); 69 this.contentHandler=contentHandler; 70 } 71 72 78 public void setLexicalHandler(LexicalHandler lexicalHandler) 79 throws IllegalStateException { 80 if (this.lexicalHandler!=null) throw new IllegalStateException (); 81 this.lexicalHandler=lexicalHandler; 82 } 83 84 public void recycle () { 85 this.contentHandler = null; 86 this.lexicalHandler = null; 87 } 88 89 92 public void setDocumentLocator (Locator locator) { 93 if (this.contentHandler==null) return; 94 else this.contentHandler.setDocumentLocator(locator); 95 } 96 97 100 public void startDocument () 101 throws SAXException { 102 if (this.contentHandler==null) 103 throw new SAXException ("ContentHandler not set"); 104 this.contentHandler.startDocument(); 105 } 106 107 110 public void endDocument () 111 throws SAXException { 112 this.contentHandler.endDocument(); 113 } 114 115 118 public void startPrefixMapping(String prefix, String uri) 119 throws SAXException { 120 if (this.contentHandler==null) 121 throw new SAXException ("ContentHandler not set"); 122 this.contentHandler.startPrefixMapping(prefix, uri); 123 } 124 125 128 public void endPrefixMapping(String prefix) 129 throws SAXException { 130 this.contentHandler.endPrefixMapping(prefix); 131 } 132 133 136 public void startElement(String uri, String loc, String raw, Attributes a) 137 throws SAXException { 138 this.contentHandler.startElement(uri, loc, raw, a); 139 } 140 141 142 145 public void endElement(String uri, String loc, String raw) 146 throws SAXException { 147 this.contentHandler.endElement(uri, loc, raw); 148 } 149 150 153 public void characters(char ch[], int start, int len) 154 throws SAXException { 155 this.contentHandler.characters(ch,start,len); 156 } 157 158 161 public void ignorableWhitespace(char ch[], int start, int len) 162 throws SAXException { 163 this.contentHandler.ignorableWhitespace(ch,start,len); 164 } 165 166 169 public void processingInstruction(String target, String data) 170 throws SAXException { 171 this.contentHandler.processingInstruction(target,data); 172 } 173 174 180 public void skippedEntity(String name) 181 throws SAXException { 182 this.contentHandler.skippedEntity(name); 183 } 184 185 194 public void startDTD(String name, String publicId, String systemId) 195 throws SAXException { 196 if (this.lexicalHandler != null) 197 this.lexicalHandler.startDTD(name, publicId, systemId); 198 } 199 200 203 public void endDTD() 204 throws SAXException { 205 if (this.lexicalHandler != null) 206 this.lexicalHandler.endDTD(); 207 } 208 209 215 public void startEntity(String name) 216 throws SAXException { 217 if (this.lexicalHandler != null) 218 this.lexicalHandler.startEntity(name); 219 } 220 221 226 public void endEntity(String name) 227 throws SAXException { 228 if (this.lexicalHandler != null) 229 this.lexicalHandler.endEntity(name); 230 } 231 232 235 public void startCDATA() 236 throws SAXException { 237 if (this.lexicalHandler != null) 238 this.lexicalHandler.startCDATA(); 239 } 240 241 244 public void endCDATA() 245 throws SAXException { 246 if (this.lexicalHandler != null) 247 this.lexicalHandler.endCDATA(); 248 } 249 250 251 258 public void comment(char ch[], int start, int len) 259 throws SAXException { 260 if (this.lexicalHandler != null) 261 this.lexicalHandler.comment(ch, start, len); 262 } 263 264 } 265 | Popular Tags |