neilg       2002/12/06 16:18:54

  Modified:    java/src/org/apache/xerces/impl/dtd DTDGrammar.java
                        XMLDTDProcessor.java XMLDTDValidator.java
  Added:       java/src/org/apache/xerces/impl/dtd XML11DTDProcessor.java
                        XML11DTDValidator.java
  Log:
  implementing XNI changes and XML 1.1 support in DTD validation code
  
  Revision  Changes    Path
  1.22      +26 -1     xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java
  
  Index: DTDGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DTDGrammar.java   20 Nov 2002 00:49:47 -0000      1.21
  +++ DTDGrammar.java   7 Dec 2002 00:18:53 -0000       1.22
  @@ -93,6 +93,8 @@
   import org.apache.xerces.xni.XMLResourceIdentifier;
   import org.apache.xerces.xni.XMLString;
   import org.apache.xerces.xni.XNIException;
  +import org.apache.xerces.xni.parser.XMLDTDSource;
  +import org.apache.xerces.xni.parser.XMLDTDContentModelSource;
   import org.apache.xerces.xni.grammars.Grammar;
   import org.apache.xerces.xni.grammars.XMLGrammarDescription;
   
  @@ -149,6 +151,9 @@
       // Data
       //
   
  +    protected XMLDTDSource fDTDSource = null;
  +    protected XMLDTDContentModelSource fDTDContentModelSource = null;
  +
       /** Current element index. */
       protected int fCurrentElementIndex;
   
  @@ -880,6 +885,16 @@
           }
       } // endDTD()
   
  +    // sets the source of this handler
  +    public void setDTDSource(XMLDTDSource source) {
  +        fDTDSource = source;
  +    } // setDTDSource(XMLDTDSource)
  +
  +    // returns the source of this handler
  +    public XMLDTDSource getDTDSource() {
  +        return fDTDSource;
  +    } // getDTDSource():  XMLDTDSource
  +
       // no-op methods
   
       /**
  @@ -985,6 +1000,16 @@
       //
       // XMLDTDContentModelHandler methods
       //
  +
  +    // set content model source
  +    public void setDTDContentModelSource(XMLDTDContentModelSource source) {
  +        fDTDContentModelSource = source;
  +    }
  +
  +    // get content model source
  +    public XMLDTDContentModelSource getDTDContentModelSource() {
  +        return fDTDContentModelSource;
  +    }
   
       /**
        * The start of a content model. Depending on the type of the content
  
  
  
  1.6       +60 -6     
xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDProcessor.java
  
  Index: XMLDTDProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDProcessor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLDTDProcessor.java      24 Sep 2002 09:39:44 -0000      1.5
  +++ XMLDTDProcessor.java      7 Dec 2002 00:18:53 -0000       1.6
  @@ -80,7 +80,9 @@
   import org.apache.xerces.xni.parser.XMLComponentManager;
   import org.apache.xerces.xni.parser.XMLConfigurationException;
   import org.apache.xerces.xni.parser.XMLDTDFilter;
  +import org.apache.xerces.xni.parser.XMLDTDSource;
   import org.apache.xerces.xni.parser.XMLDTDContentModelFilter;
  +import org.apache.xerces.xni.parser.XMLDTDContentModelSource;
   import org.apache.xerces.xni.parser.XMLInputSource;
   
   import java.util.Enumeration;
  @@ -228,9 +230,15 @@
       /** DTD handler. */
       protected XMLDTDHandler fDTDHandler;
   
  +    /** DTD source. */
  +    protected XMLDTDSource fDTDSource;
  +
       /** DTD content model handler. */
       protected XMLDTDContentModelHandler fDTDContentModelHandler;
   
  +    /** DTD content model source. */
  +    protected XMLDTDContentModelSource fDTDContentModelSource;
  +
       // grammars
   
       /** DTD Grammar. */
  @@ -478,6 +486,15 @@
           fDTDHandler = dtdHandler;
       } // setDTDHandler(XMLDTDHandler)
   
  +    /**
  +     * Returns the DTD handler.
  +     * 
  +     * @return The DTD handler.
  +     */
  +    public XMLDTDHandler getDTDHandler() {
  +        return fDTDHandler;
  +    } // getDTDHandler():  XMLDTDHandler
  +
       //
       // XMLDTDContentModelSource methods
       //
  @@ -491,6 +508,15 @@
           fDTDContentModelHandler = dtdContentModelHandler;
       } // setDTDContentModelHandler(XMLDTDContentModelHandler)
   
  +    /**
  +     * Gets the DTD content model handler.
  +     * 
  +     * @return dtdContentModelHandler The DTD content model handler.
  +     */
  +    public XMLDTDContentModelHandler getDTDContentModelHandler() {
  +        return fDTDContentModelHandler;
  +    } // getDTDContentModelHandler():  XMLDTDContentModelHandler
  +
       //
       // XMLDTDContentModelHandler and XMLDTDHandler methods
       //
  @@ -941,14 +967,14 @@
                           while (true) {
                               String nmtoken = tokenizer.nextToken();
                               if (type == XMLSymbols.fNMTOKENSSymbol) {
  -                                if (!XMLChar.isValidNmtoken(nmtoken)) {
  +                                if (!isValidNmtoken(nmtoken)) {
                                       ok = false;
                                       break;
                                   }
                               }
                               else if (type == XMLSymbols.fENTITIESSymbol ||
                                        type == XMLSymbols.fIDREFSSymbol) {
  -                                if (!XMLChar.isValidName(nmtoken)) {
  +                                if (!isValidName(nmtoken)) {
                                       ok = false;
                                       break;
                                   }
  @@ -966,7 +992,7 @@
                           type == XMLSymbols.fIDREFSymbol ||
                           type == XMLSymbols.fNOTATIONSymbol) {
   
  -                        if (!XMLChar.isValidName(value)) {
  +                        if (!isValidName(value)) {
                               ok = false;
                           }
   
  @@ -974,7 +1000,7 @@
                       else if (type == XMLSymbols.fNMTOKENSymbol ||
                                type == XMLSymbols.fENUMERATIONSymbol) {
   
  -                        if (!XMLChar.isValidNmtoken(value)) {
  +                        if (!isValidNmtoken(value)) {
                               ok = false;
                           }
                       }
  @@ -1275,10 +1301,31 @@
   
       } // endDTD()
   
  +    // sets the XMLDTDSource of this handler
  +    public void setDTDSource(XMLDTDSource source ) {
  +        fDTDSource = source;
  +    } // setDTDSource(XMLDTDSource)
  +
  +    // returns the XMLDTDSource of this handler
  +    public XMLDTDSource getDTDSource() {
  +        return fDTDSource;
  +    } // getDTDSource():  XMLDTDSource
  +
       //
       // XMLDTDContentModelHandler methods
       //
   
  +    // sets the XMLContentModelDTDSource of this handler
  +    public void setDTDContentModelSource(XMLDTDContentModelSource source ) {
  +        fDTDContentModelSource = source;
  +    } // setDTDContentModelSource(XMLDTDContentModelSource)
  +
  +    // returns the XMLDTDSource of this handler
  +    public XMLDTDContentModelSource getDTDContentModelSource() {
  +        return fDTDContentModelSource;
  +    } // getDTDContentModelSource():  XMLDTDContentModelSource
  +
  +
       /**
        * The start of a content model. Depending on the type of the content
        * model, specific methods may be called between the call to the
  @@ -1581,5 +1628,12 @@
           }
   
       } // init()
  -
  +    
  +    protected boolean isValidNmtoken(String nmtoken) {
  +        return XMLChar.isValidNmtoken(nmtoken);
  +    } // isValidNmtoken(String):  boolean
  +    
  +    protected boolean isValidName(String name) {
  +        return XMLChar.isValidName(name);
  +    } // isValidName(String):  boolean
   } // class XMLDTDProcessor
  
  
  
  1.41      +19 -13    
xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
  
  Index: XMLDTDValidator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- XMLDTDValidator.java      10 Nov 2002 03:51:42 -0000      1.40
  +++ XMLDTDValidator.java      7 Dec 2002 00:18:53 -0000       1.41
  @@ -386,28 +386,28 @@
       // attribute validators
   
       /** Datatype validator: ID. */
  -    private DatatypeValidator fValID;
  +    protected DatatypeValidator fValID;
   
       /** Datatype validator: IDREF. */
  -    private DatatypeValidator fValIDRef;
  +    protected DatatypeValidator fValIDRef;
   
       /** Datatype validator: IDREFS. */
  -    private DatatypeValidator fValIDRefs;
  +    protected DatatypeValidator fValIDRefs;
   
       /** Datatype validator: ENTITY. */
  -    private DatatypeValidator fValENTITY;
  +    protected DatatypeValidator fValENTITY;
   
       /** Datatype validator: ENTITIES. */
  -    private DatatypeValidator fValENTITIES;
  +    protected DatatypeValidator fValENTITIES;
   
       /** Datatype validator: NMTOKEN. */
  -    private DatatypeValidator fValNMTOKEN;
  +    protected DatatypeValidator fValNMTOKEN;
   
       /** Datatype validator: NMTOKENS. */
  -    private DatatypeValidator fValNMTOKENS;
  +    protected DatatypeValidator fValNMTOKENS;
   
       /** Datatype validator: NOTATION. */
  -    private DatatypeValidator fValNOTATION;
  +    protected DatatypeValidator fValNOTATION;
   
       // to check for duplicate ID or ANNOTATION attribute declare in
       // ATTLIST, and misc VCs
  @@ -626,7 +626,7 @@
       /** Returns the document handler */
       public XMLDocumentHandler getDocumentHandler() {
           return fDocumentHandler;
  -    } // setDocumentHandler(XMLDocumentHandler)
  +    } // getDocumentHandler():  XMLDocumentHandler
   
   
       //
  @@ -850,7 +850,7 @@
           //          look at the characters again. -Ac
           boolean allWhiteSpace = true;
           for (int i=text.offset; i< text.offset+text.length; i++) {
  -            if (!XMLChar.isSpace(text.ch[i])) {
  +            if (!isSpace(text.ch[i])) {
                   allWhiteSpace = false;
                   break;
               }
  @@ -1798,8 +1798,8 @@
   
       } // getAttributeTypeName(XMLAttributeDecl):String
   
  -    /** intialization */
  -    private void init() {
  +    /** initialization */
  +    protected void init() {
   
           // datatype validators
           if (fValidation) {
  @@ -2076,5 +2076,11 @@
               fDocumentHandler.endElement(fCurrentElement, augs);
           }
       }
  +
  +    // returns whether a character is space according to the
  +    // version of XML this validator supports.
  +    protected boolean isSpace(int c) {
  +        return XMLChar.isSpace(c);
  +    } // isSpace(int):  boolean
   
   } // class XMLDTDValidator
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/impl/dtd/XML11DTDProcessor.java
  
  Index: XML11DTDProcessor.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.impl.dtd;
  
  import org.apache.xerces.impl.XMLErrorReporter;
  
  import org.apache.xerces.util.SymbolTable;
  import org.apache.xerces.util.XML11Char;
  
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  import org.apache.xerces.xni.parser.XMLComponent;
  import org.apache.xerces.xni.parser.XMLEntityResolver;
  import org.apache.xerces.xni.parser.XMLComponentManager;
  import org.apache.xerces.xni.parser.XMLDTDFilter;
  
  
  /**
   * This class extends XMLDTDProcessor by giving it
   * the ability to parse XML 1.1 documents correctly.  It can also be used
   * as a DTD loader, so that XML 1.1 external subsets can
   * be processed correctly (hence it's rather anomalous-appearing
   * derivation from XMLDTDLoader).
   *
   * @author Neil Graham, IBM
   *
   * @version $Id: XML11DTDProcessor.java,v 1.1 2002/12/07 00:18:53 neilg Exp $
   */
  public class XML11DTDProcessor extends XMLDTDLoader{
  
      // constructors
  
      public XML11DTDProcessor() {
          super();
      } // <init>()
  
      public XML11DTDProcessor(SymbolTable symbolTable) {
          super(symbolTable);
      } // init(SymbolTable)
  
      public XML11DTDProcessor(SymbolTable symbolTable,
                  XMLGrammarPool grammarPool) {
          super(symbolTable, grammarPool);
      } // init(SymbolTable, XMLGrammarPool)
  
      XML11DTDProcessor(SymbolTable symbolTable,
                  XMLGrammarPool grammarPool, XMLErrorReporter errorReporter, 
                  XMLEntityResolver entityResolver) {
          super(symbolTable, grammarPool, errorReporter, entityResolver);
      } // init(SymbolTable, XMLGrammarPool, XMLErrorReporter, XMLEntityResolver)
  
      // overridden methods
  
      protected boolean isValidNmtoken(String nmtoken) {
          return XML11Char.isXML11ValidNmtoken(nmtoken);
      } // isValidNmtoken(String):  boolean
      
      protected boolean isValidName(String name) {
          return XML11Char.isXML11ValidName(name);
      } // isValidNmtoken(String):  boolean
      
  } // class XML11DTDProcessor
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/impl/dtd/XML11DTDValidator.java
  
  Index: XML11DTDValidator.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.impl.dtd;
  
  import org.apache.xerces.impl.Constants;
  import org.apache.xerces.impl.dv.DatatypeValidator;
  import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
  
  import org.apache.xerces.util.SymbolTable;
  import org.apache.xerces.util.XML11Char;
  
  import org.apache.xerces.xni.parser.XMLComponentManager;
  
  /**
   * This allows the validator to correctlyhandle XML 1.1
   * documents.
   *
   * @author Neil Graham
   * @version $Id: XML11DTDValidator.java,v 1.1 2002/12/07 00:18:53 neilg Exp $
   */
  public class XML11DTDValidator extends XMLDTDValidator {
  
      //
      // Constants
      //
  
      protected final static String DTD_VALIDATOR_PROPERTY =
          Constants.XERCES_PROPERTY_PREFIX+Constants.DTD_VALIDATOR_PROPERTY;
  
      //
      // Constructors
      //
  
      /** Default constructor. */
      public XML11DTDValidator() {
  
          super();
      } // <init>()
  
      // overridden so that this class has access to the same
      // grammarBucket as the corresponding DTDProcessor
      // will try and use...
      public void reset(XMLComponentManager manager) {
          XMLDTDValidator curr = null;
          if((curr = (XMLDTDValidator)manager.getProperty(DTD_VALIDATOR_PROPERTY)) != 
null &&
                  curr != this) {
              fGrammarBucket = curr.getGrammarBucket();
          }
          super.reset(manager);
      } //reset(XMLComponentManager)
  
      // returns whether a character is space according to the
      // version of XML this validator supports.
      protected boolean isSpace(int c) {
          return XML11Char.isXML11Space(c);
      } // isSpace(int):  boolean
  
      protected void init() {
          if(fValidation) {
              super.init();
              // now overwrite some entries in parent:
  
              try {
                  fValID       = fDatatypeValidatorFactory.getBuiltInDV("XML11ID");
                  fValIDRef    = fDatatypeValidatorFactory.getBuiltInDV("XML11IDREFS");
                  fValIDRefs   = fDatatypeValidatorFactory.getBuiltInDV("XML11IDREFS");
                  fValNMTOKEN  = 
fDatatypeValidatorFactory.getBuiltInDV("XML11NMTOKENSymbol");
                  fValNMTOKENS = 
fDatatypeValidatorFactory.getBuiltInDV("XML11NMTOKENS");
  
              }
              catch (Exception e) {
                  // should never happen
                  e.printStackTrace(System.err);
              }
          }
      } // init()
  
  } // class XML11DTDValidator
  
  
  

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

Reply via email to