1 54 package sax; 55 56 import java.io.IOException ; 57 58 import org.xml.sax.Attributes ; 59 import org.xml.sax.InputSource ; 60 import org.xml.sax.SAXException ; 61 import org.xml.sax.SAXNotRecognizedException ; 62 import org.xml.sax.SAXNotSupportedException ; 63 import org.xml.sax.XMLReader ; 64 import org.xml.sax.ext.LexicalHandler ; 65 import org.xml.sax.helpers.AttributesImpl ; 66 import org.xml.sax.helpers.XMLFilterImpl ; 67 68 111 public class XMLFilterBase extends XMLFilterImpl implements LexicalHandler 112 { 113 114 115 119 120 130 public XMLFilterBase() 131 { 132 } 133 134 135 142 public XMLFilterBase(XMLReader parent) 143 { 144 super(parent); 145 } 146 147 148 149 153 154 168 public void startElement (String uri, String localName) 169 throws SAXException 170 { 171 startElement(uri, localName, "", EMPTY_ATTS); 172 } 173 174 175 190 public void startElement (String localName, Attributes atts) 191 throws SAXException 192 { 193 startElement("", localName, "", atts); 194 } 195 196 197 211 public void startElement (String localName) 212 throws SAXException 213 { 214 startElement("", localName, "", EMPTY_ATTS); 215 } 216 217 218 231 public void endElement (String uri, String localName) 232 throws SAXException 233 { 234 endElement(uri, localName, ""); 235 } 236 237 238 251 public void endElement (String localName) 252 throws SAXException 253 { 254 endElement("", localName, ""); 255 } 256 257 258 280 public void emptyElement (String uri, String localName, 281 String qName, Attributes atts) 282 throws SAXException 283 { 284 startElement(uri, localName, qName, atts); 285 endElement(uri, localName, qName); 286 } 287 288 289 303 public void emptyElement (String uri, String localName) 304 throws SAXException 305 { 306 emptyElement(uri, localName, "", EMPTY_ATTS); 307 } 308 309 310 325 public void emptyElement (String localName, Attributes atts) 326 throws SAXException 327 { 328 emptyElement("", localName, "", atts); 329 } 330 331 332 346 public void emptyElement (String localName) 347 throws SAXException 348 { 349 emptyElement("", localName, "", EMPTY_ATTS); 350 } 351 352 353 377 public void dataElement (String uri, String localName, 378 String qName, Attributes atts, 379 String content) 380 throws SAXException 381 { 382 startElement(uri, localName, qName, atts); 383 characters(content); 384 endElement(uri, localName, qName); 385 } 386 387 388 407 public void dataElement (String uri, String localName, String content) 408 throws SAXException 409 { 410 dataElement(uri, localName, "", EMPTY_ATTS, content); 411 } 412 413 414 433 public void dataElement (String localName, Attributes atts, String content) 434 throws SAXException 435 { 436 dataElement("", localName, "", atts, content); 437 } 438 439 440 460 public void dataElement (String localName, String content) 461 throws SAXException 462 { 463 dataElement("", localName, "", EMPTY_ATTS, content); 464 } 465 466 467 479 public void characters (String data) 480 throws SAXException 481 { 482 char ch[] = data.toCharArray(); 483 characters(ch, 0, ch.length); 484 } 485 486 487 488 492 493 507 public void setProperty (String name, Object value) 508 throws SAXNotRecognizedException , SAXNotSupportedException 509 { 510 for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { 511 if (LEXICAL_HANDLER_NAMES[i].equals(name)) { 512 setLexicalHandler((LexicalHandler ) value); 513 return; 514 } 515 } 516 super.setProperty(name, value); 517 } 518 519 520 532 public Object getProperty (String name) 533 throws SAXNotRecognizedException , SAXNotSupportedException 534 { 535 for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { 536 if (LEXICAL_HANDLER_NAMES[i].equals(name)) { 537 return getLexicalHandler(); 538 } 539 } 540 return super.getProperty(name); 541 } 542 543 544 555 public void parse (InputSource input) 556 throws SAXException , IOException 557 { 558 installLexicalHandler(); 559 super.parse(input); 560 } 561 562 563 564 568 569 576 public void setLexicalHandler (LexicalHandler handler) 577 { 578 if (handler == null) { 579 throw new NullPointerException ("Null lexical handler"); 580 } else { 581 lexicalHandler = handler; 582 } 583 } 584 585 586 591 public LexicalHandler getLexicalHandler () 592 { 593 return lexicalHandler; 594 } 595 596 597 598 602 603 615 public void startDTD(String name, String publicId, String systemId) 616 throws SAXException { 617 if (lexicalHandler != null) { 618 lexicalHandler.startDTD(name, publicId, systemId); 619 } 620 } 621 622 623 630 public void endDTD() 631 throws SAXException { 632 if (lexicalHandler != null) { 633 lexicalHandler.endDTD(); 634 } 635 } 636 637 638 648 public void startEntity(String name) 649 throws SAXException { 650 if (lexicalHandler != null) { 651 lexicalHandler.startEntity(name); 652 } 653 } 654 655 656 664 public void endEntity(String name) 665 throws SAXException { 666 if (lexicalHandler != null) { 667 lexicalHandler.endEntity(name); 668 } 669 } 670 671 672 679 public void startCDATA() 680 throws SAXException { 681 if (lexicalHandler != null) { 682 lexicalHandler.startCDATA(); 683 } 684 } 685 686 687 694 public void endCDATA() 695 throws SAXException { 696 if (lexicalHandler != null) { 697 lexicalHandler.endCDATA(); 698 } 699 } 700 701 702 712 public void comment(char[] ch, int start, int length) 713 throws SAXException { 714 if (lexicalHandler != null) { 715 lexicalHandler.comment(ch, start, length); 716 } 717 } 718 719 720 721 725 726 733 private void installLexicalHandler () 734 { 735 XMLReader parent = getParent(); 736 if (parent == null) { 737 throw new NullPointerException ("No parent for filter"); 738 } 739 for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { 741 try { 742 parent.setProperty(LEXICAL_HANDLER_NAMES[i], this); 743 break; 744 } 745 catch (SAXNotRecognizedException ex) { 746 } 748 catch (SAXNotSupportedException ex) { 749 } 751 } 752 } 753 754 755 756 760 761 private LexicalHandler lexicalHandler = null; 762 763 764 765 769 770 protected static final Attributes EMPTY_ATTS = new AttributesImpl (); 771 772 protected static final String [] LEXICAL_HANDLER_NAMES = { 773 "http://xml.org/sax/properties/lexical-handler", 774 "http://xml.org/sax/handlers/LexicalHandler" 775 }; 776 777 778 } 779 780 | Popular Tags |