elena       2002/09/23 09:44:42

  Modified:    java/src/org/apache/xerces/dom CoreDocumentImpl.java
                        DOMNormalizer.java DOMValidationConfiguration.java
               java/src/org/apache/xerces/parsers DOMBuilderImpl.java
  Log:
  Add *temporary* setProperty method to DOMBuilderImpl (this method will be removed
  if the W3C adds simillar method to the DOMBuilder interface).
  Users can set grammar pool using this method.
  Also, make DOM Level 3 implementation copy grammar pool from the parser: this is also
  a temporary solution to allow using grammar pool. Intead, we should add setProperty 
to the CoreDocumentImpl
  interface.
  
  This change is based on the patch submitted by  Mikko Honkala <[EMAIL PROTECTED]>.
  
  Revision  Changes    Path
  1.31      +23 -33    xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
  
  Index: CoreDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- CoreDocumentImpl.java     23 Sep 2002 00:16:07 -0000      1.30
  +++ CoreDocumentImpl.java     23 Sep 2002 16:44:42 -0000      1.31
  @@ -93,6 +93,7 @@
   import org.w3c.dom.events.EventTarget;
   
   import org.apache.xerces.impl.Constants;
  +import org.apache.xerces.util.XMLGrammarPoolImpl;
   import org.apache.xerces.util.XMLChar;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.util.DOMErrorHandlerWrapper;
  @@ -192,11 +193,7 @@
       
       // DOM Revalidation 
       protected DOMNormalizer domNormalizer = null;
  -    protected DOMValidationConfiguration fConfiguration= null;
  -    protected ShadowedSymbolTable fSymbolTable = null;
  -    protected XMLEntityResolver fEntityResolver = null;
  -    protected Grammar fGrammar = null;
  -    
  +    protected DOMValidationConfiguration fConfiguration= null;    
   
       /** Table for quick check of child insertion. */
       private final static int[] kidOK;
  @@ -1024,21 +1021,20 @@
           if (needsSyncChildren()) {
               synchronizeChildren();
           }
  +        
           if (domNormalizer == null) {
               domNormalizer = new DOMNormalizer();
           }
   
   
           if (fConfiguration == null) {
  -            // if symbol table is not available                
  -            // it will be created by the configuration
  -            fConfiguration =  new DOMValidationConfiguration(fSymbolTable);
  +            fConfiguration =  new DOMValidationConfiguration();
           }
           if (fErrorHandlerWrapper.getErrorHandler() !=null) {           
               fConfiguration.setErrorHandler(fErrorHandlerWrapper);
           }
  -            // resets components.
  -            fConfiguration.reset();
  +        // resets components.
  +        fConfiguration.reset();
   
           if ((features & VALIDATION) != 0) {
               // REVISIT: validation is performed only against one type of grammar
  @@ -1051,11 +1047,6 @@
              // set xml-schema validator handler
               domNormalizer.setValidationHandler(
                   
CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA));
  -        
  -
  -            if (fGrammar != null) {
  -                fConfiguration.setProperty(DOMValidationConfiguration.GRAMMAR_POOL, 
domNormalizer);
  -            }
           } 
           else { // remove validation handler
                   domNormalizer.setValidationHandler(null);
  @@ -2310,29 +2301,28 @@
         * This method is called after the parsing is done 
         */
       public void copyConfigurationProperties(XMLParserConfiguration config){
  +        // REVISIT: add a set/getProperty on DocumentImpl to allow setting 
  +        //          grammar pool, symbol table, entity resolver.
  +
           // REVISIT: how should we copy symbol table?
        // It usually grows with the parser, do we need to carry all
        // data per document?
  -        fSymbolTable = new 
ShadowedSymbolTable((SymbolTable)config.getProperty(DOMValidationConfiguration.SYMBOL_TABLE));
  -        fEntityResolver =  config.getEntityResolver();
  -        
  -        // REVISIT: storing one grammar per document is not efficient
  -        // and might not be enough. We need to implement some grammar
  -        // cashing possibly on DOM Implementation
   
  +        SymbolTable symbolTable = new 
ShadowedSymbolTable((SymbolTable)config.getProperty(DOMValidationConfiguration.SYMBOL_TABLE));
  +        fConfiguration =  new DOMValidationConfiguration(symbolTable);
  +        
  +        XMLEntityResolver entityResolver =  config.getEntityResolver();
  +        if (entityResolver != null) {
  +            fConfiguration.setEntityResolver(entityResolver);
  +        }
  +        
           XMLGrammarPool pool = 
(XMLGrammarPool)config.getProperty(DOMValidationConfiguration.GRAMMAR_POOL);
           if (pool != null) {
  -            // retrieve either a DTD or XML Schema grammar
  -
  -            if (docType != null) {
  -                // retrieve DTD grammar
  -                // pool.retrieveGrammar();
  -            } else {
  -                // retrieve XML Schema grammar based on teh namespace
  -                // of the root element
  -                String targetNamespace = this.docElement.getNamespaceURI();
  -                // pool.retrieveGrammar();
  -            }
  +            // copy the grammar pool
  +            XMLGrammarPool grammarPool = new XMLGrammarPoolImpl();
  +            grammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA,  
  +                                      
pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA));
  +            fConfiguration.setProperty(DOMValidationConfiguration.GRAMMAR_POOL, 
grammarPool);
           }
       }
   
  
  
  
  1.15      +2 -3      xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java
  
  Index: DOMNormalizer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DOMNormalizer.java        27 Aug 2002 03:12:33 -0000      1.14
  +++ DOMNormalizer.java        23 Sep 2002 16:44:42 -0000      1.15
  @@ -1087,11 +1087,10 @@
       //
       // XML GrammarPool methods
       //
  -    protected final Grammar[] fGrammarPool = new Grammar[1];
   
  +    // REVISIT: should DOMNormalizer implement grammar pool?
       public Grammar[] retrieveInitialGrammarSet(String grammarType){
           // REVISIT: should take into account grammarType
  -        fGrammarPool[0] = fDocument.fGrammar;
           return null;
   
       }
  
  
  
  1.4       +6 -3      
