1 16 17 package org.apache.xerces.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 org.apache.xerces.impl.Constants; 25 import org.apache.xerces.impl.XML11DTDScannerImpl; 26 import org.apache.xerces.impl.XML11DocumentScannerImpl; 27 import org.apache.xerces.impl.XML11NSDocumentScannerImpl; 28 import org.apache.xerces.impl.XMLDTDScannerImpl; 29 import org.apache.xerces.impl.XMLDocumentScannerImpl; 30 import org.apache.xerces.impl.XMLEntityHandler; 31 import org.apache.xerces.impl.XMLEntityManager; 32 import org.apache.xerces.impl.XMLErrorReporter; 33 import org.apache.xerces.impl.XMLNSDocumentScannerImpl; 34 import org.apache.xerces.impl.XMLVersionDetector; 35 import org.apache.xerces.impl.dtd.XML11DTDProcessor; 36 import org.apache.xerces.impl.dtd.XML11DTDValidator; 37 import org.apache.xerces.impl.dtd.XML11NSDTDValidator; 38 import org.apache.xerces.impl.dtd.XMLDTDProcessor; 39 import org.apache.xerces.impl.dtd.XMLDTDValidator; 40 import org.apache.xerces.impl.dtd.XMLNSDTDValidator; 41 import org.apache.xerces.impl.dv.DTDDVFactory; 42 import org.apache.xerces.impl.msg.XMLMessageFormatter; 43 import org.apache.xerces.impl.validation.ValidationManager; 44 import org.apache.xerces.impl.xs.XMLSchemaValidator; 45 import org.apache.xerces.impl.xs.XSMessageFormatter; 46 import org.apache.xerces.util.ParserConfigurationSettings; 47 import org.apache.xerces.util.SymbolTable; 48 import org.apache.xerces.xni.XMLDTDContentModelHandler; 49 import org.apache.xerces.xni.XMLDTDHandler; 50 import org.apache.xerces.xni.XMLDocumentHandler; 51 import org.apache.xerces.xni.XMLLocator; 52 import org.apache.xerces.xni.XNIException; 53 import org.apache.xerces.xni.grammars.XMLGrammarPool; 54 import org.apache.xerces.xni.parser.XMLComponent; 55 import org.apache.xerces.xni.parser.XMLComponentManager; 56 import org.apache.xerces.xni.parser.XMLConfigurationException; 57 import org.apache.xerces.xni.parser.XMLDTDScanner; 58 import org.apache.xerces.xni.parser.XMLDocumentScanner; 59 import org.apache.xerces.xni.parser.XMLDocumentSource; 60 import org.apache.xerces.xni.parser.XMLEntityResolver; 61 import org.apache.xerces.xni.parser.XMLErrorHandler; 62 import org.apache.xerces.xni.parser.XMLInputSource; 63 import org.apache.xerces.xni.parser.XMLPullParserConfiguration; 64 65 74 public class XML11Configuration extends ParserConfigurationSettings 75 implements XMLPullParserConfiguration, XML11Configurable { 76 77 protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = 81 "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl"; 82 83 85 86 protected static final String WARN_ON_DUPLICATE_ATTDEF = 87 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 88 89 90 protected static final String WARN_ON_DUPLICATE_ENTITYDEF = 91 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE; 92 93 94 protected static final String WARN_ON_UNDECLARED_ELEMDEF = 95 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE; 96 97 98 protected static final String ALLOW_JAVA_ENCODINGS = 99 Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; 100 101 102 protected static final String CONTINUE_AFTER_FATAL_ERROR = 103 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 104 105 106 protected static final String LOAD_EXTERNAL_DTD = 107 Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; 108 109 110 protected static final String NOTIFY_BUILTIN_REFS = 111 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE; 112 113 114 protected static final String NOTIFY_CHAR_REFS = 115 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE; 116 117 118 protected static final String NORMALIZE_DATA = 119 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 120 121 122 protected static final String SCHEMA_ELEMENT_DEFAULT = 123 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; 124 125 126 protected static final String SCHEMA_AUGMENT_PSVI = 127 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 128 129 130 protected static final String XMLSCHEMA_VALIDATION = 131 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 132 133 134 protected static final String XMLSCHEMA_FULL_CHECKING = 135 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 136 137 138 protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = 139 Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE; 140 141 142 protected static final String VALIDATE_ANNOTATIONS = 143 Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE; 144 145 146 protected static final String HONOUR_ALL_SCHEMALOCATIONS = 147 Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE; 148 149 150 protected static final String USE_GRAMMAR_POOL_ONLY = 151 Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE; 152 153 155 156 protected static final String VALIDATION = 157 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 158 159 160 protected static final String NAMESPACES = 161 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 162 163 164 protected static final String EXTERNAL_GENERAL_ENTITIES = 165 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; 166 167 168 protected static final String EXTERNAL_PARAMETER_ENTITIES = 169 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; 170 171 172 173 175 176 177 protected static final String XML_STRING = 178 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 179 180 181 protected static final String SYMBOL_TABLE = 182 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 183 184 185 protected static final String ERROR_HANDLER = 186 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 187 188 189 protected static final String ENTITY_RESOLVER = 190 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 191 192 193 194 protected static final String SCHEMA_VALIDATOR = 195 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; 196 197 198 protected static final String SCHEMA_LOCATION = 199 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION; 200 201 202 protected static final String SCHEMA_NONS_LOCATION = 203 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; 204 205 207 208 protected static final String ERROR_REPORTER = 209 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 210 211 212 protected static final String ENTITY_MANAGER = 213 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 214 215 216 protected static final String DOCUMENT_SCANNER = 217 Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; 218 219 220 protected static final String DTD_SCANNER = 221 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; 222 223 224 protected static final String XMLGRAMMAR_POOL = 225 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 226 227 228 protected static final String DTD_PROCESSOR = 229 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY; 230 231 232 protected static final String DTD_VALIDATOR = 233 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 234 235 236 protected static final String NAMESPACE_BINDER = 237 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; 238 239 240 protected static final String DATATYPE_VALIDATOR_FACTORY = 241 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 242 243 protected static final String VALIDATION_MANAGER = 244 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 245 246 247 protected static final String JAXP_SCHEMA_LANGUAGE = 248 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 249 250 251 protected static final String JAXP_SCHEMA_SOURCE = 252 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 253 254 256 257 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; 258 259 263 protected SymbolTable fSymbolTable; 264 protected XMLInputSource fInputSource; 265 protected ValidationManager fValidationManager; 266 protected XMLVersionDetector fVersionDetector; 267 protected XMLLocator fLocator; 268 protected Locale fLocale; 269 270 271 protected ArrayList fComponents; 272 273 274 protected ArrayList fXML11Components = null; 275 276 277 protected ArrayList fCommonComponents = null; 278 279 280 protected XMLDocumentHandler fDocumentHandler; 281 282 283 protected XMLDTDHandler fDTDHandler; 284 285 286 protected XMLDTDContentModelHandler fDTDContentModelHandler; 287 288 289 protected XMLDocumentSource fLastComponent; 290 291 296 protected boolean fParseInProgress = false; 297 298 301 protected boolean fConfigUpdated = false; 302 303 307 308 protected DTDDVFactory fDatatypeValidatorFactory; 309 310 311 protected XMLNSDocumentScannerImpl fNamespaceScanner; 312 313 protected XMLDocumentScannerImpl fNonNSScanner; 314 315 protected XMLDTDValidator fDTDValidator; 316 317 protected XMLDTDValidator fNonNSDTDValidator; 318 319 protected XMLDTDScanner fDTDScanner; 320 321 protected XMLDTDProcessor fDTDProcessor; 322 323 327 328 protected DTDDVFactory fXML11DatatypeFactory = null; 329 330 331 protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; 332 333 334 protected XML11DocumentScannerImpl fXML11DocScanner = null; 335 336 337 protected XML11NSDTDValidator fXML11NSDTDValidator = null; 338 339 340 protected XML11DTDValidator fXML11DTDValidator = null; 341 342 343 protected XML11DTDScannerImpl fXML11DTDScanner = null; 344 345 protected XML11DTDProcessor fXML11DTDProcessor = null; 346 347 351 352 protected XMLGrammarPool fGrammarPool; 353 354 355 protected XMLErrorReporter fErrorReporter; 356 357 358 protected XMLEntityManager fEntityManager; 359 360 361 protected XMLSchemaValidator fSchemaValidator; 362 363 364 protected XMLDocumentScanner fCurrentScanner; 365 366 protected DTDDVFactory fCurrentDVFactory; 367 368 protected XMLDTDScanner fCurrentDTDScanner; 369 370 371 private boolean f11Initialized = false; 372 373 377 378 public XML11Configuration() { 379 this(null, null, null); 380 } 382 387 public XML11Configuration(SymbolTable symbolTable) { 388 this(symbolTable, null, null); 389 } 391 402 public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 403 this(symbolTable, grammarPool, null); 404 } 406 418 public XML11Configuration( 419 SymbolTable symbolTable, 420 XMLGrammarPool grammarPool, 421 XMLComponentManager parentSettings) { 422 423 super(parentSettings); 424 425 fComponents = new ArrayList (); 428 fXML11Components = new ArrayList (); 430 fCommonComponents = new ArrayList (); 432 433 fRecognizedFeatures = new ArrayList (); 435 fRecognizedProperties = new ArrayList (); 436 437 fFeatures = new HashMap (); 439 fProperties = new HashMap (); 440 441 final String [] recognizedFeatures = 443 { 444 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, VALIDATION, 446 NAMESPACES, 447 NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI, 448 GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS, 449 HONOUR_ALL_SCHEMALOCATIONS, USE_GRAMMAR_POOL_ONLY, 450 XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING, 455 EXTERNAL_GENERAL_ENTITIES, 456 EXTERNAL_PARAMETER_ENTITIES, 457 PARSER_SETTINGS 458 }; 459 addRecognizedFeatures(recognizedFeatures); 460 fFeatures.put(VALIDATION, Boolean.FALSE); 462 fFeatures.put(NAMESPACES, Boolean.TRUE); 463 fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE); 464 fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE); 465 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); 466 fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE); 467 fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE); 468 fFeatures.put(NORMALIZE_DATA, Boolean.TRUE); 469 fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); 470 fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE); 471 fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE); 472 fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE); 473 fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE); 474 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); 475 476 final String [] recognizedProperties = 478 { 479 SYMBOL_TABLE, 480 ERROR_HANDLER, 481 ENTITY_RESOLVER, 482 ERROR_REPORTER, 483 ENTITY_MANAGER, 484 DOCUMENT_SCANNER, 485 DTD_SCANNER, 486 DTD_PROCESSOR, 487 DTD_VALIDATOR, 488 DATATYPE_VALIDATOR_FACTORY, 489 VALIDATION_MANAGER, 490 SCHEMA_VALIDATOR, 491 XML_STRING, 492 XMLGRAMMAR_POOL, 493 JAXP_SCHEMA_SOURCE, 494 JAXP_SCHEMA_LANGUAGE, 495 SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, }; 500 addRecognizedProperties(recognizedProperties); 501 502 if (symbolTable == null) { 503 symbolTable = new SymbolTable(); 504 } 505 fSymbolTable = symbolTable; 506 fProperties.put(SYMBOL_TABLE, fSymbolTable); 507 508 fGrammarPool = grammarPool; 509 if (fGrammarPool != null) { 510 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); 511 } 512 513 fEntityManager = new XMLEntityManager(); 514 fProperties.put(ENTITY_MANAGER, fEntityManager); 515 addCommonComponent(fEntityManager); 516 517 fErrorReporter = new XMLErrorReporter(); 518 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); 519 fProperties.put(ERROR_REPORTER, fErrorReporter); 520 addCommonComponent(fErrorReporter); 521 522 fNamespaceScanner = new XMLNSDocumentScannerImpl(); 523 fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); 524 addComponent((XMLComponent) fNamespaceScanner); 525 526 fDTDScanner = new XMLDTDScannerImpl(); 527 fProperties.put(DTD_SCANNER, fDTDScanner); 528 addComponent((XMLComponent) fDTDScanner); 529 530 fDTDProcessor = new XMLDTDProcessor(); 531 fProperties.put(DTD_PROCESSOR, fDTDProcessor); 532 addComponent((XMLComponent) fDTDProcessor); 533 534 fDTDValidator = new XMLNSDTDValidator(); 535 fProperties.put(DTD_VALIDATOR, fDTDValidator); 536 addComponent(fDTDValidator); 537 538 fDatatypeValidatorFactory = DTDDVFactory.getInstance(); 539 fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); 540 541 fValidationManager = new ValidationManager(); 542 fProperties.put(VALIDATION_MANAGER, fValidationManager); 543 544 fVersionDetector = new XMLVersionDetector(); 545 546 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 548 XMLMessageFormatter xmft = new XMLMessageFormatter(); 549 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 550 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 551 } 552 553 try { 555 setLocale(Locale.getDefault()); 556 } catch (XNIException e) { 557 } 560 561 fConfigUpdated = false; 562 563 } 565 580 public void setInputSource(XMLInputSource inputSource) 581 throws XMLConfigurationException, IOException { 582 583 588 fInputSource = inputSource; 589 590 } 592 600 public void setLocale(Locale locale) throws XNIException { 601 fLocale = locale; 602 fErrorReporter.setLocale(locale); 603 } 610 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 611 fDocumentHandler = documentHandler; 612 if (fLastComponent != null) { 613 fLastComponent.setDocumentHandler(fDocumentHandler); 614 if (fDocumentHandler !=null){ 615 fDocumentHandler.setDocumentSource(fLastComponent); 616 } 617 } 618 } 620 621 public XMLDocumentHandler getDocumentHandler() { 622 return fDocumentHandler; 623 } 625 630 public void setDTDHandler(XMLDTDHandler dtdHandler) { 631 fDTDHandler = dtdHandler; 632 } 634 635 public XMLDTDHandler getDTDHandler() { 636 return fDTDHandler; 637 } 639 644 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 645 fDTDContentModelHandler = handler; 646 } 648 649 public XMLDTDContentModelHandler getDTDContentModelHandler() { 650 return fDTDContentModelHandler; 651 } 653 660 public void setEntityResolver(XMLEntityResolver resolver) { 661 fProperties.put(ENTITY_RESOLVER, resolver); 662 } 664 671 public XMLEntityResolver getEntityResolver() { 672 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 673 } 675 693 public void setErrorHandler(XMLErrorHandler errorHandler) { 694 fProperties.put(ERROR_HANDLER, errorHandler); 695 } 697 704 public XMLErrorHandler getErrorHandler() { 705 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 707 } 709 710 715 public void cleanup() { 716 fEntityManager.closeReaders(); 717 } 718 719 727 public void parse(XMLInputSource source) throws XNIException, IOException { 728 729 if (fParseInProgress) { 730 throw new XNIException("FWK005 parse may not be called while parsing."); 732 } 733 fParseInProgress = true; 734 735 try { 736 setInputSource(source); 737 parse(true); 738 } catch (XNIException ex) { 739 if (PRINT_EXCEPTION_STACK_TRACE) 740 ex.printStackTrace(); 741 throw ex; 742 } catch (IOException ex) { 743 if (PRINT_EXCEPTION_STACK_TRACE) 744 ex.printStackTrace(); 745 throw ex; 746 } catch (RuntimeException ex) { 747 if (PRINT_EXCEPTION_STACK_TRACE) 748 ex.printStackTrace(); 749 throw ex; 750 } catch (Exception ex) { 751 if (PRINT_EXCEPTION_STACK_TRACE) 752 ex.printStackTrace(); 753 throw new XNIException(ex); 754 } finally { 755 fParseInProgress = false; 756 this.cleanup(); 758 } 759 760 } 762 public boolean parse(boolean complete) throws XNIException, IOException { 763 if (fInputSource != null) { 766 try { 767 fValidationManager.reset(); 768 fVersionDetector.reset(this); 769 resetCommon(); 770 771 short version = fVersionDetector.determineDocVersion(fInputSource); 772 if (version == Constants.XML_VERSION_1_1) { 773 initXML11Components(); 774 configureXML11Pipeline(); 775 resetXML11(); 776 } else { 777 configurePipeline(); 778 reset(); 779 } 780 781 fConfigUpdated = false; 783 784 fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version); 786 fInputSource = null; 787 } catch (XNIException ex) { 788 if (PRINT_EXCEPTION_STACK_TRACE) 789 ex.printStackTrace(); 790 throw ex; 791 } catch (IOException ex) { 792 if (PRINT_EXCEPTION_STACK_TRACE) 793 ex.printStackTrace(); 794 throw ex; 795 } catch (RuntimeException ex) { 796 if (PRINT_EXCEPTION_STACK_TRACE) 797 ex.printStackTrace(); 798 throw ex; 799 } catch (Exception ex) { 800 if (PRINT_EXCEPTION_STACK_TRACE) 801 ex.printStackTrace(); 802 throw new XNIException(ex); 803 } 804 } 805 806 try { 807 return fCurrentScanner.scanDocument(complete); 808 } catch (XNIException ex) { 809 if (PRINT_EXCEPTION_STACK_TRACE) 810 ex.printStackTrace(); 811 throw ex; 812 } catch (IOException ex) { 813 if (PRINT_EXCEPTION_STACK_TRACE) 814 ex.printStackTrace(); 815 throw ex; 816 } catch (RuntimeException ex) { 817 if (PRINT_EXCEPTION_STACK_TRACE) 818 ex.printStackTrace(); 819 throw ex; 820 } catch (Exception ex) { 821 if (PRINT_EXCEPTION_STACK_TRACE) 822 ex.printStackTrace(); 823 throw new XNIException(ex); 824 } 825 826 } 828 840 public boolean getFeature(String featureId) 841 throws XMLConfigurationException { 842 if (featureId.equals(PARSER_SETTINGS)){ 844 return fConfigUpdated; 845 } 846 return super.getFeature(featureId); 847 848 } 850 863 public void setFeature(String featureId, boolean state) 864 throws XMLConfigurationException { 865 fConfigUpdated = true; 866 int count = fComponents.size(); 868 for (int i = 0; i < count; i++) { 869 XMLComponent c = (XMLComponent) fComponents.get(i); 870 c.setFeature(featureId, state); 871 } 872 count = fCommonComponents.size(); 874 for (int i = 0; i < count; i++) { 875 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 876 c.setFeature(featureId, state); 877 } 878 879 count = fXML11Components.size(); 881 for (int i = 0; i < count; i++) { 882 XMLComponent c = (XMLComponent) fXML11Components.get(i); 883 try{ 884 c.setFeature(featureId, state); 885 } 886 catch (Exception e){ 887 } 889 } 890 super.setFeature(featureId, state); 892 893 } 895 901 public void setProperty(String propertyId, Object value) 902 throws XMLConfigurationException { 903 fConfigUpdated = true; 904 int count = fComponents.size(); 906 for (int i = 0; i < count; i++) { 907 XMLComponent c = (XMLComponent) fComponents.get(i); 908 c.setProperty(propertyId, value); 909 } 910 count = fCommonComponents.size(); 912 for (int i = 0; i < count; i++) { 913 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 914 c.setProperty(propertyId, value); 915 } 916 count = fXML11Components.size(); 918 for (int i = 0; i < count; i++) { 919 XMLComponent c = (XMLComponent) fXML11Components.get(i); 920 try{ 921 c.setProperty(propertyId, value); 922 } 923 catch (Exception e){ 924 } 926 } 927 928 super.setProperty(propertyId, value); 930 931 } 933 934 935 public Locale getLocale() { 936 return fLocale; 937 } 939 942 protected void reset() throws XNIException { 943 int count = fComponents.size(); 944 for (int i = 0; i < count; i++) { 945 XMLComponent c = (XMLComponent) fComponents.get(i); 946 c.reset(this); 947 } 948 949 } 951 954 protected void resetCommon() throws XNIException { 955 int count = fCommonComponents.size(); 957 for (int i = 0; i < count; i++) { 958 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 959 c.reset(this); 960 } 961 962 } 964 965 968 protected void resetXML11() throws XNIException { 969 int count = fXML11Components.size(); 971 for (int i = 0; i < count; i++) { 972 XMLComponent c = (XMLComponent) fXML11Components.get(i); 973 c.reset(this); 974 } 975 976 } 978 979 983 protected void configureXML11Pipeline() { 984 if (fCurrentDVFactory != fXML11DatatypeFactory) { 985 fCurrentDVFactory = fXML11DatatypeFactory; 986 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 987 } 988 if (fCurrentDTDScanner != fXML11DTDScanner) { 989 fCurrentDTDScanner = fXML11DTDScanner; 990 setProperty(DTD_SCANNER, fCurrentDTDScanner); 991 setProperty(DTD_PROCESSOR, fXML11DTDProcessor); 992 } 993 994 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 995 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 996 fXML11DTDProcessor.setDTDHandler(fDTDHandler); 997 if (fDTDHandler != null) { 998 fDTDHandler.setDTDSource(fXML11DTDProcessor); 999 } 1000 1001 fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor); 1002 fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner); 1003 fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 1004 if (fDTDContentModelHandler != null) { 1005 fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor); 1006 } 1007 1008 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 1010 if (fCurrentScanner != fXML11NSDocScanner) { 1011 fCurrentScanner = fXML11NSDocScanner; 1012 setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner); 1013 setProperty(DTD_VALIDATOR, fXML11NSDTDValidator); 1014 } 1015 1016 fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator); 1017 fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator); 1018 fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner); 1019 fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler); 1020 1021 if (fDocumentHandler != null) { 1022 fDocumentHandler.setDocumentSource(fXML11NSDTDValidator); 1023 } 1024 fLastComponent = fXML11NSDTDValidator; 1025 1026 } else { 1027 if (fXML11DocScanner == null) { 1029 fXML11DocScanner = new XML11DocumentScannerImpl(); 1031 addXML11Component(fXML11DocScanner); 1032 fXML11DTDValidator = new XML11DTDValidator(); 1033 addXML11Component(fXML11DTDValidator); 1034 } 1035 if (fCurrentScanner != fXML11DocScanner) { 1036 fCurrentScanner = fXML11DocScanner; 1037 setProperty(DOCUMENT_SCANNER, fXML11DocScanner); 1038 setProperty(DTD_VALIDATOR, fXML11DTDValidator); 1039 } 1040 fXML11DocScanner.setDocumentHandler(fXML11DTDValidator); 1041 fXML11DTDValidator.setDocumentSource(fXML11DocScanner); 1042 fXML11DTDValidator.setDocumentHandler(fDocumentHandler); 1043 1044 if (fDocumentHandler != null) { 1045 fDocumentHandler.setDocumentSource(fXML11DTDValidator); 1046 } 1047 fLastComponent = fXML11DTDValidator; 1048 } 1049 1050 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 1052 if (fSchemaValidator == null) { 1054 fSchemaValidator = new XMLSchemaValidator(); 1055 setProperty(SCHEMA_VALIDATOR, fSchemaValidator); 1057 addCommonComponent(fSchemaValidator); 1058 fSchemaValidator.reset(this); 1059 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 1061 XSMessageFormatter xmft = new XSMessageFormatter(); 1062 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 1063 } 1064 } 1065 1066 fLastComponent.setDocumentHandler(fSchemaValidator); 1067 fSchemaValidator.setDocumentSource(fLastComponent); 1068 fSchemaValidator.setDocumentHandler(fDocumentHandler); 1069 if (fDocumentHandler != null) { 1070 fDocumentHandler.setDocumentSource(fSchemaValidator); 1071 } 1072 fLastComponent = fSchemaValidator; 1073 } 1074 1075 } 1077 1078 protected void configurePipeline() { 1079 if (fCurrentDVFactory != fDatatypeValidatorFactory) { 1080 fCurrentDVFactory = fDatatypeValidatorFactory; 1081 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 1083 } 1084 1085 if (fCurrentDTDScanner != fDTDScanner) { 1087 fCurrentDTDScanner = fDTDScanner; 1088 setProperty(DTD_SCANNER, fCurrentDTDScanner); 1089 setProperty(DTD_PROCESSOR, fDTDProcessor); 1090 } 1091 fDTDScanner.setDTDHandler(fDTDProcessor); 1092 fDTDProcessor.setDTDSource(fDTDScanner); 1093 fDTDProcessor.setDTDHandler(fDTDHandler); 1094 if (fDTDHandler != null) { 1095 fDTDHandler.setDTDSource(fDTDProcessor); 1096 } 1097 1098 fDTDScanner.setDTDContentModelHandler(fDTDProcessor); 1099 fDTDProcessor.setDTDContentModelSource(fDTDScanner); 1100 fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 1101 if (fDTDContentModelHandler != null) { 1102 fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor); 1103 } 1104 1105 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 1107 if (fCurrentScanner != fNamespaceScanner) { 1108 fCurrentScanner = fNamespaceScanner; 1109 setProperty(DOCUMENT_SCANNER, fNamespaceScanner); 1110 setProperty(DTD_VALIDATOR, fDTDValidator); 1111 } 1112 fNamespaceScanner.setDTDValidator(fDTDValidator); 1113 fNamespaceScanner.setDocumentHandler(fDTDValidator); 1114 fDTDValidator.setDocumentSource(fNamespaceScanner); 1115 fDTDValidator.setDocumentHandler(fDocumentHandler); 1116 if (fDocumentHandler != null) { 1117 fDocumentHandler.setDocumentSource(fDTDValidator); 1118 } 1119 fLastComponent = fDTDValidator; 1120 } else { 1121 if (fNonNSScanner == null) { 1123 fNonNSScanner = new XMLDocumentScannerImpl(); 1124 fNonNSDTDValidator = new XMLDTDValidator(); 1125 addComponent((XMLComponent) fNonNSScanner); 1127 addComponent((XMLComponent) fNonNSDTDValidator); 1128 } 1129 if (fCurrentScanner != fNonNSScanner) { 1130 fCurrentScanner = fNonNSScanner; 1131 setProperty(DOCUMENT_SCANNER, fNonNSScanner); 1132 setProperty(DTD_VALIDATOR, fNonNSDTDValidator); 1133 } 1134 1135 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator); 1136 fNonNSDTDValidator.setDocumentSource(fNonNSScanner); 1137 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler); 1138 if (fDocumentHandler != null) { 1139 fDocumentHandler.setDocumentSource(fNonNSDTDValidator); 1140 } 1141 fLastComponent = fNonNSDTDValidator; 1142 } 1143 1144 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 1146 if (fSchemaValidator == null) { 1148 fSchemaValidator = new XMLSchemaValidator(); 1149 setProperty(SCHEMA_VALIDATOR, fSchemaValidator); 1151 addCommonComponent(fSchemaValidator); 1152 fSchemaValidator.reset(this); 1153 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 1155 XSMessageFormatter xmft = new XSMessageFormatter(); 1156 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 1157 } 1158 1159 } 1160 fLastComponent.setDocumentHandler(fSchemaValidator); 1161 fSchemaValidator.setDocumentSource(fLastComponent); 1162 fSchemaValidator.setDocumentHandler(fDocumentHandler); 1163 if (fDocumentHandler != null) { 1164 fDocumentHandler.setDocumentSource(fSchemaValidator); 1165 } 1166 fLastComponent = fSchemaValidator; 1167 } 1168 } 1170 1171 1173 1185 protected void checkFeature(String featureId) throws XMLConfigurationException { 1186 1187 1191 if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { 1192 final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); 1193 1194 if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && 1201 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { 1202 return; 1203 } 1204 1205 if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && 1209 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { 1210 short type = XMLConfigurationException.NOT_SUPPORTED; 1212 throw new XMLConfigurationException(type, featureId); 1213 } 1214 if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && 1218 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { 1219 short type = XMLConfigurationException.NOT_SUPPORTED; 1221 throw new XMLConfigurationException(type, featureId); 1222 } 1223 if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && 1227 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { 1228 return; 1229 } 1230 if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && 1234 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { 1235 return; 1236 } 1237 1238 if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && 1242 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { 1243 short type = XMLConfigurationException.NOT_SUPPORTED; 1244 throw new XMLConfigurationException(type, featureId); 1245 } 1246 1247 if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() && 1252 featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) { 1253 return; 1254 } 1255 if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() && 1257 featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) { 1258 return; 1259 } 1260 if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() && 1263 featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) { 1264 return; 1265 } 1266 if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() && 1269 featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) { 1270 return; 1271 } 1272 1273 if (suffixLength == Constants.PARSER_SETTINGS.length() && 1275 featureId.endsWith(Constants.PARSER_SETTINGS)) { 1276 short type = XMLConfigurationException.NOT_SUPPORTED; 1277 throw new XMLConfigurationException(type, featureId); 1278 } 1279 1280 } 1281 1282 1286 super.checkFeature(featureId); 1287 1288 } 1290 1303 protected void checkProperty(String propertyId) throws XMLConfigurationException { 1304 1305 1309 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 1310 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 1311 1312 if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && 1313 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { 1314 return; 1315 } 1316 if (suffixLength == Constants.SCHEMA_LOCATION.length() && 1317 propertyId.endsWith(Constants.SCHEMA_LOCATION)) { 1318 return; 1319 } 1320 if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() && 1321 propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) { 1322 return; 1323 } 1324 } 1325 1326 if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) { 1327 final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length(); 1328 1329 if (suffixLength == Constants.SCHEMA_SOURCE.length() && 1330 propertyId.endsWith(Constants.SCHEMA_SOURCE)) { 1331 return; 1332 } 1333 } 1334 1335 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1337 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1338 1339 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1350 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1351 short type = XMLConfigurationException.NOT_SUPPORTED; 1355 throw new XMLConfigurationException(type, propertyId); 1356 } 1357 } 1358 1359 1363 super.checkProperty(propertyId); 1364 1365 } 1367 1368 1375 protected void addComponent(XMLComponent component) { 1376 1377 if (fComponents.contains(component)) { 1379 return; 1380 } 1381 fComponents.add(component); 1382 addRecognizedParamsAndSetDefaults(component); 1383 1384 } 1386 1393 protected void addCommonComponent(XMLComponent component) { 1394 1395 if (fCommonComponents.contains(component)) { 1397 return; 1398 } 1399 fCommonComponents.add(component); 1400 addRecognizedParamsAndSetDefaults(component); 1401 1402 } 1404 1411 protected void addXML11Component(XMLComponent component) { 1412 1413 if (fXML11Components.contains(component)) { 1415 return; 1416 } 1417 fXML11Components.add(component); 1418 addRecognizedParamsAndSetDefaults(component); 1419 1420 } 1422 1431 protected void addRecognizedParamsAndSetDefaults(XMLComponent component) { 1432 1433 String [] recognizedFeatures = component.getRecognizedFeatures(); 1435 addRecognizedFeatures(recognizedFeatures); 1436 1437 String [] recognizedProperties = component.getRecognizedProperties(); 1439 addRecognizedProperties(recognizedProperties); 1440 1441 if (recognizedFeatures != null) { 1443 for (int i = 0; i < recognizedFeatures.length; ++i) { 1444 String featureId = recognizedFeatures[i]; 1445 Boolean state = component.getFeatureDefault(featureId); 1446 if (state != null) { 1447 if (!fFeatures.containsKey(featureId)) { 1449 fFeatures.put(featureId, state); 1450 fConfigUpdated = true; 1455 } 1456 } 1457 } 1458 } 1459 if (recognizedProperties != null) { 1460 for (int i = 0; i < recognizedProperties.length; ++i) { 1461 String propertyId = recognizedProperties[i]; 1462 Object value = component.getPropertyDefault(propertyId); 1463 if (value != null) { 1464 if (!fProperties.containsKey(propertyId)) { 1466 fProperties.put(propertyId, value); 1467 fConfigUpdated = true; 1472 } 1473 } 1474 } 1475 } 1476 } 1477 1478 private void initXML11Components() { 1479 if (!f11Initialized) { 1480 1481 fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); 1483 1484 fXML11DTDScanner = new XML11DTDScannerImpl(); 1486 addXML11Component(fXML11DTDScanner); 1487 fXML11DTDProcessor = new XML11DTDProcessor(); 1488 addXML11Component(fXML11DTDProcessor); 1489 1490 fXML11NSDocScanner = new XML11NSDocumentScannerImpl(); 1492 addXML11Component(fXML11NSDocScanner); 1493 fXML11NSDTDValidator = new XML11NSDTDValidator(); 1494 addXML11Component(fXML11NSDTDValidator); 1495 1496 f11Initialized = true; 1497 } 1498 } 1499 1500 1505 boolean getFeature0(String featureId) 1506 throws XMLConfigurationException { 1507 return super.getFeature(featureId); 1508 } 1509 1510} | Popular Tags |