1 16 17 package org.apache.xerces.dom; 18 19 import java.io.IOException ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.Locale ; 23 import java.util.Vector ; 24 25 import org.w3c.dom.DOMConfiguration ; 26 import org.w3c.dom.DOMErrorHandler ; 27 import org.w3c.dom.DOMStringList ; 28 29 import org.apache.xerces.impl.Constants; 30 import org.apache.xerces.impl.XMLEntityManager; 31 import org.apache.xerces.impl.XMLErrorReporter; 32 import org.apache.xerces.impl.dv.DTDDVFactory; 33 import org.apache.xerces.impl.msg.XMLMessageFormatter; 34 import org.apache.xerces.impl.validation.ValidationManager; 35 import org.apache.xerces.util.DOMEntityResolverWrapper; 36 import org.apache.xerces.util.DOMErrorHandlerWrapper; 37 import org.apache.xerces.util.MessageFormatter; 38 import org.apache.xerces.util.ParserConfigurationSettings; 39 import org.apache.xerces.util.SymbolTable; 40 import org.apache.xerces.xni.XMLDTDContentModelHandler; 41 import org.apache.xerces.xni.XMLDTDHandler; 42 import org.apache.xerces.xni.XMLDocumentHandler; 43 import org.apache.xerces.xni.XNIException; 44 import org.apache.xerces.xni.grammars.XMLGrammarPool; 45 import org.apache.xerces.xni.parser.XMLComponent; 46 import org.apache.xerces.xni.parser.XMLComponentManager; 47 import org.apache.xerces.xni.parser.XMLConfigurationException; 48 import org.apache.xerces.xni.parser.XMLEntityResolver; 49 import org.apache.xerces.xni.parser.XMLErrorHandler; 50 import org.apache.xerces.xni.parser.XMLInputSource; 51 import org.apache.xerces.xni.parser.XMLParserConfiguration; 52 import org.w3c.dom.DOMException ; 53 import org.w3c.dom.ls.LSResourceResolver ; 54 55 56 57 66 public class DOMConfigurationImpl extends ParserConfigurationSettings 67 implements XMLParserConfiguration, DOMConfiguration { 68 69 73 75 76 protected static final String XERCES_VALIDATION = 77 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 78 79 80 protected static final String XERCES_NAMESPACES = 81 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 82 83 protected static final String SCHEMA = 84 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 85 86 protected static final String SCHEMA_FULL_CHECKING = 87 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 88 89 protected static final String DYNAMIC_VALIDATION = 90 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 91 92 protected static final String NORMALIZE_DATA = 93 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 94 95 96 protected static final String SEND_PSVI = 97 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 98 99 protected final static String DTD_VALIDATOR_FACTORY_PROPERTY = 100 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 101 102 104 105 protected static final String ENTITY_MANAGER = 106 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 107 108 109 protected static final String ERROR_REPORTER = 110 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 111 112 113 protected static final String XML_STRING = 114 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 115 116 117 protected static final String SYMBOL_TABLE = 118 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 119 120 121 protected static final String GRAMMAR_POOL = 122 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 123 124 125 protected static final String ERROR_HANDLER = 126 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 127 128 129 protected static final String ENTITY_RESOLVER = 130 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 131 132 133 protected static final String JAXP_SCHEMA_LANGUAGE = 134 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 135 136 137 protected static final String JAXP_SCHEMA_SOURCE = 138 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 139 140 protected static final String VALIDATION_MANAGER = 141 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 142 XMLDocumentHandler fDocumentHandler; 146 147 148 protected short features = 0; 149 150 protected final static short NAMESPACES = 0x1<<0; 151 protected final static short DTNORMALIZATION = 0x1<<1; 152 protected final static short ENTITIES = 0x1<<2; 153 protected final static short CDATA = 0x1<<3; 154 protected final static short SPLITCDATA = 0x1<<4; 155 protected final static short COMMENTS = 0x1<<5; 156 protected final static short VALIDATE = 0x1<<6; 157 protected final static short PSVI = 0x1<<7; 158 protected final static short WELLFORMED = 0x1<<8; 159 protected final static short NSDECL = 0x1<<9; 160 161 protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED | NSDECL; 162 protected final static short INFOSET_FALSE_PARAMS = ENTITIES | DTNORMALIZATION | CDATA; 163 protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS | INFOSET_FALSE_PARAMS; 164 165 167 168 protected SymbolTable fSymbolTable; 169 170 171 protected ArrayList fComponents; 172 173 protected ValidationManager fValidationManager; 174 175 176 protected Locale fLocale; 177 178 179 protected XMLErrorReporter fErrorReporter; 180 181 protected final DOMErrorHandlerWrapper fErrorHandlerWrapper = 182 new DOMErrorHandlerWrapper(); 183 184 186 private DOMStringList fRecognizedParameters; 187 188 189 193 194 protected DOMConfigurationImpl() { 195 this(null, null); 196 } 198 203 protected DOMConfigurationImpl(SymbolTable symbolTable) { 204 this(symbolTable, null); 205 } 207 214 protected DOMConfigurationImpl(SymbolTable symbolTable, 215 XMLComponentManager parentSettings) { 216 super(parentSettings); 217 218 fRecognizedFeatures = new ArrayList (); 220 fRecognizedProperties = new ArrayList (); 221 222 fFeatures = new HashMap (); 224 fProperties = new HashMap (); 225 226 final String [] recognizedFeatures = { 228 XERCES_VALIDATION, 229 XERCES_NAMESPACES, 230 SCHEMA, 231 SCHEMA_FULL_CHECKING, 232 DYNAMIC_VALIDATION, 233 NORMALIZE_DATA, 234 SEND_PSVI, 235 }; 236 addRecognizedFeatures(recognizedFeatures); 237 238 setFeature(XERCES_VALIDATION, false); 240 setFeature(SCHEMA, false); 241 setFeature(SCHEMA_FULL_CHECKING, false); 242 setFeature(DYNAMIC_VALIDATION, false); 243 setFeature(NORMALIZE_DATA, false); 244 setFeature(XERCES_NAMESPACES, true); 245 setFeature(SEND_PSVI, true); 246 247 final String [] recognizedProperties = { 249 XML_STRING, 250 SYMBOL_TABLE, 251 ERROR_HANDLER, 252 ENTITY_RESOLVER, 253 ERROR_REPORTER, 254 ENTITY_MANAGER, 255 VALIDATION_MANAGER, 256 GRAMMAR_POOL, 257 JAXP_SCHEMA_SOURCE, 258 JAXP_SCHEMA_LANGUAGE, 259 DTD_VALIDATOR_FACTORY_PROPERTY 260 }; 261 addRecognizedProperties(recognizedProperties); 262 263 features |= NAMESPACES; 265 features |= ENTITIES; 266 features |= COMMENTS; 267 features |= CDATA; 268 features |= SPLITCDATA; 269 features |= WELLFORMED; 270 features |= NSDECL; 271 272 if (symbolTable == null) { 273 symbolTable = new SymbolTable(); 274 } 275 fSymbolTable = symbolTable; 276 277 fComponents = new ArrayList (); 278 279 setProperty(SYMBOL_TABLE, fSymbolTable); 280 fErrorReporter = new XMLErrorReporter(); 281 setProperty(ERROR_REPORTER, fErrorReporter); 282 addComponent(fErrorReporter); 283 284 setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, DTDDVFactory.getInstance()); 285 286 XMLEntityManager manager = new XMLEntityManager(); 287 setProperty(ENTITY_MANAGER, manager); 288 addComponent(manager); 289 290 fValidationManager = createValidationManager(); 291 setProperty(VALIDATION_MANAGER, fValidationManager); 292 293 294 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 296 XMLMessageFormatter xmft = new XMLMessageFormatter(); 297 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 298 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 299 } 300 301 if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) { 305 MessageFormatter xmft = null; 306 try { 307 xmft = (MessageFormatter)( 308 ObjectFactory.newInstance("org.apache.xerces.impl.xs.XSMessageFormatter", 309 ObjectFactory.findClassLoader(), true)); 310 } catch (Exception exception){ 311 } 312 313 if (xmft != null) { 314 fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft); 315 } 316 } 317 318 319 try { 321 setLocale(Locale.getDefault()); 322 } 323 catch (XNIException e) { 324 } 327 328 329 } 331 332 336 360 public void parse(XMLInputSource inputSource) 361 throws XNIException, IOException { 362 } 364 365 371 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 372 fDocumentHandler = documentHandler; 373 } 375 376 public XMLDocumentHandler getDocumentHandler() { 377 return fDocumentHandler; 378 } 380 385 public void setDTDHandler(XMLDTDHandler dtdHandler) { 386 } 389 390 public XMLDTDHandler getDTDHandler() { 391 return null; 392 } 394 399 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 400 402 } 404 405 public XMLDTDContentModelHandler getDTDContentModelHandler() { 406 return null; 407 } 409 416 public void setEntityResolver(XMLEntityResolver resolver) { 417 if (resolver !=null) { 418 fProperties.put(ENTITY_RESOLVER, resolver); 419 } 420 } 422 429 public XMLEntityResolver getEntityResolver() { 430 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 431 } 433 451 public void setErrorHandler(XMLErrorHandler errorHandler) { 452 if (errorHandler != null) { 453 fProperties.put(ERROR_HANDLER, errorHandler); 454 } 455 } 457 464 public XMLErrorHandler getErrorHandler() { 465 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 466 } 468 481 public void setFeature(String featureId, boolean state) 482 throws XMLConfigurationException { 483 484 super.setFeature(featureId, state); 486 487 } 489 495 public void setProperty(String propertyId, Object value) 496 throws XMLConfigurationException { 497 498 super.setProperty(propertyId, value); 500 501 } 503 511 public void setLocale(Locale locale) throws XNIException { 512 fLocale = locale; 513 fErrorReporter.setLocale(locale); 514 515 } 517 518 public Locale getLocale() { 519 return fLocale; 520 } 522 526 public void setParameter(String name, Object value) throws DOMException { 527 boolean found = true; 528 529 if(value instanceof Boolean ){ 532 boolean state = ((Boolean )value).booleanValue(); 533 534 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { 535 features = (short) (state ? features | COMMENTS : features & ~COMMENTS); 536 } 537 else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { 538 setFeature(NORMALIZE_DATA, state); 539 features = 540 (short) (state ? features | DTNORMALIZATION : features & ~DTNORMALIZATION); 541 if (state) { 542 features = (short) (features | VALIDATE); 543 } 544 } 545 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { 546 features = (short) (state ? features | NAMESPACES : features & ~NAMESPACES); 547 } 548 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 549 features = (short) (state ? features | CDATA : features & ~CDATA); 550 } 551 else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { 552 features = (short) (state ? features | ENTITIES : features & ~ENTITIES); 553 } 554 else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { 555 features = (short) (state ? features | SPLITCDATA : features & ~SPLITCDATA); 556 } 557 else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { 558 features = (short) (state ? features | VALIDATE : features & ~VALIDATE); 559 } 560 else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { 561 features = (short) (state ? features | WELLFORMED : features & ~WELLFORMED ); 562 } 563 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) { 564 features = (short) (state ? features | NSDECL : features & ~NSDECL); 565 } 566 else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { 567 if (state) { 569 features = (short) (features | INFOSET_TRUE_PARAMS); 570 features = (short) (features & ~INFOSET_FALSE_PARAMS); 571 setFeature(NORMALIZE_DATA, false); 572 } 573 } 574 else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 575 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 576 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 577 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 578 ) { 579 if (state) { String msg = 581 DOMMessageFormatter.formatMessage( 582 DOMMessageFormatter.DOM_DOMAIN, 583 "FEATURE_NOT_SUPPORTED", 584 new Object [] { name }); 585 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 586 } 587 } 588 else if ( name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 589 if (!state) { String msg = 591 DOMMessageFormatter.formatMessage( 592 DOMMessageFormatter.DOM_DOMAIN, 593 "FEATURE_NOT_SUPPORTED", 594 new Object [] { name }); 595 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 596 } 597 } 598 else if (name.equalsIgnoreCase(SEND_PSVI) ){ 599 if (!state) { String msg = 604 DOMMessageFormatter.formatMessage( 605 DOMMessageFormatter.DOM_DOMAIN, 606 "FEATURE_NOT_SUPPORTED", 607 new Object [] { name }); 608 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, msg); 609 } 610 } 611 else if (name.equalsIgnoreCase(Constants.DOM_PSVI)){ 612 features = (short) (state ? features | PSVI : features & ~PSVI); 613 } 614 else { 615 found = false; 616 624 } 625 626 } 627 628 if (!found || !(value instanceof Boolean )) { found = true; 630 631 if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 632 if (value instanceof DOMErrorHandler || value == null) { 633 fErrorHandlerWrapper.setErrorHandler((DOMErrorHandler )value); 634 setErrorHandler(fErrorHandlerWrapper); 635 } 636 637 else { 638 String msg = 640 DOMMessageFormatter.formatMessage( 641 DOMMessageFormatter.DOM_DOMAIN, 642 "TYPE_MISMATCH_ERR", 643 new Object [] { name }); 644 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 645 } 646 } 647 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 648 if (value instanceof LSResourceResolver || value == null) { 649 try { 650 setEntityResolver(new DOMEntityResolverWrapper((LSResourceResolver ) value)); 651 } 652 catch (XMLConfigurationException e) {} 653 } 654 else { 655 String msg = 657 DOMMessageFormatter.formatMessage( 658 DOMMessageFormatter.DOM_DOMAIN, 659 "TYPE_MISMATCH_ERR", 660 new Object [] { name }); 661 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 662 } 663 664 } 665 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 666 if (value instanceof String || value == null) { 667 try { 668 setProperty( 670 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, 671 value); 672 } 673 catch (XMLConfigurationException e) {} 674 } 675 else { 676 String msg = 678 DOMMessageFormatter.formatMessage( 679 DOMMessageFormatter.DOM_DOMAIN, 680 "TYPE_MISMATCH_ERR", 681 new Object [] { name }); 682 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 683 } 684 685 } 686 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 687 if (value instanceof String || value == null) { 688 try { 689 if (value == null) { 690 setProperty( 691 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 692 null); 693 } 694 else if (value.equals(Constants.NS_XMLSCHEMA)) { 695 setProperty( 697 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 698 Constants.NS_XMLSCHEMA); 699 } 700 else if (value.equals(Constants.NS_DTD)) { 701 setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, 703 Constants.NS_DTD); 704 } 705 } 706 catch (XMLConfigurationException e) {} 707 } 708 else { 709 String msg = 710 DOMMessageFormatter.formatMessage( 711 DOMMessageFormatter.DOM_DOMAIN, 712 "TYPE_MISMATCH_ERR", 713 new Object [] { name }); 714 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 715 } 716 717 } 718 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 719 if (value instanceof SymbolTable){ 721 setProperty(SYMBOL_TABLE, value); 722 } 723 else { 724 String msg = 726 DOMMessageFormatter.formatMessage( 727 DOMMessageFormatter.DOM_DOMAIN, 728 "TYPE_MISMATCH_ERR", 729 new Object [] { name }); 730 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 731 } 732 } 733 else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ 734 if (value instanceof XMLGrammarPool){ 735 setProperty(GRAMMAR_POOL, value); 736 } 737 else { 738 String msg = 740 DOMMessageFormatter.formatMessage( 741 DOMMessageFormatter.DOM_DOMAIN, 742 "TYPE_MISMATCH_ERR", 743 new Object [] { name }); 744 throw new DOMException (DOMException.TYPE_MISMATCH_ERR, msg); 745 } 746 747 } 748 else { 749 String msg = 752 DOMMessageFormatter.formatMessage( 753 DOMMessageFormatter.DOM_DOMAIN, 754 "FEATURE_NOT_FOUND", 755 new Object [] { name }); 756 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 757 } 758 } 759 760 } 761 762 763 767 public Object getParameter(String name) throws DOMException { 768 769 772 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) { 773 return ((features & COMMENTS) != 0) ? Boolean.TRUE : Boolean.FALSE; 774 } 775 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) { 776 return (features & NAMESPACES) != 0 ? Boolean.TRUE : Boolean.FALSE; 777 } 778 else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) { 779 return (features & DTNORMALIZATION) != 0 ? Boolean.TRUE : Boolean.FALSE; 781 } 782 else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) { 783 return (features & CDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; 784 } 785 else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) { 786 return (features & ENTITIES) != 0 ? Boolean.TRUE : Boolean.FALSE; 787 } 788 else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) { 789 return (features & SPLITCDATA) != 0 ? Boolean.TRUE : Boolean.FALSE; 790 } 791 else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) { 792 return (features & VALIDATE) != 0 ? Boolean.TRUE : Boolean.FALSE; 793 } 794 else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) { 795 return (features & WELLFORMED) != 0 ? Boolean.TRUE : Boolean.FALSE; 796 } 797 else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) { 798 return (features & NSDECL) != 0 ? Boolean.TRUE : Boolean.FALSE; 799 } 800 else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) { 801 return (features & INFOSET_MASK) == INFOSET_TRUE_PARAMS ? Boolean.TRUE : Boolean.FALSE; 802 } 803 else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 804 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 805 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 806 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 807 ) { 808 return Boolean.FALSE; 809 } 810 else if (name.equalsIgnoreCase(SEND_PSVI)) { 811 return Boolean.TRUE; 812 } 813 else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) { 814 return (features & PSVI) != 0 ? Boolean.TRUE : Boolean.FALSE; 815 } 816 else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) { 817 return Boolean.TRUE; 818 } 819 else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 820 return fErrorHandlerWrapper.getErrorHandler(); 821 } 822 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 823 XMLEntityResolver entityResolver = getEntityResolver(); 824 if (entityResolver != null && entityResolver instanceof DOMEntityResolverWrapper) { 825 return ((DOMEntityResolverWrapper) entityResolver).getEntityResolver(); 826 } 827 return null; 828 } 829 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 830 return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); 831 } 832 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 833 return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE); 834 } 835 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 836 return getProperty(SYMBOL_TABLE); 837 } 838 else if (name.equalsIgnoreCase(GRAMMAR_POOL)){ 839 return getProperty(GRAMMAR_POOL); 840 } 841 else { 842 String msg = 843 DOMMessageFormatter.formatMessage( 844 DOMMessageFormatter.DOM_DOMAIN, 845 "FEATURE_NOT_FOUND", 846 new Object [] { name }); 847 throw new DOMException (DOMException.NOT_FOUND_ERR, msg); 848 } 849 850 } 851 852 865 public boolean canSetParameter(String name, Object value) { 866 867 if (value == null){ 868 return true ; 875 } 876 if( value instanceof Boolean ){ 877 if (name.equalsIgnoreCase(Constants.DOM_COMMENTS) 881 || name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION) 882 || name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS) 883 || name.equalsIgnoreCase(Constants.DOM_ENTITIES) 884 || name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA) 885 || name.equalsIgnoreCase(Constants.DOM_NAMESPACES) 886 || name.equalsIgnoreCase(Constants.DOM_VALIDATE) 887 || name.equalsIgnoreCase(Constants.DOM_WELLFORMED) 888 || name.equalsIgnoreCase(Constants.DOM_INFOSET) 889 || name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS) 890 ) { 891 return true; 892 } else if ( 894 name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) 895 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM) 896 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA) 897 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) 898 ) { 899 return (value.equals(Boolean.TRUE)) ? false : true; 900 } else if( name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE) 902 || name.equalsIgnoreCase(SEND_PSVI) 903 ) { 904 return (value.equals(Boolean.TRUE)) ? true : false; 905 } else { 907 return false ; 908 } 909 } 910 else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) { 911 return (value instanceof DOMErrorHandler ) ? true : false ; 912 } 913 else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) { 914 return (value instanceof LSResourceResolver ) ? true : false ; 915 } 916 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) { 917 return (value instanceof String ) ? true : false ; 918 } 919 else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) { 920 return ( (value instanceof String ) && value.equals(Constants.NS_XMLSCHEMA) ) ? true : false ; 923 } 924 else if (name.equalsIgnoreCase(SYMBOL_TABLE)){ 925 return (value instanceof SymbolTable) ? true : false ; 927 } 928 else if (name.equalsIgnoreCase (GRAMMAR_POOL)){ 929 return (value instanceof XMLGrammarPool) ? true : false ; 930 } 931 else { 932 return false ; 934 } 935 936 } 938 946 public DOMStringList getParameterNames() { 947 if (fRecognizedParameters == null){ 948 Vector parameters = new Vector (); 949 950 parameters.add(Constants.DOM_COMMENTS); 954 parameters.add(Constants.DOM_DATATYPE_NORMALIZATION); 955 parameters.add(Constants.DOM_CDATA_SECTIONS); 956 parameters.add(Constants.DOM_ENTITIES); 957 parameters.add(Constants.DOM_SPLIT_CDATA); 958 parameters.add(Constants.DOM_NAMESPACES); 959 parameters.add(Constants.DOM_VALIDATE); 960 961 parameters.add(Constants.DOM_INFOSET); 962 parameters.add(Constants.DOM_NORMALIZE_CHARACTERS); 963 parameters.add(Constants.DOM_CANONICAL_FORM); 964 parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA); 965 parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION); 966 parameters.add(Constants.DOM_WELLFORMED); 967 968 parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS); 969 parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE); 970 971 parameters.add(Constants.DOM_ERROR_HANDLER); 972 parameters.add(Constants.DOM_SCHEMA_TYPE); 973 parameters.add(Constants.DOM_SCHEMA_LOCATION); 974 parameters.add(Constants.DOM_RESOURCE_RESOLVER); 975 976 parameters.add(GRAMMAR_POOL); 978 parameters.add(SYMBOL_TABLE); 979 parameters.add(SEND_PSVI); 980 981 fRecognizedParameters = new DOMStringListImpl(parameters); 982 983 } 984 985 return fRecognizedParameters; 986 } 988 992 995 protected void reset() throws XNIException { 996 997 if (fValidationManager != null) 998 fValidationManager.reset(); 999 1000 int count = fComponents.size(); 1001 for (int i = 0; i < count; i++) { 1002 XMLComponent c = (XMLComponent) fComponents.get(i); 1003 c.reset(this); 1004 } 1005 1006 } 1008 1017 protected void checkProperty(String propertyId) 1018 throws XMLConfigurationException { 1019 1020 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1022 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1023 1024 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1035 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1036 short type = XMLConfigurationException.NOT_SUPPORTED; 1040 throw new XMLConfigurationException(type, propertyId); 1041 } 1042 } 1043 1044 super.checkProperty(propertyId); 1046 1047 } 1049 1050 protected void addComponent(XMLComponent component) { 1051 1052 if (fComponents.contains(component)) { 1054 return; 1055 } 1056 fComponents.add(component); 1057 1058 String [] recognizedFeatures = component.getRecognizedFeatures(); 1060 addRecognizedFeatures(recognizedFeatures); 1061 1062 String [] recognizedProperties = component.getRecognizedProperties(); 1064 addRecognizedProperties(recognizedProperties); 1065 1066 } 1068 protected ValidationManager createValidationManager(){ 1069 return new ValidationManager(); 1070 } 1071 1072} | Popular Tags |