1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 import java.io.IOException ; 61 import java.util.ArrayList ; 62 import java.util.HashMap ; 63 import java.util.Locale ; 64 import java.util.Vector ; 65 66 import org.w3c.dom.DOMConfiguration ; 67 import org.w3c.dom.DOMErrorHandler ; 68 import org.w3c.dom.DOMStringList ; 69 70 import com.sun.org.apache.xerces.internal.impl.Constants; 71 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; 72 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 73 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 74 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 75 import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; 76 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper; 77 import com.sun.org.apache.xerces.internal.util.MessageFormatter; 78 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; 79 import com.sun.org.apache.xerces.internal.util.SymbolTable; 80 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 81 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 82 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 83 import com.sun.org.apache.xerces.internal.xni.XNIException; 84 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 85 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 86 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 87 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 88 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 89 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 90 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 91 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; 92 import org.w3c.dom.DOMException ; 93 import org.w3c.dom.ls.LSResourceResolver ; 94 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; 95 96 97 104 public class DOMConfigurationImpl extends ParserConfigurationSettings 105 implements XMLParserConfiguration, DOMConfiguration { 106 107 111 113 114 protected static final String XERCES_VALIDATION = 115 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 116 117 118 protected static final String XERCES_NAMESPACES = 119 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 120 121 protected static final String SCHEMA = 122 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 123 124 protected static final String DYNAMIC_VALIDATION = 125 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 126 127 protected static final String NORMALIZE_DATA = 128 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 129 protected static final String DATATYPE_VALIDATOR_FACTORY = 130 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 131 132 133 protected static final String SEND_PSVI = 134 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 135 136 137 139 140 protected static final String ENTITY_MANAGER = 141 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 142 143 144 protected static final String ERROR_REPORTER = 145 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 146 147 148 protected static final String XML_STRING = 149 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 150 151 152 protected static final String SYMBOL_TABLE = 153 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 154 155 156 protected static final String GRAMMAR_POOL = 157 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 158 159 160 protected static final String ERROR_HANDLER = 161 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 162 163 164 protected static final String ENTITY_RESOLVER = 165 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 166 167 168 protected static final String JAXP_SCHEMA_LANGUAGE = 169 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 170 171 172 protected static final String JAXP_SCHEMA_SOURCE = 173 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 174 175 protected static final String VALIDATION_MANAGER = 176 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 177 XMLDocumentHandler fDocumentHandler; 181 182 183 protected short features = 0; 184 185 protected final static short NAMESPACES = 0x1<<0; 186 protected final static short DTNORMALIZATION = 0x1<<1; 187 protected final static short ENTITIES = 0x1<<2; 188 protected final static short CDATA = 0x1<<3; 189 protected final static short SPLITCDATA = 0x1<<4; 190 protected final static short COMMENTS = 0x1<<5; 191 protected final static short VALIDATE = 0x1<<6; 192 protected final static short PSVI = 0x1<<7; 193 protected final static short WELLFORMED = 0x1<<8; 194 195 protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED; 196 protected final static short INFOSET_FALSE_PARAMS = ENTITIES | DTNORMALIZATION | CDATA; 197 protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS | INFOSET_FALSE_PARAMS; 198 199 201 202 protected SymbolTable fSymbolTable; 203 204 protected DTDDVFactory fDatatypeValidatorFactory; 205 206 protected ArrayList fComponents; 207 208 protected ValidationManager fValidationManager; 209 210 211 protected Locale fLocale; 212 213 214 protected XMLErrorReporter fErrorReporter; 215 216 protected final DOMErrorHandlerWrapper fErrorHandlerWrapper = 217 new DOMErrorHandlerWrapper(); 218 219 221 private DOMStringList fRecognizedParameters; 222 223 224 228 229 protected DOMConfigurationImpl() { 230 this(null, null); 231 } 233 238 protected DOMConfigurationImpl(SymbolTable symbolTable) { 239 this(symbolTable, null); 240 } 242 249 protected DOMConfigurationImpl(SymbolTable symbolTable, 250 XMLComponentManager parentSettings) { 251 super(parentSettings); 252 253 fRecognizedFeatures = new ArrayList (); 255 fRecognizedProperties = new ArrayList (); 256 257 fFeatures = new HashMap (); 259 fProperties = new HashMap (); 260 261 final String [] recognizedFeatures = { 263 XERCES_VALIDATION, 264 XERCES_NAMESPACES, 265 SCHEMA, 266 DYNAMIC_VALIDATION, 267 NORMALIZE_DATA, 268 SEND_PSVI, 269 }; 270 addRecognizedFeatures(recognizedFeatures); 271 272 setFeature(XERCES_VALIDATION, false); 274 setFeature(SCHEMA, false); 275 setFeature(DYNAMIC_VALIDATION, false); 276 setFeature(NORMALIZE_DATA, false); 277 setFeature(XERCES_NAMESPACES, true); 278 setFeature(SEND_PSVI, true); 279 280 final String [] recognizedProperties = { 282 XML_STRING, 283 SYMBOL_TABLE, 284 ERROR_HANDLER, 285 ENTITY_RESOLVER, 286 ERROR_REPORTER, 287 ENTITY_MANAGER, 288 VALIDATION_MANAGER, 289 DATATYPE_VALIDATOR_FACTORY, 290 GRAMMAR_POOL, 291 JAXP_SCHEMA_SOURCE, 292 JAXP_SCHEMA_LANGUAGE 293 }; 294 addRecognizedProperties(recognizedProperties); 295 296 features |= NAMESPACES; 298 features |= ENTITIES; 299 features |= COMMENTS; 300 features |= CDATA; 301 features |= SPLITCDATA; 302 features |= WELLFORMED; 303 304 if (symbolTable == null) { 305 symbolTable = new SymbolTable(); 306 } 307 fSymbolTable = symbolTable; 308 309 fComponents = new ArrayList (); 310 311 setProperty(SYMBOL_TABLE, fSymbolTable); 312 fErrorReporter = new XMLErrorReporter(); 313 setProperty(ERROR_REPORTER, fErrorReporter); 314 addComponent(fErrorReporter); 315 316 XMLEntityManager manager = new XMLEntityManager(); 317 setProperty(ENTITY_MANAGER, manager); 318 addComponent(manager); 319 320 fValidationManager = createValidationManager(); 321 setProperty(VALIDATION_MANAGER, fValidationManager); 322 323 fDatatypeValidatorFactory = createDatatypeValidatorFactory(); 324 if (fDatatypeValidatorFactory != null) { 325 setProperty(DATATYPE_VALIDATOR_FACTORY, 326 fDatatypeValidatorFactory); 327 } 328 329 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 331 XMLMessageFormatter xmft = new XMLMessageFormatter(); 332 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 333 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 334 } 335 336 if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) { 340 MessageFormatter xmft = null; 341 try { 342 xmft = (MessageFormatter)( 343 ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter", 344 ObjectFactory.findClassLoader(), true)); 345 } catch (Exception exception){ 346 } 347 348 if (xmft != null) { 349 fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft); 350 } 351 } 352 353 354 try { 356 setLocale(Locale.getDefault()); 357 } 358 catch (XNIException e) { 359 } 362 363 364 } 366 367 371 395 public void parse(XMLInputSource inputSource) 396 throws XNIException, IOException { 397 } 399 400 406 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 407 fDocumentHandler = documentHandler; 408 } 410 411 public XMLDocumentHandler getDocumentHandler() { 412 return fDocumentHandler; 413 } 415 420 public void setDTDHandler(XMLDTDHandler dtdHandler) { 421 } 424 425 public XMLDTDHandler getDTDHandler() { 426 return null; 427 } 429 434 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 435 437 } 439 440 public XMLDTDContentModelHandler getDTDContentModelHandler() { 441 return null; 442 } 444 451 public void setEntityResolver(XMLEntityResolver resolver) { 452 if (resolver !=null) { 453 fProperties.put(ENTITY_RESOLVER, resolver); 454 } 455 } 457 464 public XMLEntityResolver getEntityResolver() { 465 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 466 } 468 486 public void setErrorHandler(XMLErrorHandler errorHandler) { 487 if (errorHandler != null) { 488 fProperties.put(ERROR_HANDLER, errorHandler); 489 } 490 } 492 499 public XMLErrorHandler getErrorHandler() { 500 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 501 } 503 516 public void setFeature(String featureId, boolean state) 517 throws XMLConfigurationException { 518 519 super.setFeature(featureId, state); 521 522 } 524 530 public void setProperty(String propertyId, Object value) 531 throws XMLConfigurationException { 532 533 super.setProperty(propertyId, value); 535 536 } 538 546 public void setLocale(Locale locale) throws XNIException { 547 fLocale = locale; 548 fErrorReporter.setLocale(locale); 549 550 } 552 553 public Locale getLocale() { 554 return fLocale; 555 } 557 561 public void setParameter(String name, Object value) throws DOMException { 562 563 if(value instanceof Boolean ){ 566 boolean state = ((Boolean )value).booleanValue(); 567 568 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { 569 features = (short) (state ? features | COMMENTS : features & ~COMMENTS); 570 } 571 else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { 572 setFeature(NORMALIZE_DATA, state); 573 features = 574 (short) (state ? features | DTNORMALIZATION : features & ~DTNORMALIZATION); 575 if (state) { 576 features = (short) (features | VALIDATE); 577 } 578 } 579 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { 580 features = (short) (state ? features | NAMESPACES : features & ~NAMESPACES); 581 } 582 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 583 features = (short) (state ? features | CDATA : features & ~CDATA); 584 } 585 else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { 586 features = (short) (state ? features | ENTITIES : features & ~ENTITIES); 587 } 588 else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { 589 features = (short) (state ? features | SPLITCDATA : features & ~SPLITCDATA); 590 } 591 else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { 592 features = (short) (state ? features | VALIDATE : features & ~VALIDATE); 593 } 594 else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { 595 features = (short) (state ? features | WELLFORMED : features & ~WELLFORMED ); 596 } 597 else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { 598 if (state) { 600 features = (short) (features | INFOSET_TRUE_PARAMS); 601 features = (short) (features & ~INFOSET_FALSE_PARAMS); 602 setFeature(NORMALIZE_DATA, false); 603 } 604 } 605 else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 606 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 607 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 608 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 609 ) { 610 if (state) { String msg = 612 DOMMessageFormatter.formatMessage( 613 DOMMessageFormatter.DOM_DOMAIN, 614 "FEATURE_NOT_SUPPORTED", 615 new Object [] { name }); 616 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 617 } 618 } 619 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) 620 || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 621 if (!state) { String msg = 623 DOMMessageFormatter.formatMessage( 624 DOMMessageFormatter.DOM_DOMAIN, 625 "FEATURE_NOT_SUPPORTED", 626 new Object [] { name }); 627 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 628 } 629 630 } 631 else if (name.equalsIgnoreCase(SEND_PSVI) ){ 632 if (!state) { String msg = 637 DOMMessageFormatter.formatMessage( 638 DOMMessageFormatter.DOM_DOMAIN, 639 "FEATURE_NOT_SUPPORTED", 640 new Object [] { name }); 641 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 642 } 643 } 644 else if (name.equalsIgnoreCase(Constants.DOM_PSVI)){ 645 features = (short) (state ? features | PSVI : features & ~PSVI); 646 } 647 else { 648 String msg = 649 DOMMessageFormatter.formatMessage( 650 DOMMessageFormatter.DOM_DOMAIN, 651 "FEATURE_NOT_FOUND", 652 new Object [] { name }); 653 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 654 } 655 } 656 else { if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 658 if (value instanceof DOMErrorHandler || value == null) { 659 fErrorHandlerWrapper.setErrorHandler((DOMErrorHandler )value); 660 setErrorHandler(fErrorHandlerWrapper); 661 } 662 663 else { 664 String msg = 666 DOMMessageFormatter.formatMessage( 667 DOMMessageFormatter.DOM_DOMAIN, 668 "TYPE_MISMATCH_ERR", 669 new Object [] { name }); 670 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 671 } 672 } 673 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 674 if (value instanceof LSResourceResolver || value == null) { 675 try { 676 setEntityResolver(new DOMEntityResolverWrapper((LSResourceResolver ) value)); 677 } 678 catch (XMLConfigurationException e) {} 679 } 680 else { 681 String msg = 683 DOMMessageFormatter.formatMessage( 684 DOMMessageFormatter.DOM_DOMAIN, 685 "TYPE_MISMATCH_ERR", 686 new Object [] { name }); 687 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 688 } 689 690 } 691 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 692 if (value instanceof String || value == null) { 693 try { 694 String schemaType = (String ) getProperty( 695 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); 696 if (schemaType == Constants.NS_XMLSCHEMA || value == null) { 697 setProperty( 699 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, 700 value); 701 } 702 else { 703 String msg = 706 DOMMessageFormatter.formatMessage( 707 DOMMessageFormatter.DOM_DOMAIN, 708 "FEATURE_NOT_SUPPORTED", 709 new Object [] { name }); 710 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 711 } 712 713 } 714 catch (XMLConfigurationException e) {} 715 } 716 else { 717 String msg = 719 DOMMessageFormatter.formatMessage( 720 DOMMessageFormatter.DOM_DOMAIN, 721 "TYPE_MISMATCH_ERR", 722 new Object [] { name }); 723 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 724 } 725 726 } 727 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 728 if (value instanceof String || value == null) { 729 try { 730 if (value == null) { 731 setProperty( 732 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 733 null); 734 } 735 else if (value.equals(Constants.NS_XMLSCHEMA)) { 736 setProperty( 738 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 739 Constants.NS_XMLSCHEMA); 740 } 741 else if (value.equals(Constants.NS_DTD)) { 742 String msg = DOMMessageFormatter.formatMessage( 744 DOMMessageFormatter.DOM_DOMAIN, 745 "FEATURE_NOT_SUPPORTED", 746 new Object [] { name }); 747 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 748 } 749 } 750 catch (XMLConfigurationException e) {} 751 } 752 else { 753 String msg = 754 DOMMessageFormatter.formatMessage( 755 DOMMessageFormatter.DOM_DOMAIN, 756 "TYPE_MISMATCH_ERR", 757 new Object [] { name }); 758 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 759 } 760 761 } 762 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 763 if (value instanceof SymbolTable){ 765 setProperty(SYMBOL_TABLE, value); 766 } 767 else { 768 String msg = 770 DOMMessageFormatter.formatMessage( 771 DOMMessageFormatter.DOM_DOMAIN, 772 "TYPE_MISMATCH_ERR", 773 new Object [] { name }); 774 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 775 } 776 } 777 else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ 778 if (value instanceof XMLGrammarPool){ 779 setProperty(GRAMMAR_POOL, value); 780 } 781 else { 782 String msg = 784 DOMMessageFormatter.formatMessage( 785 DOMMessageFormatter.DOM_DOMAIN, 786 "TYPE_MISMATCH_ERR", 787 new Object [] { name }); 788 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 789 } 790 791 } 792 else { 793 String msg = 796 DOMMessageFormatter.formatMessage( 797 DOMMessageFormatter.DOM_DOMAIN, 798 "FEATURE_NOT_FOUND", 799 new Object [] { name }); 800 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 801 } 802 } 803 804 } 805 806 807 811 public Object getParameter(String name) throws DOMException { 812 813 816 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { 817 return ((features & COMMENTS) != 0) ? Boolean.TRUE : Boolean.FALSE; 818 } 819 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { 820 return (features & NAMESPACES) != 0 ? Boolean.TRUE : Boolean.FALSE; 821 } 822 else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { 823 return (features & DTNORMALIZATION) != 0 ? Boolean.TRUE : Boolean.FALSE; 825 } 826 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 827 return (features & CDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; 828 } 829 else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { 830 return (features & ENTITIES) != 0 ? Boolean.TRUE : Boolean.FALSE; 831 } 832 else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { 833 return (features & SPLITCDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; 834 } 835 else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { 836 return (features & VALIDATE) != 0 ? Boolean.TRUE : Boolean.FALSE; 837 } 838 else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { 839 return (features & WELLFORMED) != 0 ? Boolean.TRUE : Boolean.FALSE; 840 } 841 else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { 842 return (features & INFOSET_MASK) == INFOSET_TRUE_PARAMS ? Boolean.TRUE : Boolean.FALSE; 843 } 844 else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 845 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 846 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 847 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 848 ) { 849 return Boolean.FALSE; 850 } 851 else if (name.equalsIgnoreCase(SEND_PSVI)) { 852 return Boolean.TRUE; 853 } 854 else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) { 855 return (features & PSVI) != 0 ? Boolean.TRUE : Boolean.FALSE; 856 } 857 else if ( 858 name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) 859 || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 860 return Boolean.TRUE; 861 } 862 else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 863 return fErrorHandlerWrapper.getErrorHandler(); 864 } 865 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 866 XMLEntityResolver entityResolver = getEntityResolver(); 867 if (entityResolver != null && entityResolver instanceof DOMEntityResolverWrapper) { 868 return ((DOMEntityResolverWrapper) entityResolver).getEntityResolver(); 869 } 870 return null; 871 } 872 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 873 return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); 874 } 875 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 876 return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE); 877 } 878 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 879 return getProperty(SYMBOL_TABLE); 880 } 881 else if (name.equalsIgnoreCase(GRAMMAR_POOL)){ 882 return getProperty(GRAMMAR_POOL); 883 } 884 else { 885 String msg = 886 DOMMessageFormatter.formatMessage( 887 DOMMessageFormatter.DOM_DOMAIN, 888 "FEATURE_NOT_FOUND", 889 new Object [] { name }); 890 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 891 } 892 893 } 894 895 908 public boolean canSetParameter(String name, Object value) { 909 910 if (value == null){ 911 return true ; 918 } 919 if( value instanceof Boolean ){ 920 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS) 924 || name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION) 925 || name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS) 926 || name.equalsIgnoreCase(Constants.DOM_ENTITIES) 927 || name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA) 928 || name.equalsIgnoreCase(Constants.DOM_NAMESPACES) 929 || name.equalsIgnoreCase(Constants.DOM_VALIDATE) 930 || name.equalsIgnoreCase(Constants.DOM_WELLFORMED) 931 || name.equalsIgnoreCase(Constants.DOM_INFOSET) 932 ) { 933 return true ; 934 } else if ( 936 name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 937 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 938 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 939 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 940 ) { 941 return (value.equals(Boolean.TRUE)) ? false : true; 942 } else if( name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) 944 || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE) 945 || name.equalsIgnoreCase(SEND_PSVI) 946 ) { 947 return (value.equals(Boolean.TRUE)) ? true : false; 948 } else { 950 return false ; 951 } 952 } 953 else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 954 return (value instanceof DOMErrorHandler ) ? true : false ; 955 } 956 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 957 return (value instanceof LSResourceResolver ) ? true : false ; 958 } 959 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 960 return (value instanceof String ) ? true : false ; 961 } 962 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 963 return ( (value instanceof String ) && value.equals(Constants.NS_XMLSCHEMA) ) ? true : false ; 966 } 967 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 968 return (value instanceof SymbolTable) ? true : false ; 970 } 971 else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ 972 return (value instanceof XMLGrammarPool) ? true : false ; 973 } 974 else { 975 return false ; 977 } 978 979 } 981 989 public DOMStringList getParameterNames() { 990 if (fRecognizedParameters == null){ 991 Vector parameters = new Vector (); 992 993 parameters.add(Constants.DOM_COMMENTS); 997 parameters.add(Constants.DOM_DATATYPE_NORMALIZATION); 998 parameters.add(Constants.DOM_CDATA_SECTIONS); 999 parameters.add(Constants.DOM_ENTITIES); 1000 parameters.add(Constants.DOM_SPLIT_CDATA); 1001 parameters.add(Constants.DOM_NAMESPACES); 1002 parameters.add(Constants.DOM_VALIDATE); 1003 1004 parameters.add(Constants.DOM_INFOSET); 1005 parameters.add(Constants.DOM_NORMALIZE_CHARACTERS); 1006 parameters.add(Constants.DOM_CANONICAL_FORM); 1007 parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA); 1008 parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION); 1009 parameters.add(Constants.DOM_WELLFORMED); 1010 1011 parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS); 1012 parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE); 1013 1014 parameters.add(Constants.DOM_ERROR_HANDLER); 1015 parameters.add(Constants.DOM_SCHEMA_TYPE); 1016 parameters.add(Constants.DOM_SCHEMA_LOCATION); 1017 parameters.add(Constants.DOM_RESOURCE_RESOLVER); 1018 parameters.add(GRAMMAR_POOL); 1019 parameters.add(SYMBOL_TABLE); 1020 parameters.add(SEND_PSVI); 1021 1022 1023 fRecognizedParameters = new DOMStringListImpl(parameters); 1024 1025 } 1026 1027 return fRecognizedParameters; 1028 } 1030 1034 1037 protected void reset() throws XNIException { 1038 1039 if (fValidationManager != null) 1040 fValidationManager.reset(); 1041 1042 int count = fComponents.size(); 1043 for (int i = 0; i < count; i++) { 1044 XMLComponent c = (XMLComponent) fComponents.get(i); 1045 c.reset(this); 1046 } 1047 1048 } 1050 1059 protected void checkProperty(String propertyId) 1060 throws XMLConfigurationException { 1061 1062 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1064 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1065 1066 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1077 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1078 short type = XMLConfigurationException.NOT_SUPPORTED; 1082 throw new XMLConfigurationException(type, propertyId); 1083 } 1084 } 1085 1086 super.checkProperty(propertyId); 1088 1089 } 1091 1092 protected void addComponent(XMLComponent component) { 1093 1094 if (fComponents.contains(component)) { 1096 return; 1097 } 1098 fComponents.add(component); 1099 1100 String [] recognizedFeatures = component.getRecognizedFeatures(); 1102 addRecognizedFeatures(recognizedFeatures); 1103 1104 String [] recognizedProperties = component.getRecognizedProperties(); 1106 addRecognizedProperties(recognizedProperties); 1107 1108 } 1110 protected ValidationManager createValidationManager(){ 1111 return new ValidationManager(); 1112 } 1113 protected DTDDVFactory createDatatypeValidatorFactory() { 1114 return DTDDVFactory.getInstance(); 1115 } 1117} | Popular Tags |