1 17 18 19 20 package org.apache.fop.util; 21 22 import java.io.IOException ; 23 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.ContentHandler ; 26 import org.xml.sax.DTDHandler ; 27 import org.xml.sax.EntityResolver ; 28 import org.xml.sax.ErrorHandler ; 29 import org.xml.sax.InputSource ; 30 import org.xml.sax.Locator ; 31 import org.xml.sax.SAXException ; 32 import org.xml.sax.SAXParseException ; 33 import org.xml.sax.ext.LexicalHandler ; 34 35 43 public class DelegatingContentHandler 44 implements EntityResolver , DTDHandler , ContentHandler , LexicalHandler , ErrorHandler { 45 46 private ContentHandler delegate; 47 private EntityResolver entityResolver; 48 private DTDHandler dtdHandler; 49 private LexicalHandler lexicalHandler; 50 private ErrorHandler errorHandler; 51 52 55 public DelegatingContentHandler() { 56 } 58 59 62 public ContentHandler getDelegateContentHandler() { 63 return this.delegate; 64 } 65 66 70 public void setDelegateContentHandler(ContentHandler handler) { 71 this.delegate = handler; 72 } 73 74 78 public void setDelegateEntityResolver(EntityResolver resolver) { 79 this.entityResolver = resolver; 80 } 81 82 86 public void setDelegateDTDHandler(DTDHandler handler) { 87 this.dtdHandler = handler; 88 } 89 90 94 public void setDelegateLexicalHandler(LexicalHandler handler) { 95 this.lexicalHandler = handler; 96 } 97 98 102 public void setDelegateErrorHandler(ErrorHandler handler) { 103 this.errorHandler = handler; 104 } 105 106 108 111 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 112 if (entityResolver != null) { 113 return entityResolver.resolveEntity(publicId, systemId); 114 } else { 115 return null; 116 } 117 } 118 119 121 124 public void notationDecl(String name, String publicId, String systemId) throws SAXException { 125 if (dtdHandler != null) { 126 dtdHandler.notationDecl(name, publicId, systemId); 127 } 128 } 129 130 133 public void unparsedEntityDecl(String name, String publicId, String systemId, 134 String notationName) throws SAXException { 135 if (dtdHandler != null) { 136 dtdHandler.unparsedEntityDecl(name, publicId, systemId, notationName); 137 } 138 } 139 140 142 145 public void setDocumentLocator(Locator locator) { 146 delegate.setDocumentLocator(locator); 147 } 148 149 152 public void startDocument() throws SAXException { 153 delegate.startDocument(); 154 } 155 156 159 public void endDocument() throws SAXException { 160 delegate.endDocument(); 161 } 162 163 166 public void startPrefixMapping(String prefix, String uri) throws SAXException { 167 delegate.startPrefixMapping(prefix, uri); 168 } 169 170 173 public void endPrefixMapping(String prefix) throws SAXException { 174 delegate.endPrefixMapping(prefix); 175 } 176 177 180 public void startElement(String uri, String localName, String qName, 181 Attributes atts) throws SAXException { 182 delegate.startElement(uri, localName, qName, atts); 183 } 184 185 188 public void endElement(String uri, String localName, String qName) throws SAXException { 189 delegate.endElement(uri, localName, qName); 190 } 191 192 195 public void characters(char[] ch, int start, int length) throws SAXException { 196 delegate.characters(ch, start, length); 197 } 198 199 202 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { 203 delegate.ignorableWhitespace(ch, start, length); 204 } 205 206 209 public void processingInstruction(String target, String data) throws SAXException { 210 delegate.processingInstruction(target, data); 211 } 212 213 216 public void skippedEntity(String name) throws SAXException { 217 delegate.skippedEntity(name); 218 } 219 220 222 225 public void startDTD(String name, String publicId, String systemId) throws SAXException { 226 if (lexicalHandler != null) { 227 lexicalHandler.startDTD(name, publicId, systemId); 228 } 229 230 } 231 232 235 public void endDTD() throws SAXException { 236 if (lexicalHandler != null) { 237 lexicalHandler.endDTD(); 238 } 239 } 240 241 244 public void startEntity(String name) throws SAXException { 245 if (lexicalHandler != null) { 246 lexicalHandler.startEntity(name); 247 } 248 } 249 250 253 public void endEntity(String name) throws SAXException { 254 if (lexicalHandler != null) { 255 lexicalHandler.endEntity(name); 256 } 257 } 258 259 262 public void startCDATA() throws SAXException { 263 if (lexicalHandler != null) { 264 lexicalHandler.startCDATA(); 265 } 266 } 267 268 271 public void endCDATA() throws SAXException { 272 if (lexicalHandler != null) { 273 lexicalHandler.endCDATA(); 274 } 275 } 276 277 280 public void comment(char[] ch, int start, int length) throws SAXException { 281 if (lexicalHandler != null) { 282 lexicalHandler.comment(ch, start, length); 283 } 284 } 285 286 288 291 public void warning(SAXParseException exception) throws SAXException { 292 if (errorHandler != null) { 293 errorHandler.warning(exception); 294 } 295 } 296 297 300 public void error(SAXParseException exception) throws SAXException { 301 if (errorHandler != null) { 302 errorHandler.error(exception); 303 } 304 } 305 306 309 public void fatalError(SAXParseException exception) throws SAXException { 310 if (errorHandler != null) { 311 errorHandler.fatalError(exception); 312 } 313 } 314 315 } 316 | Popular Tags |