1 16 17 package sax; 18 19 import java.io.OutputStream ; 20 import java.io.OutputStreamWriter ; 21 import java.io.PrintWriter ; 22 import java.io.UnsupportedEncodingException ; 23 import java.io.Writer ; 24 25 import org.xml.sax.AttributeList ; 26 import org.xml.sax.Attributes ; 27 import org.xml.sax.ContentHandler ; 28 import org.xml.sax.DocumentHandler ; 29 import org.xml.sax.DTDHandler ; 30 import org.xml.sax.ErrorHandler ; 31 import org.xml.sax.Locator ; 32 import org.xml.sax.Parser ; 33 import org.xml.sax.SAXException ; 34 import org.xml.sax.SAXNotRecognizedException ; 35 import org.xml.sax.SAXNotSupportedException ; 36 import org.xml.sax.SAXParseException ; 37 import org.xml.sax.XMLReader ; 38 import org.xml.sax.helpers.DefaultHandler ; 39 import org.xml.sax.helpers.ParserAdapter ; 40 import org.xml.sax.helpers.ParserFactory ; 41 import org.xml.sax.helpers.XMLReaderFactory ; 42 import org.xml.sax.ext.DeclHandler ; 43 import org.xml.sax.ext.LexicalHandler ; 44 45 55 public class DocumentTracer 56 extends DefaultHandler 57 implements ContentHandler , DTDHandler , ErrorHandler , DeclHandler , LexicalHandler , DocumentHandler { 61 62 66 68 69 protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces"; 70 71 72 protected static final String NAMESPACE_PREFIXES_FEATURE_ID = "http://xml.org/sax/features/namespace-prefixes"; 73 74 75 protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation"; 76 77 78 protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema"; 79 80 81 protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking"; 82 83 84 protected static final String VALIDATE_ANNOTATIONS_ID = "http://apache.org/xml/features/validate-annotations"; 85 86 87 protected static final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic"; 88 89 90 protected static final String LOAD_EXTERNAL_DTD_FEATURE_ID = "http://apache.org/xml/features/nonvalidating/load-external-dtd"; 91 92 93 protected static final String XINCLUDE_FEATURE_ID = "http://apache.org/xml/features/xinclude"; 94 95 96 protected static final String XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID = "http://apache.org/xml/features/xinclude/fixup-base-uris"; 97 98 99 protected static final String XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID = "http://apache.org/xml/features/xinclude/fixup-language"; 100 101 103 104 protected static final String LEXICAL_HANDLER_PROPERTY_ID = "http://xml.org/sax/properties/lexical-handler"; 105 106 108 109 protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser"; 110 111 112 protected static final boolean DEFAULT_NAMESPACES = true; 113 114 115 protected static final boolean DEFAULT_NAMESPACE_PREFIXES = false; 116 117 118 protected static final boolean DEFAULT_VALIDATION = false; 119 120 121 protected static final boolean DEFAULT_LOAD_EXTERNAL_DTD = true; 122 123 124 protected static final boolean DEFAULT_SCHEMA_VALIDATION = false; 125 126 127 protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false; 128 129 130 protected static final boolean DEFAULT_VALIDATE_ANNOTATIONS = false; 131 132 133 protected static final boolean DEFAULT_DYNAMIC_VALIDATION = false; 134 135 136 protected static final boolean DEFAULT_XINCLUDE = false; 137 138 139 protected static final boolean DEFAULT_XINCLUDE_FIXUP_BASE_URIS = true; 140 141 142 protected static final boolean DEFAULT_XINCLUDE_FIXUP_LANGUAGE = true; 143 144 148 149 protected PrintWriter fOut; 150 151 152 protected int fIndent; 153 154 158 159 public DocumentTracer() { 160 setOutput(new PrintWriter (System.out)); 161 } 163 167 168 public void setOutput(OutputStream stream, String encoding) 169 throws UnsupportedEncodingException { 170 171 if (encoding == null) { 172 encoding = "UTF8"; 173 } 174 175 Writer writer = new OutputStreamWriter (stream, encoding); 176 fOut = new PrintWriter (writer); 177 178 } 180 181 public void setOutput(Writer writer) { 182 183 fOut = writer instanceof PrintWriter 184 ? (PrintWriter )writer : new PrintWriter (writer); 185 186 } 188 192 193 public void setDocumentLocator(Locator locator) { 194 195 printIndent(); 196 fOut.print("setDocumentLocator("); 197 fOut.print("locator="); 198 fOut.print(locator); 199 fOut.println(')'); 200 fOut.flush(); 201 202 } 204 205 public void startDocument() throws SAXException { 206 207 fIndent = 0; 208 printIndent(); 209 fOut.println("startDocument()"); 210 fOut.flush(); 211 fIndent++; 212 213 } 215 216 public void processingInstruction(String target, String data) 217 throws SAXException { 218 219 printIndent(); 220 fOut.print("processingInstruction("); 221 fOut.print("target="); 222 printQuotedString(target); 223 fOut.print(','); 224 fOut.print("data="); 225 printQuotedString(data); 226 fOut.println(')'); 227 fOut.flush(); 228 229 } 231 232 public void characters(char[] ch, int offset, int length) 233 throws SAXException { 234 235 printIndent(); 236 fOut.print("characters("); 237 fOut.print("text="); 238 printQuotedString(ch, offset, length); 239 fOut.println(')'); 240 fOut.flush(); 241 242 } 244 245 public void ignorableWhitespace(char[] ch, int offset, int length) 246 throws SAXException { 247 248 printIndent(); 249 fOut.print("ignorableWhitespace("); 250 fOut.print("text="); 251 printQuotedString(ch, offset, length); 252 fOut.println(')'); 253 fOut.flush(); 254 255 } 257 258 public void endDocument() throws SAXException { 259 260 fIndent--; 261 printIndent(); 262 fOut.println("endDocument()"); 263 fOut.flush(); 264 265 } 267 271 272 public void startPrefixMapping(String prefix, String uri) 273 throws SAXException { 274 275 printIndent(); 276 fOut.print("startPrefixMapping("); 277 fOut.print("prefix="); 278 printQuotedString(prefix); 279 fOut.print(','); 280 fOut.print("uri="); 281 printQuotedString(uri); 282 fOut.println(')'); 283 fOut.flush(); 284 285 } 287 288 public void startElement(String uri, String localName, String qname, 289 Attributes attributes) throws SAXException { 290 291 printIndent(); 292 fOut.print("startElement("); 293 fOut.print("uri="); 294 printQuotedString(uri); 295 fOut.print(','); 296 fOut.print("localName="); 297 printQuotedString(localName); 298 fOut.print(','); 299 fOut.print("qname="); 300 printQuotedString(qname); 301 fOut.print(','); 302 fOut.print("attributes="); 303 if (attributes == null) { 304 fOut.println("null"); 305 } 306 else { 307 fOut.print('{'); 308 int length = attributes.getLength(); 309 for (int i = 0; i < length; i++) { 310 if (i > 0) { 311 fOut.print(','); 312 } 313 String attrLocalName = attributes.getLocalName(i); 314 String attrQName = attributes.getQName(i); 315 String attrURI = attributes.getURI(i); 316 String attrType = attributes.getType(i); 317 String attrValue = attributes.getValue(i); 318 fOut.print('{'); 319 fOut.print("uri="); 320 printQuotedString(attrURI); 321 fOut.print(','); 322 fOut.print("localName="); 323 printQuotedString(attrLocalName); 324 fOut.print(','); 325 fOut.print("qname="); 326 printQuotedString(attrQName); 327 fOut.print(','); 328 fOut.print("type="); 329 printQuotedString(attrType); 330 fOut.print(','); 331 fOut.print("value="); 332 printQuotedString(attrValue); 333 fOut.print('}'); 334 } 335 fOut.print('}'); 336 } 337 fOut.println(')'); 338 fOut.flush(); 339 fIndent++; 340 341 } 343 344 public void endElement(String uri, String localName, String qname) 345 throws SAXException { 346 347 fIndent--; 348 printIndent(); 349 fOut.print("endElement("); 350 fOut.print("uri="); 351 printQuotedString(uri); 352 fOut.print(','); 353 fOut.print("localName="); 354 printQuotedString(localName); 355 fOut.print(','); 356 fOut.print("qname="); 357 printQuotedString(qname); 358 fOut.println(')'); 359 fOut.flush(); 360 361 } 363 364 public void endPrefixMapping(String prefix) throws SAXException { 365 366 printIndent(); 367 fOut.print("endPrefixMapping("); 368 fOut.print("prefix="); 369 printQuotedString(prefix); 370 fOut.println(')'); 371 fOut.flush(); 372 373 } 375 376 public void skippedEntity(String name) throws SAXException { 377 378 printIndent(); 379 fOut.print("skippedEntity("); 380 fOut.print("name="); 381 printQuotedString(name); 382 fOut.println(')'); 383 fOut.flush(); 384 385 } 387 391 392 public void startElement(String name, AttributeList attributes) 393 throws SAXException { 394 395 printIndent(); 396 fOut.print("startElement("); 397 fOut.print("name="); 398 printQuotedString(name); 399 fOut.print(','); 400 fOut.print("attributes="); 401 if (attributes == null) { 402 fOut.println("null"); 403 } 404 else { 405 fOut.print('{'); 406 int length = attributes.getLength(); 407 for (int i = 0; i < length; i++) { 408 if (i > 0) { 409 System.out.print(','); 410 } 411 String attrName = attributes.getName(i); 412 String attrType = attributes.getType(i); 413 String attrValue = attributes.getValue(i); 414 fOut.print('{'); 415 fOut.print("name="); 416 printQuotedString(attrName); 417 fOut.print(','); 418 fOut.print("type="); 419 printQuotedString(attrType); 420 fOut.print(','); 421 fOut.print("value="); 422 printQuotedString(attrValue); 423 fOut.print('}'); 424 } 425 fOut.print('}'); 426 } 427 fOut.println(')'); 428 fOut.flush(); 429 fIndent++; 430 431 } 433 434 public void endElement(String name) throws SAXException { 435 436 fIndent--; 437 printIndent(); 438 fOut.print("endElement("); 439 fOut.print("name="); 440 printQuotedString(name); 441 fOut.println(')'); 442 fOut.flush(); 443 444 } 446 450 451 public void notationDecl(String name, String publicId, String systemId) 452 throws SAXException { 453 454 printIndent(); 455 fOut.print("notationDecl("); 456 fOut.print("name="); 457 printQuotedString(name); 458 fOut.print(','); 459 fOut.print("publicId="); 460 printQuotedString(publicId); 461 fOut.print(','); 462 fOut.print("systemId="); 463 printQuotedString(systemId); 464 fOut.println(')'); 465 fOut.flush(); 466 467 } 469 470 public void unparsedEntityDecl(String name, 471 String publicId, String systemId, 472 String notationName) throws SAXException { 473 printIndent(); 474 fOut.print("unparsedEntityDecl("); 475 fOut.print("name="); 476 printQuotedString(name); 477 fOut.print(','); 478 fOut.print("publicId="); 479 printQuotedString(publicId); 480 fOut.print(','); 481 fOut.print("systemId="); 482 printQuotedString(systemId); 483 fOut.print(','); 484 fOut.print("notationName="); 485 printQuotedString(notationName); 486 fOut.println(')'); 487 fOut.flush(); 488 489 } 491 495 496 public void startDTD(String name, String publicId, String systemId) 497 throws SAXException { 498 499 printIndent(); 500 fOut.print("startDTD("); 501 fOut.print("name="); 502 printQuotedString(name); 503 fOut.print(','); 504 fOut.print("publicId="); 505 printQuotedString(publicId); 506 fOut.print(','); 507 fOut.print("systemId="); 508 printQuotedString(systemId); 509 fOut.println(')'); 510 fOut.flush(); 511 fIndent++; 512 513 } 515 516 public void startEntity(String name) throws SAXException { 517 518 printIndent(); 519 fOut.print("startEntity("); 520 fOut.print("name="); 521 printQuotedString(name); 522 fOut.println(')'); 523 fOut.flush(); 524 fIndent++; 525 526 } 528 529 public void startCDATA() throws SAXException { 530 531 printIndent(); 532 fOut.println("startCDATA()"); 533 fOut.flush(); 534 fIndent++; 535 536 } 538 539 public void endCDATA() throws SAXException { 540 541 fIndent--; 542 printIndent(); 543 fOut.println("endCDATA()"); 544 fOut.flush(); 545 546 } 548 549 public void comment(char[] ch, int offset, int length) 550 throws SAXException { 551 552 printIndent(); 553 fOut.print("comment("); 554 fOut.print("text="); 555 printQuotedString(ch, offset, length); 556 fOut.println(')'); 557 fOut.flush(); 558 559 } 561 562 public void endEntity(String name) throws SAXException { 563 564 fIndent--; 565 printIndent(); 566 fOut.print("endEntity("); 567 fOut.print("name="); 568 printQuotedString(name); 569 fOut.println(')'); 570 571 } 573 574 public void endDTD() throws SAXException { 575 576 fIndent--; 577 printIndent(); 578 fOut.println("endDTD()"); 579 fOut.flush(); 580 581 } 583 587 588 public void elementDecl(String name, String contentModel) 589 throws SAXException { 590 591 printIndent(); 592 fOut.print("elementDecl("); 593 fOut.print("name="); 594 printQuotedString(name); 595 fOut.print(','); 596 fOut.print("contentModel="); 597 printQuotedString(contentModel); 598 fOut.println(')'); 599 fOut.flush(); 600 601 } 603 604 public void attributeDecl(String elementName, String attributeName, 605 String type, String valueDefault, 606 String value) throws SAXException { 607 608 printIndent(); 609 fOut.print("attributeDecl("); 610 fOut.print("elementName="); 611 printQuotedString(elementName); 612 fOut.print(','); 613 fOut.print("attributeName="); 614 printQuotedString(attributeName); 615 fOut.print(','); 616 fOut.print("type="); 617 printQuotedString(type); 618 fOut.print(','); 619 fOut.print("valueDefault="); 620 printQuotedString(valueDefault); 621 fOut.print(','); 622 fOut.print("value="); 623 printQuotedString(value); 624 fOut.println(')'); 625 fOut.flush(); 626 627 } 629 630 public void internalEntityDecl(String name, String text) 631 throws SAXException { 632 633 printIndent(); 634 fOut.print("internalEntityDecl("); 635 fOut.print("name="); 636 printQuotedString(name); 637 fOut.print(','); 638 fOut.print("text="); 639 printQuotedString(text); 640 fOut.println(')'); 641 fOut.flush(); 642 643 } 645 646 public void externalEntityDecl(String name, 647 String publicId, String systemId) 648 throws SAXException { 649 650 printIndent(); 651 fOut.print("externalEntityDecl("); 652 fOut.print("name="); 653 printQuotedString(name); 654 fOut.print(','); 655 fOut.print("publicId="); 656 printQuotedString(publicId); 657 fOut.print(','); 658 fOut.print("systemId="); 659 printQuotedString(systemId); 660 fOut.println(')'); 661 fOut.flush(); 662 663 } 665 669 670 public void warning(SAXParseException ex) throws SAXException { 671 printError("Warning", ex); 672 } 674 675 public void error(SAXParseException ex) throws SAXException { 676 printError("Error", ex); 677 } 679 680 public void fatalError(SAXParseException ex) throws SAXException { 681 printError("Fatal Error", ex); 682 throw ex; 683 } 685 689 690 protected void printQuotedString(String s) { 691 692 if (s == null) { 693 fOut.print("null"); 694 return; 695 } 696 697 fOut.print('"'); 698 int length = s.length(); 699 for (int i = 0; i < length; i++) { 700 char c = s.charAt(i); 701 normalizeAndPrint(c); 702 } 703 fOut.print('"'); 704 705 } 707 708 protected void printQuotedString(char[] ch, int offset, int length) { 709 710 fOut.print('"'); 711 for (int i = 0; i < length; i++) { 712 normalizeAndPrint(ch[offset + i]); 713 } 714 fOut.print('"'); 715 716 } 718 719 protected void normalizeAndPrint(char c) { 720 721 switch (c) { 722 case '\n': { 723 fOut.print("\\n"); 724 break; 725 } 726 case '\r': { 727 fOut.print("\\r"); 728 break; 729 } 730 case '\t': { 731 fOut.print("\\t"); 732 break; 733 } 734 case '\\': { 735 fOut.print("\\\\"); 736 break; 737 } 738 case '"': { 739 fOut.print("\\\""); 740 break; 741 } 742 default: { 743 fOut.print(c); 744 } 745 } 746 747 } 749 750 protected void printError(String type, SAXParseException ex) { 751 752 System.err.print("["); 753 System.err.print(type); 754 System.err.print("] "); 755 String systemId = ex.getSystemId(); 756 if (systemId != null) { 757 int index = systemId.lastIndexOf('/'); 758 if (index != -1) 759 systemId = systemId.substring(index + 1); 760 System.err.print(systemId); 761 } 762 System.err.print(':'); 763 System.err.print(ex.getLineNumber()); 764 System.err.print(':'); 765 System.err.print(ex.getColumnNumber()); 766 System.err.print(": "); 767 System.err.print(ex.getMessage()); 768 System.err.println(); 769 System.err.flush(); 770 771 } 773 774 protected void printIndent() { 775 for (int i = 0; i < fIndent; i++) { 776 fOut.print(' '); 777 } 778 } 779 780 784 785 public static void main(String [] argv) throws Exception { 786 787 if (argv.length == 0) { 789 printUsage(); 790 System.exit(1); 791 } 792 793 DocumentTracer tracer = new DocumentTracer(); 795 PrintWriter out = new PrintWriter (System.out); 796 XMLReader parser = null; 797 boolean namespaces = DEFAULT_NAMESPACES; 798 boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES; 799 boolean validation = DEFAULT_VALIDATION; 800 boolean externalDTD = DEFAULT_LOAD_EXTERNAL_DTD; 801 boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION; 802 boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING; 803 boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS; 804 boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION; 805 boolean xincludeProcessing = DEFAULT_XINCLUDE; 806 boolean xincludeFixupBaseURIs = DEFAULT_XINCLUDE_FIXUP_BASE_URIS; 807 boolean xincludeFixupLanguage = DEFAULT_XINCLUDE_FIXUP_LANGUAGE; 808 809 for (int i = 0; i < argv.length; i++) { 811 String arg = argv[i]; 812 if (arg.startsWith("-")) { 813 String option = arg.substring(1); 814 if (option.equals("p")) { 815 if (++i == argv.length) { 817 System.err.println("error: Missing argument to -p option."); 818 } 819 String parserName = argv[i]; 820 821 try { 823 parser = XMLReaderFactory.createXMLReader(parserName); 824 } 825 catch (Exception e) { 826 try { 827 Parser sax1Parser = ParserFactory.makeParser(parserName); 828 parser = new ParserAdapter (sax1Parser); 829 System.err.println("warning: Features and properties not supported on SAX1 parsers."); 830 } 831 catch (Exception ex) { 832 parser = null; 833 System.err.println("error: Unable to instantiate parser ("+parserName+")"); 834 } 835 } 836 continue; 837 } 838 if (option.equalsIgnoreCase("n")) { 839 namespaces = option.equals("n"); 840 continue; 841 } 842 if (option.equalsIgnoreCase("np")) { 843 namespacePrefixes = option.equals("np"); 844 continue; 845 } 846 if (option.equalsIgnoreCase("v")) { 847 validation = option.equals("v"); 848 continue; 849 } 850 if (option.equalsIgnoreCase("xd")) { 851 externalDTD = option.equals("xd"); 852 continue; 853 } 854 if (option.equalsIgnoreCase("s")) { 855 schemaValidation = option.equals("s"); 856 continue; 857 } 858 if (option.equalsIgnoreCase("f")) { 859 schemaFullChecking = option.equals("f"); 860 continue; 861 } 862 if (option.equalsIgnoreCase("va")) { 863 validateAnnotations = option.equals("va"); 864 continue; 865 } 866 if (option.equalsIgnoreCase("dv")) { 867 dynamicValidation = option.equals("dv"); 868 continue; 869 } 870 if (option.equalsIgnoreCase("xi")) { 871 xincludeProcessing = option.equals("xi"); 872 continue; 873 } 874 if (option.equalsIgnoreCase("xb")) { 875 xincludeFixupBaseURIs = option.equals("xb"); 876 continue; 877 } 878 if (option.equalsIgnoreCase("xl")) { 879 xincludeFixupLanguage = option.equals("xl"); 880 continue; 881 } 882 if (option.equals("h")) { 883 printUsage(); 884 continue; 885 } 886 } 887 888 if (parser == null) { 890 891 try { 893 parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME); 894 } 895 catch (Exception e) { 896 System.err.println("error: Unable to instantiate parser ("+DEFAULT_PARSER_NAME+")"); 897 continue; 898 } 899 } 900 901 try { 903 parser.setFeature(NAMESPACES_FEATURE_ID, namespaces); 904 } 905 catch (SAXException e) { 906 System.err.println("warning: Parser does not support feature ("+NAMESPACES_FEATURE_ID+")"); 907 } 908 try { 909 parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes); 910 } 911 catch (SAXException e) { 912 System.err.println("warning: Parser does not support feature ("+NAMESPACE_PREFIXES_FEATURE_ID+")"); 913 } 914 try { 915 parser.setFeature(VALIDATION_FEATURE_ID, validation); 916 } 917 catch (SAXException e) { 918 System.err.println("warning: Parser does not support feature ("+VALIDATION_FEATURE_ID+")"); 919 } 920 try { 921 parser.setFeature(LOAD_EXTERNAL_DTD_FEATURE_ID, externalDTD); 922 } 923 catch (SAXNotRecognizedException e) { 924 System.err.println("warning: Parser does not recognize feature ("+LOAD_EXTERNAL_DTD_FEATURE_ID+")"); 925 } 926 catch (SAXNotSupportedException e) { 927 System.err.println("warning: Parser does not support feature ("+LOAD_EXTERNAL_DTD_FEATURE_ID+")"); 928 } 929 try { 930 parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation); 931 } 932 catch (SAXNotRecognizedException e) { 933 System.err.println("warning: Parser does not recognize feature ("+SCHEMA_VALIDATION_FEATURE_ID+")"); 934 } 935 catch (SAXNotSupportedException e) { 936 System.err.println("warning: Parser does not support feature ("+SCHEMA_VALIDATION_FEATURE_ID+")"); 937 } 938 try { 939 parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking); 940 } 941 catch (SAXNotRecognizedException e) { 942 System.err.println("warning: Parser does not recognize feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")"); 943 } 944 catch (SAXNotSupportedException e) { 945 System.err.println("warning: Parser does not support feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")"); 946 } 947 try { 948 parser.setFeature(VALIDATE_ANNOTATIONS_ID, validateAnnotations); 949 } 950 catch (SAXNotRecognizedException e) { 951 System.err.println("warning: Parser does not recognize feature ("+VALIDATE_ANNOTATIONS_ID+")"); 952 } 953 catch (SAXNotSupportedException e) { 954 System.err.println("warning: Parser does not support feature ("+VALIDATE_ANNOTATIONS_ID+")"); 955 } 956 try { 957 parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation); 958 } 959 catch (SAXNotRecognizedException e) { 960 System.err.println("warning: Parser does not recognize feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")"); 961 } 962 catch (SAXNotSupportedException e) { 963 System.err.println("warning: Parser does not support feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")"); 964 } 965 try { 966 parser.setFeature(XINCLUDE_FEATURE_ID, xincludeProcessing); 967 } 968 catch (SAXNotRecognizedException e) { 969 System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FEATURE_ID+")"); 970 } 971 catch (SAXNotSupportedException e) { 972 System.err.println("warning: Parser does not support feature ("+XINCLUDE_FEATURE_ID+")"); 973 } 974 try { 975 parser.setFeature(XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID, xincludeFixupBaseURIs); 976 } 977 catch (SAXNotRecognizedException e) { 978 System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID+")"); 979 } 980 catch (SAXNotSupportedException e) { 981 System.err.println("warning: Parser does not support feature ("+XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID+")"); 982 } 983 try { 984 parser.setFeature(XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID, xincludeFixupLanguage); 985 } 986 catch (SAXNotRecognizedException e) { 987 System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID+")"); 988 } 989 catch (SAXNotSupportedException e) { 990 System.err.println("warning: Parser does not support feature ("+XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID+")"); 991 } 992 993 parser.setDTDHandler(tracer); 995 parser.setErrorHandler(tracer); 996 if (parser instanceof XMLReader ) { 997 parser.setContentHandler(tracer); 998 try { 999 parser.setProperty("http://xml.org/sax/properties/declaration-handler", tracer); 1000 } 1001 catch (SAXException e) { 1002 e.printStackTrace(System.err); 1003 } 1004 try { 1005 parser.setProperty("http://xml.org/sax/properties/lexical-handler", tracer); 1006 } 1007 catch (SAXException e) { 1008 e.printStackTrace(System.err); 1009 } 1010 } 1011 else { 1012 ((Parser )parser).setDocumentHandler(tracer); 1013 } 1014 1015 try { 1017 parser.parse(arg); 1018 } 1019 catch (SAXParseException e) { 1020 } 1022 catch (Exception e) { 1023 System.err.println("error: Parse error occurred - "+e.getMessage()); 1024 if (e instanceof SAXException ) { 1025 Exception nested = ((SAXException )e).getException(); 1026 if (nested != null) { 1027 e = nested; 1028 } 1029 } 1030 e.printStackTrace(System.err); 1031 } 1032 } 1033 1034 } 1036 1040 1041 private static void printUsage() { 1042 1043 System.err.println("usage: java sax.DocumentTracer (options) uri ..."); 1044 System.err.println(); 1045 1046 System.err.println("options:"); 1047 System.err.println(" -p name Select parser by name."); 1048 System.err.println(" -n | -N Turn on/off namespace processing."); 1049 System.err.println(" -np | -NP Turn on/off namespace prefixes."); 1050 System.err.println(" NOTE: Requires use of -n."); 1051 System.err.println(" -v | -V Turn on/off validation."); 1052 System.err.println(" -xd | -XD Turn on/off loading of external DTDs."); 1053 System.err.println(" NOTE: Always on when -v in use and not supported by all parsers."); 1054 System.err.println(" -s | -S Turn on/off Schema validation support."); 1055 System.err.println(" NOTE: Not supported by all parsers."); 1056 System.err.println(" -f | -F Turn on/off Schema full checking."); 1057 System.err.println(" NOTE: Requires use of -s and not supported by all parsers."); 1058 System.err.println(" -va | -VA Turn on/off validation of schema annotations."); 1059 System.err.println(" NOTE: Requires use of -s and not supported by all parsers."); 1060 System.err.println(" -dv | -DV Turn on/off dynamic validation."); 1061 System.err.println(" NOTE: Not supported by all parsers."); 1062 System.err.println(" -xi | -XI Turn on/off XInclude processing."); 1063 System.err.println(" NOTE: Not supported by all parsers."); 1064 System.err.println(" -xb | -XB Turn on/off base URI fixup during XInclude processing."); 1065 System.err.println(" NOTE: Requires use of -xi and not supported by all parsers."); 1066 System.err.println(" -xl | -XL Turn on/off language fixup during XInclude processing."); 1067 System.err.println(" NOTE: Requires use of -xi and not supported by all parsers."); 1068 System.err.println(" -h This help screen."); 1069 System.err.println(); 1070 1071 System.err.println("defaults:"); 1072 System.err.println(" Parser: "+DEFAULT_PARSER_NAME); 1073 System.err.print(" Namespaces: "); 1074 System.err.println(DEFAULT_NAMESPACES ? "on" : "off"); 1075 System.err.print(" Prefixes: "); 1076 System.err.println(DEFAULT_NAMESPACE_PREFIXES ? "on" : "off"); 1077 System.err.print(" Validation: "); 1078 System.err.println(DEFAULT_VALIDATION ? "on" : "off"); 1079 System.err.print(" Load External DTD: "); 1080 System.err.println(DEFAULT_LOAD_EXTERNAL_DTD ? "on" : "off"); 1081 System.err.print(" Schema: "); 1082 System.err.println(DEFAULT_SCHEMA_VALIDATION ? "on" : "off"); 1083 System.err.print(" Schema full checking: "); 1084 System.err.println(DEFAULT_SCHEMA_FULL_CHECKING ? "on" : "off"); 1085 System.err.print(" Dynamic: "); 1086 System.err.println(DEFAULT_DYNAMIC_VALIDATION ? "on" : "off"); 1087 System.err.print(" XInclude: "); 1088 System.err.println(DEFAULT_XINCLUDE ? "on" : "off"); 1089 System.err.print(" XInclude base URI fixup: "); 1090 System.err.println(DEFAULT_XINCLUDE_FIXUP_BASE_URIS ? "on" : "off"); 1091 System.err.print(" XInclude language fixup: "); 1092 System.err.println(DEFAULT_XINCLUDE_FIXUP_LANGUAGE ? "on" : "off"); 1093 1094 } 1096} | Popular Tags |