1 54 package sax; 55 56 import java.io.IOException ; 57 58 import org.xml.sax.Attributes ; 59 import org.xml.sax.ContentHandler ; 60 import org.xml.sax.DTDHandler ; 61 import org.xml.sax.EntityResolver ; 62 import org.xml.sax.ErrorHandler ; 63 import org.xml.sax.InputSource ; 64 import org.xml.sax.Locator ; 65 import org.xml.sax.SAXException ; 66 import org.xml.sax.SAXParseException ; 67 import org.xml.sax.SAXNotSupportedException ; 68 import org.xml.sax.SAXNotRecognizedException ; 69 import org.xml.sax.XMLReader ; 70 import org.xml.sax.ext.LexicalHandler ; 71 import org.xml.sax.helpers.AttributesImpl ; 72 import org.xml.sax.helpers.DefaultHandler ; 73 74 75 80 public abstract class XMLReaderBase extends DefaultHandler 81 implements LexicalHandler , XMLReader 82 { 83 84 88 89 92 public XMLReaderBase () 93 { 94 } 95 96 97 101 102 116 public void startElement (String uri, String localName) 117 throws SAXException 118 { 119 startElement(uri, localName, "", EMPTY_ATTS); 120 } 121 122 123 138 public void startElement (String localName, Attributes atts) 139 throws SAXException 140 { 141 startElement("", localName, "", atts); 142 } 143 144 145 159 public void startElement (String localName) 160 throws SAXException 161 { 162 startElement("", localName, "", EMPTY_ATTS); 163 } 164 165 166 179 public void endElement (String uri, String localName) 180 throws SAXException 181 { 182 endElement(uri, localName, ""); 183 } 184 185 186 199 public void endElement (String localName) 200 throws SAXException 201 { 202 endElement("", localName, ""); 203 } 204 205 206 228 public void emptyElement (String uri, String localName, 229 String qName, Attributes atts) 230 throws SAXException 231 { 232 startElement(uri, localName, qName, atts); 233 endElement(uri, localName, qName); 234 } 235 236 237 251 public void emptyElement (String uri, String localName) 252 throws SAXException 253 { 254 emptyElement(uri, localName, "", EMPTY_ATTS); 255 } 256 257 258 273 public void emptyElement (String localName, Attributes atts) 274 throws SAXException 275 { 276 emptyElement("", localName, "", atts); 277 } 278 279 280 294 public void emptyElement (String localName) 295 throws SAXException 296 { 297 emptyElement("", localName, "", EMPTY_ATTS); 298 } 299 300 301 325 public void dataElement (String uri, String localName, 326 String qName, Attributes atts, 327 String content) 328 throws SAXException 329 { 330 startElement(uri, localName, qName, atts); 331 characters(content); 332 endElement(uri, localName, qName); 333 } 334 335 336 355 public void dataElement (String uri, String localName, String content) 356 throws SAXException 357 { 358 dataElement(uri, localName, "", EMPTY_ATTS, content); 359 } 360 361 362 381 public void dataElement (String localName, Attributes atts, String content) 382 throws SAXException 383 { 384 dataElement("", localName, "", atts, content); 385 } 386 387 388 408 public void dataElement (String localName, String content) 409 throws SAXException 410 { 411 dataElement("", localName, "", EMPTY_ATTS, content); 412 } 413 414 415 427 public void characters (String data) 428 throws SAXException 429 { 430 char ch[] = data.toCharArray(); 431 characters(ch, 0, ch.length); 432 } 433 434 435 436 440 441 455 public void setFeature (String name, boolean state) 456 throws SAXNotRecognizedException , SAXNotSupportedException 457 { 458 throw new SAXNotRecognizedException ("Feature: " + name); 459 } 460 461 462 476 public boolean getFeature (String name) 477 throws SAXNotRecognizedException , SAXNotSupportedException 478 { 479 throw new SAXNotRecognizedException ("Feature: " + name); 480 } 481 482 483 497 public void setProperty (String name, Object value) 498 throws SAXNotRecognizedException , SAXNotSupportedException 499 { 500 for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { 501 if (LEXICAL_HANDLER_NAMES[i].equals(name)) { 502 setLexicalHandler((LexicalHandler ) value); 503 return; 504 } 505 } 506 throw new SAXNotRecognizedException ("Property: " + name); 507 } 508 509 510 524 public Object getProperty (String name) 525 throws SAXNotRecognizedException , SAXNotSupportedException 526 { 527 for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { 528 if (LEXICAL_HANDLER_NAMES[i].equals(name)) { 529 return getLexicalHandler(); 530 } 531 } 532 throw new SAXNotRecognizedException ("Property: " + name); 533 } 534 535 536 547 public abstract void parse (InputSource input) 548 throws SAXException , IOException ; 549 550 551 562 public void parse (String systemId) 563 throws SAXException , IOException 564 { 565 parse(new InputSource (systemId)); 566 } 567 568 569 577 public void setEntityResolver (EntityResolver resolver) 578 { 579 if (resolver == null) { 580 throw new NullPointerException ("Null entity resolver"); 581 } else { 582 entityResolver = resolver; 583 } 584 } 585 586 587 593 public EntityResolver getEntityResolver () 594 { 595 return entityResolver; 596 } 597 598 599 607 public void setDTDHandler (DTDHandler handler) 608 { 609 if (handler == null) { 610 throw new NullPointerException ("Null DTD handler"); 611 } else { 612 dtdHandler = handler; 613 } 614 } 615 616 617 623 public DTDHandler getDTDHandler () 624 { 625 return dtdHandler; 626 } 627 628 629 637 public void setContentHandler (ContentHandler handler) 638 { 639 if (handler == null) { 640 throw new NullPointerException ("Null content handler"); 641 } else { 642 contentHandler = handler; 643 } 644 } 645 646 647 653 public ContentHandler getContentHandler () 654 { 655 return contentHandler; 656 } 657 658 659 667 public void setErrorHandler (ErrorHandler handler) 668 { 669 if (handler == null) { 670 throw new NullPointerException ("Null error handler"); 671 } else { 672 errorHandler = handler; 673 } 674 } 675 676 677 683 public ErrorHandler getErrorHandler () 684 { 685 return errorHandler; 686 } 687 688 689 690 694 695 702 public void setLexicalHandler (LexicalHandler handler) 703 { 704 if (handler == null) { 705 throw new NullPointerException ("Null lexical handler"); 706 } else { 707 lexicalHandler = handler; 708 } 709 } 710 711 712 717 public LexicalHandler getLexicalHandler () 718 { 719 return lexicalHandler; 720 } 721 722 723 724 728 729 742 public InputSource resolveEntity (String publicId, String systemId) 743 throws SAXException 744 { 745 if (entityResolver != null) { 746 try { 747 return entityResolver.resolveEntity(publicId, systemId); 748 } 749 catch (IOException ex) { 750 throw new SAXException (ex); 751 } 752 } else { 753 return null; 754 } 755 } 756 757 758 759 763 764 774 public void notationDecl (String name, String publicId, String systemId) 775 throws SAXException 776 { 777 if (dtdHandler != null) { 778 dtdHandler.notationDecl(name, publicId, systemId); 779 } 780 } 781 782 783 794 public void unparsedEntityDecl (String name, String publicId, 795 String systemId, String notationName) 796 throws SAXException 797 { 798 if (dtdHandler != null) { 799 dtdHandler.unparsedEntityDecl(name, publicId, systemId, 800 notationName); 801 } 802 } 803 804 805 806 810 811 817 public void setDocumentLocator (Locator locator) 818 { 819 this.locator = locator; 820 if (contentHandler != null) { 821 contentHandler.setDocumentLocator(locator); 822 } 823 } 824 825 826 833 public void startDocument () 834 throws SAXException 835 { 836 if (contentHandler != null) { 837 contentHandler.startDocument(); 838 } 839 } 840 841 842 849 public void endDocument () 850 throws SAXException 851 { 852 if (contentHandler != null) { 853 contentHandler.endDocument(); 854 } 855 } 856 857 858 867 public void startPrefixMapping (String prefix, String uri) 868 throws SAXException 869 { 870 if (contentHandler != null) { 871 contentHandler.startPrefixMapping(prefix, uri); 872 } 873 } 874 875 876 884 public void endPrefixMapping (String prefix) 885 throws SAXException 886 { 887 if (contentHandler != null) { 888 contentHandler.endPrefixMapping(prefix); 889 } 890 } 891 892 893 905 public void startElement (String uri, String localName, String qName, 906 Attributes atts) 907 throws SAXException 908 { 909 if (contentHandler != null) { 910 contentHandler.startElement(uri, localName, qName, atts); 911 } 912 } 913 914 915 926 public void endElement (String uri, String localName, String qName) 927 throws SAXException 928 { 929 if (contentHandler != null) { 930 contentHandler.endElement(uri, localName, qName); 931 } 932 } 933 934 935 945 public void characters (char ch[], int start, int length) 946 throws SAXException 947 { 948 if (contentHandler != null) { 949 contentHandler.characters(ch, start, length); 950 } 951 } 952 953 954 964 public void ignorableWhitespace (char ch[], int start, int length) 965 throws SAXException 966 { 967 if (contentHandler != null) { 968 contentHandler.ignorableWhitespace(ch, start, length); 969 } 970 } 971 972 973 982 public void processingInstruction (String target, String data) 983 throws SAXException 984 { 985 if (contentHandler != null) { 986 contentHandler.processingInstruction(target, data); 987 } 988 } 989 990 991 999 public void skippedEntity (String name) 1000 throws SAXException 1001 { 1002 if (contentHandler != null) { 1003 contentHandler.skippedEntity(name); 1004 } 1005 } 1006 1007 1008 1009 1013 1014 1022 public void warning (SAXParseException e) 1023 throws SAXException 1024 { 1025 if (errorHandler != null) { 1026 errorHandler.warning(e); 1027 } 1028 } 1029 1030 1031 1039 public void error (SAXParseException e) 1040 throws SAXException 1041 { 1042 if (errorHandler != null) { 1043 errorHandler.error(e); 1044 } 1045 } 1046 1047 1048 1056 public void fatalError (SAXParseException e) 1057 throws SAXException 1058 { 1059 if (errorHandler != null) { 1060 errorHandler.fatalError(e); 1061 } 1062 } 1063 1064 1065 1066 1070 1071 1083 public void startDTD(String name, String publicId, String systemId) 1084 throws SAXException { 1085 if (lexicalHandler != null) { 1086 lexicalHandler.startDTD(name, publicId, systemId); 1087 } 1088 } 1089 1090 1091 1098 public void endDTD() 1099 throws SAXException { 1100 if (lexicalHandler != null) { 1101 lexicalHandler.endDTD(); 1102 } 1103 } 1104 1105 1106 1116 public void startEntity(String name) 1117 throws SAXException { 1118 if (lexicalHandler != null) { 1119 lexicalHandler.startEntity(name); 1120 } 1121 } 1122 1123 1124 1132 public void endEntity(String name) 1133 throws SAXException { 1134 if (lexicalHandler != null) { 1135 lexicalHandler.endEntity(name); 1136 } 1137 } 1138 1139 1140 1147 public void startCDATA() 1148 throws SAXException { 1149 if (lexicalHandler != null) { 1150 lexicalHandler.startCDATA(); 1151 } 1152 } 1153 1154 1155 1162 public void endCDATA() 1163 throws SAXException { 1164 if (lexicalHandler != null) { 1165 lexicalHandler.endCDATA(); 1166 } 1167 } 1168 1169 1170 1180 public void comment(char[] ch, int start, int length) 1181 throws SAXException { 1182 if (lexicalHandler != null) { 1183 lexicalHandler.comment(ch, start, length); 1184 } 1185 } 1186 1187 1188 1189 1193 private Locator locator = null; 1194 private EntityResolver entityResolver = null; 1195 private DTDHandler dtdHandler = null; 1196 private ContentHandler contentHandler = null; 1197 private ErrorHandler errorHandler = null; 1198 private LexicalHandler lexicalHandler = null; 1199 1200 1201 1202 1206 1207 protected static final Attributes EMPTY_ATTS = new AttributesImpl (); 1208 1209 protected static final String [] LEXICAL_HANDLER_NAMES = { 1210 "http://xml.org/sax/properties/lexical-handler", 1211 "http://xml.org/sax/handlers/LexicalHandler" 1212 }; 1213 1214 1215} 1216 1217 | Popular Tags |