You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/10/03 04:09:40 UTC

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

andyc       00/10/02 19:09:40

  Modified:    java/src/org/apache/xerces/impl Tag: xerces_j_2
                        XMLEntityManager.java
  Log:
  Made some modifications to the entity manager API. There's
  really no need to separate general and parameter entities.
  I've changed it so that we use the SAX2 naming convention
  for entities: general entities just use their name;
  parameter entity names start with a leading '%'; the DTD
  entity has the name "[dtd]"; and I'm adding the document
  entity with the name "[xml]", even though this even would
  never get passed to the SAX2 ext handler.
  
  In making this change, I added some inner classes to store
  both internal and external entity declarations. This part
  may change as I start working on the internals of the
  entity manager and entity scanner implementation.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +97 -82    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.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- XMLEntityManager.java	2000/10/02 23:19:11	1.1.2.3
  +++ XMLEntityManager.java	2000/10/03 02:09:40	1.1.2.4
  @@ -101,7 +101,7 @@
    * @author Stubs generated by DesignDoc on Mon Sep 18 18:23:16 PDT 2000
    * @author Andy Clark, IBM
    *
  - * @version $Id: XMLEntityManager.java,v 1.1.2.3 2000/10/02 23:19:11 andyc Exp $
  + * @version $Id: XMLEntityManager.java,v 1.1.2.4 2000/10/03 02:09:40 andyc Exp $
    */
   public class XMLEntityManager
       implements XMLComponent {
  @@ -153,17 +153,14 @@
       /** Entity scanner. */
       protected XMLEntityScanner fEntityScanner;
   
  -    /** General entities. */
  -    protected Hashtable fGeneralEntities = new Hashtable();
  +    /** Entities. */
  +    protected Hashtable fEntities = new Hashtable();
   
  -    /** Parameter entities. */
  -    protected Hashtable fParameterEntities = new Hashtable();
  -
       /** Entity stack. */
       protected Stack fEntityStack = new Stack();
   
       /** Current entity. */
  -    protected Entity fEntity;
  +    protected ScannedEntity fCurrentEntity;
   
       // private
   
  @@ -198,53 +195,31 @@
           fEntityHandler = entityHandler;
       }
   
  -    /**
  -     * addGeneralEntity
  -     * 
  -     * @param name 
  -     * @param publicId 
  -     * @param systemId 
  -     * @param baseSystemId 
  -     */
  -    public void addGeneralEntity(String name, String publicId, String systemId, String baseSystemId) {
  -        Entity entity = new ExternalEntity(name, publicId, systemId, baseSystemId);
  -        fGeneralEntities.put(name, entity);
  -    } // addGeneralEntity(String,String,String,String)
  -
  -    /**
  -     * addGeneralEntity
  -     * 
  -     * @param name 
  -     * @param text 
  -     */
  -    public void addGeneralEntity(String name, String text) {
  -        Entity entity = new InternalEntity(name, text);
  -        fGeneralEntities.put(name, entity);
  -    } // addGeneralEntity(String,String)
  -
       /**
  -     * addParameterEntity
  +     * addExternalEntity
        * 
        * @param name 
        * @param publicId 
        * @param systemId 
        * @param baseSystemId 
        */
  -    public void addParameterEntity(String name, String publicId, String systemId, String baseSystemId) {
  +    public void addExternalEntity(String name, String publicId, String systemId, String baseSystemId) {
  +        name = fSymbolTable.addSymbol(name);
           Entity entity = new ExternalEntity(name, publicId, systemId, baseSystemId);
  -        fParameterEntities.put(name, entity);
  -    } // addParameterEntity(String,String,String,String)
  +        fEntities.put(name, entity);
  +    } // addExternalEntity(String,String,String,String)
   
       /**
  -     * addParameterEntity
  +     * addInternalEntity
        * 
        * @param name 
        * @param text 
        */
  -    public void addParameterEntity(String name, String text) {
  +    public void addInternalEntity(String name, String text) {
  +        name = fSymbolTable.addSymbol(name);
           Entity entity = new InternalEntity(name, text);
  -        fParameterEntities.put(name, entity);
  -    } // addParameterEntity(String,String)
  +        fEntities.put(name, entity);
  +    } // addInternalEntity(String,String)
   
       /**
        * resolveEntity
  @@ -261,16 +236,16 @@
       } // resolveEntity
   
       /**
  -     * startGeneralEntity
  +     * startEntity
        * 
        * @param entityName 
        * @param parameter 
        */
  -    public void startGeneralEntity(String entityName) 
  +    public void startEntity(String entityName) 
           throws IOException, SAXException {
   
           // resolve external entity
  -        Entity entity = (Entity)fGeneralEntities.get(entityName);
  +        Entity entity = (Entity)fEntities.get(entityName);
           InputSource inputSource = null;
           if (entity.isExternal()) {
               ExternalEntity externalEntity = (ExternalEntity)entity;
  @@ -289,40 +264,8 @@
   
           // start the entity
           startEntity(entityName, inputSource);
  -
  -    } // startGeneralEntity(String)
  -
  -    /**
  -     * startParameterEntity
  -     * 
  -     * @param entityName 
  -     * @param parameter 
  -     */
  -    public void startParameterEntity(String entityName) 
  -        throws IOException, SAXException {
  -
  -        // resolve external entity
  -        Entity entity = (Entity)fParameterEntities.get(entityName);
  -        InputSource inputSource = null;
  -        if (entity.isExternal()) {
  -            ExternalEntity externalEntity = (ExternalEntity)entity;
  -            String publicId = externalEntity.publicId;
  -            String systemId = externalEntity.systemId;
  -            String baseSystemId = externalEntity.baseSystemId;
  -            inputSource = resolveEntity(publicId, systemId, baseSystemId);
  -        }
  -
  -        // wrap internal entity
  -        else {
  -            InternalEntity internalEntity = (InternalEntity)entity;
  -            Reader reader = new StringReader(internalEntity.text);
  -            inputSource = new InputSource(reader);
  -        }
  -
  -        // start the entity
  -        startEntity("%"+entityName, inputSource);
   
  -    } // startParameterEntity(String)
  +    } // startEntity(String)
   
       /**
        * startDocumentEntity
  @@ -372,10 +315,16 @@
           fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
   
           // initialize state
  -        fGeneralEntities.clear();
  -        fParameterEntities.clear();
  +        fEntities.clear();
           fEntityStack.removeAllElements();
   
  +        // add default entities
  +        addInternalEntity("lt", "<");
  +        addInternalEntity("gt", ">");
  +        addInternalEntity("amp", "&");
  +        addInternalEntity("apos", "'");
  +        addInternalEntity("quot", "\"");
  +
           // initialize scanner info
           fReader = null;
   
  @@ -443,7 +392,7 @@
           fReader = new PushbackReader(reader, 32);
   
           // push entity on stack
  -        Entity entity = new ExternalEntity(name, publicId, systemId, encoding);
  +        ScannedEntity entity = new ScannedEntity(name, publicId, systemId, reader);
           fEntityStack.push(entity);
   
           // call handler
  @@ -586,6 +535,72 @@
       } // class ExternalEntity
   
       /**
  +     * Entity state.
  +     *
  +     * @author Andy Clark, IBM
  +     */
  +    protected static class ScannedEntity 
  +        extends Entity {
  +
  +        //
  +        // Data
  +        //
  +
  +        // i/o
  +
  +        /** Reader. */
  +        public Reader reader;
  +
  +        // locator information
  +
  +        /** Public identifier. */
  +        public String publicId;
  +
  +        /** System identifier. */
  +        public String systemId;
  +
  +        /** Line number. */
  +        public int lineNumber;
  +
  +        /** Column number. */
  +        public int columnNumber;
  +
  +        // buffer
  +
  +        /** Character buffer. */
  +        public char[] ch;
  +
  +        /** Offset. */
  +        public int offset;
  +
  +        /** Length. */
  +        public int length;
  +
  +        //
  +        // Constructors
  +        //
  +
  +        /** Constructs a scanned entity. */
  +        public ScannedEntity(String name, String publicId, String systemId,
  +                             Reader reader) {
  +            super(name);
  +            this.publicId = publicId;
  +            this.systemId = systemId;
  +            this.reader = reader;
  +        } // <init>(Reader,String,String,String)
  +
  +        //
  +        // Entity methods
  +        //
  +
  +        /** Returns true if this is an external entity. */
  +        public final boolean isExternal() {
  +            return systemId != null;
  +        } // isExternal():boolean
  +
  +    } // class ScannedEntity
  +
  +    /**
        * Implements the entity scanner methods.
        *
        * @author Andy Clark, IBM
  @@ -840,7 +855,7 @@
            * @return 
            */
           public String getPublicId() {
  -            throw new RuntimeException("getPublicId not implemented");
  +            return fCurrentEntity.publicId;
           } // getPublicId():String
       
           /**
  @@ -849,7 +864,7 @@
            * @return 
            */
           public String getSystemId() {
  -            throw new RuntimeException("getSystemId not implemented");
  +            return fCurrentEntity.systemId;
           } // getSystemId():String
       
           /**
  @@ -858,7 +873,7 @@
            * @return 
            */
           public int getLineNumber() {
  -            throw new RuntimeException("getLineNumber not implemented");
  +            return fCurrentEntity.lineNumber;
           } // getLineNumber():int
       
           /**
  @@ -867,7 +882,7 @@
            * @return 
            */
           public int getColumnNumber() {
  -            throw new RuntimeException("getColumnNumber not implemented");
  +            return fCurrentEntity.columnNumber;
           } // getColumnNumber():int
       
           //