1 7 package org.xml.sax.helpers; 8 9 import java.io.IOException ; 10 11 import org.xml.sax.XMLReader ; 12 import org.xml.sax.XMLFilter ; 13 import org.xml.sax.InputSource ; 14 import org.xml.sax.Locator ; 15 import org.xml.sax.Attributes ; 16 import org.xml.sax.EntityResolver ; 17 import org.xml.sax.DTDHandler ; 18 import org.xml.sax.ContentHandler ; 19 import org.xml.sax.ErrorHandler ; 20 import org.xml.sax.SAXException ; 21 import org.xml.sax.SAXParseException ; 22 import org.xml.sax.SAXNotSupportedException ; 23 import org.xml.sax.SAXNotRecognizedException ; 24 25 26 53 public class XMLFilterImpl 54 implements XMLFilter , EntityResolver , DTDHandler , ContentHandler , ErrorHandler 55 { 56 57 58 62 63 75 public XMLFilterImpl () 76 { 77 super(); 78 } 79 80 81 87 public XMLFilterImpl (XMLReader parent) 88 { 89 super(); 90 setParent(parent); 91 } 92 93 94 95 99 100 113 public void setParent (XMLReader parent) 114 { 115 this.parent = parent; 116 } 117 118 119 125 public XMLReader getParent () 126 { 127 return parent; 128 } 129 130 131 132 136 137 150 public void setFeature (String name, boolean value) 151 throws SAXNotRecognizedException , SAXNotSupportedException 152 { 153 if (parent != null) { 154 parent.setFeature(name, value); 155 } else { 156 throw new SAXNotRecognizedException ("Feature: " + name); 157 } 158 } 159 160 161 174 public boolean getFeature (String name) 175 throws SAXNotRecognizedException , SAXNotSupportedException 176 { 177 if (parent != null) { 178 return parent.getFeature(name); 179 } else { 180 throw new SAXNotRecognizedException ("Feature: " + name); 181 } 182 } 183 184 185 198 public void setProperty (String name, Object value) 199 throws SAXNotRecognizedException , SAXNotSupportedException 200 { 201 if (parent != null) { 202 parent.setProperty(name, value); 203 } else { 204 throw new SAXNotRecognizedException ("Property: " + name); 205 } 206 } 207 208 209 220 public Object getProperty (String name) 221 throws SAXNotRecognizedException , SAXNotSupportedException 222 { 223 if (parent != null) { 224 return parent.getProperty(name); 225 } else { 226 throw new SAXNotRecognizedException ("Property: " + name); 227 } 228 } 229 230 231 236 public void setEntityResolver (EntityResolver resolver) 237 { 238 entityResolver = resolver; 239 } 240 241 242 247 public EntityResolver getEntityResolver () 248 { 249 return entityResolver; 250 } 251 252 253 258 public void setDTDHandler (DTDHandler handler) 259 { 260 dtdHandler = handler; 261 } 262 263 264 269 public DTDHandler getDTDHandler () 270 { 271 return dtdHandler; 272 } 273 274 275 280 public void setContentHandler (ContentHandler handler) 281 { 282 contentHandler = handler; 283 } 284 285 286 291 public ContentHandler getContentHandler () 292 { 293 return contentHandler; 294 } 295 296 297 302 public void setErrorHandler (ErrorHandler handler) 303 { 304 errorHandler = handler; 305 } 306 307 308 313 public ErrorHandler getErrorHandler () 314 { 315 return errorHandler; 316 } 317 318 319 329 public void parse (InputSource input) 330 throws SAXException , IOException 331 { 332 setupParse(); 333 parent.parse(input); 334 } 335 336 337 347 public void parse (String systemId) 348 throws SAXException , IOException 349 { 350 parse(new InputSource (systemId)); 351 } 352 353 354 355 359 360 372 public InputSource resolveEntity (String publicId, String systemId) 373 throws SAXException , IOException 374 { 375 if (entityResolver != null) { 376 return entityResolver.resolveEntity(publicId, systemId); 377 } else { 378 return null; 379 } 380 } 381 382 383 384 388 389 398 public void notationDecl (String name, String publicId, String systemId) 399 throws SAXException 400 { 401 if (dtdHandler != null) { 402 dtdHandler.notationDecl(name, publicId, systemId); 403 } 404 } 405 406 407 417 public void unparsedEntityDecl (String name, String publicId, 418 String systemId, String notationName) 419 throws SAXException 420 { 421 if (dtdHandler != null) { 422 dtdHandler.unparsedEntityDecl(name, publicId, systemId, 423 notationName); 424 } 425 } 426 427 428 429 433 434 439 public void setDocumentLocator (Locator locator) 440 { 441 this.locator = locator; 442 if (contentHandler != null) { 443 contentHandler.setDocumentLocator(locator); 444 } 445 } 446 447 448 454 public void startDocument () 455 throws SAXException 456 { 457 if (contentHandler != null) { 458 contentHandler.startDocument(); 459 } 460 } 461 462 463 469 public void endDocument () 470 throws SAXException 471 { 472 if (contentHandler != null) { 473 contentHandler.endDocument(); 474 } 475 } 476 477 478 486 public void startPrefixMapping (String prefix, String uri) 487 throws SAXException 488 { 489 if (contentHandler != null) { 490 contentHandler.startPrefixMapping(prefix, uri); 491 } 492 } 493 494 495 502 public void endPrefixMapping (String prefix) 503 throws SAXException 504 { 505 if (contentHandler != null) { 506 contentHandler.endPrefixMapping(prefix); 507 } 508 } 509 510 511 522 public void startElement (String uri, String localName, String qName, 523 Attributes atts) 524 throws SAXException 525 { 526 if (contentHandler != null) { 527 contentHandler.startElement(uri, localName, qName, atts); 528 } 529 } 530 531 532 542 public void endElement (String uri, String localName, String qName) 543 throws SAXException 544 { 545 if (contentHandler != null) { 546 contentHandler.endElement(uri, localName, qName); 547 } 548 } 549 550 551 560 public void characters (char ch[], int start, int length) 561 throws SAXException 562 { 563 if (contentHandler != null) { 564 contentHandler.characters(ch, start, length); 565 } 566 } 567 568 569 578 public void ignorableWhitespace (char ch[], int start, int length) 579 throws SAXException 580 { 581 if (contentHandler != null) { 582 contentHandler.ignorableWhitespace(ch, start, length); 583 } 584 } 585 586 587 595 public void processingInstruction (String target, String data) 596 throws SAXException 597 { 598 if (contentHandler != null) { 599 contentHandler.processingInstruction(target, data); 600 } 601 } 602 603 604 611 public void skippedEntity (String name) 612 throws SAXException 613 { 614 if (contentHandler != null) { 615 contentHandler.skippedEntity(name); 616 } 617 } 618 619 620 621 625 626 633 public void warning (SAXParseException e) 634 throws SAXException 635 { 636 if (errorHandler != null) { 637 errorHandler.warning(e); 638 } 639 } 640 641 642 649 public void error (SAXParseException e) 650 throws SAXException 651 { 652 if (errorHandler != null) { 653 errorHandler.error(e); 654 } 655 } 656 657 658 665 public void fatalError (SAXParseException e) 666 throws SAXException 667 { 668 if (errorHandler != null) { 669 errorHandler.fatalError(e); 670 } 671 } 672 673 674 675 679 680 687 private void setupParse () 688 { 689 if (parent == null) { 690 throw new NullPointerException ("No parent for filter"); 691 } 692 parent.setEntityResolver(this); 693 parent.setDTDHandler(this); 694 parent.setContentHandler(this); 695 parent.setErrorHandler(this); 696 } 697 698 699 700 704 private XMLReader parent = null; 705 private Locator locator = null; 706 private EntityResolver entityResolver = null; 707 private DTDHandler dtdHandler = null; 708 private ContentHandler contentHandler = null; 709 private ErrorHandler errorHandler = null; 710 711 } 712 713 | Popular Tags |