1 57 58 59 package com.sun.org.apache.xerces.internal.parsers; 60 61 import java.io.StringReader ; 62 import java.util.Locale ; 63 import java.util.Stack ; 64 import java.util.StringTokenizer ; 65 import java.util.Vector ; 66 import java.util.Locale ; 67 68 import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl; 69 import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter; 70 import com.sun.org.apache.xerces.internal.dom.DOMStringListImpl; 71 import org.w3c.dom.DOMError ; 72 import com.sun.org.apache.xerces.internal.impl.Constants; 73 import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; 74 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper; 75 import com.sun.org.apache.xerces.internal.util.SymbolTable; 76 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 77 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 78 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 79 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 80 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; 81 import org.w3c.dom.DOMConfiguration ; 82 import org.w3c.dom.DOMErrorHandler ; 83 import org.w3c.dom.DOMException ; 84 import org.w3c.dom.Document ; 85 import org.w3c.dom.DOMStringList ; 86 import org.w3c.dom.Node ; 87 import org.w3c.dom.ls.LSException ; 88 import org.w3c.dom.ls.LSParser ; 89 import org.w3c.dom.ls.LSParserFilter ; 90 import org.w3c.dom.ls.LSResourceResolver ; 91 import org.w3c.dom.ls.LSInput ; 92 93 94 104 public class DOMParserImpl 105 extends AbstractDOMParser implements LSParser , DOMConfiguration { 106 107 108 109 111 112 protected static final String NAMESPACES = 113 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 114 115 116 protected static final String VALIDATION_FEATURE = 117 Constants.SAX_FEATURE_PREFIX+Constants.VALIDATION_FEATURE; 118 119 120 protected static final String XMLSCHEMA = 121 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 122 123 124 protected static final String DYNAMIC_VALIDATION = 125 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 126 127 128 protected static final String NORMALIZE_DATA = 129 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 130 131 132 protected static final String DISALLOW_DOCTYPE_DECL_FEATURE = 133 Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; 134 135 protected static final String SYMBOL_TABLE = 137 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 138 139 protected static final String PSVI_AUGMENT = 140 Constants.XERCES_FEATURE_PREFIX +Constants.SCHEMA_AUGMENT_PSVI; 141 Thread currentThread = null; 142 143 147 148 protected String fSchemaType = null; 151 152 protected boolean fBusy = false; 153 154 protected final static boolean DEBUG = false; 155 156 private Vector fSchemaLocations = new Vector (); 157 private String fSchemaLocation = null; 158 private DOMStringList fRecognizedParameters; 159 160 private boolean abortNow = false; 161 162 166 169 public DOMParserImpl (String configuration, String schemaType) { 170 this ( 171 (XMLParserConfiguration) ObjectFactory.createObject ( 172 "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", 173 configuration)); 174 if (schemaType != null) { 175 if (schemaType.equals (Constants.NS_DTD)) { 176 fConfiguration.setFeature ( 177 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, 178 false); 179 fConfiguration.setProperty ( 180 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 181 Constants.NS_DTD); 182 fSchemaType = Constants.NS_DTD; 183 } 184 else if (schemaType.equals (Constants.NS_XMLSCHEMA)) { 185 fConfiguration.setProperty ( 187 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 188 Constants.NS_XMLSCHEMA); 189 } 190 } 191 192 } 193 194 197 public DOMParserImpl (XMLParserConfiguration config) { 198 super (config); 199 200 final String [] domRecognizedFeatures = { 202 Constants.DOM_CANONICAL_FORM, 203 Constants.DOM_CDATA_SECTIONS, 204 Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING, 205 Constants.DOM_INFOSET, 206 Constants.DOM_NAMESPACE_DECLARATIONS, 207 Constants.DOM_SPLIT_CDATA, 208 Constants.DOM_SUPPORTED_MEDIATYPES_ONLY, 209 Constants.DOM_CERTIFIED, 210 Constants.DOM_WELLFORMED, 211 Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, 212 }; 213 214 215 fConfiguration.addRecognizedFeatures (domRecognizedFeatures); 216 217 fConfiguration.setFeature (DEFER_NODE_EXPANSION, false); 219 220 229 fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true); 230 fConfiguration.setFeature(Constants.DOM_WELLFORMED, true); 231 fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true); 232 fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true); 233 fConfiguration.setFeature(NAMESPACES, true); 234 235 fConfiguration.setFeature(DYNAMIC_VALIDATION, false); 236 fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false); 237 fConfiguration.setFeature(NORMALIZE_DATA, false); 238 fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false); 239 240 fConfiguration.setFeature (Constants.DOM_CANONICAL_FORM, false); 242 fConfiguration.setFeature (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING, true); 243 fConfiguration.setFeature (Constants.DOM_SPLIT_CDATA, true); 244 fConfiguration.setFeature (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY, false); 245 fConfiguration.setFeature (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, true); 246 247 fConfiguration.setFeature (Constants.DOM_CERTIFIED, true); 250 251 fConfiguration.setFeature( NORMALIZE_DATA, false ); 253 } 255 258 public DOMParserImpl(SymbolTable symbolTable) { 259 this( 260 (XMLParserConfiguration) ObjectFactory.createObject( 261 "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", 262 "com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration")); 263 fConfiguration.setProperty( 264 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY, 265 symbolTable); 266 } 268 269 273 public DOMParserImpl(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 274 this( 275 (XMLParserConfiguration) ObjectFactory.createObject( 276 "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", 277 "com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration")); 278 fConfiguration.setProperty( 279 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY, 280 symbolTable); 281 fConfiguration.setProperty( 282 Constants.XERCES_PROPERTY_PREFIX 283 + Constants.XMLGRAMMAR_POOL_PROPERTY, 284 grammarPool); 285 } 286 287 292 public void reset() { 293 super.reset(); 294 if (fSkippedElemStack!=null) { 296 fSkippedElemStack.removeAllElements(); 297 } 298 fSchemaLocations.clear(); 299 fRejectedElement.clear(); 300 fFilterReject = false; 301 fSchemaType = null; 302 303 } 305 309 public DOMConfiguration getDomConfig (){ 310 return this; 311 } 312 313 314 323 public LSParserFilter getFilter() { 324 return fDOMFilter; 325 } 326 327 336 public void setFilter(LSParserFilter filter) { 337 fDOMFilter = filter; 338 if (fSkippedElemStack == null) { 339 fSkippedElemStack = new Stack (); 340 } 341 } 342 343 346 public void setParameter (String name, Object value) throws DOMException { 347 if(value instanceof Boolean ){ 349 boolean state = ((Boolean )value).booleanValue (); 350 try { 351 if (name.equalsIgnoreCase (Constants.DOM_COMMENTS)) { 352 fConfiguration.setFeature (INCLUDE_COMMENTS_FEATURE, state); 353 } 354 else if (name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION)) { 355 fConfiguration.setFeature (NORMALIZE_DATA, state); 356 } 357 else if (name.equalsIgnoreCase (Constants.DOM_ENTITIES)) { 358 fConfiguration.setFeature (CREATE_ENTITY_REF_NODES, state); 359 } 360 else if (name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE)) { 361 fConfiguration.setFeature (DISALLOW_DOCTYPE_DECL_FEATURE, state); 362 } 363 else if (name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) 364 || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 365 || name.equalsIgnoreCase (Constants.DOM_CHECK_CHAR_NORMALIZATION) 366 || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM)) { 367 if (state) { String msg = 369 DOMMessageFormatter.formatMessage ( 370 DOMMessageFormatter.DOM_DOMAIN, 371 "FEATURE_NOT_SUPPORTED", 372 new Object [] { name }); 373 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 374 } 375 } 377 else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACES)) { 378 fConfiguration.setFeature (NAMESPACES, state); 379 } 380 else if (name.equalsIgnoreCase (Constants.DOM_INFOSET)) { 381 if (state) { 383 fConfiguration.setFeature(NAMESPACES, true); 385 fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true); 386 fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true); 387 388 fConfiguration.setFeature(DYNAMIC_VALIDATION, false); 391 fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false); 392 fConfiguration.setFeature(NORMALIZE_DATA, false); 393 fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false); 394 } 395 } 396 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 397 fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state); 398 } 399 else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACE_DECLARATIONS) 400 || name.equalsIgnoreCase (Constants.DOM_WELLFORMED) 401 || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) { 402 if (!state) { String msg = 404 DOMMessageFormatter.formatMessage ( 405 DOMMessageFormatter.DOM_DOMAIN, 406 "FEATURE_NOT_SUPPORTED", 407 new Object [] { name }); 408 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 409 } 410 } 413 else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE)) { 414 fConfiguration.setFeature (VALIDATION_FEATURE, state); 415 if (fSchemaType != Constants.NS_DTD) { 416 fConfiguration.setFeature (XMLSCHEMA, state); 417 } 418 if (state){ 419 fConfiguration.setFeature (DYNAMIC_VALIDATION, false); 420 } 421 } 422 else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA)) { 423 fConfiguration.setFeature (DYNAMIC_VALIDATION, state); 424 if (state){ 426 fConfiguration.setFeature(VALIDATION_FEATURE, false); 427 } 428 } 429 else if (name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 430 fConfiguration.setFeature (INCLUDE_IGNORABLE_WHITESPACE, state); 431 } 432 else if (name.equalsIgnoreCase (Constants.DOM_PSVI)){ 433 fConfiguration.setFeature(PSVI_AUGMENT, true); 435 fConfiguration.setProperty(DOCUMENT_CLASS_NAME, 436 "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl"); 437 } 438 else { 439 fConfiguration.setFeature (name.toLowerCase(Locale.ENGLISH), state); 443 } 444 445 } 446 catch (XMLConfigurationException e) { 447 String msg = 448 DOMMessageFormatter.formatMessage ( 449 DOMMessageFormatter.DOM_DOMAIN, 450 "FEATURE_NOT_FOUND", 451 new Object [] { name }); 452 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 453 } 454 } 455 else { if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) { 457 if (value instanceof DOMErrorHandler || value == null) { 458 try { 459 fErrorHandler = new DOMErrorHandlerWrapper ((DOMErrorHandler ) value); 460 fConfiguration.setProperty (ERROR_HANDLER, fErrorHandler); 461 } 462 catch (XMLConfigurationException e) {} 463 } 464 else { 465 String msg = 467 DOMMessageFormatter.formatMessage ( 468 DOMMessageFormatter.DOM_DOMAIN, 469 "TYPE_MISMATCH_ERR", 470 new Object [] { name }); 471 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 472 } 473 474 } 475 else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) { 476 if (value instanceof LSResourceResolver || value == null) { 477 try { 478 fConfiguration.setProperty (ENTITY_RESOLVER, new DOMEntityResolverWrapper ((LSResourceResolver ) value)); 479 } 480 catch (XMLConfigurationException e) {} 481 } 482 else { 483 String msg = 485 DOMMessageFormatter.formatMessage ( 486 DOMMessageFormatter.DOM_DOMAIN, 487 "TYPE_MISMATCH_ERR", 488 new Object [] { name }); 489 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 490 } 491 492 } 493 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) { 494 if (value instanceof String || value == null) { 495 try { 496 if (value == null) { 497 fConfiguration.setProperty ( 498 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, 499 null); 500 } 501 else if (fSchemaType == Constants.NS_XMLSCHEMA) { 502 fSchemaLocation = (String )value; 503 StringTokenizer t = new StringTokenizer (fSchemaLocation, " \n\t\r"); 506 if (t.hasMoreTokens ()){ 507 fSchemaLocations.clear (); 508 fSchemaLocations.add (t.nextToken ()); 509 while (t.hasMoreTokens ()) { 510 fSchemaLocations.add (t.nextToken ()); 511 } 512 fConfiguration.setProperty ( 513 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, 514 fSchemaLocations.toArray ()); 515 } 516 else { 517 fConfiguration.setProperty ( 518 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, 519 value); 520 } 521 } 522 else { 523 String msg = 525 DOMMessageFormatter.formatMessage ( 526 DOMMessageFormatter.DOM_DOMAIN, 527 "FEATURE_NOT_SUPPORTED", 528 new Object [] { name }); 529 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 530 } 531 532 } 533 catch (XMLConfigurationException e) {} 534 } 535 else { 536 String msg = 538 DOMMessageFormatter.formatMessage ( 539 DOMMessageFormatter.DOM_DOMAIN, 540 "TYPE_MISMATCH_ERR", 541 new Object [] { name }); 542 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 543 } 544 545 } 546 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) { 547 if (value instanceof String || value == null) { 548 try { 549 if (value == null) { 550 fConfiguration.setFeature ( 552 Constants.XERCES_FEATURE_PREFIX 553 + Constants.SCHEMA_VALIDATION_FEATURE, 554 false); 555 fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX 557 + Constants.SCHEMA_LANGUAGE, 558 null); 559 fSchemaType = null; 560 } 561 else if (value.equals (Constants.NS_XMLSCHEMA)) { 562 fConfiguration.setFeature (Constants.XERCES_FEATURE_PREFIX 564 + Constants.SCHEMA_VALIDATION_FEATURE, 565 true); 566 fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX 568 + Constants.SCHEMA_LANGUAGE, 569 Constants.NS_XMLSCHEMA); 570 fSchemaType = Constants.NS_XMLSCHEMA; 571 } 572 else if (value.equals (Constants.NS_DTD)) { 573 fConfiguration.setFeature ( 575 Constants.XERCES_FEATURE_PREFIX 576 + Constants.SCHEMA_VALIDATION_FEATURE, 577 false); 578 fConfiguration.setProperty ( Constants.JAXP_PROPERTY_PREFIX 580 + Constants.SCHEMA_LANGUAGE, 581 Constants.NS_DTD); 582 fSchemaType = Constants.NS_DTD; 583 } 584 } 585 catch (XMLConfigurationException e) {} 586 } 587 else { 588 String msg = 589 DOMMessageFormatter.formatMessage ( 590 DOMMessageFormatter.DOM_DOMAIN, 591 "TYPE_MISMATCH_ERR", 592 new Object [] { name }); 593 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 594 } 595 596 } 597 else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)) { 598 fConfiguration.setProperty (DOCUMENT_CLASS_NAME, value); 599 } 600 else { 601 String msg = 604 DOMMessageFormatter.formatMessage ( 605 DOMMessageFormatter.DOM_DOMAIN, 606 "FEATURE_NOT_FOUND", 607 new Object [] { name }); 608 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 609 } 610 } 611 } 612 613 616 public Object getParameter (String name) throws DOMException { 617 if (name.equalsIgnoreCase (Constants.DOM_COMMENTS)) { 618 return (fConfiguration.getFeature (INCLUDE_COMMENTS_FEATURE)) 619 ? Boolean.TRUE 620 : Boolean.FALSE; 621 } 622 else if (name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION)) { 623 return (fConfiguration.getFeature (NORMALIZE_DATA)) 624 ? Boolean.TRUE 625 : Boolean.FALSE; 626 } 627 else if (name.equalsIgnoreCase (Constants.DOM_ENTITIES)) { 628 return (fConfiguration.getFeature (CREATE_ENTITY_REF_NODES)) 629 ? Boolean.TRUE 630 : Boolean.FALSE; 631 } 632 else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACES)) { 633 return (fConfiguration.getFeature (NAMESPACES)) 634 ? Boolean.TRUE 635 : Boolean.FALSE; 636 } 637 else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE)) { 638 return (fConfiguration.getFeature (VALIDATION_FEATURE)) 639 ? Boolean.TRUE 640 : Boolean.FALSE; 641 } 642 else if (name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA)) { 643 return (fConfiguration.getFeature (DYNAMIC_VALIDATION)) 644 ? Boolean.TRUE 645 : Boolean.FALSE; 646 } 647 else if (name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 648 return (fConfiguration.getFeature (INCLUDE_IGNORABLE_WHITESPACE)) 649 ? Boolean.TRUE 650 : Boolean.FALSE; 651 } 652 else if (name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE)) { 653 return (fConfiguration.getFeature (DISALLOW_DOCTYPE_DECL_FEATURE)) 654 ? Boolean.TRUE 655 : Boolean.FALSE; 656 } 657 else if (name.equalsIgnoreCase (Constants.DOM_INFOSET)) { 658 boolean infoset = fConfiguration.getFeature(NAMESPACES) && 663 fConfiguration.getFeature(INCLUDE_COMMENTS_FEATURE) && 664 fConfiguration.getFeature(INCLUDE_IGNORABLE_WHITESPACE) && 665 !fConfiguration.getFeature(DYNAMIC_VALIDATION) && 666 !fConfiguration.getFeature(CREATE_ENTITY_REF_NODES) && 667 !fConfiguration.getFeature(NORMALIZE_DATA) && 668 !fConfiguration.getFeature(CREATE_CDATA_NODES_FEATURE); 669 return (infoset) ? Boolean.TRUE : Boolean.FALSE; 670 } 671 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 672 return (fConfiguration.getFeature(CREATE_CDATA_NODES_FEATURE)) 673 ? Boolean.TRUE : Boolean.FALSE; 674 } 675 else if (name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION ) || 676 name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)){ 677 return Boolean.FALSE; 678 } 679 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) 680 || name.equalsIgnoreCase (Constants.DOM_WELLFORMED) 681 || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS) 682 || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM) 683 || name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) 684 || name.equalsIgnoreCase (Constants.DOM_SPLIT_CDATA) 685 || name.equalsIgnoreCase (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING)) { 686 return (fConfiguration.getFeature (name.toLowerCase(Locale.ENGLISH))) 687 ? Boolean.TRUE 688 : Boolean.FALSE; 689 } 690 else if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) { 691 if (fErrorHandler != null) { 692 return fErrorHandler.getErrorHandler (); 693 } 694 return null; 695 } 696 else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) { 697 try { 698 XMLEntityResolver entityResolver = 699 (XMLEntityResolver) fConfiguration.getProperty (ENTITY_RESOLVER); 700 if (entityResolver != null 701 && entityResolver instanceof DOMEntityResolverWrapper) { 702 return ((DOMEntityResolverWrapper) entityResolver).getEntityResolver (); 703 } 704 return null; 705 } 706 catch (XMLConfigurationException e) {} 707 } 708 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) { 709 return fConfiguration.getProperty ( 710 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); 711 } 712 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) { 713 return fSchemaLocation; 714 } 715 else if (name.equalsIgnoreCase (SYMBOL_TABLE)){ 716 return fConfiguration.getProperty (SYMBOL_TABLE); 717 } 718 else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)) { 719 return fConfiguration.getProperty (DOCUMENT_CLASS_NAME); 720 } 721 else { 722 String msg = 723 DOMMessageFormatter.formatMessage ( 724 DOMMessageFormatter.DOM_DOMAIN, 725 "FEATURE_NOT_FOUND", 726 new Object [] { name }); 727 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 728 } 729 return null; 730 } 731 732 public boolean canSetParameter (String name, Object value) { 733 if(value instanceof Boolean ){ 734 boolean state = ((Boolean )value).booleanValue (); 735 if ( name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) 736 || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 737 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION ) 738 || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM) ) { 739 return (state) ? false : true; 741 } 742 else if (name.equalsIgnoreCase (Constants.DOM_NAMESPACE_DECLARATIONS) 743 || name.equalsIgnoreCase (Constants.DOM_WELLFORMED) 744 || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) { 745 return (state) ? true : false; 747 } 748 else if (name.equalsIgnoreCase (Constants.DOM_CDATA_SECTIONS) 749 || name.equalsIgnoreCase (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING) 750 || name.equalsIgnoreCase (Constants.DOM_COMMENTS) 751 || name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION) 752 || name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE) 753 || name.equalsIgnoreCase (Constants.DOM_ENTITIES) 754 || name.equalsIgnoreCase (Constants.DOM_INFOSET) 755 || name.equalsIgnoreCase (Constants.DOM_NAMESPACES) 756 || name.equalsIgnoreCase (Constants.DOM_VALIDATE) 757 || name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA) 758 || name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE) 759 || name.equalsIgnoreCase (Constants.DOM_XMLDECL)) { 760 return true; 761 } 762 763 try { 765 fConfiguration.getFeature(name.toLowerCase(Locale.ENGLISH)); 766 return true; 767 } 768 catch (XMLConfigurationException e) { 769 return false; 770 } 771 } 772 else { if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) { 774 if (value instanceof DOMErrorHandler || value == null) { 775 return true; 776 } 777 return false; 778 } 779 else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) { 780 if (value instanceof LSResourceResolver || value == null) { 781 return true; 782 } 783 return false; 784 } 785 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) { 786 if ((value instanceof String 787 && (value.equals (Constants.NS_XMLSCHEMA) 788 || value.equals (Constants.NS_DTD))) || value == null) { 789 return true; 790 } 791 return false; 792 } 793 else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) { 794 if (value instanceof String || value == null) 795 return true; 796 return false; 797 } 798 else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)){ 799 return true; 800 } 801 return false; 802 } 803 } 804 805 813 public DOMStringList getParameterNames () { 814 if (fRecognizedParameters == null){ 815 Vector parameters = new Vector (); 816 817 parameters.add(Constants.DOM_NAMESPACES); 819 parameters.add(Constants.DOM_CDATA_SECTIONS); 820 parameters.add(Constants.DOM_CANONICAL_FORM); 821 parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS); 822 parameters.add(Constants.DOM_SPLIT_CDATA); 823 824 parameters.add(Constants.DOM_ENTITIES); 825 parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA); 826 parameters.add(Constants.DOM_VALIDATE); 827 parameters.add(Constants.DOM_DATATYPE_NORMALIZATION); 828 829 parameters.add(Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING); 830 parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION); 831 parameters.add(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY); 832 parameters.add(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS); 833 834 parameters.add(Constants.DOM_NORMALIZE_CHARACTERS); 835 parameters.add(Constants.DOM_WELLFORMED); 836 parameters.add(Constants.DOM_INFOSET); 837 parameters.add(Constants.DOM_DISALLOW_DOCTYPE); 838 parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE); 839 parameters.add(Constants.DOM_COMMENTS); 840 841 parameters.add(Constants.DOM_ERROR_HANDLER); 842 parameters.add(Constants.DOM_RESOURCE_RESOLVER); 843 parameters.add(Constants.DOM_SCHEMA_LOCATION); 844 parameters.add(Constants.DOM_SCHEMA_TYPE); 845 846 fRecognizedParameters = new DOMStringListImpl(parameters); 847 848 } 849 850 return fRecognizedParameters; 851 } 852 853 859 public Document parseURI (String uri) throws LSException { 860 861 if ( fBusy ) { 864 String msg = DOMMessageFormatter.formatMessage ( 865 DOMMessageFormatter.DOM_DOMAIN, 866 "INVALID_STATE_ERR",null); 867 throw new DOMException ( DOMException.INVALID_STATE_ERR,msg); 868 } 869 870 XMLInputSource source = new XMLInputSource (null, uri, null); 871 try { 872 if(!fBusy)currentThread = Thread.currentThread(); 875 fBusy = true; 876 parse (source); 877 fBusy = false; 878 if(abortNow && currentThread.isInterrupted()) 879 { 880 abortNow = false; 882 currentThread.interrupted(); 883 } 884 } catch (Exception e){ 885 fBusy = false; 886 if(abortNow && currentThread.isInterrupted()) 889 { 890 currentThread.interrupted(); 892 } 893 894 if(abortNow){ 895 abortNow = false; 896 return null; 897 } 898 if (e != abort) { 899 if (fErrorHandler != null) { 900 DOMErrorImpl error = new DOMErrorImpl (); 901 error.fException = e; 902 error.fMessage = e.getMessage (); 903 error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; 904 fErrorHandler.getErrorHandler ().handleError (error); 905 } 906 if (DEBUG) { 907 e.printStackTrace (); 908 } 909 throw new LSException (LSException.PARSE_ERR, e.getMessage()); 910 } 911 } 912 return getDocument (); 913 } 914 915 920 public Document parse (LSInput is) throws LSException { 921 922 XMLInputSource xmlInputSource = dom2xmlInputSource (is); 924 if ( fBusy ) { 925 String msg = DOMMessageFormatter.formatMessage ( 926 DOMMessageFormatter.DOM_DOMAIN, 927 "INVALID_STATE_ERR",null); 928 throw new DOMException ( DOMException.INVALID_STATE_ERR,msg); 929 } 930 931 try { 932 if(!fBusy)currentThread = Thread.currentThread(); 935 fBusy = true; 936 parse(xmlInputSource); 937 fBusy = false; 938 if(abortNow && currentThread.isInterrupted()) 939 { 940 abortNow = false; 942 currentThread.interrupted(); 943 } 944 } catch (Exception e) { 945 fBusy = false; 946 if(abortNow && currentThread.isInterrupted()) 949 { 950 currentThread.interrupted(); 952 } 953 if(abortNow){ 954 abortNow = false; 955 return null; 956 } 957 if (e != abort) { 958 if (fErrorHandler != null) { 959 DOMErrorImpl error = new DOMErrorImpl (); 960 error.fException = e; 961 error.fMessage = e.getMessage (); 962 error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; 963 fErrorHandler.getErrorHandler().handleError (error); 964 } 965 if (DEBUG) { 966 e.printStackTrace (); 967 } 968 throw new LSException (LSException.PARSE_ERR, e.getMessage()); 969 } 970 } 971 return getDocument (); 972 } 973 974 993 public Node parseWithContext (LSInput is, Node cnode, 994 short action) throws DOMException , LSException { 995 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, "Not supported"); 997 } 998 999 1000 1006 XMLInputSource dom2xmlInputSource(LSInput is) { 1007 XMLInputSource xis = null; 1009 if (is.getCharacterStream () != null) { 1012 xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), 1013 is.getBaseURI (), is.getCharacterStream (), 1014 "UTF-16"); 1015 } 1016 else if (is.getByteStream () != null) { 1018 xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), 1019 is.getBaseURI (), is.getByteStream (), 1020 is.getEncoding ()); 1021 } 1022 else if (is.getStringData () != null && is.getStringData().length() > 0) { 1025 xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), 1026 is.getBaseURI (), new StringReader (is.getStringData ()), 1027 "UTF-16"); 1028 } 1029 else if ((is.getSystemId() != null && is.getSystemId().length() > 0) || 1031 (is.getPublicId() != null && is.getPublicId().length() > 0)) { 1032 xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), 1033 is.getBaseURI ()); 1034 } 1035 else { 1036 if (fErrorHandler != null) { 1038 DOMErrorImpl error = new DOMErrorImpl(); 1039 error.fType = "no-input-specified"; 1040 error.fMessage = "no-input-specified"; 1041 error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; 1042 fErrorHandler.getErrorHandler().handleError(error); 1043 } 1044 throw new LSException (LSException.PARSE_ERR, "no-input-specified"); 1045 } 1046 return xis; 1047 } 1048 1049 1052 public boolean getAsync () { 1053 return false; 1054 } 1055 1056 1059 public boolean getBusy () { 1060 return fBusy; 1061 } 1062 1063 1066 public void abort () { 1067 if ( fBusy ) { 1069 fBusy = false; 1070 abortNow = true; 1071 try{ 1072 1076 reset(); 1077 1078 if(currentThread != null )currentThread.interrupt(); 1082 }catch(Exception ex){ 1083 } 1084 } 1085 return; } 1087 1088} | Popular Tags |