1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.parsers;
  22 
  23 import java.io.IOException;
  24 import java.util.Locale;
  25 
  26 import com.sun.org.apache.xerces.internal.impl.Constants;
  27 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
  28 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
  29 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  30 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  31 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
  32 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  33 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  34 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  35 import com.sun.org.apache.xerces.internal.util.FeatureState;
  36 import com.sun.org.apache.xerces.internal.util.PropertyState;
  37 import com.sun.org.apache.xerces.internal.util.Status;
  38 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  39 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
  40 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
  41 import com.sun.org.apache.xerces.internal.xni.XNIException;
  42 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  43 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  44 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  49 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
  50 
  51 /**
  52  * This is the non validating parser configuration. It extends the basic
  53  * configuration with the set of following parser components:
  54  * Document scanner, DTD scanner, namespace binder, document handler.
  55  * <p>
  56  * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>
  57  * non-validating XML processor, since conformant non-validating processor is required
  58  * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,
  59  * include the replacement text of internal entities, and supply default attribute values".
  60  *
  61  * @author Elena Litani, IBM
  62  */
  63 public class NonValidatingConfiguration
  64     extends BasicParserConfiguration
  65     implements XMLPullParserConfiguration {
  66 
  67     //
  68     // Constants
  69     //
  70 
  71     // feature identifiers
  72 
  73     /** Feature identifier: warn on duplicate attribute definition. */
  74     protected static final String WARN_ON_DUPLICATE_ATTDEF =
  75         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
  76 
  77     /** Feature identifier: warn on duplicate entity definition. */
  78     protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
  79         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
  80 
  81     /** Feature identifier: warn on undeclared element definition. */
  82     protected static final String WARN_ON_UNDECLARED_ELEMDEF =
  83         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
  84 
  85     /** Feature identifier: allow Java encodings. */
  86     protected static final String ALLOW_JAVA_ENCODINGS =
  87         Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
  88 
  89     /** Feature identifier: continue after fatal error. */
  90     protected static final String CONTINUE_AFTER_FATAL_ERROR =
  91         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
  92 
  93     /** Feature identifier: load external DTD. */
  94     protected static final String LOAD_EXTERNAL_DTD =
  95         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
  96 
  97     /** Feature identifier: notify built-in refereces. */
  98     protected static final String NOTIFY_BUILTIN_REFS =
  99         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
 100 
 101     /** Feature identifier: notify character refereces. */
 102     protected static final String NOTIFY_CHAR_REFS =
 103         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
 104 
 105 
 106     /** Feature identifier: expose schema normalized value */
 107     protected static final String NORMALIZE_DATA =
 108     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
 109 
 110 
 111     /** Feature identifier: send element default value via characters() */
 112     protected static final String SCHEMA_ELEMENT_DEFAULT =
 113     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
 114 
 115     // property identifiers
 116 
 117     /** Property identifier: error reporter. */
 118     protected static final String ERROR_REPORTER =
 119         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
 120 
 121     /** Property identifier: entity manager. */
 122     protected static final String ENTITY_MANAGER =
 123         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
 124 
 125     /** Property identifier document scanner: */
 126     protected static final String DOCUMENT_SCANNER =
 127         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
 128 
 129     /** Property identifier: DTD scanner. */
 130     protected static final String DTD_SCANNER =
 131         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
 132 
 133     /** Property identifier: grammar pool. */
 134     protected static final String XMLGRAMMAR_POOL =
 135         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
 136 
 137     /** Property identifier: DTD validator. */
 138     protected static final String DTD_VALIDATOR =
 139         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
 140 
 141     /** Property identifier: namespace binder. */
 142     protected static final String NAMESPACE_BINDER =
 143         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
 144 
 145     /** Property identifier: datatype validator factory. */
 146     protected static final String DATATYPE_VALIDATOR_FACTORY =
 147         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
 148 
 149     protected static final String VALIDATION_MANAGER =
 150         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
 151 
 152     /** Property identifier: XML Schema validator. */
 153     protected static final String SCHEMA_VALIDATOR =
 154         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
 155 
 156     /** Property identifier: locale. */
 157     protected static final String LOCALE =
 158         Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
 159 
 160       /** Property identifier: Security property manager. */
 161       protected static final String XML_SECURITY_PROPERTY_MANAGER =
 162               Constants.XML_SECURITY_PROPERTY_MANAGER;
 163 
 164      /** Property identifier: Security manager. */
 165      private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER;
 166 
 167     // debugging
 168 
 169     /** Set to true and recompile to print exception stack trace. */
 170     private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
 171 
 172     //
 173     // Data
 174     //
 175 
 176     // components (non-configurable)
 177 
 178     /** Grammar pool. */
 179     protected XMLGrammarPool fGrammarPool;
 180 
 181     /** Datatype validator factory. */
 182     protected DTDDVFactory fDatatypeValidatorFactory;
 183 
 184     // components (configurable)
 185 
 186     /** Error reporter. */
 187     protected XMLErrorReporter fErrorReporter;
 188 
 189     /** Entity manager. */
 190     protected XMLEntityManager fEntityManager;
 191 
 192     /** Document scanner. */
 193     protected XMLDocumentScanner fScanner;
 194 
 195     /** Input Source */
 196     protected XMLInputSource fInputSource;
 197 
 198     /** DTD scanner. */
 199     protected XMLDTDScanner fDTDScanner;
 200 
 201 
 202     protected ValidationManager fValidationManager;
 203 
 204     // private data
 205 
 206     /** Document scanner that does namespace binding. */
 207     private XMLNSDocumentScannerImpl fNamespaceScanner;
 208 
 209     /** Default Xerces implementation of scanner*/
 210     private XMLDocumentScannerImpl fNonNSScanner;
 211 
 212 
 213         /** fConfigUpdated is set to true if there has been any change to the configuration settings,
 214          * i.e a feature or a property was changed.
 215          */
 216         protected boolean fConfigUpdated = false;
 217 
 218 
 219     // state
 220 
 221     /** Locator */
 222     protected XMLLocator fLocator;
 223 
 224     /**
 225      * True if a parse is in progress. This state is needed because
 226      * some features/properties cannot be set while parsing (e.g.
 227      * validation and namespaces).
 228      */
 229     protected boolean fParseInProgress = false;
 230 
 231     //
 232     // Constructors
 233     //
 234 
 235     /** Default constructor. */
 236     public NonValidatingConfiguration() {
 237         this(null, null, null);
 238     } // <init>()
 239 
 240     /**
 241      * Constructs a parser configuration using the specified symbol table.
 242      *
 243      * @param symbolTable The symbol table to use.
 244      */
 245     public NonValidatingConfiguration(SymbolTable symbolTable) {
 246         this(symbolTable, null, null);
 247     } // <init>(SymbolTable)
 248 
 249     /**
 250      * Constructs a parser configuration using the specified symbol table and
 251      * grammar pool.
 252      * <p>
 253      * <strong>REVISIT:</strong>
 254      * Grammar pool will be updated when the new validation engine is
 255      * implemented.
 256      *
 257      * @param symbolTable The symbol table to use.
 258      * @param grammarPool The grammar pool to use.
 259      */
 260     public NonValidatingConfiguration(SymbolTable symbolTable,
 261                                        XMLGrammarPool grammarPool) {
 262         this(symbolTable, grammarPool, null);
 263     } // <init>(SymbolTable,XMLGrammarPool)
 264 
 265     /**
 266      * Constructs a parser configuration using the specified symbol table,
 267      * grammar pool, and parent settings.
 268      * <p>
 269      * <strong>REVISIT:</strong>
 270      * Grammar pool will be updated when the new validation engine is
 271      * implemented.
 272      *
 273      * @param symbolTable    The symbol table to use.
 274      * @param grammarPool    The grammar pool to use.
 275      * @param parentSettings The parent settings.
 276      */
 277     public NonValidatingConfiguration(SymbolTable symbolTable,
 278                                        XMLGrammarPool grammarPool,
 279                                        XMLComponentManager parentSettings) {
 280         super(symbolTable, parentSettings);
 281 
 282         // add default recognized features
 283         final String[] recognizedFeatures = {
 284                 PARSER_SETTINGS,
 285                         NAMESPACES,
 286             //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl
 287             //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl
 288             //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager
 289             CONTINUE_AFTER_FATAL_ERROR,
 290             //LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl
 291             //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
 292             //NOTIFY_CHAR_REFS,         // from XMLDocumentFragmentScannerImpl
 293             //WARN_ON_DUPLICATE_ENTITYDEF   // from XMLEntityManager
 294         };
 295         addRecognizedFeatures(recognizedFeatures);
 296 
 297         // set state for default features
 298         //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl
 299         //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);    // from XMLDTDScannerImpl
 300         //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager
 301         fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
 302                 fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
 303                 fFeatures.put(NAMESPACES, Boolean.TRUE);
 304         //setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl
 305         //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
 306         //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
 307         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
 308 
 309         // add default recognized properties
 310         final String[] recognizedProperties = {
 311             ERROR_REPORTER,
 312             ENTITY_MANAGER,
 313             DOCUMENT_SCANNER,
 314             DTD_SCANNER,
 315             DTD_VALIDATOR,
 316             NAMESPACE_BINDER,
 317             XMLGRAMMAR_POOL,
 318             DATATYPE_VALIDATOR_FACTORY,
 319             VALIDATION_MANAGER,
 320             LOCALE,
 321             SECURITY_MANAGER,
 322             XML_SECURITY_PROPERTY_MANAGER
 323         };
 324         addRecognizedProperties(recognizedProperties);
 325 
 326         fGrammarPool = grammarPool;
 327         if(fGrammarPool != null){
 328                         fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
 329         }
 330 
 331         fEntityManager = createEntityManager();
 332                 fProperties.put(ENTITY_MANAGER, fEntityManager);
 333         addComponent(fEntityManager);
 334 
 335         fErrorReporter = createErrorReporter();
 336         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
 337                 fProperties.put(ERROR_REPORTER, fErrorReporter);
 338         addComponent(fErrorReporter);
 339 
 340         // this configuration delays creation of the scanner
 341         // till it is known if namespace processing should be performed
 342 
 343         fDTDScanner = createDTDScanner();
 344         if (fDTDScanner != null) {
 345                         fProperties.put(DTD_SCANNER, fDTDScanner);
 346             if (fDTDScanner instanceof XMLComponent) {
 347                 addComponent((XMLComponent)fDTDScanner);
 348             }
 349         }
 350 
 351         fDatatypeValidatorFactory = createDatatypeValidatorFactory();
 352         if (fDatatypeValidatorFactory != null) {
 353                         fProperties.put(DATATYPE_VALIDATOR_FACTORY,
 354                         fDatatypeValidatorFactory);
 355         }
 356         fValidationManager = createValidationManager();
 357 
 358         if (fValidationManager != null) {
 359                         fProperties.put(VALIDATION_MANAGER, fValidationManager);
 360         }
 361         // add message formatters
 362         if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
 363             XMLMessageFormatter xmft = new XMLMessageFormatter();
 364             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
 365             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
 366         }
 367 
 368                 fConfigUpdated = false;
 369 
 370         // set locale
 371         try {
 372             setLocale(Locale.getDefault());
 373         }
 374         catch (XNIException e) {
 375             // do nothing
 376             // REVISIT: What is the right thing to do? -Ac
 377         }
 378 
 379         setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager());
 380     } // <init>(SymbolTable,XMLGrammarPool)
 381 
 382     //
 383     // Public methods
 384     //
 385         public void setFeature(String featureId, boolean state)
 386                 throws XMLConfigurationException {
 387                 fConfigUpdated = true;
 388                 super.setFeature(featureId, state);
 389         }
 390 
 391         public PropertyState getPropertyState(String propertyId)
 392              throws XMLConfigurationException {
 393              if (LOCALE.equals(propertyId)) {
 394                  return PropertyState.is(getLocale());
 395              }
 396              return super.getPropertyState(propertyId);
 397          }
 398 
 399         public void setProperty(String propertyId, Object value)
 400              throws XMLConfigurationException {
 401              fConfigUpdated = true;
 402              if (LOCALE.equals(propertyId)) {
 403                  setLocale((Locale) value);
 404              }
 405              super.setProperty(propertyId, value);
 406          }
 407 
 408     /**
 409      * Set the locale to use for messages.
 410      *
 411      * @param locale The locale object to use for localization of messages.
 412      *
 413      * @exception XNIException Thrown if the parser does not support the
 414      *                         specified locale.
 415      */
 416     public void setLocale(Locale locale) throws XNIException {
 417         super.setLocale(locale);
 418         fErrorReporter.setLocale(locale);
 419     } // setLocale(Locale)
 420 
 421         public FeatureState getFeatureState(String featureId)
 422                 throws XMLConfigurationException {
 423                         // make this feature special
 424                 if (featureId.equals(PARSER_SETTINGS)){
 425                         return FeatureState.is(fConfigUpdated);
 426                 }
 427                 return super.getFeatureState(featureId);
 428 
 429         } // getFeature(String):boolean
 430     //
 431     // XMLPullParserConfiguration methods
 432     //
 433 
 434     // parsing
 435 
 436     /**
 437      * Sets the input source for the document to parse.
 438      *
 439      * @param inputSource The document's input source.
 440      *
 441      * @exception XMLConfigurationException Thrown if there is a
 442      *                        configuration error when initializing the
 443      *                        parser.
 444      * @exception IOException Thrown on I/O error.
 445      *
 446      * @see #parse(boolean)
 447      */
 448     public void setInputSource(XMLInputSource inputSource)
 449         throws XMLConfigurationException, IOException {
 450 
 451         // REVISIT: this method used to reset all the components and
 452         //          construct the pipeline. Now reset() is called
 453         //          in parse (boolean) just before we parse the document
 454         //          Should this method still throw exceptions..?
 455 
 456         fInputSource = inputSource;
 457 
 458     } // setInputSource(XMLInputSource)
 459 
 460     /**
 461      * Parses the document in a pull parsing fashion.
 462      *
 463      * @param complete True if the pull parser should parse the
 464      *                 remaining document completely.
 465      *
 466      * @return True if there is more document to parse.
 467      *
 468      * @exception XNIException Any XNI exception, possibly wrapping
 469      *                         another exception.
 470      * @exception IOException  An IO exception from the parser, possibly
 471      *                         from a byte stream or character stream
 472      *                         supplied by the parser.
 473      *
 474      * @see #setInputSource
 475      */
 476     public boolean parse(boolean complete) throws XNIException, IOException {
 477         //
 478         // reset and configure pipeline and set InputSource.
 479         if (fInputSource !=null) {
 480             try {
 481                 // resets and sets the pipeline.
 482                 reset();
 483                 fScanner.setInputSource(fInputSource);
 484                 fInputSource = null;
 485             }
 486             catch (XNIException ex) {
 487                 if (PRINT_EXCEPTION_STACK_TRACE)
 488                     ex.printStackTrace();
 489                 throw ex;
 490             }
 491             catch (IOException ex) {
 492                 if (PRINT_EXCEPTION_STACK_TRACE)
 493                     ex.printStackTrace();
 494                 throw ex;
 495             }
 496             catch (RuntimeException ex) {
 497                 if (PRINT_EXCEPTION_STACK_TRACE)
 498                     ex.printStackTrace();
 499                 throw ex;
 500             }
 501             catch (Exception ex) {
 502                 if (PRINT_EXCEPTION_STACK_TRACE)
 503                     ex.printStackTrace();
 504                 throw new XNIException(ex);
 505             }
 506         }
 507 
 508         try {
 509             return fScanner.scanDocument(complete);
 510         }
 511         catch (XNIException ex) {
 512             if (PRINT_EXCEPTION_STACK_TRACE)
 513                 ex.printStackTrace();
 514             throw ex;
 515         }
 516         catch (IOException ex) {
 517             if (PRINT_EXCEPTION_STACK_TRACE)
 518                 ex.printStackTrace();
 519             throw ex;
 520         }
 521         catch (RuntimeException ex) {
 522             if (PRINT_EXCEPTION_STACK_TRACE)
 523                 ex.printStackTrace();
 524             throw ex;
 525         }
 526         catch (Exception ex) {
 527             if (PRINT_EXCEPTION_STACK_TRACE)
 528                 ex.printStackTrace();
 529             throw new XNIException(ex);
 530         }
 531 
 532     } // parse(boolean):boolean
 533 
 534     /**
 535      * If the application decides to terminate parsing before the xml document
 536      * is fully parsed, the application should call this method to free any
 537      * resource allocated during parsing. For example, close all opened streams.
 538      */
 539     public void cleanup() {
 540         fEntityManager.closeReaders();
 541     }
 542 
 543     //
 544     // XMLParserConfiguration methods
 545     //
 546 
 547     /**
 548      * Parses the specified input source.
 549      *
 550      * @param source The input source.
 551      *
 552      * @exception XNIException Throws exception on XNI error.
 553      * @exception java.io.IOException Throws exception on i/o error.
 554      */
 555     public void parse(XMLInputSource source) throws XNIException, IOException {
 556 
 557         if (fParseInProgress) {
 558             // REVISIT - need to add new error message
 559             throw new XNIException("FWK005 parse may not be called while parsing.");
 560         }
 561         fParseInProgress = true;
 562 
 563         try {
 564             setInputSource(source);
 565             parse(true);
 566         }
 567         catch (XNIException ex) {
 568             if (PRINT_EXCEPTION_STACK_TRACE)
 569                 ex.printStackTrace();
 570             throw ex;
 571         }
 572         catch (IOException ex) {
 573             if (PRINT_EXCEPTION_STACK_TRACE)
 574                 ex.printStackTrace();
 575             throw ex;
 576         }
 577         catch (RuntimeException ex) {
 578             if (PRINT_EXCEPTION_STACK_TRACE)
 579                 ex.printStackTrace();
 580             throw ex;
 581         }
 582         catch (Exception ex) {
 583             if (PRINT_EXCEPTION_STACK_TRACE)
 584                 ex.printStackTrace();
 585             throw new XNIException(ex);
 586         }
 587         finally {
 588             fParseInProgress = false;
 589             // close all streams opened by xerces
 590             this.cleanup();
 591         }
 592 
 593     } // parse(InputSource)
 594 
 595     //
 596     // Protected methods
 597     //
 598 
 599     /**
 600      * Reset all components before parsing.
 601      *
 602      * @throws XNIException Thrown if an error occurs during initialization.
 603      */
 604     protected void reset() throws XNIException {
 605 
 606         if (fValidationManager != null)
 607             fValidationManager.reset();
 608         // configure the pipeline and initialize the components
 609         configurePipeline();
 610         super.reset();
 611 
 612     } // reset()
 613 
 614     /** Configures the pipeline. */
 615     protected void configurePipeline() {
 616         // create appropriate scanner
 617         // and register it as one of the components.
 618         if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
 619             if (fNamespaceScanner == null) {
 620                 fNamespaceScanner = new XMLNSDocumentScannerImpl();
 621                 addComponent((XMLComponent)fNamespaceScanner);
 622             }
 623             fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
 624             fNamespaceScanner.setDTDValidator(null);
 625             fScanner = fNamespaceScanner;
 626         }
 627         else {
 628             if (fNonNSScanner == null) {
 629                 fNonNSScanner = new XMLDocumentScannerImpl();
 630                 addComponent((XMLComponent)fNonNSScanner);
 631             }
 632             fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
 633             fScanner = fNonNSScanner;
 634         }
 635 
 636         fScanner.setDocumentHandler(fDocumentHandler);
 637         fLastComponent = fScanner;
 638         // setup dtd pipeline
 639         if (fDTDScanner != null) {
 640                 fDTDScanner.setDTDHandler(fDTDHandler);
 641                 fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
 642         }
 643 
 644 
 645     } // configurePipeline()
 646 
 647     // features and properties
 648 
 649     /**
 650      * Check a feature. If feature is know and supported, this method simply
 651      * returns. Otherwise, the appropriate exception is thrown.
 652      *
 653      * @param featureId The unique identifier (URI) of the feature.
 654      *
 655      * @throws XMLConfigurationException Thrown for configuration error.
 656      *                                   In general, components should
 657      *                                   only throw this exception if
 658      *                                   it is <strong>really</strong>
 659      *                                   a critical error.
 660      */
 661     protected FeatureState checkFeature(String featureId)
 662         throws XMLConfigurationException {
 663 
 664         //
 665         // Xerces Features
 666         //
 667 
 668         if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
 669             final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
 670 
 671             //
 672             // http://apache.org/xml/features/validation/dynamic
 673             //   Allows the parser to validate a document only when it
 674             //   contains a grammar. Validation is turned on/off based
 675             //   on each document instance, automatically.
 676             //
 677             if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
 678                 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
 679                 return FeatureState.RECOGNIZED;
 680             }
 681             //
 682             // http://apache.org/xml/features/validation/default-attribute-values
 683             //
 684             if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
 685                 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
 686                 // REVISIT
 687                 return FeatureState.NOT_SUPPORTED;
 688             }
 689             //
 690             // http://apache.org/xml/features/validation/default-attribute-values
 691             //
 692             if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
 693                 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
 694                 // REVISIT
 695                 return FeatureState.NOT_SUPPORTED;
 696             }
 697             //
 698             // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
 699             //
 700             if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
 701                 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
 702                 return FeatureState.RECOGNIZED;
 703             }
 704             //
 705             // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
 706             //
 707             if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
 708                 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
 709                 return FeatureState.RECOGNIZED;
 710             }
 711 
 712             //
 713             // http://apache.org/xml/features/validation/default-attribute-values
 714             //
 715             if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
 716                 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
 717                 return FeatureState.NOT_SUPPORTED;
 718             }
 719         }
 720 
 721         //
 722         // Not recognized
 723         //
 724 
 725         return super.checkFeature(featureId);
 726 
 727     } // checkFeature(String)
 728 
 729     /**
 730      * Check a property. If the property is know and supported, this method
 731      * simply returns. Otherwise, the appropriate exception is thrown.
 732      *
 733      * @param propertyId The unique identifier (URI) of the property
 734      *                   being set.
 735      *
 736      * @throws XMLConfigurationException Thrown for configuration error.
 737      *                                   In general, components should
 738      *                                   only throw this exception if
 739      *                                   it is <strong>really</strong>
 740      *                                   a critical error.
 741      */
 742     protected PropertyState checkProperty(String propertyId)
 743         throws XMLConfigurationException {
 744 
 745         //
 746         // Xerces Properties
 747         //
 748 
 749         if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
 750             final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
 751 
 752             if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
 753                 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
 754                 return PropertyState.RECOGNIZED;
 755             }
 756         }
 757 
 758         if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
 759             final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
 760 
 761             if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
 762                 propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
 763                 return PropertyState.RECOGNIZED;
 764             }
 765         }
 766 
 767         //
 768         // Not recognized
 769         //
 770 
 771         return super.checkProperty(propertyId);
 772 
 773     } // checkProperty(String)
 774 
 775     // factory methods
 776 
 777     /** Creates an entity manager. */
 778     protected XMLEntityManager createEntityManager() {
 779         return new XMLEntityManager();
 780     } // createEntityManager():XMLEntityManager
 781 
 782     /** Creates an error reporter. */
 783     protected XMLErrorReporter createErrorReporter() {
 784         return new XMLErrorReporter();
 785     } // createErrorReporter():XMLErrorReporter
 786 
 787     /** Create a document scanner. */
 788     protected XMLDocumentScanner createDocumentScanner() {
 789         return null;
 790     } // createDocumentScanner():XMLDocumentScanner
 791 
 792     /** Create a DTD scanner. */
 793     protected XMLDTDScanner createDTDScanner() {
 794         return new XMLDTDScannerImpl();
 795     } // createDTDScanner():XMLDTDScanner
 796 
 797     /** Create a datatype validator factory. */
 798     protected DTDDVFactory createDatatypeValidatorFactory() {
 799         return DTDDVFactory.getInstance();
 800     } // createDatatypeValidatorFactory():DatatypeValidatorFactory
 801     protected ValidationManager createValidationManager(){
 802         return new ValidationManager();
 803     }
 804 
 805 } // class NonValidatingConfiguration