You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2002/09/16 19:54:40 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers IntegratedParserConfiguration.java NonValidatingConfiguration.java StandardParserConfiguration.java org.apache.xerces.xni.parser.XMLParserConfiguration

elena       2002/09/16 10:54:40

  Modified:    java/src/org/apache/xerces/impl
                        XMLNSDocumentScannerImpl.java
               java/src/org/apache/xerces/parsers
                        IntegratedParserConfiguration.java
                        NonValidatingConfiguration.java
                        StandardParserConfiguration.java
                        org.apache.xerces.xni.parser.XMLParserConfiguration
  Log:
  The NonValidatingParserConfiguration now uses optimazed scanner (that binds namespaces).
  This commit also re-organizes some configuration code.
  
  Revision  Changes    Path
  1.2       +2 -2      xml-xerces/java/src/org/apache/xerces/impl/XMLNSDocumentScannerImpl.java
  
  Index: XMLNSDocumentScannerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLNSDocumentScannerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLNSDocumentScannerImpl.java	12 Sep 2002 21:56:56 -0000	1.1
  +++ XMLNSDocumentScannerImpl.java	16 Sep 2002 17:54:39 -0000	1.2
  @@ -609,7 +609,7 @@
            */
           protected boolean scanRootElementHook()
           throws IOException, XNIException {
  -            if (!fDTDValidator.hasGrammar()) {
  +            if (fDTDValidator != null && !fDTDValidator.hasGrammar()) {
                   fBindNamespaces = true;                
                   fPerformValidation = fDTDValidator.validate();
                   // re-configure pipeline
  
  
  
  1.2       +20 -170   xml-xerces/java/src/org/apache/xerces/parsers/IntegratedParserConfiguration.java
  
  Index: IntegratedParserConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/IntegratedParserConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntegratedParserConfiguration.java	12 Sep 2002 21:56:57 -0000	1.1
  +++ IntegratedParserConfiguration.java	16 Sep 2002 17:54:39 -0000	1.2
  @@ -132,180 +132,16 @@
   
       /** Document scanner that does namespace binding. */
       protected XMLNSDocumentScannerImpl fNamespaceScanner;
  +
  +    /** Default Xerces implementation of scanner */
       protected XMLDocumentScannerImpl fNonNSScanner;
   
  +    /** DTD Validator that binds namespaces */
       protected XMLNSDTDValidator fNSDTDValidator;
  -
  -    protected static final String XMLSCHEMA_VALIDATION = 
  -    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
  -
       
  -    /** Default constructor. */
  -    public IntegratedParserConfiguration() {
  -        this(null, null, null);
  -    } // <init>()
       
  -
  -    public IntegratedParserConfiguration(SymbolTable symbolTable,
  -                                       XMLGrammarPool grammarPool) {
  -        this(symbolTable, grammarPool, null);
  -    } // <init>(SymbolTable,XMLGrammarPool)
  -
  -    /**
  -     * Constructs a parser configuration using the specified symbol table,
  -     * grammar pool, and parent settings.
  -     * <p>
  -     * <strong>REVISIT:</strong> 
  -     * Grammar pool will be updated when the new validation engine is
  -     * implemented.
  -     *
  -     * @param symbolTable    The symbol table to use.
  -     * @param grammarPool    The grammar pool to use.
  -     * @param parentSettings The parent settings.
  -     */
  -    public IntegratedParserConfiguration(SymbolTable symbolTable,
  -                                      XMLGrammarPool grammarPool,
  -                                      XMLComponentManager parentSettings) {
  -
  -
  -        // save parent
  -        fParentSettings = parentSettings;
  -        // create a vector to hold all the components in use
  -        fComponents = new Vector();
  -
  -        // create storage for recognized features and properties
  -        fRecognizedFeatures = new Vector();
  -        fRecognizedProperties = new Vector();
  -
  -        // create table for features and properties
  -        fFeatures = new Hashtable();
  -        fProperties = new Hashtable();
  -
  -        // add default recognized features
  -        final String[] recognizedFeatures = {
  -
  -            VALIDATION,                 NAMESPACES, 
  -            EXTERNAL_GENERAL_ENTITIES,  EXTERNAL_PARAMETER_ENTITIES,
  -            WARN_ON_DUPLICATE_ATTDEF,   WARN_ON_UNDECLARED_ELEMDEF,
  -            ALLOW_JAVA_ENCODINGS,       CONTINUE_AFTER_FATAL_ERROR,
  -            LOAD_EXTERNAL_DTD,          NOTIFY_BUILTIN_REFS,
  -            NOTIFY_CHAR_REFS,       WARN_ON_DUPLICATE_ENTITYDEF,
  -            NORMALIZE_DATA,             SCHEMA_ELEMENT_DEFAULT
  -        };
  -        addRecognizedFeatures(recognizedFeatures);
  -
  -        // set state for default features
  -        setFeature(VALIDATION, false);
  -        setFeature(NAMESPACES, true);
  -        setFeature(EXTERNAL_GENERAL_ENTITIES, true);
  -        setFeature(EXTERNAL_PARAMETER_ENTITIES, true);
  -        setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
  -        setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
  -        setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);
  -        setFeature(ALLOW_JAVA_ENCODINGS, false);
  -        setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
  -        setFeature(LOAD_EXTERNAL_DTD, true);
  -        setFeature(NOTIFY_BUILTIN_REFS, false);
  -        setFeature(NOTIFY_CHAR_REFS, false);
  -        setFeature(SCHEMA_ELEMENT_DEFAULT, true);
  -        setFeature(NORMALIZE_DATA, true);
  -
  -        // add default recognized properties
  -        final String[] recognizedProperties = {
  -            XML_STRING,     
  -            SYMBOL_TABLE,
  -            ERROR_HANDLER,  
  -            ENTITY_RESOLVER,
  -            ERROR_REPORTER,             
  -            ENTITY_MANAGER, 
  -            DOCUMENT_SCANNER,
  -            DTD_SCANNER,
  -            DTD_PROCESSOR,
  -            DTD_VALIDATOR,
  -            NAMESPACE_BINDER,
  -            XMLGRAMMAR_POOL,   
  -            DATATYPE_VALIDATOR_FACTORY,
  -            VALIDATION_MANAGER 
  -        };
  -
  -        addRecognizedProperties(recognizedProperties);
  -
  -        if (symbolTable == null) {
  -            symbolTable = new SymbolTable();
  -        }
  -        fSymbolTable = symbolTable;
  -        setProperty(SYMBOL_TABLE, fSymbolTable);
  -
  -        fGrammarPool = grammarPool;
  -        if (fGrammarPool != null) {
  -            setProperty(XMLGRAMMAR_POOL, fGrammarPool);
  -        }
  -
  -        fEntityManager = createEntityManager();
  -        setProperty(ENTITY_MANAGER, fEntityManager);
  -        addComponent(fEntityManager);
  -
  -        fErrorReporter = createErrorReporter();
  -        fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  -        setProperty(ERROR_REPORTER, fErrorReporter);
  -        addComponent(fErrorReporter);
  -
  -        // create namespace aware scanner
  -        fNamespaceScanner = new XMLNSDocumentScannerImpl();
  -        addComponent((XMLComponent)fNamespaceScanner);
  -        setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
  -
  -        // create namespace + dtd validator
  -        fNSDTDValidator = new XMLNSDTDValidator();
  -        setProperty(DTD_VALIDATOR, fNSDTDValidator);
  -        addComponent(fNSDTDValidator);                                                  
  -
  -        fDTDScanner = createDTDScanner();
  -        if (fDTDScanner != null) {
  -            setProperty(DTD_SCANNER, fDTDScanner);
  -            if (fDTDScanner instanceof XMLComponent) {
  -                addComponent((XMLComponent)fDTDScanner);
  -            }
  -        }
  -
  -        fDTDProcessor = createDTDProcessor();
  -        if (fDTDProcessor != null) {
  -            setProperty(DTD_PROCESSOR, fDTDProcessor);
  -            if (fDTDProcessor instanceof XMLComponent) {
  -                addComponent((XMLComponent)fDTDProcessor);
  -            }
  -        }
  -
  -        fDatatypeValidatorFactory = createDatatypeValidatorFactory();
  -        if (fDatatypeValidatorFactory != null) {
  -            setProperty(DATATYPE_VALIDATOR_FACTORY,
  -                        fDatatypeValidatorFactory);
  -        }
  -        fValidationManager = createValidationManager();
  -
  -        if (fValidationManager != null) {
  -            setProperty (VALIDATION_MANAGER, fValidationManager);
  -        }
  -        // add message formatters
  -        if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
  -            XMLMessageFormatter xmft = new XMLMessageFormatter();
  -            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
  -            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
  -        }
  -
  -        // set locale
  -        try {
  -            setLocale(Locale.getDefault());
  -        } catch (XNIException e) {
  -            // do nothing
  -            // REVISIT: What is the right thing to do? -Ac
  -        }
  -
  -    } // <init>(SymbolTable,XMLGrammarPool)
  -
       /** Configures the pipeline. */
       protected void configurePipeline() {
  -
           // setup dtd pipeline
           if (fDTDScanner != null) {
               if (fDTDProcessor != null) {
  @@ -335,7 +171,6 @@
                   }
   
               }
  -
               fProperties.put(DTD_VALIDATOR, fNSDTDValidator);
               fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
               fScanner = fNamespaceScanner;
  @@ -351,7 +186,6 @@
           else {
   
               if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
  -
                   fScanner = fNamespaceScanner;
                   fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
                   fNamespaceScanner.setComponents(null, fNSDTDValidator, fDocumentHandler);
  @@ -381,6 +215,22 @@
   
       } // configurePipeline()
   
  +
  +
  +    /** Create a document scanner: this scanner performs namespace binding 
  +      */
  +    protected XMLDocumentScanner createDocumentScanner() {
  +        fNamespaceScanner = new XMLNSDocumentScannerImpl();
  +        return fNamespaceScanner;
  +    } // createDocumentScanner():XMLDocumentScanner
  +
  +
  +    /** Create a DTD validator: this validator performs namespace binding.
  +      */
  +    protected XMLDTDValidator createDTDValidator() {
  +        fNSDTDValidator = new XMLNSDTDValidator();
  +        return fNSDTDValidator;
  +    } // createDTDValidator():XMLDTDValidator
   
   } // class IntegratedParserConfiguration
   
  
  
  
  1.4       +42 -23    xml-xerces/java/src/org/apache/xerces/parsers/NonValidatingConfiguration.java
  
  Index: NonValidatingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/NonValidatingConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NonValidatingConfiguration.java	22 May 2002 13:06:19 -0000	1.3
  +++ NonValidatingConfiguration.java	16 Sep 2002 17:54:39 -0000	1.4
  @@ -62,6 +62,7 @@
   
   import org.apache.xerces.impl.Constants;
   import org.apache.xerces.impl.XMLDocumentScannerImpl;
  +import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
   import org.apache.xerces.impl.XMLDTDScannerImpl;
   import org.apache.xerces.impl.XMLErrorReporter;
   import org.apache.xerces.impl.XMLEntityManager;
  @@ -87,6 +88,11 @@
    * This is the non validating parser configuration. It extends the basic
    * configuration with the set of following parser components:
    * Document scanner, DTD scanner, namespace binder, document handler.
  + * <p>
  + * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a> 
  + * non-validating XML processor, since conformant non-validating processor is required  
  + * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values, 
  + * include the replacement text of internal entities, and supply default attribute values".
    * 
    * @author Elena Litani, IBM
    * @version $Id$
  @@ -223,6 +229,16 @@
       protected XMLNamespaceBinder fNamespaceBinder;
   
       protected ValidationManager fValidationManager;
  +
  +    // private data
  +
  +    /** Document scanner that does namespace binding. */
  +    private XMLNSDocumentScannerImpl fNamespaceScanner;
  +
  +    /** Default Xerces implementation of scanner*/
  +    private XMLDocumentScannerImpl fNonNSScanner;
  +
  +
       // state
   
       /** Locator */
  @@ -333,11 +349,8 @@
           setProperty(ERROR_REPORTER, fErrorReporter);
           addComponent(fErrorReporter);
   
  -        fScanner = createDocumentScanner();
  -        setProperty(DOCUMENT_SCANNER, fScanner);
  -        if (fScanner instanceof XMLComponent) {
  -            addComponent((XMLComponent)fScanner);
  -        }
  +        // this configuration delays creation of the scanner
  +        // till it is known if namespace processing should be performed
   
           fDTDScanner = createDTDScanner();
           if (fDTDScanner != null) {
  @@ -582,21 +595,28 @@
   
       /** Configures the pipeline. */
       protected void configurePipeline() {
  +        // create appropriate scanner
  +        // and register it as one of the components.
  +        if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
  +            if (fNamespaceScanner == null) {
  +                fNamespaceScanner = new XMLNSDocumentScannerImpl();
  +                addComponent((XMLComponent)fNamespaceScanner);
  +            }
  +            fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
  +            fNamespaceScanner.setComponents(null, null, fDocumentHandler);
  +            fScanner = fNamespaceScanner;
  +        } 
  +        else {
  +            if (fNonNSScanner == null) {
  +                fNonNSScanner = new XMLDocumentScannerImpl();
  +                addComponent((XMLComponent)fNonNSScanner);
  +            }
  +            fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
  +            fScanner = fNonNSScanner;
  +        }
   
  -        // REVISIT: This should be better designed. In other words, we
  -        //          need to figure out what is the best way for people to
  -        //          re-use *most* of the standard configuration but do 
  -        //          things common things such as remove a component (e.g.
  -        //          the validator), insert a new component (e.g. XInclude), 
  -        //          etc... -Ac
  -
  -        // setup document pipeline
  -        fScanner.setDocumentHandler(fNamespaceBinder);
  -        fNamespaceBinder.setDocumentHandler(fDocumentHandler);
  -        
  -
  -        fLastComponent = fNamespaceBinder;
  -
  +        fScanner.setDocumentHandler(fDocumentHandler);
  +        fLastComponent = fScanner;
           // setup dtd pipeline
           if (fDTDScanner != null) {
                   fDTDScanner.setDTDHandler(fDTDHandler);
  @@ -741,7 +761,7 @@
   
       /** Create a document scanner. */
       protected XMLDocumentScanner createDocumentScanner() {
  -        return new XMLDocumentScannerImpl();
  +        return null;
       } // createDocumentScanner():XMLDocumentScanner
   
       /** Create a DTD scanner. */
  @@ -749,10 +769,9 @@
           return new XMLDTDScannerImpl();
       } // createDTDScanner():XMLDTDScanner
   
  -
       /** Create a namespace binder. */
       protected XMLNamespaceBinder createNamespaceBinder() {
  -        return new XMLNamespaceBinder();
  +        return null;
       } // createNamespaceBinder():XMLNamespaceBinder
   
       /** Create a datatype validator factory. */
  
  
  
  1.24      +8 -2      xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java
  
  Index: StandardParserConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- StandardParserConfiguration.java	16 Aug 2002 18:08:38 -0000	1.23
  +++ StandardParserConfiguration.java	16 Sep 2002 17:54:39 -0000	1.24
  @@ -125,6 +125,11 @@
       protected static final String SCHEMA_ELEMENT_DEFAULT =
       Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
   
  +
  +    /** feature identifier: XML Schema validation */
  +    protected static final String XMLSCHEMA_VALIDATION = 
  +    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
  +
       // property identifiers
   
       /** Property identifier: XML Schema validator. */
  @@ -132,6 +137,7 @@
           Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
   
   
  +
       // debugging
   
       /** Set to true and recompile to print exception stack trace. */
  @@ -219,7 +225,7 @@
       /** Configures the pipeline. */
       protected void configurePipeline() {
           super.configurePipeline();
  -        if ( getFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE)) {
  +        if ( getFeature(XMLSCHEMA_VALIDATION )) {
               // If schema validator was not in the pipeline insert it.
               if (fSchemaValidator == null) {
                   fSchemaValidator = new XMLSchemaValidator(); 
  
  
  
  1.2       +1 -1      xml-xerces/java/src/org/apache/xerces/parsers/org.apache.xerces.xni.parser.XMLParserConfiguration
  
  Index: org.apache.xerces.xni.parser.XMLParserConfiguration
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/org.apache.xerces.xni.parser.XMLParserConfiguration,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- org.apache.xerces.xni.parser.XMLParserConfiguration	12 Jan 2002 02:58:00 -0000	1.1
  +++ org.apache.xerces.xni.parser.XMLParserConfiguration	16 Sep 2002 17:54:40 -0000	1.2
  @@ -1 +1 @@
  -org.apache.xerces.parsers.StandardParserConfiguration
  +org.apache.xerces.parsers.IntegratedParserConfiguration
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org