1 57 58 59 package com.sun.org.apache.xerces.internal.parsers; 60 61 import java.io.IOException ; 62 import java.util.ArrayList ; 63 import java.util.HashMap ; 64 import java.util.Locale ; 65 66 import com.sun.org.apache.xerces.internal.impl.Constants; 67 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl; 68 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl; 69 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl; 70 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl; 71 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl; 72 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler; 73 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; 74 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 75 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl; 76 import com.sun.org.apache.xerces.internal.impl.XMLVersionDetector; 77 import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDProcessor; 78 import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDValidator; 79 import com.sun.org.apache.xerces.internal.impl.dtd.XML11NSDTDValidator; 80 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor; 81 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator; 82 import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator; 83 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; 84 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 85 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 86 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator; 87 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; 88 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; 89 import com.sun.org.apache.xerces.internal.util.SymbolTable; 90 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 91 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 92 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 93 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 94 import com.sun.org.apache.xerces.internal.xni.XNIException; 95 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 96 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 97 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 98 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 99 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; 100 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; 101 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 102 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 103 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 104 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 105 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; 106 107 117 public class XML11Configuration extends ParserConfigurationSettings 118 implements XMLPullParserConfiguration { 119 120 protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = 124 "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl"; 125 126 128 129 protected static final String WARN_ON_DUPLICATE_ATTDEF = 130 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 131 132 133 protected static final String WARN_ON_DUPLICATE_ENTITYDEF = 134 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE; 135 136 137 protected static final String WARN_ON_UNDECLARED_ELEMDEF = 138 Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE; 139 140 141 protected static final String ALLOW_JAVA_ENCODINGS = 142 Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; 143 144 145 protected static final String CONTINUE_AFTER_FATAL_ERROR = 146 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 147 148 149 protected static final String LOAD_EXTERNAL_DTD = 150 Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; 151 152 153 protected static final String NOTIFY_BUILTIN_REFS = 154 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE; 155 156 157 protected static final String NOTIFY_CHAR_REFS = 158 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE; 159 160 161 protected static final String NORMALIZE_DATA = 162 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 163 164 165 protected static final String SCHEMA_ELEMENT_DEFAULT = 166 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; 167 168 169 protected static final String SCHEMA_AUGMENT_PSVI = 170 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 171 172 173 protected static final String XMLSCHEMA_VALIDATION = 174 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 175 176 177 protected static final String XMLSCHEMA_FULL_CHECKING = 178 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 179 180 182 183 protected static final String VALIDATION = 184 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 185 186 187 protected static final String NAMESPACES = 188 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 189 190 191 protected static final String EXTERNAL_GENERAL_ENTITIES = 192 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; 193 194 195 protected static final String EXTERNAL_PARAMETER_ENTITIES = 196 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; 197 198 protected static final String EXPAND_URIS = Constants.SAX_FEATURE_PREFIX + Constants.RESOLVE_DTD_URIS_FEATURE; 199 protected static final String XML_VERSION_SUPPORT = Constants.SAX_FEATURE_PREFIX + Constants.XML_11_FEATURE; 200 protected static final String NORMALIZAION_CHECKS = Constants.SAX_FEATURE_PREFIX + Constants.UNICODE_NORMALIZATION_CHECKING_FEATURE; 201 202 204 205 206 protected static final String XML_STRING = 207 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 208 209 210 protected static final String SYMBOL_TABLE = 211 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 212 213 214 protected static final String ERROR_HANDLER = 215 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 216 217 218 protected static final String ENTITY_RESOLVER = 219 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 220 221 222 223 protected static final String SCHEMA_VALIDATOR = 224 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; 225 226 227 protected static final String SCHEMA_LOCATION = 228 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION; 229 230 231 protected static final String SCHEMA_NONS_LOCATION = 232 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; 233 234 236 237 protected static final String ERROR_REPORTER = 238 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 239 240 241 protected static final String ENTITY_MANAGER = 242 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 243 244 245 protected static final String DOCUMENT_SCANNER = 246 Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; 247 248 249 protected static final String DTD_SCANNER = 250 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; 251 252 253 protected static final String XMLGRAMMAR_POOL = 254 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 255 256 257 protected static final String DTD_PROCESSOR = 258 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY; 259 260 261 protected static final String DTD_VALIDATOR = 262 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 263 264 265 protected static final String NAMESPACE_BINDER = 266 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; 267 268 269 protected static final String DATATYPE_VALIDATOR_FACTORY = 270 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 271 272 protected static final String VALIDATION_MANAGER = 273 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 274 275 276 protected static final String JAXP_SCHEMA_LANGUAGE = 277 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 278 279 280 protected static final String JAXP_SCHEMA_SOURCE = 281 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 282 283 284 286 287 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; 288 289 293 protected SymbolTable fSymbolTable; 294 protected XMLInputSource fInputSource; 295 protected ValidationManager fValidationManager; 296 protected XMLVersionDetector fVersionDetector; 297 protected XMLLocator fLocator; 298 protected Locale fLocale; 299 300 301 protected ArrayList fComponents; 302 303 304 protected ArrayList fXML11Components = null; 305 306 307 protected ArrayList fCommonComponents = null; 308 309 310 protected XMLDocumentHandler fDocumentHandler; 311 312 313 protected XMLDTDHandler fDTDHandler; 314 315 316 protected XMLDTDContentModelHandler fDTDContentModelHandler; 317 318 319 protected XMLDocumentSource fLastComponent; 320 321 326 protected boolean fParseInProgress = false; 327 328 331 protected boolean fConfigUpdated = false; 332 333 337 338 protected DTDDVFactory fDatatypeValidatorFactory; 339 340 341 protected XMLNSDocumentScannerImpl fNamespaceScanner; 342 343 protected XMLDocumentScannerImpl fNonNSScanner; 344 345 protected XMLDTDValidator fDTDValidator; 346 347 protected XMLDTDValidator fNonNSDTDValidator; 348 349 protected XMLDTDScanner fDTDScanner; 350 351 protected XMLDTDProcessor fDTDProcessor; 352 353 357 358 protected DTDDVFactory fXML11DatatypeFactory = null; 359 360 361 protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; 362 363 364 protected XML11DocumentScannerImpl fXML11DocScanner = null; 365 366 367 protected XML11NSDTDValidator fXML11NSDTDValidator = null; 368 369 370 protected XML11DTDValidator fXML11DTDValidator = null; 371 372 373 protected XML11DTDScannerImpl fXML11DTDScanner = null; 374 375 protected XML11DTDProcessor fXML11DTDProcessor = null; 376 377 381 382 protected XMLGrammarPool fGrammarPool; 383 384 385 protected XMLErrorReporter fErrorReporter; 386 387 388 protected XMLEntityManager fEntityManager; 389 390 391 protected XMLSchemaValidator fSchemaValidator; 392 393 394 protected XMLDocumentScanner fCurrentScanner; 395 396 protected DTDDVFactory fCurrentDVFactory; 397 398 protected XMLDTDScanner fCurrentDTDScanner; 399 400 401 private boolean f11Initialized = false; 402 403 407 408 public XML11Configuration() { 409 this(null, null, null); 410 } 412 417 public XML11Configuration(SymbolTable symbolTable) { 418 this(symbolTable, null, null); 419 } 421 432 public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 433 this(symbolTable, grammarPool, null); 434 } 436 448 public XML11Configuration( 449 SymbolTable symbolTable, 450 XMLGrammarPool grammarPool, 451 XMLComponentManager parentSettings) { 452 453 super(parentSettings); 454 455 fComponents = new ArrayList (); 458 fXML11Components = new ArrayList (); 460 fCommonComponents = new ArrayList (); 462 463 fRecognizedFeatures = new ArrayList (); 465 fRecognizedProperties = new ArrayList (); 466 467 fFeatures = new HashMap (); 469 fProperties = new HashMap (); 470 471 final String [] recognizedFeatures = { 473 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, VALIDATION, 475 NAMESPACES, 476 NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI, 477 XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING, 482 EXTERNAL_GENERAL_ENTITIES, 483 EXTERNAL_PARAMETER_ENTITIES, 484 PARSER_SETTINGS, 485 EXPAND_URIS, 486 XML_VERSION_SUPPORT, 487 NORMALIZAION_CHECKS 488 }; 489 addRecognizedFeatures(recognizedFeatures); 490 fFeatures.put(VALIDATION, Boolean.FALSE); 492 fFeatures.put(NAMESPACES, Boolean.TRUE); 493 fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE); 494 fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE); 495 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); 496 fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE); 497 fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE); 498 fFeatures.put(NORMALIZE_DATA, Boolean.TRUE); 499 fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); 500 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); 501 fFeatures.put(EXPAND_URIS, Boolean.TRUE); 502 fFeatures.put(XML_VERSION_SUPPORT, Boolean.TRUE); 503 fFeatures.put(NORMALIZAION_CHECKS, Boolean.FALSE); 504 final String [] recognizedProperties = { 506 SYMBOL_TABLE, 507 ERROR_HANDLER, 508 ENTITY_RESOLVER, 509 ERROR_REPORTER, 510 ENTITY_MANAGER, 511 DOCUMENT_SCANNER, 512 DTD_SCANNER, 513 DTD_PROCESSOR, 514 DTD_VALIDATOR, 515 DATATYPE_VALIDATOR_FACTORY, 516 VALIDATION_MANAGER, 517 SCHEMA_VALIDATOR, 518 XML_STRING, 519 XMLGRAMMAR_POOL, 520 JAXP_SCHEMA_SOURCE, 521 JAXP_SCHEMA_LANGUAGE, 522 SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, }; 527 addRecognizedProperties(recognizedProperties); 528 529 if (symbolTable == null) { 530 symbolTable = new SymbolTable(); 531 } 532 fSymbolTable = symbolTable; 533 fProperties.put(SYMBOL_TABLE, fSymbolTable); 534 535 fGrammarPool = grammarPool; 536 if (fGrammarPool != null) { 537 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); 538 } 539 540 fEntityManager = new XMLEntityManager(); 541 fProperties.put(ENTITY_MANAGER, fEntityManager); 542 addCommonComponent(fEntityManager); 543 544 fErrorReporter = new XMLErrorReporter(); 545 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); 546 fProperties.put(ERROR_REPORTER, fErrorReporter); 547 addCommonComponent(fErrorReporter); 548 549 fNamespaceScanner = new XMLNSDocumentScannerImpl(); 550 fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); 551 addComponent((XMLComponent) fNamespaceScanner); 552 553 fDTDScanner = new XMLDTDScannerImpl(); 554 fProperties.put(DTD_SCANNER, fDTDScanner); 555 addComponent((XMLComponent) fDTDScanner); 556 557 fDTDProcessor = new XMLDTDProcessor(); 558 fProperties.put(DTD_PROCESSOR, fDTDProcessor); 559 addComponent((XMLComponent) fDTDProcessor); 560 561 fDTDValidator = new XMLNSDTDValidator(); 562 fProperties.put(DTD_VALIDATOR, fDTDValidator); 563 addComponent(fDTDValidator); 564 565 fDatatypeValidatorFactory = DTDDVFactory.getInstance(); 566 fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); 567 568 fValidationManager = new ValidationManager(); 569 fProperties.put(VALIDATION_MANAGER, fValidationManager); 570 571 fVersionDetector = new XMLVersionDetector(); 572 573 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 575 XMLMessageFormatter xmft = new XMLMessageFormatter(); 576 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 577 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 578 } 579 580 try { 582 setLocale(Locale.getDefault()); 583 } catch (XNIException e) { 584 } 587 588 fConfigUpdated = false; 589 590 } 592 607 public void setInputSource(XMLInputSource inputSource) 608 throws XMLConfigurationException, IOException { 609 610 615 fInputSource = inputSource; 616 617 } 619 627 public void setLocale(Locale locale) throws XNIException { 628 fLocale = locale; 629 fErrorReporter.setLocale(locale); 630 } 637 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 638 fDocumentHandler = documentHandler; 639 if (fLastComponent != null) { 640 fLastComponent.setDocumentHandler(fDocumentHandler); 641 if (fDocumentHandler !=null){ 642 fDocumentHandler.setDocumentSource(fLastComponent); 643 } 644 } 645 } 647 648 public XMLDocumentHandler getDocumentHandler() { 649 return fDocumentHandler; 650 } 652 657 public void setDTDHandler(XMLDTDHandler dtdHandler) { 658 fDTDHandler = dtdHandler; 659 } 661 662 public XMLDTDHandler getDTDHandler() { 663 return fDTDHandler; 664 } 666 671 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 672 fDTDContentModelHandler = handler; 673 } 675 676 public XMLDTDContentModelHandler getDTDContentModelHandler() { 677 return fDTDContentModelHandler; 678 } 680 687 public void setEntityResolver(XMLEntityResolver resolver) { 688 fProperties.put(ENTITY_RESOLVER, resolver); 689 } 691 698 public XMLEntityResolver getEntityResolver() { 699 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 700 } 702 720 public void setErrorHandler(XMLErrorHandler errorHandler) { 721 fProperties.put(ERROR_HANDLER, errorHandler); 722 } 724 731 public XMLErrorHandler getErrorHandler() { 732 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 734 } 736 737 742 public void cleanup() { 743 fEntityManager.closeReaders(); 744 } 745 746 754 public void parse(XMLInputSource source) throws XNIException, IOException { 755 756 if (fParseInProgress) { 757 throw new XNIException("FWK005 parse may not be called while parsing."); 759 } 760 fParseInProgress = true; 761 762 try { 763 setInputSource(source); 764 parse(true); 765 } catch (XNIException ex) { 766 if (PRINT_EXCEPTION_STACK_TRACE) 767 ex.printStackTrace(); 768 throw ex; 769 } catch (IOException ex) { 770 if (PRINT_EXCEPTION_STACK_TRACE) 771 ex.printStackTrace(); 772 throw ex; 773 } catch (RuntimeException ex) { 774 if (PRINT_EXCEPTION_STACK_TRACE) 775 ex.printStackTrace(); 776 throw ex; 777 } catch (Exception ex) { 778 if (PRINT_EXCEPTION_STACK_TRACE) 779 ex.printStackTrace(); 780 throw new XNIException(ex); 781 } finally { 782 fParseInProgress = false; 783 this.cleanup(); 785 } 786 787 } 789 public boolean parse(boolean complete) throws XNIException, IOException { 790 if (fInputSource != null) { 793 try { 794 fValidationManager.reset(); 795 fVersionDetector.reset(this); 796 resetCommon(); 797 798 short version = fVersionDetector.determineDocVersion(fInputSource); 799 if (version == Constants.XML_VERSION_1_1) { 800 initXML11Components(); 801 configureXML11Pipeline(); 802 resetXML11(); 803 } else { 804 configurePipeline(); 805 reset(); 806 } 807 808 fConfigUpdated = false; 810 811 fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version); 813 fInputSource = null; 814 } catch (XNIException ex) { 815 if (PRINT_EXCEPTION_STACK_TRACE) 816 ex.printStackTrace(); 817 throw ex; 818 } catch (IOException ex) { 819 if (PRINT_EXCEPTION_STACK_TRACE) 820 ex.printStackTrace(); 821 throw ex; 822 } catch (RuntimeException ex) { 823 if (PRINT_EXCEPTION_STACK_TRACE) 824 ex.printStackTrace(); 825 throw ex; 826 } catch (Exception ex) { 827 if (PRINT_EXCEPTION_STACK_TRACE) 828 ex.printStackTrace(); 829 throw new XNIException(ex); 830 } 831 } 832 833 try { 834 return fCurrentScanner.scanDocument(complete); 835 } catch (XNIException ex) { 836 if (PRINT_EXCEPTION_STACK_TRACE) 837 ex.printStackTrace(); 838 throw ex; 839 } catch (IOException ex) { 840 if (PRINT_EXCEPTION_STACK_TRACE) 841 ex.printStackTrace(); 842 throw ex; 843 } catch (RuntimeException ex) { 844 if (PRINT_EXCEPTION_STACK_TRACE) 845 ex.printStackTrace(); 846 throw ex; 847 } catch (Exception ex) { 848 if (PRINT_EXCEPTION_STACK_TRACE) 849 ex.printStackTrace(); 850 throw new XNIException(ex); 851 } 852 853 } 855 867 public boolean getFeature(String featureId) 868 throws XMLConfigurationException { 869 if (featureId.equals(PARSER_SETTINGS)){ 871 return fConfigUpdated; 872 } 873 return super.getFeature(featureId); 874 875 } 877 890 public void setFeature(String featureId, boolean state) 891 throws XMLConfigurationException { 892 fConfigUpdated = true; 893 int count = fComponents.size(); 895 for (int i = 0; i < count; i++) { 896 XMLComponent c = (XMLComponent) fComponents.get(i); 897 c.setFeature(featureId, state); 898 } 899 count = fCommonComponents.size(); 901 for (int i = 0; i < count; i++) { 902 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 903 c.setFeature(featureId, state); 904 } 905 906 count = fXML11Components.size(); 908 for (int i = 0; i < count; i++) { 909 XMLComponent c = (XMLComponent) fXML11Components.get(i); 910 try{ 911 c.setFeature(featureId, state); 912 } 913 catch (Exception e){ 914 } 916 } 917 super.setFeature(featureId, state); 919 920 } 922 928 public void setProperty(String propertyId, Object value) 929 throws XMLConfigurationException { 930 fConfigUpdated = true; 931 int count = fComponents.size(); 933 for (int i = 0; i < count; i++) { 934 XMLComponent c = (XMLComponent) fComponents.get(i); 935 c.setProperty(propertyId, value); 936 } 937 count = fCommonComponents.size(); 939 for (int i = 0; i < count; i++) { 940 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 941 c.setProperty(propertyId, value); 942 } 943 count = fXML11Components.size(); 945 for (int i = 0; i < count; i++) { 946 XMLComponent c = (XMLComponent) fXML11Components.get(i); 947 try{ 948 c.setProperty(propertyId, value); 949 } 950 catch (Exception e){ 951 } 953 } 954 955 super.setProperty(propertyId, value); 957 958 } 960 961 962 public Locale getLocale() { 963 return fLocale; 964 } 966 969 protected void reset() throws XNIException { 970 int count = fComponents.size(); 971 for (int i = 0; i < count; i++) { 972 XMLComponent c = (XMLComponent) fComponents.get(i); 973 c.reset(this); 974 } 975 976 } 978 981 protected void resetCommon() throws XNIException { 982 int count = fCommonComponents.size(); 984 for (int i = 0; i < count; i++) { 985 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 986 c.reset(this); 987 } 988 989 } 991 992 995 protected void resetXML11() throws XNIException { 996 int count = fXML11Components.size(); 998 for (int i = 0; i < count; i++) { 999 XMLComponent c = (XMLComponent) fXML11Components.get(i); 1000 c.reset(this); 1001 } 1002 1003 } 1005 1006 1010 protected void configureXML11Pipeline() { 1011 if (fCurrentDVFactory != fXML11DatatypeFactory) { 1012 fCurrentDVFactory = fXML11DatatypeFactory; 1013 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 1014 } 1015 if (fCurrentDTDScanner != fXML11DTDScanner) { 1016 fCurrentDTDScanner = fXML11DTDScanner; 1017 setProperty(DTD_SCANNER, fCurrentDTDScanner); 1018 setProperty(DTD_PROCESSOR, fXML11DTDProcessor); 1019 } 1020 1021 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 1022 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 1023 fXML11DTDProcessor.setDTDHandler(fDTDHandler); 1024 if (fDTDHandler != null) { 1025 fDTDHandler.setDTDSource(fXML11DTDProcessor); 1026 } 1027 1028 fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor); 1029 fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner); 1030 fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 1031 if (fDTDContentModelHandler != null) { 1032 fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor); 1033 } 1034 1035 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 1037 if (fCurrentScanner != fXML11NSDocScanner) { 1038 fCurrentScanner = fXML11NSDocScanner; 1039 setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner); 1040 setProperty(DTD_VALIDATOR, fXML11NSDTDValidator); 1041 } 1042 1043 fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator); 1044 fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator); 1045 fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner); 1046 fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler); 1047 1048 if (fDocumentHandler != null) { 1049 fDocumentHandler.setDocumentSource(fXML11NSDTDValidator); 1050 } 1051 fLastComponent = fXML11NSDTDValidator; 1052 1053 } else { 1054 if (fXML11DocScanner == null) { 1056 fXML11DocScanner = new XML11DocumentScannerImpl(); 1058 addXML11Component(fXML11DocScanner); 1059 fXML11DTDValidator = new XML11DTDValidator(); 1060 addXML11Component(fXML11DTDValidator); 1061 } 1062 if (fCurrentScanner != fXML11DocScanner) { 1063 fCurrentScanner = fXML11DocScanner; 1064 setProperty(DOCUMENT_SCANNER, fXML11DocScanner); 1065 setProperty(DTD_VALIDATOR, fXML11DTDValidator); 1066 } 1067 fXML11DocScanner.setDocumentHandler(fXML11DTDValidator); 1068 fXML11DTDValidator.setDocumentSource(fXML11DocScanner); 1069 fXML11DTDValidator.setDocumentHandler(fDocumentHandler); 1070 1071 if (fDocumentHandler != null) { 1072 fDocumentHandler.setDocumentSource(fXML11DTDValidator); 1073 } 1074 fLastComponent = fXML11DTDValidator; 1075 } 1076 1077 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 1079 if (fSchemaValidator == null) { 1081 fSchemaValidator = new XMLSchemaValidator(); 1082 setProperty(SCHEMA_VALIDATOR, fSchemaValidator); 1084 addCommonComponent(fSchemaValidator); 1085 fSchemaValidator.reset(this); 1086 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 1088 XSMessageFormatter xmft = new XSMessageFormatter(); 1089 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 1090 } 1091 } 1092 1093 fLastComponent.setDocumentHandler(fSchemaValidator); 1094 fSchemaValidator.setDocumentSource(fLastComponent); 1095 fSchemaValidator.setDocumentHandler(fDocumentHandler); 1096 if (fDocumentHandler != null) { 1097 fDocumentHandler.setDocumentSource(fSchemaValidator); 1098 } 1099 fLastComponent = fSchemaValidator; 1100 } 1101 1102 } 1104 1105 protected void configurePipeline() { 1106 if (fCurrentDVFactory != fDatatypeValidatorFactory) { 1107 fCurrentDVFactory = fDatatypeValidatorFactory; 1108 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 1110 } 1111 1112 if (fCurrentDTDScanner != fDTDScanner) { 1114 fCurrentDTDScanner = fDTDScanner; 1115 setProperty(DTD_SCANNER, fCurrentDTDScanner); 1116 setProperty(DTD_PROCESSOR, fDTDProcessor); 1117 } 1118 fDTDScanner.setDTDHandler(fDTDProcessor); 1119 fDTDProcessor.setDTDSource(fDTDScanner); 1120 fDTDProcessor.setDTDHandler(fDTDHandler); 1121 if (fDTDHandler != null) { 1122 fDTDHandler.setDTDSource(fDTDProcessor); 1123 } 1124 1125 fDTDScanner.setDTDContentModelHandler(fDTDProcessor); 1126 fDTDProcessor.setDTDContentModelSource(fDTDScanner); 1127 fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 1128 if (fDTDContentModelHandler != null) { 1129 fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor); 1130 } 1131 1132 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 1134 if (fCurrentScanner != fNamespaceScanner) { 1135 fCurrentScanner = fNamespaceScanner; 1136 setProperty(DOCUMENT_SCANNER, fNamespaceScanner); 1137 setProperty(DTD_VALIDATOR, fDTDValidator); 1138 } 1139 fNamespaceScanner.setDTDValidator(fDTDValidator); 1140 fNamespaceScanner.setDocumentHandler(fDTDValidator); 1141 fDTDValidator.setDocumentSource(fNamespaceScanner); 1142 fDTDValidator.setDocumentHandler(fDocumentHandler); 1143 if (fDocumentHandler != null) { 1144 fDocumentHandler.setDocumentSource(fDTDValidator); 1145 } 1146 fLastComponent = fDTDValidator; 1147 } else { 1148 if (fNonNSScanner == null) { 1150 fNonNSScanner = new XMLDocumentScannerImpl(); 1151 fNonNSDTDValidator = new XMLDTDValidator(); 1152 addComponent((XMLComponent) fNonNSScanner); 1154 addComponent((XMLComponent) fNonNSDTDValidator); 1155 } 1156 if (fCurrentScanner != fNonNSScanner) { 1157 fCurrentScanner = fNonNSScanner; 1158 setProperty(DOCUMENT_SCANNER, fNonNSScanner); 1159 setProperty(DTD_VALIDATOR, fNonNSDTDValidator); 1160 } 1161 1162 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator); 1163 fNonNSDTDValidator.setDocumentSource(fNonNSScanner); 1164 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler); 1165 if (fDocumentHandler != null) { 1166 fDocumentHandler.setDocumentSource(fNonNSDTDValidator); 1167 } 1168 fLastComponent = fNonNSDTDValidator; 1169 } 1170 1171 if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { 1173 if (fSchemaValidator == null) { 1175 fSchemaValidator = new XMLSchemaValidator(); 1176 setProperty(SCHEMA_VALIDATOR, fSchemaValidator); 1178 addCommonComponent(fSchemaValidator); 1179 fSchemaValidator.reset(this); 1180 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 1182 XSMessageFormatter xmft = new XSMessageFormatter(); 1183 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 1184 } 1185 1186 } 1187 fLastComponent.setDocumentHandler(fSchemaValidator); 1188 fSchemaValidator.setDocumentSource(fLastComponent); 1189 fSchemaValidator.setDocumentHandler(fDocumentHandler); 1190 if (fDocumentHandler != null) { 1191 fDocumentHandler.setDocumentSource(fSchemaValidator); 1192 } 1193 fLastComponent = fSchemaValidator; 1194 } 1195 } 1197 1198 1200 1212 protected void checkFeature(String featureId) throws XMLConfigurationException { 1213 1214 1218 if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { 1219 final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); 1220 1221 if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && 1228 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { 1229 return; 1230 } 1231 1232 if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && 1236 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { 1237 short type = XMLConfigurationException.NOT_SUPPORTED; 1239 throw new XMLConfigurationException(type, featureId); 1240 } 1241 if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && 1245 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { 1246 short type = XMLConfigurationException.NOT_SUPPORTED; 1248 throw new XMLConfigurationException(type, featureId); 1249 } 1250 if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && 1254 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { 1255 return; 1256 } 1257 if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && 1261 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { 1262 return; 1263 } 1264 1265 if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && 1269 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { 1270 short type = XMLConfigurationException.NOT_SUPPORTED; 1271 throw new XMLConfigurationException(type, featureId); 1272 } 1273 1274 if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() && 1279 featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) { 1280 return; 1281 } 1282 if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() && 1284 featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) { 1285 return; 1286 } 1287 if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() && 1290 featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) { 1291 return; 1292 } 1293 if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() && 1296 featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) { 1297 return; 1298 } 1299 1300 if (suffixLength == Constants.PARSER_SETTINGS.length() && 1302 featureId.endsWith(Constants.PARSER_SETTINGS)) { 1303 short type = XMLConfigurationException.NOT_SUPPORTED; 1304 throw new XMLConfigurationException(type, featureId); 1305 } 1306 1307 } 1308 1309 1313 super.checkFeature(featureId); 1314 1315 } 1317 1330 protected void checkProperty(String propertyId) throws XMLConfigurationException { 1331 1332 1336 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 1337 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 1338 1339 if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && 1340 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { 1341 return; 1342 } 1343 if (suffixLength == Constants.SCHEMA_LOCATION.length() && 1344 propertyId.endsWith(Constants.SCHEMA_LOCATION)) { 1345 return; 1346 } 1347 if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() && 1348 propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) { 1349 return; 1350 } 1351 } 1352 1353 if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) { 1354 final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length(); 1355 1356 if (suffixLength == Constants.SCHEMA_SOURCE.length() && 1357 propertyId.endsWith(Constants.SCHEMA_SOURCE)) { 1358 return; 1359 } 1360 } 1361 1362 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1364 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1365 1366 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1377 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1378 short type = XMLConfigurationException.NOT_SUPPORTED; 1382 throw new XMLConfigurationException(type, propertyId); 1383 } 1384 } 1385 1386 1390 super.checkProperty(propertyId); 1391 1392 } 1394 1395 1402 protected void addComponent(XMLComponent component) { 1403 1404 if (fComponents.contains(component)) { 1406 return; 1407 } 1408 fComponents.add(component); 1409 addRecognizedParamsAndSetDefaults(component); 1410 1411 } 1413 1420 protected void addCommonComponent(XMLComponent component) { 1421 1422 if (fCommonComponents.contains(component)) { 1424 return; 1425 } 1426 fCommonComponents.add(component); 1427 addRecognizedParamsAndSetDefaults(component); 1428 1429 } 1431 1438 protected void addXML11Component(XMLComponent component) { 1439 1440 if (fXML11Components.contains(component)) { 1442 return; 1443 } 1444 fXML11Components.add(component); 1445 addRecognizedParamsAndSetDefaults(component); 1446 1447 } 1449 1458 protected void addRecognizedParamsAndSetDefaults(XMLComponent component) { 1459 1460 String [] recognizedFeatures = component.getRecognizedFeatures(); 1462 addRecognizedFeatures(recognizedFeatures); 1463 1464 String [] recognizedProperties = component.getRecognizedProperties(); 1466 addRecognizedProperties(recognizedProperties); 1467 1468 if (recognizedFeatures != null) { 1470 for (int i = 0; i < recognizedFeatures.length; ++i) { 1471 String featureId = recognizedFeatures[i]; 1472 Boolean state = component.getFeatureDefault(featureId); 1473 if (state != null) { 1474 if (!fFeatures.containsKey(featureId)) { 1476 fFeatures.put(featureId, state); 1477 fConfigUpdated = true; 1482 } 1483 } 1484 } 1485 } 1486 if (recognizedProperties != null) { 1487 for (int i = 0; i < recognizedProperties.length; ++i) { 1488 String propertyId = recognizedProperties[i]; 1489 Object value = component.getPropertyDefault(propertyId); 1490 if (value != null) { 1491 if (!fProperties.containsKey(propertyId)) { 1493 fProperties.put(propertyId, value); 1494 fConfigUpdated = true; 1499 } 1500 } 1501 } 1502 } 1503 } 1504 1505 private void initXML11Components() { 1506 if (!f11Initialized) { 1507 1508 fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); 1510 1511 fXML11DTDScanner = new XML11DTDScannerImpl(); 1513 addXML11Component(fXML11DTDScanner); 1514 fXML11DTDProcessor = new XML11DTDProcessor(); 1515 addXML11Component(fXML11DTDProcessor); 1516 1517 fXML11NSDocScanner = new XML11NSDocumentScannerImpl(); 1519 addXML11Component(fXML11NSDocScanner); 1520 fXML11NSDTDValidator = new XML11NSDTDValidator(); 1521 addXML11Component(fXML11NSDTDValidator); 1522 1523 f11Initialized = true; 1524 } 1525 } 1526 1527} | Popular Tags |