xml-xerces/java/src/org/apache/xerces/dom/DOMValidationConfiguration.java
  
  Index: DOMValidationConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMValidationConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMValidationConfiguration.java   10 Sep 2002 14:04:52 -0000      1.3
  +++ DOMValidationConfiguration.java   23 Sep 2002 16:44:42 -0000      1.4
  @@ -121,7 +121,9 @@
       protected static final String NORMALIZE_DATA = 
           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
   
  -    
  +    /** Property identifier: namespace context */
  +    protected static final String NAMESPACE_CONTEXT_PROPERTY =
  +        Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;
       
       // property identifiers
   
  @@ -239,7 +241,8 @@
               ERROR_REPORTER,
               ENTITY_MANAGER,
               VALIDATION_MANAGER,
  -            GRAMMAR_POOL
  +            GRAMMAR_POOL, 
  +            NAMESPACE_CONTEXT_PROPERTY
           };
           addRecognizedProperties(recognizedProperties);
   
  
  
  
  1.23      +40 -29    
xml-xerces/java/src/org/apache/xerces/parsers/DOMBuilderImpl.java
  
  Index: DOMBuilderImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMBuilderImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- DOMBuilderImpl.java       19 Sep 2002 17:55:22 -0000      1.22
  +++ DOMBuilderImpl.java       23 Sep 2002 16:44:42 -0000      1.23
  @@ -209,7 +209,7 @@
       public DOMBuilderImpl(SymbolTable symbolTable) {
           this((XMLParserConfiguration)ObjectFactory.createObject(
                                                                  
"org.apache.xerces.xni.parser.XMLParserConfiguration",
  -                                                               
"org.apache.xerces.parsers.StandardParserConfiguration"
  +                                                               
"org.apache.xerces.parsers.IntegratedParserConfiguration"
                                                                  ));
           
fConfiguration.setProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SYMBOL_TABLE_PROPERTY,
 symbolTable);
       } // <init>(SymbolTable)
  @@ -504,8 +504,6 @@
       public Document parseURI(String uri)  {
           XMLInputSource source = new XMLInputSource(null, uri, null);
   
  -        // initialize grammar pool
  -        initGrammarPool();
           try {        
               parse(source);
           } catch (Exception e){
  @@ -534,9 +532,6 @@
           // need to wrap the DOMInputSource with an XMLInputSource
           XMLInputSource xmlInputSource = dom2xmlInputSource(is);
   
  -
  -        // initialize grammar pool
  -        initGrammarPool();
           try {        
               parse(xmlInputSource);
           } catch (Exception e) {
  @@ -555,26 +550,6 @@
           return getDocument();
       }
   
  -    protected void initGrammarPool(){
  -
  -        // REVISIT: do we want to use custome grammar pool to be able
  -        //          to retrieve a grammar used in validation of the document
  -        //          for dom revalidation?
  -        
  -        /*
  -        fGrammarPool = (XMLGrammarPool)fConfiguration.getProperty(GRAMMAR_POOL);
  -        if (fGrammarPool == null) {
  -            fGrammarPool = new XMLGrammarPoolImpl();
  -            // set our own grammar pool
  -            fConfiguration.setProperty(GRAMMAR_POOL, fGrammarPool);
  -        }
  -        else {
  -            //REVISIT: if user sets its own grammar pool do we do anything?
  -        }
  -        */
  -        
  -    }
  -
       /**
        *  Parse an XML document or fragment from a resource identified by an 
        * <code>DOMInputSource</code> and insert the content into an existing 
  @@ -653,11 +628,47 @@
   
           // If this is a DOM Level 3 implementation we should copy some information
           if (fDocumentImpl != null) {  
  -            CoreDocumentImpl doc = (CoreDocumentImpl)fDocument;
  -            doc.copyConfigurationProperties(fConfiguration);
  +            fDocumentImpl.copyConfigurationProperties(fConfiguration);
           }
   
       } // endDocument()
  +
  +
  +    /**
  +     * Set the value of any property in a DOMBuilder parser.  The parser
  +     * might not recognize the property, and if it does recognize
  +     * it, it might not support the requested value.
  +     *
  +     * NOTE: this method is experimental and might be removed in the next
  +     *       Xerces release. 
  +     * 
  +     * @param propertyId The unique identifier (URI) of the property
  +     *                   being set.
  +     * @param Object The value to which the property is being set.
  +     *
  +     * @exception DOMException: NotRecognizedException If the
  +     *            requested property is not known.
  +     * @exception DOMException: NotSupportedException If the
  +     *            requested property is known, but the requested
  +     *            value is not supported.
  +     */
  +    public void setProperty(String propertyId, Object value)
  +        throws DOMException {
  +
  +        try {
  +            fConfiguration.setProperty(propertyId, value);
  +        }
  +        catch (XMLConfigurationException e) {
  +            String message = e.getMessage();
  +            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
  +                throw new DOMException(DOMException.NOT_FOUND_ERR, message);
  +            }
  +            else {
  +                throw new DOMException(DOMException.NOT_SUPPORTED_ERR, message);
  +            }
  +        }
  +
  +    } // setProperty(String,Object)
   
   
   } // class DOMBuilderImpl
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to