You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by le...@locus.apache.org on 2000/11/15 02:08:10 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl XMLDTDScanner.java XMLDocumentScanner.java XMLEntityManager.java XMLScanner.java

lehors      00/11/14 17:08:09

  Modified:    java/src/org/apache/xerces/impl Tag: xerces_j_2
                        XMLDTDScanner.java XMLDocumentScanner.java
                        XMLEntityManager.java XMLScanner.java
  Log:
  moved the code to check whether an entity is declared or not from
  the entity manager to the various scanners so that we have all the context
  needed to make the right check. Added a isDeclaredEntity() method to the
  entity manager.
  Note: this is by far the most obscure part of the XML spec, this may still
  not be completely exact but at least we pass all the tests succesfully.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.71  +6 -2      xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDTDScanner.java
  
  Index: XMLDTDScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDTDScanner.java,v
  retrieving revision 1.1.2.70
  retrieving revision 1.1.2.71
  diff -u -r1.1.2.70 -r1.1.2.71
  --- XMLDTDScanner.java	2000/11/09 00:47:49	1.1.2.70
  +++ XMLDTDScanner.java	2000/11/15 01:08:08	1.1.2.71
  @@ -89,7 +89,7 @@
    * @author Andy Clark, IBM
    * @author Glenn Marcy, IBM
    *
  - * @version $Id: XMLDTDScanner.java,v 1.1.2.70 2000/11/09 00:47:49 ericye Exp $
  + * @version $Id: XMLDTDScanner.java,v 1.1.2.71 2000/11/15 01:08:08 lehors Exp $
    */
   public class XMLDTDScanner
       extends XMLScanner
  @@ -528,6 +528,9 @@
       protected void startPE(String name, boolean literal) 
           throws IOException, SAXException {
           int depth = fPEDepth;
  +        if (fValidation && !fEntityManager.isDeclaredEntity(name)) {
  +            reportFatalError("EntityNotDeclared", new Object[]{name});
  +        }
           fEntityManager.startEntity(fSymbolTable.addSymbol("%" + name),
                                      literal);
           // if we actually got a new entity and it's external
  @@ -1199,7 +1202,8 @@
               }
               // AttValue 
               scanAttributeValue(defaultVal, atName,
  -                               fAttributes, 0, type.equals("CDATA"));
  +                               fAttributes, 0, type.equals("CDATA"),
  +                               scanningInternalSubset());
           }
           return defaultType;
   
  
  
  
  1.1.2.74  +6 -3      xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java
  
  Index: XMLDocumentScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLDocumentScanner.java,v
  retrieving revision 1.1.2.73
  retrieving revision 1.1.2.74
  diff -u -r1.1.2.73 -r1.1.2.74
  --- XMLDocumentScanner.java	2000/11/14 22:45:37	1.1.2.73
  +++ XMLDocumentScanner.java	2000/11/15 01:08:08	1.1.2.74
  @@ -106,7 +106,7 @@
    * @author Andy Clark, IBM
    * @author Arnaud  Le Hors, IBM
    *
  - * @version $Id: XMLDocumentScanner.java,v 1.1.2.73 2000/11/14 22:45:37 lehors Exp $
  + * @version $Id: XMLDocumentScanner.java,v 1.1.2.74 2000/11/15 01:08:08 lehors Exp $
    */
   public class XMLDocumentScanner
       extends XMLScanner
  @@ -815,8 +815,8 @@
                   cdata = false;
               }
           }
  -        scanAttributeValue(fString, fAttributeQName.rawname,
  -                           attributes, attributes.getLength() - 1, cdata);
  +        scanAttributeValue(fString, fAttributeQName.rawname, attributes,
  +                           attributes.getLength() - 1, cdata, true);
           attributes.setValue(attributes.getLength() - 1, fString.toString());
   
           if (DEBUG_CONTENT_SCANNING) System.out.println("<<< scanAttribute()");
  @@ -1053,6 +1053,9 @@
               reportFatalError("ReferenceToUnparsedEntity", new Object[]{name});
           }
           else {
  +            if (!fEntityManager.isDeclaredEntity(name)) {
  +                reportFatalError("EntityNotDeclared", new Object[]{name});
  +            }
               fEntityManager.startEntity(name, false);
           }
   
  
  
  
  1.1.2.65  +19 -23    xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLEntityManager.java,v
  retrieving revision 1.1.2.64
  retrieving revision 1.1.2.65
  diff -u -r1.1.2.64 -r1.1.2.65
  --- XMLEntityManager.java	2000/11/14 01:27:31	1.1.2.64
  +++ XMLEntityManager.java	2000/11/15 01:08:08	1.1.2.65
  @@ -116,7 +116,7 @@
    * @author Andy Clark, IBM
    * @author Arnaud  Le Hors, IBM
    *
  - * @version $Id: XMLEntityManager.java,v 1.1.2.64 2000/11/14 01:27:31 andyc Exp $
  + * @version $Id: XMLEntityManager.java,v 1.1.2.65 2000/11/15 01:08:08 lehors Exp $
    */
   public class XMLEntityManager
       implements XMLComponent {
  @@ -321,18 +321,13 @@
        * Checks whether an entity given by name is external.
        *
        * @param entityName The name of the entity to check.
  -     * @returns True if the entity is external.
  +     * @returns True if the entity is external, false otherwise
  +     *           (including when the entity is not declared).
        */
  -    public boolean isExternalEntity(String entityName) throws SAXException {
  +    public boolean isExternalEntity(String entityName) {
   
           Entity entity = (Entity)fEntities.get(entityName);
           if (entity == null) {
  -            if (fValidation || !entityName.startsWith("%")) {
  -                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  -                                           "EntityNotDeclared",
  -                                           new Object[] { entityName },
  -                                           XMLErrorReporter.SEVERITY_FATAL_ERROR);
  -            }
               return false;
           }
           return entity.isExternal();
  @@ -367,24 +362,31 @@
        * Checks whether an entity given by name is unparsed.
        *
        * @param entityName The name of the entity to check.
  -     * @returns True if the entity is unparsed.
  +     * @returns True if the entity is unparsed, false otherwise
  +     *          (including when the entity is not declared).
        */
  -    public boolean isUnparsedEntity(String entityName) throws SAXException {
  +    public boolean isUnparsedEntity(String entityName) {
   
           Entity entity = (Entity)fEntities.get(entityName);
           if (entity == null) {
  -            if (fValidation || !entityName.startsWith("%")) {
  -                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  -                                           "EntityNotDeclared",
  -                                           new Object[] { entityName },
  -                                           XMLErrorReporter.SEVERITY_FATAL_ERROR);
  -            }
               return false;
           }
           return entity.isUnparsed();
       }
   
       /**
  +     * Checks whether an entity given by name is declared.
  +     *
  +     * @param entityName The name of the entity to check.
  +     * @returns True if the entity is declared, false otherwise.
  +     */
  +    public boolean isDeclaredEntity(String entityName) {
  +
  +        Entity entity = (Entity)fEntities.get(entityName);
  +        return entity != null;
  +    }
  +
  +    /**
        * Resolves the specified public and system identifiers. This
        * method first attempts to resolve the entity based on the
        * EntityResolver registered by the application. If no entity
  @@ -458,12 +460,6 @@
           // was entity declared?
           Entity entity = (Entity)fEntities.get(entityName);
           if (entity == null) {
  -            if (fValidation || !entityName.startsWith("%")) {
  -                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  -                                           "EntityNotDeclared",
  -                                           new Object[] { entityName },
  -                                           XMLErrorReporter.SEVERITY_FATAL_ERROR);
  -            }
               if (fEntityHandler != null) {
                   final String publicId = null;
                   final String systemId = null;
  
  
  
  1.1.2.38  +9 -2      xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLScanner.java
  
  Index: XMLScanner.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLScanner.java,v
  retrieving revision 1.1.2.37
  retrieving revision 1.1.2.38
  diff -u -r1.1.2.37 -r1.1.2.38
  --- XMLScanner.java	2000/11/14 22:45:37	1.1.2.37
  +++ XMLScanner.java	2000/11/15 01:08:08	1.1.2.38
  @@ -93,7 +93,7 @@
    * @author Andy Clark, IBM
    * @author Arnaud  Le Hors, IBM
    *
  - * @version $Id: XMLScanner.java,v 1.1.2.37 2000/11/14 22:45:37 lehors Exp $
  + * @version $Id: XMLScanner.java,v 1.1.2.38 2000/11/15 01:08:08 lehors Exp $
    */
   public abstract class XMLScanner 
       implements XMLComponent {
  @@ -608,13 +608,15 @@
        * @param attrIndex The index of the attribute to use from the list.
        * @param cdata Specifies whether the attribute is of type CDATA or not, so
        *              that the appropriate normalization can be performed.
  +     * @param checkEntities Specifies whether undeclared entities should be
  +     *                      checked.
        *
        * <strong>Note:</strong> This method uses fStringBuffer2, anything in it
        * at the time of calling is lost.
        **/
       protected void scanAttributeValue(XMLString value, String atName,
                                         XMLAttributes attributes, int attrIndex,
  -                                      boolean cdata)
  +                                      boolean cdata, boolean checkEntities)
           throws IOException, SAXException
       {
           // quote
  @@ -741,6 +743,11 @@
                                                    new Object[] { entityName });
                               }
                               else {
  +                                if (checkEntities &&
  +                                    !fEntityManager.isDeclaredEntity(entityName)) {
  +                                    reportFatalError("EntityNotDeclared",
  +                                                     new Object[]{entityName});
  +                                }
                                   fEntityManager.startEntity(entityName, false);
                               }
                           }