1 16 17 package com.sun.org.apache.xerces.internal.parsers; 18 19 import java.io.IOException ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.Locale ; 23 24 import com.sun.org.apache.xerces.internal.impl.Constants; 25 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl; 26 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl; 27 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl; 28 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl; 29 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl; 30 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler; 31 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; 32 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 33 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl; 34 import com.sun.org.apache.xerces.internal.impl.XMLVersionDetector; 35 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; 36 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 37 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 38 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; 39 import com.sun.org.apache.xerces.internal.util.SymbolTable; 40 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 41 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 42 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 43 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 44 import com.sun.org.apache.xerces.internal.xni.XNIException; 45 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 46 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 47 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 48 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 49 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; 50 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; 51 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 52 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 53 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 54 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 55 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; 56 57 72 public class XML11NonValidatingConfiguration extends ParserConfigurationSettings 73 implements XMLPullParserConfiguration, XML11Configurable { 74 75 protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = 79 "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl"; 80 81 83 84 protected static final String VALIDATION = 85 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 86 87 88 protected static final String NAMESPACES = 89 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 90 91 92 protected static final String EXTERNAL_GENERAL_ENTITIES = 93 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; 94 95 96 protected static final String EXTERNAL_PARAMETER_ENTITIES = 97 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; 98 99 100 101 protected static final String CONTINUE_AFTER_FATAL_ERROR = 102 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 103 104 105 107 108 protected static final String XML_STRING = 109 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 110 111 112 protected static final String SYMBOL_TABLE = 113 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 114 115 116 protected static final String ERROR_HANDLER = 117 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 118 119 120 protected static final String ENTITY_RESOLVER = 121 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 122 123 124 protected static final String ERROR_REPORTER = 125 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 126 127 128 protected static final String ENTITY_MANAGER = 129 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 130 131 132 protected static final String DOCUMENT_SCANNER = 133 Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; 134 135 136 protected static final String DTD_SCANNER = 137 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; 138 139 140 protected static final String XMLGRAMMAR_POOL = 141 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 142 143 144 protected static final String DTD_VALIDATOR = 145 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 146 147 148 protected static final String NAMESPACE_BINDER = 149 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; 150 151 152 protected static final String DATATYPE_VALIDATOR_FACTORY = 153 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 154 155 protected static final String VALIDATION_MANAGER = 156 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 157 158 160 161 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; 162 163 protected SymbolTable fSymbolTable; 167 protected XMLInputSource fInputSource; 168 protected ValidationManager fValidationManager; 169 protected XMLVersionDetector fVersionDetector; 170 protected XMLLocator fLocator; 171 protected Locale fLocale; 172 173 174 protected ArrayList fComponents; 175 176 177 protected ArrayList fXML11Components = null; 178 179 180 protected ArrayList fCommonComponents = null; 181 182 183 protected XMLDocumentHandler fDocumentHandler; 184 185 186 protected XMLDTDHandler fDTDHandler; 187 188 189 protected XMLDTDContentModelHandler fDTDContentModelHandler; 190 191 192 protected XMLDocumentSource fLastComponent; 193 194 199 protected boolean fParseInProgress = false; 200 201 204 protected boolean fConfigUpdated = false; 205 206 210 211 protected DTDDVFactory fDatatypeValidatorFactory; 212 213 214 protected XMLNSDocumentScannerImpl fNamespaceScanner; 215 216 217 protected XMLDocumentScannerImpl fNonNSScanner; 218 219 220 protected XMLDTDScanner fDTDScanner; 221 222 226 227 protected DTDDVFactory fXML11DatatypeFactory = null; 228 229 230 protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; 231 232 233 protected XML11DocumentScannerImpl fXML11DocScanner = null; 234 235 236 protected XML11DTDScannerImpl fXML11DTDScanner = null; 237 238 242 243 protected XMLGrammarPool fGrammarPool; 244 245 246 protected XMLErrorReporter fErrorReporter; 247 248 249 protected XMLEntityManager fEntityManager; 250 251 252 protected XMLDocumentScanner fCurrentScanner; 253 254 255 protected DTDDVFactory fCurrentDVFactory; 256 257 258 protected XMLDTDScanner fCurrentDTDScanner; 259 260 261 262 private boolean f11Initialized = false; 263 264 268 269 public XML11NonValidatingConfiguration() { 270 this(null, null, null); 271 } 273 278 public XML11NonValidatingConfiguration(SymbolTable symbolTable) { 279 this(symbolTable, null, null); 280 } 282 293 public XML11NonValidatingConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 294 this(symbolTable, grammarPool, null); 295 } 297 309 public XML11NonValidatingConfiguration( 310 SymbolTable symbolTable, 311 XMLGrammarPool grammarPool, 312 XMLComponentManager parentSettings) { 313 314 super(parentSettings); 315 316 fComponents = new ArrayList (); 319 fXML11Components = new ArrayList (); 321 fCommonComponents = new ArrayList (); 323 324 fRecognizedFeatures = new ArrayList (); 326 fRecognizedProperties = new ArrayList (); 327 328 fFeatures = new HashMap (); 330 fProperties = new HashMap (); 331 332 final String [] recognizedFeatures = 334 { 335 CONTINUE_AFTER_FATAL_ERROR, VALIDATION, 337 NAMESPACES, 338 EXTERNAL_GENERAL_ENTITIES, 339 EXTERNAL_PARAMETER_ENTITIES, 340 PARSER_SETTINGS 341 }; 342 addRecognizedFeatures(recognizedFeatures); 343 344 fFeatures.put(VALIDATION, Boolean.FALSE); 346 fFeatures.put(NAMESPACES, Boolean.TRUE); 347 fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE); 348 fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE); 349 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); 350 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); 351 352 final String [] recognizedProperties = 354 { 355 XML_STRING, 356 SYMBOL_TABLE, 357 ERROR_HANDLER, 358 ENTITY_RESOLVER, 359 ERROR_REPORTER, 360 ENTITY_MANAGER, 361 DOCUMENT_SCANNER, 362 DTD_SCANNER, 363 DTD_VALIDATOR, 364 DATATYPE_VALIDATOR_FACTORY, 365 VALIDATION_MANAGER, 366 XML_STRING, 367 XMLGRAMMAR_POOL, }; 368 addRecognizedProperties(recognizedProperties); 369 370 if (symbolTable == null) { 371 symbolTable = new SymbolTable(); 372 } 373 fSymbolTable = symbolTable; 374 fProperties.put(SYMBOL_TABLE, fSymbolTable); 375 376 fGrammarPool = grammarPool; 377 if (fGrammarPool != null) { 378 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); 379 } 380 381 fEntityManager = new XMLEntityManager(); 382 fProperties.put(ENTITY_MANAGER, fEntityManager); 383 addCommonComponent(fEntityManager); 384 385 fErrorReporter = new XMLErrorReporter(); 386 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); 387 fProperties.put(ERROR_REPORTER, fErrorReporter); 388 addCommonComponent(fErrorReporter); 389 390 fNamespaceScanner = new XMLNSDocumentScannerImpl(); 391 fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); 392 addComponent((XMLComponent) fNamespaceScanner); 393 394 fDTDScanner = new XMLDTDScannerImpl(); 395 fProperties.put(DTD_SCANNER, fDTDScanner); 396 addComponent((XMLComponent) fDTDScanner); 397 398 fDatatypeValidatorFactory = DTDDVFactory.getInstance(); 399 fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); 400 401 fValidationManager = new ValidationManager(); 402 fProperties.put(VALIDATION_MANAGER, fValidationManager); 403 404 fVersionDetector = new XMLVersionDetector(); 405 406 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 408 XMLMessageFormatter xmft = new XMLMessageFormatter(); 409 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 410 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 411 } 412 413 try { 415 setLocale(Locale.getDefault()); 416 } catch (XNIException e) { 417 } 420 421 fConfigUpdated = false; 422 423 } 425 437 public void setInputSource(XMLInputSource inputSource) 438 throws XMLConfigurationException, IOException { 439 440 445 fInputSource = inputSource; 446 447 } 449 457 public void setLocale(Locale locale) throws XNIException { 458 fLocale = locale; 459 fErrorReporter.setLocale(locale); 460 } 462 468 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 469 fDocumentHandler = documentHandler; 470 if (fLastComponent != null) { 471 fLastComponent.setDocumentHandler(fDocumentHandler); 472 if (fDocumentHandler !=null){ 473 fDocumentHandler.setDocumentSource(fLastComponent); 474 } 475 } 476 } 478 479 public XMLDocumentHandler getDocumentHandler() { 480 return fDocumentHandler; 481 } 483 488 public void setDTDHandler(XMLDTDHandler dtdHandler) { 489 fDTDHandler = dtdHandler; 490 } 492 493 public XMLDTDHandler getDTDHandler() { 494 return fDTDHandler; 495 } 497 502 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 503 fDTDContentModelHandler = handler; 504 } 506 507 public XMLDTDContentModelHandler getDTDContentModelHandler() { 508 return fDTDContentModelHandler; 509 } 511 518 public void setEntityResolver(XMLEntityResolver resolver) { 519 fProperties.put(ENTITY_RESOLVER, resolver); 520 } 522 529 public XMLEntityResolver getEntityResolver() { 530 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 531 } 533 551 public void setErrorHandler(XMLErrorHandler errorHandler) { 552 fProperties.put(ERROR_HANDLER, errorHandler); 553 } 555 562 public XMLErrorHandler getErrorHandler() { 563 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 565 } 567 568 573 public void cleanup() { 574 fEntityManager.closeReaders(); 575 } 576 577 585 public void parse(XMLInputSource source) throws XNIException, IOException { 586 587 if (fParseInProgress) { 588 throw new XNIException("FWK005 parse may not be called while parsing."); 590 } 591 fParseInProgress = true; 592 593 try { 594 setInputSource(source); 595 parse(true); 596 } catch (XNIException ex) { 597 if (PRINT_EXCEPTION_STACK_TRACE) 598 ex.printStackTrace(); 599 throw ex; 600 } catch (IOException ex) { 601 if (PRINT_EXCEPTION_STACK_TRACE) 602 ex.printStackTrace(); 603 throw ex; 604 } catch (RuntimeException ex) { 605 if (PRINT_EXCEPTION_STACK_TRACE) 606 ex.printStackTrace(); 607 throw ex; 608 } catch (Exception ex) { 609 if (PRINT_EXCEPTION_STACK_TRACE) 610 ex.printStackTrace(); 611 throw new XNIException(ex); 612 } finally { 613 fParseInProgress = false; 614 this.cleanup(); 616 } 617 618 } 620 public boolean parse(boolean complete) throws XNIException, IOException { 621 if (fInputSource != null) { 624 try { 625 fValidationManager.reset(); 626 fVersionDetector.reset(this); 627 resetCommon(); 628 629 short version = fVersionDetector.determineDocVersion(fInputSource); 630 if (version == Constants.XML_VERSION_1_1) { 631 initXML11Components(); 632 configureXML11Pipeline(); 633 resetXML11(); 634 } else { 635 configurePipeline(); 636 reset(); 637 } 638 639 fConfigUpdated = false; 641 642 fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version); 644 fInputSource = null; 645 } catch (XNIException ex) { 646 if (PRINT_EXCEPTION_STACK_TRACE) 647 ex.printStackTrace(); 648 throw ex; 649 } catch (IOException ex) { 650 if (PRINT_EXCEPTION_STACK_TRACE) 651 ex.printStackTrace(); 652 throw ex; 653 } catch (RuntimeException ex) { 654 if (PRINT_EXCEPTION_STACK_TRACE) 655 ex.printStackTrace(); 656 throw ex; 657 } catch (Exception ex) { 658 if (PRINT_EXCEPTION_STACK_TRACE) 659 ex.printStackTrace(); 660 throw new XNIException(ex); 661 } 662 } 663 664 try { 665 return fCurrentScanner.scanDocument(complete); 666 } catch (XNIException ex) { 667 if (PRINT_EXCEPTION_STACK_TRACE) 668 ex.printStackTrace(); 669 throw ex; 670 } catch (IOException ex) { 671 if (PRINT_EXCEPTION_STACK_TRACE) 672 ex.printStackTrace(); 673 throw ex; 674 } catch (RuntimeException ex) { 675 if (PRINT_EXCEPTION_STACK_TRACE) 676 ex.printStackTrace(); 677 throw ex; 678 } catch (Exception ex) { 679 if (PRINT_EXCEPTION_STACK_TRACE) 680 ex.printStackTrace(); 681 throw new XNIException(ex); 682 } 683 684 } 686 698 public boolean getFeature(String featureId) 699 throws XMLConfigurationException { 700 if (featureId.equals(PARSER_SETTINGS)){ 702 return fConfigUpdated; 703 } 704 return super.getFeature(featureId); 705 706 } 708 721 public void setFeature(String featureId, boolean state) 722 throws XMLConfigurationException { 723 fConfigUpdated = true; 724 int count = fComponents.size(); 726 for (int i = 0; i < count; i++) { 727 XMLComponent c = (XMLComponent) fComponents.get(i); 728 c.setFeature(featureId, state); 729 } 730 count = fCommonComponents.size(); 732 for (int i = 0; i < count; i++) { 733 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 734 c.setFeature(featureId, state); 735 } 736 737 count = fXML11Components.size(); 739 for (int i = 0; i < count; i++) { 740 XMLComponent c = (XMLComponent) fXML11Components.get(i); 741 try{ 742 c.setFeature(featureId, state); 743 } 744 catch (Exception e){ 745 } 747 } 748 super.setFeature(featureId, state); 750 751 } 753 759 public void setProperty(String propertyId, Object value) 760 throws XMLConfigurationException { 761 fConfigUpdated = true; 762 int count = fComponents.size(); 764 for (int i = 0; i < count; i++) { 765 XMLComponent c = (XMLComponent) fComponents.get(i); 766 c.setProperty(propertyId, value); 767 } 768 count = fCommonComponents.size(); 770 for (int i = 0; i < count; i++) { 771 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 772 c.setProperty(propertyId, value); 773 } 774 count = fXML11Components.size(); 776 for (int i = 0; i < count; i++) { 777 XMLComponent c = (XMLComponent) fXML11Components.get(i); 778 try{ 779 c.setProperty(propertyId, value); 780 } 781 catch (Exception e){ 782 } 784 } 785 786 super.setProperty(propertyId, value); 788 789 } 791 792 793 public Locale getLocale() { 794 return fLocale; 795 } 797 800 protected void reset() throws XNIException { 801 int count = fComponents.size(); 802 for (int i = 0; i < count; i++) { 803 XMLComponent c = (XMLComponent) fComponents.get(i); 804 c.reset(this); 805 } 806 807 } 809 812 protected void resetCommon() throws XNIException { 813 int count = fCommonComponents.size(); 815 for (int i = 0; i < count; i++) { 816 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 817 c.reset(this); 818 } 819 820 } 822 823 826 protected void resetXML11() throws XNIException { 827 int count = fXML11Components.size(); 829 for (int i = 0; i < count; i++) { 830 XMLComponent c = (XMLComponent) fXML11Components.get(i); 831 c.reset(this); 832 } 833 834 } 836 837 841 protected void configureXML11Pipeline() { 842 if (fCurrentDVFactory != fXML11DatatypeFactory) { 843 fCurrentDVFactory = fXML11DatatypeFactory; 844 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 845 } 846 847 if (fCurrentDTDScanner != fXML11DTDScanner) { 849 fCurrentDTDScanner = fXML11DTDScanner; 850 setProperty(DTD_SCANNER, fCurrentDTDScanner); 851 } 852 fXML11DTDScanner.setDTDHandler(fDTDHandler); 853 fXML11DTDScanner.setDTDContentModelHandler(fDTDContentModelHandler); 854 855 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 857 if (fCurrentScanner != fXML11NSDocScanner) { 858 fCurrentScanner = fXML11NSDocScanner; 859 setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner); 860 } 861 862 fXML11NSDocScanner.setDTDValidator(null); 863 fXML11NSDocScanner.setDocumentHandler(fDocumentHandler); 864 if (fDocumentHandler != null) { 865 fDocumentHandler.setDocumentSource(fXML11NSDocScanner); 866 } 867 fLastComponent = fXML11NSDocScanner; 868 869 } else { 870 if (fXML11DocScanner == null) { 872 fXML11DocScanner = new XML11DocumentScannerImpl(); 874 addXML11Component(fXML11DocScanner); 875 } 876 if (fCurrentScanner != fXML11DocScanner) { 877 fCurrentScanner = fXML11DocScanner; 878 setProperty(DOCUMENT_SCANNER, fXML11DocScanner); 879 } 880 fXML11DocScanner.setDocumentHandler(fDocumentHandler); 881 882 if (fDocumentHandler != null) { 883 fDocumentHandler.setDocumentSource(fXML11DocScanner); 884 } 885 fLastComponent = fXML11DocScanner; 886 } 887 888 } 890 891 protected void configurePipeline() { 892 if (fCurrentDVFactory != fDatatypeValidatorFactory) { 893 fCurrentDVFactory = fDatatypeValidatorFactory; 894 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 896 } 897 898 if (fCurrentDTDScanner != fDTDScanner) { 900 fCurrentDTDScanner = fDTDScanner; 901 setProperty(DTD_SCANNER, fCurrentDTDScanner); 902 } 903 fDTDScanner.setDTDHandler(fDTDHandler); 904 fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler); 905 906 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 908 if (fCurrentScanner != fNamespaceScanner) { 909 fCurrentScanner = fNamespaceScanner; 910 setProperty(DOCUMENT_SCANNER, fNamespaceScanner); 911 } 912 fNamespaceScanner.setDTDValidator(null); 913 fNamespaceScanner.setDocumentHandler(fDocumentHandler); 914 if (fDocumentHandler != null) { 915 fDocumentHandler.setDocumentSource(fNamespaceScanner); 916 } 917 fLastComponent = fNamespaceScanner; 918 } else { 919 if (fNonNSScanner == null) { 921 fNonNSScanner = new XMLDocumentScannerImpl(); 922 addComponent((XMLComponent) fNonNSScanner); 924 925 } 926 if (fCurrentScanner != fNonNSScanner) { 927 fCurrentScanner = fNonNSScanner; 928 setProperty(DOCUMENT_SCANNER, fNonNSScanner); 929 930 } 931 932 fNonNSScanner.setDocumentHandler(fDocumentHandler); 933 if (fDocumentHandler != null) { 934 fDocumentHandler.setDocumentSource(fNonNSScanner); 935 } 936 fLastComponent = fNonNSScanner; 937 } 938 939 } 941 942 944 956 protected void checkFeature(String featureId) throws XMLConfigurationException { 957 958 962 if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { 963 final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); 964 965 if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && 972 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { 973 return; 974 } 975 976 if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && 980 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { 981 short type = XMLConfigurationException.NOT_SUPPORTED; 983 throw new XMLConfigurationException(type, featureId); 984 } 985 if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && 989 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { 990 short type = XMLConfigurationException.NOT_SUPPORTED; 992 throw new XMLConfigurationException(type, featureId); 993 } 994 if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && 998 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { 999 return; 1000 } 1001 if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && 1005 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { 1006 return; 1007 } 1008 1009 if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && 1013 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { 1014 short type = XMLConfigurationException.NOT_SUPPORTED; 1015 throw new XMLConfigurationException(type, featureId); 1016 } 1017 1018 if (suffixLength == Constants.PARSER_SETTINGS.length() && 1020 featureId.endsWith(Constants.PARSER_SETTINGS)) { 1021 short type = XMLConfigurationException.NOT_SUPPORTED; 1022 throw new XMLConfigurationException(type, featureId); 1023 } 1024 } 1025 1026 1030 super.checkFeature(featureId); 1031 1032 } 1034 1047 protected void checkProperty(String propertyId) throws XMLConfigurationException { 1048 1049 1053 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 1054 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 1055 1056 if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && 1057 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { 1058 return; 1059 } 1060 } 1061 1062 if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) { 1063 final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length(); 1064 1065 if (suffixLength == Constants.SCHEMA_SOURCE.length() && 1066 propertyId.endsWith(Constants.SCHEMA_SOURCE)) { 1067 return; 1068 } 1069 } 1070 1071 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1073 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1074 1075 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1086 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1087 short type = XMLConfigurationException.NOT_SUPPORTED; 1091 throw new XMLConfigurationException(type, propertyId); 1092 } 1093 } 1094 1095 1099 super.checkProperty(propertyId); 1100 1101 } 1103 1104 1111 protected void addComponent(XMLComponent component) { 1112 1113 if (fComponents.contains(component)) { 1115 return; 1116 } 1117 fComponents.add(component); 1118 addRecognizedParamsAndSetDefaults(component); 1119 1120 } 1122 1129 protected void addCommonComponent(XMLComponent component) { 1130 1131 if (fCommonComponents.contains(component)) { 1133 return; 1134 } 1135 fCommonComponents.add(component); 1136 addRecognizedParamsAndSetDefaults(component); 1137 1138 } 1140 1147 protected void addXML11Component(XMLComponent component) { 1148 1149 if (fXML11Components.contains(component)) { 1151 return; 1152 } 1153 fXML11Components.add(component); 1154 addRecognizedParamsAndSetDefaults(component); 1155 1156 } 1158 1167 protected void addRecognizedParamsAndSetDefaults(XMLComponent component) { 1168 1169 String [] recognizedFeatures = component.getRecognizedFeatures(); 1171 addRecognizedFeatures(recognizedFeatures); 1172 1173 String [] recognizedProperties = component.getRecognizedProperties(); 1175 addRecognizedProperties(recognizedProperties); 1176 1177 if (recognizedFeatures != null) { 1179 for (int i = 0; i < recognizedFeatures.length; ++i) { 1180 String featureId = recognizedFeatures[i]; 1181 Boolean state = component.getFeatureDefault(featureId); 1182 if (state != null) { 1183 if (!fFeatures.containsKey(featureId)) { 1185 fFeatures.put(featureId, state); 1186 fConfigUpdated = true; 1191 } 1192 } 1193 } 1194 } 1195 if (recognizedProperties != null) { 1196 for (int i = 0; i < recognizedProperties.length; ++i) { 1197 String propertyId = recognizedProperties[i]; 1198 Object value = component.getPropertyDefault(propertyId); 1199 if (value != null) { 1200 if (!fProperties.containsKey(propertyId)) { 1202 fProperties.put(propertyId, value); 1203 fConfigUpdated = true; 1208 } 1209 } 1210 } 1211 } 1212 } 1213 1214 private void initXML11Components() { 1215 if (!f11Initialized) { 1216 1217 fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); 1219 1220 fXML11DTDScanner = new XML11DTDScannerImpl(); 1222 addXML11Component(fXML11DTDScanner); 1223 1224 fXML11NSDocScanner = new XML11NSDocumentScannerImpl(); 1226 addXML11Component(fXML11NSDocScanner); 1227 1228 f11Initialized = true; 1229 } 1230 } 1231 1232} | Popular Tags |