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.dtd.XML11DTDProcessor; 36 import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDValidator; 37 import com.sun.org.apache.xerces.internal.impl.dtd.XML11NSDTDValidator; 38 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor; 39 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator; 40 import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator; 41 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; 42 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 43 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 44 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; 45 import com.sun.org.apache.xerces.internal.util.SymbolTable; 46 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 47 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 48 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 49 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 50 import com.sun.org.apache.xerces.internal.xni.XNIException; 51 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 52 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 53 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 54 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 55 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; 56 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; 57 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 58 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 59 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 60 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 61 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; 62 63 101 public class XML11DTDConfiguration extends ParserConfigurationSettings 102 implements XMLPullParserConfiguration, XML11Configurable { 103 104 protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = 108 "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl"; 109 110 112 113 protected static final String VALIDATION = 114 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 115 116 117 protected static final String NAMESPACES = 118 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 119 120 121 protected static final String EXTERNAL_GENERAL_ENTITIES = 122 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; 123 124 125 protected static final String EXTERNAL_PARAMETER_ENTITIES = 126 Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; 127 128 129 protected static final String CONTINUE_AFTER_FATAL_ERROR = 130 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 131 132 133 protected static final String LOAD_EXTERNAL_DTD = 134 Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; 135 136 138 139 protected static final String XML_STRING = 140 Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; 141 142 143 protected static final String SYMBOL_TABLE = 144 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 145 146 147 protected static final String ERROR_HANDLER = 148 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 149 150 151 protected static final String ENTITY_RESOLVER = 152 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 153 154 155 protected static final String ERROR_REPORTER = 156 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 157 158 159 protected static final String ENTITY_MANAGER = 160 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 161 162 163 protected static final String DOCUMENT_SCANNER = 164 Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; 165 166 167 protected static final String DTD_SCANNER = 168 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; 169 170 171 protected static final String XMLGRAMMAR_POOL = 172 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 173 174 175 protected static final String DTD_PROCESSOR = 176 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY; 177 178 179 protected static final String DTD_VALIDATOR = 180 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 181 182 183 protected static final String NAMESPACE_BINDER = 184 Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; 185 186 187 protected static final String DATATYPE_VALIDATOR_FACTORY = 188 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 189 190 protected static final String VALIDATION_MANAGER = 191 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 192 193 194 protected static final String JAXP_SCHEMA_LANGUAGE = 195 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 196 197 198 protected static final String JAXP_SCHEMA_SOURCE = 199 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 200 201 203 204 protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; 205 206 protected SymbolTable fSymbolTable; 210 protected XMLInputSource fInputSource; 211 protected ValidationManager fValidationManager; 212 protected XMLVersionDetector fVersionDetector; 213 protected XMLLocator fLocator; 214 protected Locale fLocale; 215 216 217 protected ArrayList fComponents; 218 219 220 protected ArrayList fXML11Components = null; 221 222 223 protected ArrayList fCommonComponents = null; 224 225 226 protected XMLDocumentHandler fDocumentHandler; 227 228 229 protected XMLDTDHandler fDTDHandler; 230 231 232 protected XMLDTDContentModelHandler fDTDContentModelHandler; 233 234 235 protected XMLDocumentSource fLastComponent; 236 237 242 protected boolean fParseInProgress = false; 243 244 248 protected boolean fConfigUpdated = false; 249 250 254 255 protected DTDDVFactory fDatatypeValidatorFactory; 256 257 258 protected XMLNSDocumentScannerImpl fNamespaceScanner; 259 260 261 protected XMLDocumentScannerImpl fNonNSScanner; 262 263 264 protected XMLDTDValidator fDTDValidator; 265 266 267 protected XMLDTDValidator fNonNSDTDValidator; 268 269 270 protected XMLDTDScanner fDTDScanner; 271 272 273 protected XMLDTDProcessor fDTDProcessor; 274 275 279 280 protected DTDDVFactory fXML11DatatypeFactory = null; 281 282 283 protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; 284 285 286 protected XML11DocumentScannerImpl fXML11DocScanner = null; 287 288 289 protected XML11NSDTDValidator fXML11NSDTDValidator = null; 290 291 292 protected XML11DTDValidator fXML11DTDValidator = null; 293 294 295 protected XML11DTDScannerImpl fXML11DTDScanner = null; 296 297 298 protected XML11DTDProcessor fXML11DTDProcessor = null; 299 300 304 305 protected XMLGrammarPool fGrammarPool; 306 307 308 protected XMLErrorReporter fErrorReporter; 309 310 311 protected XMLEntityManager fEntityManager; 312 313 314 protected XMLDocumentScanner fCurrentScanner; 315 316 317 protected DTDDVFactory fCurrentDVFactory; 318 319 320 protected XMLDTDScanner fCurrentDTDScanner; 321 322 323 private boolean f11Initialized = false; 324 325 329 330 public XML11DTDConfiguration() { 331 this(null, null, null); 332 } 334 339 public XML11DTDConfiguration(SymbolTable symbolTable) { 340 this(symbolTable, null, null); 341 } 343 354 public XML11DTDConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 355 this(symbolTable, grammarPool, null); 356 } 358 370 public XML11DTDConfiguration( 371 SymbolTable symbolTable, 372 XMLGrammarPool grammarPool, 373 XMLComponentManager parentSettings) { 374 375 super(parentSettings); 376 377 fComponents = new ArrayList (); 380 fXML11Components = new ArrayList (); 382 fCommonComponents = new ArrayList (); 384 385 fRecognizedFeatures = new ArrayList (); 387 fRecognizedProperties = new ArrayList (); 388 389 fFeatures = new HashMap (); 391 fProperties = new HashMap (); 392 393 final String [] recognizedFeatures = 395 { 396 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, VALIDATION, 398 NAMESPACES, 399 EXTERNAL_GENERAL_ENTITIES, 400 EXTERNAL_PARAMETER_ENTITIES, 401 PARSER_SETTINGS 402 }; 403 addRecognizedFeatures(recognizedFeatures); 404 fFeatures.put(VALIDATION, Boolean.FALSE); 406 fFeatures.put(NAMESPACES, Boolean.TRUE); 407 fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE); 408 fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE); 409 fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); 410 fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE); 411 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); 412 413 final String [] recognizedProperties = 415 { 416 SYMBOL_TABLE, 417 ERROR_HANDLER, 418 ENTITY_RESOLVER, 419 ERROR_REPORTER, 420 ENTITY_MANAGER, 421 DOCUMENT_SCANNER, 422 DTD_SCANNER, 423 DTD_PROCESSOR, 424 DTD_VALIDATOR, 425 DATATYPE_VALIDATOR_FACTORY, 426 VALIDATION_MANAGER, 427 XML_STRING, 428 XMLGRAMMAR_POOL, 429 JAXP_SCHEMA_SOURCE, 430 JAXP_SCHEMA_LANGUAGE}; 431 addRecognizedProperties(recognizedProperties); 432 433 if (symbolTable == null) { 434 symbolTable = new SymbolTable(); 435 } 436 fSymbolTable = symbolTable; 437 fProperties.put(SYMBOL_TABLE, fSymbolTable); 438 439 fGrammarPool = grammarPool; 440 if (fGrammarPool != null) { 441 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); 442 } 443 444 fEntityManager = new XMLEntityManager(); 445 fProperties.put(ENTITY_MANAGER, fEntityManager); 446 addCommonComponent(fEntityManager); 447 448 fErrorReporter = new XMLErrorReporter(); 449 fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); 450 fProperties.put(ERROR_REPORTER, fErrorReporter); 451 addCommonComponent(fErrorReporter); 452 453 fNamespaceScanner = new XMLNSDocumentScannerImpl(); 454 fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); 455 addComponent((XMLComponent) fNamespaceScanner); 456 457 fDTDScanner = new XMLDTDScannerImpl(); 458 fProperties.put(DTD_SCANNER, fDTDScanner); 459 addComponent((XMLComponent) fDTDScanner); 460 461 fDTDProcessor = new XMLDTDProcessor(); 462 fProperties.put(DTD_PROCESSOR, fDTDProcessor); 463 addComponent((XMLComponent) fDTDProcessor); 464 465 fDTDValidator = new XMLNSDTDValidator(); 466 fProperties.put(DTD_VALIDATOR, fDTDValidator); 467 addComponent(fDTDValidator); 468 469 fDatatypeValidatorFactory = DTDDVFactory.getInstance(); 470 fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); 471 472 fValidationManager = new ValidationManager(); 473 fProperties.put(VALIDATION_MANAGER, fValidationManager); 474 475 fVersionDetector = new XMLVersionDetector(); 476 477 if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { 479 XMLMessageFormatter xmft = new XMLMessageFormatter(); 480 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); 481 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); 482 } 483 484 try { 486 setLocale(Locale.getDefault()); 487 } catch (XNIException e) { 488 } 491 492 fConfigUpdated = false; 493 494 } 496 511 public void setInputSource(XMLInputSource inputSource) 512 throws XMLConfigurationException, IOException { 513 514 519 fInputSource = inputSource; 520 521 } 523 531 public void setLocale(Locale locale) throws XNIException { 532 fLocale = locale; 533 fErrorReporter.setLocale(locale); 534 } 536 542 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 543 fDocumentHandler = documentHandler; 544 if (fLastComponent != null) { 545 fLastComponent.setDocumentHandler(fDocumentHandler); 546 if (fDocumentHandler !=null){ 547 fDocumentHandler.setDocumentSource(fLastComponent); 548 } 549 } 550 } 552 553 public XMLDocumentHandler getDocumentHandler() { 554 return fDocumentHandler; 555 } 557 562 public void setDTDHandler(XMLDTDHandler dtdHandler) { 563 fDTDHandler = dtdHandler; 564 } 566 567 public XMLDTDHandler getDTDHandler() { 568 return fDTDHandler; 569 } 571 576 public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { 577 fDTDContentModelHandler = handler; 578 } 580 581 public XMLDTDContentModelHandler getDTDContentModelHandler() { 582 return fDTDContentModelHandler; 583 } 585 592 public void setEntityResolver(XMLEntityResolver resolver) { 593 fProperties.put(ENTITY_RESOLVER, resolver); 594 } 596 603 public XMLEntityResolver getEntityResolver() { 604 return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); 605 } 607 625 public void setErrorHandler(XMLErrorHandler errorHandler) { 626 fProperties.put(ERROR_HANDLER, errorHandler); 627 } 629 636 public XMLErrorHandler getErrorHandler() { 637 return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); 639 } 641 642 647 public void cleanup() { 648 fEntityManager.closeReaders(); 649 } 650 651 659 public void parse(XMLInputSource source) throws XNIException, IOException { 660 661 if (fParseInProgress) { 662 throw new XNIException("FWK005 parse may not be called while parsing."); 664 } 665 fParseInProgress = true; 666 667 try { 668 setInputSource(source); 669 parse(true); 670 } catch (XNIException ex) { 671 if (PRINT_EXCEPTION_STACK_TRACE) 672 ex.printStackTrace(); 673 throw ex; 674 } catch (IOException ex) { 675 if (PRINT_EXCEPTION_STACK_TRACE) 676 ex.printStackTrace(); 677 throw ex; 678 } catch (RuntimeException ex) { 679 if (PRINT_EXCEPTION_STACK_TRACE) 680 ex.printStackTrace(); 681 throw ex; 682 } catch (Exception ex) { 683 if (PRINT_EXCEPTION_STACK_TRACE) 684 ex.printStackTrace(); 685 throw new XNIException(ex); 686 } finally { 687 fParseInProgress = false; 688 this.cleanup(); 690 } 691 692 } 694 public boolean parse(boolean complete) throws XNIException, IOException { 695 if (fInputSource != null) { 698 try { 699 fValidationManager.reset(); 700 fVersionDetector.reset(this); 701 resetCommon(); 702 703 short version = fVersionDetector.determineDocVersion(fInputSource); 704 if (version == Constants.XML_VERSION_1_1) { 705 initXML11Components(); 706 configureXML11Pipeline(); 707 resetXML11(); 708 } else { 709 configurePipeline(); 710 reset(); 711 } 712 713 fConfigUpdated = false; 715 716 fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version); 718 fInputSource = null; 719 } catch (XNIException ex) { 720 if (PRINT_EXCEPTION_STACK_TRACE) 721 ex.printStackTrace(); 722 throw ex; 723 } catch (IOException ex) { 724 if (PRINT_EXCEPTION_STACK_TRACE) 725 ex.printStackTrace(); 726 throw ex; 727 } catch (RuntimeException ex) { 728 if (PRINT_EXCEPTION_STACK_TRACE) 729 ex.printStackTrace(); 730 throw ex; 731 } catch (Exception ex) { 732 if (PRINT_EXCEPTION_STACK_TRACE) 733 ex.printStackTrace(); 734 throw new XNIException(ex); 735 } 736 } 737 738 try { 739 return fCurrentScanner.scanDocument(complete); 740 } catch (XNIException ex) { 741 if (PRINT_EXCEPTION_STACK_TRACE) 742 ex.printStackTrace(); 743 throw ex; 744 } catch (IOException ex) { 745 if (PRINT_EXCEPTION_STACK_TRACE) 746 ex.printStackTrace(); 747 throw ex; 748 } catch (RuntimeException ex) { 749 if (PRINT_EXCEPTION_STACK_TRACE) 750 ex.printStackTrace(); 751 throw ex; 752 } catch (Exception ex) { 753 if (PRINT_EXCEPTION_STACK_TRACE) 754 ex.printStackTrace(); 755 throw new XNIException(ex); 756 } 757 758 } 760 772 public boolean getFeature(String featureId) 773 throws XMLConfigurationException { 774 if (featureId.equals(PARSER_SETTINGS)){ 776 return fConfigUpdated; 777 } 778 return super.getFeature(featureId); 779 780 } 782 795 public void setFeature(String featureId, boolean state) 796 throws XMLConfigurationException { 797 fConfigUpdated = true; 798 int count = fComponents.size(); 800 for (int i = 0; i < count; i++) { 801 XMLComponent c = (XMLComponent) fComponents.get(i); 802 c.setFeature(featureId, state); 803 } 804 count = fCommonComponents.size(); 806 for (int i = 0; i < count; i++) { 807 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 808 c.setFeature(featureId, state); 809 } 810 811 count = fXML11Components.size(); 813 for (int i = 0; i < count; i++) { 814 XMLComponent c = (XMLComponent) fXML11Components.get(i); 815 try{ 816 c.setFeature(featureId, state); 817 } 818 catch (Exception e){ 819 } 821 } 822 super.setFeature(featureId, state); 824 825 } 827 833 public void setProperty(String propertyId, Object value) 834 throws XMLConfigurationException { 835 fConfigUpdated = true; 836 int count = fComponents.size(); 838 for (int i = 0; i < count; i++) { 839 XMLComponent c = (XMLComponent) fComponents.get(i); 840 c.setProperty(propertyId, value); 841 } 842 count = fCommonComponents.size(); 844 for (int i = 0; i < count; i++) { 845 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 846 c.setProperty(propertyId, value); 847 } 848 count = fXML11Components.size(); 850 for (int i = 0; i < count; i++) { 851 XMLComponent c = (XMLComponent) fXML11Components.get(i); 852 try{ 853 c.setProperty(propertyId, value); 854 } 855 catch (Exception e){ 856 } 858 } 859 860 super.setProperty(propertyId, value); 862 863 } 865 866 867 public Locale getLocale() { 868 return fLocale; 869 } 871 874 protected void reset() throws XNIException { 875 int count = fComponents.size(); 876 for (int i = 0; i < count; i++) { 877 XMLComponent c = (XMLComponent) fComponents.get(i); 878 c.reset(this); 879 } 880 881 } 883 886 protected void resetCommon() throws XNIException { 887 int count = fCommonComponents.size(); 889 for (int i = 0; i < count; i++) { 890 XMLComponent c = (XMLComponent) fCommonComponents.get(i); 891 c.reset(this); 892 } 893 894 } 896 899 protected void resetXML11() throws XNIException { 900 int count = fXML11Components.size(); 902 for (int i = 0; i < count; i++) { 903 XMLComponent c = (XMLComponent) fXML11Components.get(i); 904 c.reset(this); 905 } 906 907 } 909 913 protected void configureXML11Pipeline() { 914 if (fCurrentDVFactory != fXML11DatatypeFactory) { 915 fCurrentDVFactory = fXML11DatatypeFactory; 916 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 917 } 918 if (fCurrentDTDScanner != fXML11DTDScanner) { 919 fCurrentDTDScanner = fXML11DTDScanner; 920 setProperty(DTD_SCANNER, fCurrentDTDScanner); 921 setProperty(DTD_PROCESSOR, fXML11DTDProcessor); 922 } 923 924 fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); 925 fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); 926 fXML11DTDProcessor.setDTDHandler(fDTDHandler); 927 if (fDTDHandler != null) { 928 fDTDHandler.setDTDSource(fXML11DTDProcessor); 929 } 930 931 fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor); 932 fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner); 933 fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 934 if (fDTDContentModelHandler != null) { 935 fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor); 936 } 937 938 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 940 if (fCurrentScanner != fXML11NSDocScanner) { 941 fCurrentScanner = fXML11NSDocScanner; 942 setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner); 943 setProperty(DTD_VALIDATOR, fXML11NSDTDValidator); 944 } 945 946 fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator); 947 fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator); 948 fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner); 949 fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler); 950 951 if (fDocumentHandler != null) { 952 fDocumentHandler.setDocumentSource(fXML11NSDTDValidator); 953 } 954 fLastComponent = fXML11NSDTDValidator; 955 956 } else { 957 if (fXML11DocScanner == null) { 959 fXML11DocScanner = new XML11DocumentScannerImpl(); 961 addXML11Component(fXML11DocScanner); 962 fXML11DTDValidator = new XML11DTDValidator(); 963 addXML11Component(fXML11DTDValidator); 964 } 965 if (fCurrentScanner != fXML11DocScanner) { 966 fCurrentScanner = fXML11DocScanner; 967 setProperty(DOCUMENT_SCANNER, fXML11DocScanner); 968 setProperty(DTD_VALIDATOR, fXML11DTDValidator); 969 } 970 fXML11DocScanner.setDocumentHandler(fXML11DTDValidator); 971 fXML11DTDValidator.setDocumentSource(fXML11DocScanner); 972 fXML11DTDValidator.setDocumentHandler(fDocumentHandler); 973 974 if (fDocumentHandler != null) { 975 fDocumentHandler.setDocumentSource(fXML11DTDValidator); 976 } 977 fLastComponent = fXML11DTDValidator; 978 } 979 980 } 982 983 protected void configurePipeline() { 984 if (fCurrentDVFactory != fDatatypeValidatorFactory) { 985 fCurrentDVFactory = fDatatypeValidatorFactory; 986 setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory); 988 } 989 990 if (fCurrentDTDScanner != fDTDScanner) { 992 fCurrentDTDScanner = fDTDScanner; 993 setProperty(DTD_SCANNER, fCurrentDTDScanner); 994 setProperty(DTD_PROCESSOR, fDTDProcessor); 995 } 996 fDTDScanner.setDTDHandler(fDTDProcessor); 997 fDTDProcessor.setDTDSource(fDTDScanner); 998 fDTDProcessor.setDTDHandler(fDTDHandler); 999 if (fDTDHandler != null) { 1000 fDTDHandler.setDTDSource(fDTDProcessor); 1001 } 1002 1003 fDTDScanner.setDTDContentModelHandler(fDTDProcessor); 1004 fDTDProcessor.setDTDContentModelSource(fDTDScanner); 1005 fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); 1006 if (fDTDContentModelHandler != null) { 1007 fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor); 1008 } 1009 1010 if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { 1012 if (fCurrentScanner != fNamespaceScanner) { 1013 fCurrentScanner = fNamespaceScanner; 1014 setProperty(DOCUMENT_SCANNER, fNamespaceScanner); 1015 setProperty(DTD_VALIDATOR, fDTDValidator); 1016 } 1017 fNamespaceScanner.setDTDValidator(fDTDValidator); 1018 fNamespaceScanner.setDocumentHandler(fDTDValidator); 1019 fDTDValidator.setDocumentSource(fNamespaceScanner); 1020 fDTDValidator.setDocumentHandler(fDocumentHandler); 1021 if (fDocumentHandler != null) { 1022 fDocumentHandler.setDocumentSource(fDTDValidator); 1023 } 1024 fLastComponent = fDTDValidator; 1025 } else { 1026 if (fNonNSScanner == null) { 1028 fNonNSScanner = new XMLDocumentScannerImpl(); 1029 fNonNSDTDValidator = new XMLDTDValidator(); 1030 addComponent((XMLComponent) fNonNSScanner); 1032 addComponent((XMLComponent) fNonNSDTDValidator); 1033 } 1034 if (fCurrentScanner != fNonNSScanner) { 1035 fCurrentScanner = fNonNSScanner; 1036 setProperty(DOCUMENT_SCANNER, fNonNSScanner); 1037 setProperty(DTD_VALIDATOR, fNonNSDTDValidator); 1038 } 1039 1040 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator); 1041 fNonNSDTDValidator.setDocumentSource(fNonNSScanner); 1042 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler); 1043 if (fDocumentHandler != null) { 1044 fDocumentHandler.setDocumentSource(fNonNSDTDValidator); 1045 } 1046 fLastComponent = fNonNSDTDValidator; 1047 } 1048 1049 } 1051 1052 1054 1066 protected void checkFeature(String featureId) throws XMLConfigurationException { 1067 1068 1072 if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { 1073 final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); 1074 1075 if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && 1082 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { 1083 return; 1084 } 1085 1086 if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && 1090 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { 1091 short type = XMLConfigurationException.NOT_SUPPORTED; 1093 throw new XMLConfigurationException(type, featureId); 1094 } 1095 if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && 1099 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { 1100 short type = XMLConfigurationException.NOT_SUPPORTED; 1102 throw new XMLConfigurationException(type, featureId); 1103 } 1104 if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && 1108 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { 1109 return; 1110 } 1111 if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && 1115 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { 1116 return; 1117 } 1118 1119 if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && 1123 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { 1124 short type = XMLConfigurationException.NOT_SUPPORTED; 1125 throw new XMLConfigurationException(type, featureId); 1126 } 1127 1128 if (suffixLength == Constants.PARSER_SETTINGS.length() && 1130 featureId.endsWith(Constants.PARSER_SETTINGS)) { 1131 short type = XMLConfigurationException.NOT_SUPPORTED; 1132 throw new XMLConfigurationException(type, featureId); 1133 } 1134 } 1135 1136 1140 super.checkFeature(featureId); 1141 1142 } 1144 1157 protected void checkProperty(String propertyId) throws XMLConfigurationException { 1158 1159 1163 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 1164 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 1165 1166 if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && 1167 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { 1168 return; 1169 } 1170 } 1171 1172 if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) { 1174 final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length(); 1175 1176 if (suffixLength == Constants.XML_STRING_PROPERTY.length() && 1187 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) { 1188 short type = XMLConfigurationException.NOT_SUPPORTED; 1192 throw new XMLConfigurationException(type, propertyId); 1193 } 1194 } 1195 1196 1200 super.checkProperty(propertyId); 1201 1202 } 1204 1205 1212 protected void addComponent(XMLComponent component) { 1213 1214 if (fComponents.contains(component)) { 1216 return; 1217 } 1218 fComponents.add(component); 1219 addRecognizedParamsAndSetDefaults(component); 1220 1221 } 1223 1230 protected void addCommonComponent(XMLComponent component) { 1231 1232 if (fCommonComponents.contains(component)) { 1234 return; 1235 } 1236 fCommonComponents.add(component); 1237 addRecognizedParamsAndSetDefaults(component); 1238 1239 } 1241 1248 protected void addXML11Component(XMLComponent component) { 1249 1250 if (fXML11Components.contains(component)) { 1252 return; 1253 } 1254 fXML11Components.add(component); 1255 addRecognizedParamsAndSetDefaults(component); 1256 1257 } 1259 1268 protected void addRecognizedParamsAndSetDefaults(XMLComponent component) { 1269 1270 String [] recognizedFeatures = component.getRecognizedFeatures(); 1272 addRecognizedFeatures(recognizedFeatures); 1273 1274 String [] recognizedProperties = component.getRecognizedProperties(); 1276 addRecognizedProperties(recognizedProperties); 1277 1278 if (recognizedFeatures != null) { 1280 for (int i = 0; i < recognizedFeatures.length; ++i) { 1281 String featureId = recognizedFeatures[i]; 1282 Boolean state = component.getFeatureDefault(featureId); 1283 if (state != null) { 1284 if (!fFeatures.containsKey(featureId)) { 1286 fFeatures.put(featureId, state); 1287 fConfigUpdated = true; 1292 } 1293 } 1294 } 1295 } 1296 if (recognizedProperties != null) { 1297 for (int i = 0; i < recognizedProperties.length; ++i) { 1298 String propertyId = recognizedProperties[i]; 1299 Object value = component.getPropertyDefault(propertyId); 1300 if (value != null) { 1301 if (!fProperties.containsKey(propertyId)) { 1303 fProperties.put(propertyId, value); 1304 fConfigUpdated = true; 1309 } 1310 } 1311 } 1312 } 1313 } 1314 1315 private void initXML11Components() { 1316 if (!f11Initialized) { 1317 1318 fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); 1320 1321 fXML11DTDScanner = new XML11DTDScannerImpl(); 1323 addXML11Component(fXML11DTDScanner); 1324 fXML11DTDProcessor = new XML11DTDProcessor(); 1325 addXML11Component(fXML11DTDProcessor); 1326 1327 fXML11NSDocScanner = new XML11NSDocumentScannerImpl(); 1329 addXML11Component(fXML11NSDocScanner); 1330 fXML11NSDTDValidator = new XML11NSDTDValidator(); 1331 addXML11Component(fXML11NSDTDValidator); 1332 1333 f11Initialized = true; 1334 } 1335 } 1336 1337} | Popular Tags |