You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2002/06/11 01:46:02 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl XMLDocumentScannerImpl.java XMLDTDScannerImpl.java XMLScanner.java XMLEntityManager.java Constants.java

neilg       2002/06/10 16:46:02

  Modified:    java/src/org/apache/xerces/impl XMLDocumentScannerImpl.java
                        XMLDTDScannerImpl.java XMLScanner.java
                        XMLEntityManager.java Constants.java
  Log:
  in order to make DTD preparsing/cacing work, I had to make the document scanners aware whether there was a need to build a grammar (and hence to expand entities).  I also had to add some new functionality to the DTD scanner so that it can be reset outside of a component manager.  (it could be argued that the DTD preparser should be a componentManager, but I saw no reason to complicate the implementation by doing that at this stage.)
  
  Revision  Changes    Path
  1.17      +19 -3     xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java
  
  Index: XMLDocumentScannerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XMLDocumentScannerImpl.java	12 Mar 2002 21:32:48 -0000	1.16
  +++ XMLDocumentScannerImpl.java	10 Jun 2002 23:46:01 -0000	1.17
  @@ -65,6 +65,7 @@
   import org.apache.xerces.impl.XMLEntityScanner;
   import org.apache.xerces.impl.XMLErrorReporter;
   import org.apache.xerces.impl.msg.XMLMessageFormatter;
  +import org.apache.xerces.impl.validation.ValidationManager;
   
   import org.apache.xerces.util.XMLAttributesImpl;
   import org.apache.xerces.util.XMLStringBuffer;
  @@ -150,6 +151,10 @@
       protected static final String DTD_SCANNER =
           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
   
  +    // property identifier:  ValidationManager
  +    protected static final String VALIDATION_MANAGER =
  +        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  +
       // recognized features and properties
   
       /** Recognized features. */
  @@ -167,6 +172,7 @@
           ERROR_REPORTER,
           ENTITY_MANAGER,
           DTD_SCANNER,
  +        VALIDATION_MANAGER,
       };
   
       //
  @@ -177,6 +183,8 @@
   
       /** DTD scanner. */
       protected XMLDTDScanner fDTDScanner;
  +    /** Validation manager . */
  +    protected ValidationManager fValidationManager;
   
       // protected data
   
  @@ -292,6 +300,12 @@
           
           // xerces properties
           fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER);
  +        try {
  +            fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fValidationManager = null;
  +        }
   
           // initialize vars
           fScanningDTD = false;
  @@ -699,7 +713,8 @@
                                   setDispatcher(fDTDDispatcher);
                                   return true;
                               }
  -                            if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD)) {
  +                            if (fDoctypeSystemId != null && ((fValidation || fLoadExternalDTD) 
  +                                    && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
                                   setScannerState(SCANNER_STATE_DTD_EXTERNAL);
                                   setDispatcher(fDTDDispatcher);
                                   return true;
  @@ -789,7 +804,8 @@
                                   fMarkupDepth--;
   
                                   // scan external subset next
  -                                if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD)) {
  +                                if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD) 
  +                                        && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
                                       setScannerState(SCANNER_STATE_DTD_EXTERNAL);
                                   }
   
  
  
  
  1.22      +33 -15    xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java
  
  Index: XMLDTDScannerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- XMLDTDScannerImpl.java	7 May 2002 19:29:04 -0000	1.21
  +++ XMLDTDScannerImpl.java	10 Jun 2002 23:46:01 -0000	1.22
  @@ -242,6 +242,14 @@
       /** Default constructor. */
       public XMLDTDScannerImpl() {} // <init>()
   
  +    /** Constructor for he use of non-XMLComponentManagers. */
  +    public XMLDTDScannerImpl(SymbolTable symbolTable,
  +                XMLErrorReporter errorReporter, XMLEntityManager entityManager) {
  +        fSymbolTable = symbolTable;
  +        fErrorReporter = errorReporter;
  +        fEntityManager = entityManager;
  +    }
  +
       //
       // XMLDTDScanner methods
       //
  @@ -368,23 +376,16 @@
           throws XMLConfigurationException {
           
           super.reset(componentManager);
  -
  -        // reset state related data
  -        fStartDTDCalled = false;
  -        fExtEntityDepth = 0;
  -        fIncludeSectDepth = 0;
  -        fMarkUpDepth = 0;
  -        fPEDepth = 0;
  -
  -        fStandalone = false;
  -        fSeenExternalDTD = false;
  -        fSeenExternalPE = false;
  -
  -        // set starting state
  -        setScannerState(SCANNER_STATE_TEXT_DECL);
  +        init();
   
       } // reset(XMLComponentManager)
   
  +    // this is made for something like XMLDTDLoader--XMLComponentManager-free operation...
  +    public void reset() {
  +        super.reset();
  +        init();
  +    }
  +
       /**
        * Returns a list of feature identifiers that are recognized by
        * this component. This method may return null if no features
  @@ -1972,6 +1973,23 @@
               System.arraycopy(fEnumeration, 0, newEnum, 0, size);
               fEnumeration = newEnum;
           }
  +    }
  +
  +    // private methods
  +    private void init() {
  +        // reset state related data
  +        fStartDTDCalled = false;
  +        fExtEntityDepth = 0;
  +        fIncludeSectDepth = 0;
  +        fMarkUpDepth = 0;
  +        fPEDepth = 0;
  +
  +        fStandalone = false;
  +        fSeenExternalDTD = false;
  +        fSeenExternalPE = false;
  +
  +        // set starting state
  +        setScannerState(SCANNER_STATE_TEXT_DECL);
       }
   
   } // class XMLDTDScannerImpl
  
  
  
  1.16      +47 -20    xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java
  
  Index: XMLScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLScanner.java	2 May 2002 14:33:35 -0000	1.15
  +++ XMLScanner.java	10 Jun 2002 23:46:01 -0000	1.16
  @@ -246,24 +246,7 @@
           fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
           fEntityManager = (XMLEntityManager)componentManager.getProperty(ENTITY_MANAGER);
   
  -        // initialize scanner
  -        fEntityScanner = fEntityManager.getEntityScanner();
  -        
  -        // initialize vars
  -        fEntityDepth = 0;
  -        fReportEntity = true;
  -        fResourceIdentifier.clear();
  -
  -        // save built-in entity names
  -        fVersionSymbol = fSymbolTable.addSymbol("version");
  -        fEncodingSymbol = fSymbolTable.addSymbol("encoding");
  -        fStandaloneSymbol = fSymbolTable.addSymbol("standalone");
  -        fAmpSymbol = fSymbolTable.addSymbol("amp");
  -        fLtSymbol = fSymbolTable.addSymbol("lt");
  -        fGtSymbol = fSymbolTable.addSymbol("gt");
  -        fQuotSymbol = fSymbolTable.addSymbol("quot");
  -        fAposSymbol = fSymbolTable.addSymbol("apos");
  -        
  +        init();
           // sax features
           try {
               fValidation = componentManager.getFeature(VALIDATION);
  @@ -302,7 +285,6 @@
               else if (property.equals(Constants.ENTITY_MANAGER_PROPERTY)) {
                   fEntityManager = (XMLEntityManager)value;
               }
  -            return;
           }
   
       } // setProperty(String,Object)
  @@ -320,10 +302,34 @@
           }
       }
       
  +    /*
  +     * Gets the state of the feature of the scanner.
  +     */
  +    public boolean getFeature(String featureId)
  +        throws XMLConfigurationException {
  +            
  +        if (VALIDATION.equals(featureId)) {
  +            return fValidation;
  +        } else if (NOTIFY_CHAR_REFS.equals(featureId)) {
  +            return fNotifyCharRefs;
  +        }
  +        throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
  +    }
  +    
       //
       // Protected methods
       //
   
  +    // anybody calling this had better have set Symtoltable!
  +    protected void reset() {
  +        init();
  +
  +        // DTD preparsing defaults:
  +        fValidation = true;
  +        fNotifyCharRefs = false;
  +
  +    }
  +
       // common scanning methods
   
       /**
  @@ -1264,5 +1270,26 @@
                                      msgId, args,
                                      XMLErrorReporter.SEVERITY_FATAL_ERROR);
       }
  +
  +    // private methods
  +    private void init() {
  +        // initialize scanner
  +        fEntityScanner = fEntityManager.getEntityScanner();
  +        
  +        // initialize vars
  +        fEntityDepth = 0;
  +        fReportEntity = true;
  +        fResourceIdentifier.clear();
  +
  +        // save built-in entity names
  +        fVersionSymbol = fSymbolTable.addSymbol("version");
  +        fEncodingSymbol = fSymbolTable.addSymbol("encoding");
  +        fStandaloneSymbol = fSymbolTable.addSymbol("standalone");
  +        fAmpSymbol = fSymbolTable.addSymbol("amp");
  +        fLtSymbol = fSymbolTable.addSymbol("lt");
  +        fGtSymbol = fSymbolTable.addSymbol("gt");
  +        fQuotSymbol = fSymbolTable.addSymbol("quot");
  +        fAposSymbol = fSymbolTable.addSymbol("apos"); 
  +    } 
   
   } // class XMLScanner
  
  
  
  1.31      +30 -14    xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- XMLEntityManager.java	22 May 2002 13:06:18 -0000	1.30
  +++ XMLEntityManager.java	10 Jun 2002 23:46:01 -0000	1.31
  @@ -75,6 +75,7 @@
   import org.apache.xerces.impl.io.UCSReader;
   import org.apache.xerces.impl.io.UTF8Reader;
   import org.apache.xerces.impl.msg.XMLMessageFormatter;
  +import org.apache.xerces.impl.validation.ValidationManager;
   
   import org.apache.xerces.util.EncodingMap;
   import org.apache.xerces.util.SymbolTable;
  @@ -166,6 +167,10 @@
       protected static final String ENTITY_RESOLVER =
           Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
   
  +    // property identifier:  ValidationManager
  +    protected static final String VALIDATION_MANAGER =
  +        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  +
       // recognized features and properties
   
       /** Recognized features. */
  @@ -182,6 +187,7 @@
           SYMBOL_TABLE,
           ERROR_REPORTER,
           ENTITY_RESOLVER,
  +        VALIDATION_MANAGER,
       };
   
       // debugging
  @@ -257,6 +263,12 @@
        */
       protected XMLEntityResolver fEntityResolver;
   
  +    /**
  +     * Validation manager. This property identifier is:
  +     * http://apache.org/xml/properties/internal/validation-manager
  +     */
  +    protected ValidationManager fValidationManager;
  +
       // settings
   
       /**
  @@ -631,7 +643,7 @@
   
           // should we skip external entities?
           boolean external = entity.isExternal();
  -        if (external) {
  +        if (external && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
               boolean unparsed = entity.isUnparsed();
               boolean parameter = entityName.startsWith("%");
               boolean general = !parameter;
  @@ -640,18 +652,16 @@
                   if (fEntityHandler != null) {
                       fResourceIdentifier.clear();
                       final String encoding = null;
  -                    if (external) {
  -                        ExternalEntity externalEntity = (ExternalEntity)entity;
  -                        //REVISIT:  since we're storing expandedSystemId in the
  -                        // externalEntity, how could this have got here if it wasn't already
  -                        // expanded??? - neilg
  -                        String extLitSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getLiteralSystemId() : null);
  -                        String extBaseSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getBaseSystemId() : null);
  -                        String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId);
  -                        fResourceIdentifier.setValues(
  -                                (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null),
  -                                extLitSysId, extBaseSysId, expandedSystemId);
  -                    }
  +                    ExternalEntity externalEntity = (ExternalEntity)entity;
  +                    //REVISIT:  since we're storing expandedSystemId in the
  +                    // externalEntity, how could this have got here if it wasn't already
  +                    // expanded??? - neilg
  +                    String extLitSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getLiteralSystemId() : null);
  +                    String extBaseSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getBaseSystemId() : null);
  +                    String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId);
  +                    fResourceIdentifier.setValues(
  +                            (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null),
  +                            extLitSysId, extBaseSysId, expandedSystemId);
                       fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding);
                       fEntityHandler.endEntity(entityName);
                   }
  @@ -958,6 +968,12 @@
           }
           catch (XMLConfigurationException e) {
               fEntityResolver = null;
  +        }
  +        try {
  +            fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fValidationManager = null;
           }
           // initialize state
           fStandalone = false;
  
  
  
  1.17      +3 -3      xml-xerces/java/src/org/apache/xerces/impl/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Constants.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Constants.java	4 Jun 2002 13:41:43 -0000	1.16
  +++ Constants.java	10 Jun 2002 23:46:01 -0000	1.17
  @@ -273,8 +273,8 @@
       /** DTD scanner property ("internal/dtd-scanner"). */
       public static final String DTD_SCANNER_PROPERTY = "internal/dtd-scanner";
   
  -    /** DTD loader property ("internal/dtd-loader"). */
  -    public static final String DTD_LOADER_PROPERTY = "internal/dtd-loader";
  +    /** DTD processor property ("internal/dtd-processor"). */
  +    public static final String DTD_PROCESSOR_PROPERTY = "internal/dtd-processor";
   
       /** Validator property ("internal/validator"). */
       public static final String VALIDATOR_PROPERTY = "internal/validator";
  
  
  

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