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/12 23:53:53 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers DOMParser.java XMLDocumentParser.java XMLParser.java

andyc       00/10/12 14:53:52

  Modified:    java/src/org/apache/xerces/dom Tag: xerces_j_2
                        DOMExceptionImpl.java
               java/src/org/apache/xerces/parsers Tag: xerces_j_2
                        DOMParser.java XMLDocumentParser.java
                        XMLParser.java
  Log:
  Implemented basic DOM parser using the DocumentImpl class.
  Most of the creation is done by using the Document factory
  methods, except for the Document and DocumentType nodes.
  This implementation does *not* support the deferred DOM
  (which would need massive work, anyway) nor does it support
  creating a generic DOM tree by class name.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.4.1 +9 -2      xml-xerces/java/src/org/apache/xerces/dom/Attic/DOMExceptionImpl.java
  
  Index: DOMExceptionImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/Attic/DOMExceptionImpl.java,v
  retrieving revision 1.1.1.1
  retrieving revision 1.1.1.1.4.1
  diff -u -r1.1.1.1 -r1.1.1.1.4.1
  --- DOMExceptionImpl.java	1999/11/09 01:13:23	1.1.1.1
  +++ DOMExceptionImpl.java	2000/10/12 21:53:47	1.1.1.1.4.1
  @@ -57,8 +57,7 @@
   
   package org.apache.xerces.dom;
   
  -import org.apache.xerces.domx.DOMException;
  -//import org.w3c.dom.DOMException;
  +import org.w3c.dom.DOMException;
   
   /**
    * DOMExceptions are thrown when one of the
  @@ -110,6 +109,14 @@
   public class DOMExceptionImpl 
       extends DOMException {
   
  +    //
  +    // Constants
  +    //
  +
  +    // DOM has named these but hasn't values yet. Stopgap:
  +    public static final short           UNSPECIFIED_EVENT_TYPE= 100;
  +    public static final short           UNSUPPORTED_EVENT_TYPE= 101;
  +    
       //
       // Constructors
       //
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.19.2.6  +390 -13   xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java
  
  Index: DOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMParser.java,v
  retrieving revision 1.19.2.5
  retrieving revision 1.19.2.6
  diff -u -r1.19.2.5 -r1.19.2.6
  --- DOMParser.java	2000/10/02 00:40:12	1.19.2.5
  +++ DOMParser.java	2000/10/12 21:53:48	1.19.2.6
  @@ -57,26 +57,76 @@
   
   package org.apache.xerces.parsers;
   
  -import org.apache.xerces.util.SymbolTable;
  +import org.apache.xerces.dom.DocumentImpl;
  +import org.apache.xerces.dom.TextImpl;
  +
   import org.apache.xerces.impl.validation.GrammarPool;
  +
  +import org.apache.xerces.util.SymbolTable;
  +
  +import org.apache.xerces.xni.QName;
  +import org.apache.xerces.xni.XMLAttributes;
  +import org.apache.xerces.xni.XMLString;
  +
  +import org.w3c.dom.Attr;
  +import org.w3c.dom.CDATASection;
  +import org.w3c.dom.Comment;
   import org.w3c.dom.Document;
  +import org.w3c.dom.DocumentType;
  +import org.w3c.dom.DOMImplementation;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.EntityReference;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.ProcessingInstruction;
  +import org.w3c.dom.Text;
   
  +import org.xml.sax.SAXException;
  +
   /**
    * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
  - * @version $Id: DOMParser.java,v 1.19.2.5 2000/10/02 00:40:12 lehors Exp $
  + * @author Andy Clark, IBM
  + *
  + * @version $Id: DOMParser.java,v 1.19.2.6 2000/10/12 21:53:48 andyc Exp $
    */
   public class DOMParser
       extends XMLDocumentParser {
   
       //
  +    // Data
  +    //
  +
  +    // dom information
  +
  +    /** The document. */
  +    protected Document fDocument;
  +
  +    /** Current node. */
  +    protected Node fCurrentNode;
  +
  +    // state
  +
  +    /** True if inside document. */
  +    protected boolean fInDocument;
  +
  +    /** True if inside DTD. */
  +    protected boolean fInDTD;
  +
  +    /** True if inside CDATA section. */
  +    protected boolean fInCDATASection;
  +
  +    // data
  +    
  +    /** Attribute QName. */
  +    private QName fAttrQName = new QName();
  +
  +    //
       // Constructors
       //
   
  -    /**
  -     * 
  -     */
  +    /** Default constructor. */
       public DOMParser() {
  -    }
  +        this(new SymbolTable(), new GrammarPool());
  +    } // <init>()
   
       /**
        * 
  @@ -85,19 +135,346 @@
        * @param grammarPool 
        */
       protected DOMParser(SymbolTable symbolTable, GrammarPool grammarPool) {
  -    }
  +        super(symbolTable, grammarPool);
  +    } // <init>(SymbolTable,GrammarPool)
  +
  +    //
  +    // Public methods
  +    //
  +
  +    /** Returns the DOM document object. */
  +    public Document getDocument() {
  +        return fDocument;
  +    } // getDocument():Document
  +
  +    //
  +    // XMLDocumentParser methods
  +    //
   
  +    /**
  +     * Resets the parser state.
  +     *
  +     * @throws SAXException Thrown on initialization error.
  +     */
  +    public void reset() throws SAXException {
  +        super.reset();
  +
  +        // reset dom information
  +        fDocument = null;
  +        fCurrentNode = null;
  +
  +        // reset state information
  +        fInDocument = false;
  +        fInDTD = false;
  +        fInCDATASection = false;
  +
  +    } // reset()
  +
       //
  -    // Methods
  +    // XMLDocumentHandler methods
       //
   
       /**
  -     * getDocument
  +     * This method notifies of the start of an entity. The document entity
  +     * has the pseudo-name of "[xml]"; The DTD has the pseudo-name of "[dtd]; 
  +     * parameter entity names start with '%'; and general entity names are
  +     * just the entity name.
  +     * <p>
  +     * <strong>Note:</strong> Since the document is an entity, the handler
  +     * will be notified of the start of the document entity by calling the
  +     * startEntity method with the entity name "[xml]" <em>before</em> calling
  +     * the startDocument method. When exposing entity boundaries through the
  +     * SAX API, the document entity is never reported, however.
  +     * <p>
  +     * <strong>Note:</strong> Since the DTD is an entity, the handler
  +     * will be notified of the start of the DTD entity by calling the
  +     * startEntity method with the entity name "[dtd]" <em>before</em> calling
  +     * the startDTD method.
  +     * <p>
  +     * <strong>Note:</strong> This method is not called for entity references
  +     * appearing as part of attribute values.
        * 
  -     * @return 
  +     * @param name     The name of the entity.
  +     * @param publicId The public identifier of the entity if the entity
  +     *                 is external, null otherwise.
  +     * @param systemId The system identifier of the entity if the entity
  +     *                 is external, null otherwise.
  +     * @param encoding The auto-detected IANA encoding name of the entity
  +     *                 stream. This value will be null in those situations
  +     *                 where the entity encoding is not auto-detected (e.g.
  +     *                 internal parameter entities).
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
        */
  -    public Document getDocument() {
  -        return null;
  -    } // getDocument
  +    public void startEntity(String name, String publicId, String systemId,
  +                            String encoding) throws SAXException {
  +
  +        if (fInDocument && !fInDTD) {
  +            EntityReference entityRef = fDocument.createEntityReference(name);
  +            fCurrentNode.appendChild(entityRef);
  +            fCurrentNode = entityRef;
  +        }
  +
  +    } // startEntity(String,String,String,String)
  +
  +    /**
  +     * A comment.
  +     * 
  +     * @param text The text in the comment.
  +     *
  +     * @throws SAXException Thrown by application to signal an error.
  +     */
  +    public void comment(XMLString text) throws SAXException {
  +
  +        Comment comment = fDocument.createComment(text.toString());
  +        fCurrentNode.appendChild(comment);
  +
  +    } // comment(XMLString)
  +
  +    /**
  +     * A processing instruction. Processing instructions consist of a
  +     * target name and, optionally, text data. The data is only meaningful
  +     * to the application.
  +     * <p>
  +     * Typically, a processing instruction's data will contain a series
  +     * of pseudo-attributes. These pseudo-attributes follow the form of
  +     * element attributes but are <strong>not</strong> parsed or presented
  +     * to the application as anything other than text. The application is
  +     * responsible for parsing the data.
  +     * 
  +     * @param target The target.
  +     * @param data   The data or null if none specified.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void processingInstruction(String target, XMLString data)
  +        throws SAXException {
  +
  +        ProcessingInstruction pi = fDocument.createProcessingInstruction(target, data.toString());
  +        fCurrentNode.appendChild(pi);
  +
  +    } // processingInstruction(String,XMLString)
  +
  +    /**
  +     * The start of the document.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void startDocument() throws SAXException {
  +
  +        fInDocument = true;
  +        fDocument = new DocumentImpl();
  +        fCurrentNode = fDocument;
  +
  +    } // startDocument()
  +
  +    /**
  +     * Notifies of the presence of the DOCTYPE line in the document.
  +     * 
  +     * @param rootElement The name of the root element.
  +     * @param publicId    The public identifier if an external DTD or null
  +     *                    if the external DTD is specified using SYSTEM.
  +     * @param systemId    The system identifier if an external DTD, null
  +     *                    otherwise.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void doctypeDecl(String rootElement, String publicId, String systemId)
  +        throws SAXException {
  +        
  +        DocumentImpl docimpl = (DocumentImpl)fDocument;
  +        DocumentType doctype = docimpl.createDocumentType(rootElement, publicId, systemId);
  +        fCurrentNode.appendChild(doctype);
  +
  +    } // doctypeDecl(String,String,String)
  +
  +    /**
  +     * The start of an element. If the document specifies the start element
  +     * by using an empty tag, then the startElement method will immediately
  +     * be followed by the endElement method, with no intervening methods.
  +     * 
  +     * @param element    The name of the element.
  +     * @param attributes The element attributes.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void startElement(QName element, XMLAttributes attributes)
  +        throws SAXException {
  +
  +        Element elementNode = element.prefix != null
  +                            ? fDocument.createElementNS(element.uri, element.rawname)
  +                            : fDocument.createElement(element.rawname);
  +        int attrCount = attributes.getLength();
  +        for (int i = 0; i < attrCount; i++) {
  +            attributes.getName(i, fAttrQName);
  +            Attr attr = fAttrQName.prefix != null
  +                      ? fDocument.createAttributeNS(fAttrQName.uri, fAttrQName.rawname)
  +                      : fDocument.createAttribute(fAttrQName.rawname);
  +            attr.setNodeValue(attributes.getValue(i));
  +            // REVISIT: Handle entities in attribute value.
  +            elementNode.setAttributeNode(attr);
  +        }
  +        fCurrentNode.appendChild(elementNode);
  +        fCurrentNode = elementNode;
  +
  +    } // startElement(QName,XMLAttributes)
  +
  +    /**
  +     * Character content.
  +     * 
  +     * @param text The content.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void characters(XMLString text) throws SAXException {
  +
  +        if (fInCDATASection) {
  +            CDATASection cdataSection = (CDATASection)fCurrentNode;
  +            cdataSection.appendData(text.toString());
  +        }
  +        else {
  +            Node child = fCurrentNode.getLastChild();
  +            if (child != null && child.getNodeType() == Node.TEXT_NODE) {
  +                Text textNode = (Text)child;
  +                textNode.appendData(text.toString());
  +            }
  +            else {
  +                Text textNode = fDocument.createTextNode(text.toString());
  +                fCurrentNode.appendChild(textNode);
  +            }
  +        }
  +
  +    } // characters(XMLString)
  +
  +    /**
  +     * Ignorable whitespace. For this method to be called, the document
  +     * source must have some way of determining that the text containing
  +     * only whitespace characters should be considered ignorable. For
  +     * example, the validator can determine if a length of whitespace
  +     * characters in the document are ignorable based on the element
  +     * content model.
  +     * 
  +     * @param text The ignorable whitespace.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void ignorableWhitespace(XMLString text) throws SAXException {
  +    } // ignorableWhitespace(XMLString)
  +
  +    /**
  +     * The end of an element.
  +     * 
  +     * @param element The name of the element.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endElement(QName element) throws SAXException {
  +
  +        fCurrentNode = fCurrentNode.getParentNode();
  +
  +    } // endElement(QName)
  +
  +    /**
  +     * The end of a namespace prefix mapping. This method will only be
  +     * called when namespace processing is enabled.
  +     * 
  +     * @param prefix The namespace prefix.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endPrefixMapping(String prefix) throws SAXException {
  +    } // endPrefixMapping(String)
  +
  +    /** 
  +     * The start of a CDATA section. 
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void startCDATA() throws SAXException {
  +
  +        fInCDATASection = true;
  +        CDATASection cdataSection = fDocument.createCDATASection("");
  +        fCurrentNode.appendChild(cdataSection);
  +        fCurrentNode = cdataSection;
  +
  +    } // startCDATA()
  +
  +    /**
  +     * The end of a CDATA section. 
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endCDATA() throws SAXException {
  +
  +        fInCDATASection = false;
  +        fCurrentNode = fCurrentNode.getParentNode();
  +
  +    } // endCDATA()
  +
  +    /**
  +     * The end of the document.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endDocument() throws SAXException {
  +
  +        fInDocument = false;
  +        fCurrentNode = null;
  +
  +    } // endDocument()
  +
  +    /**
  +     * This method notifies the end of an entity. The document entity has
  +     * the pseudo-name of "[xml]"; the DTD has the pseudo-name of "[dtd]; 
  +     * parameter entity names start with '%'; and general entity names are
  +     * just the entity name.
  +     * <p>
  +     * <strong>Note:</strong> Since the document is an entity, the handler
  +     * will be notified of the end of the document entity by calling the
  +     * endEntity method with the entity name "[xml]" <em>after</em> calling
  +     * the endDocument method. When exposing entity boundaries through the
  +     * SAX API, the document entity is never reported, however.
  +     * <p>
  +     * <strong>Note:</strong> Since the DTD is an entity, the handler
  +     * will be notified of the end of the DTD entity by calling the
  +     * endEntity method with the entity name "[dtd]" <em>after</em> calling
  +     * the endDTD method.
  +     * <p>
  +     * <strong>Note:</strong> This method is not called for entity references
  +     * appearing as part of attribute values.
  +     * 
  +     * @param name The name of the entity.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endEntity(String name) throws SAXException {
  +
  +        if (fInDocument && !fInDTD) {
  +            fCurrentNode = fCurrentNode.getParentNode();
  +        }
  +
  +    } // endEntity(String)
  +
  +    //
  +    // XMLDTDHandler methods
  +    //
  +
  +    /**
  +     * The start of the DTD.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void startDTD() throws SAXException {
  +        fInDTD = true;
  +    } // startDTD()
  +
  +    /**
  +     * The end of the DTD.
  +     *
  +     * @throws SAXException Thrown by handler to signal an error.
  +     */
  +    public void endDTD() throws SAXException {
  +        fInDTD = false;
  +    } // endDTD()
   
   } // class DOMParser
  
  
  
  1.1.2.20  +196 -193  xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java
  
  Index: XMLDocumentParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java,v
  retrieving revision 1.1.2.19
  retrieving revision 1.1.2.20
  diff -u -r1.1.2.19 -r1.1.2.20
  --- XMLDocumentParser.java	2000/10/12 17:16:29	1.1.2.19
  +++ XMLDocumentParser.java	2000/10/12 21:53:49	1.1.2.20
  @@ -91,7 +91,7 @@
    * @author Arnaud  Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: XMLDocumentParser.java,v 1.1.2.19 2000/10/12 17:16:29 andyc Exp $
  + * @version $Id: XMLDocumentParser.java,v 1.1.2.20 2000/10/12 21:53:49 andyc Exp $
    */
   public abstract class XMLDocumentParser
       extends XMLParser
  @@ -101,26 +101,32 @@
       // Data
       //
   
  -    /** Entity manager. */
  -    protected XMLEntityManager fEntityManager;
  +    // components (non-configurable)
   
  -    /** fScanner */
  +    /** Grammar pool. */
  +    protected GrammarPool fGrammarPool;
  +
  +    /** Datatype validator factory. */
  +    protected DatatypeValidatorFactory fDatatypeValidatorFactory;
  +
  +    // components (configurable)
  +
  +    /** Document scanner. */
       protected XMLDocumentScanner fScanner;
   
  -    /** fDTDScanner */
  +    /** DTD scanner. */
       protected XMLDTDScanner fDTDScanner;
   
  -    /** fValidator */
  +    /** Validator. */
       protected XMLValidator fValidator;
   
  -    /** fGrammarPool */
  -    protected GrammarPool fGrammarPool;
  -
  -    /** fDatatypeValidatorFactory */
  -    protected DatatypeValidatorFactory fDatatypeValidatorFactory;
  -
       // state
   
  +    /** 
  +     * True if a parse is in progress. This state is needed because
  +     * some features/properties cannot be set while parsing (e.g.
  +     * validation and namespaces).
  +     */
       protected boolean fParseInProgress = false;
   
       // debugging
  @@ -136,9 +142,9 @@
        * Default Constructor.
        * Creates an XMLDocumentParser with its own SymbolTable and GrammarPool. 
        */
  -    public XMLDocumentParser() {
  +    protected XMLDocumentParser() {
           this(new SymbolTable(), new GrammarPool());
  -    }
  +    } // <init>()
   
       /**
        * Constructor allowing to specify the SymbolTable and GrammarPool to use
  @@ -168,10 +174,6 @@
           final String GRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.GRAMMAR_POOL_PROPERTY;
           fProperties.put(GRAMMAR_POOL, fGrammarPool);
   
  -        fEntityManager = new XMLEntityManager();
  -        final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
  -        fProperties.put(ENTITY_MANAGER, fEntityManager);
  -
           fScanner = new XMLDocumentScanner();
           final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
           fProperties.put(DOCUMENT_SCANNER, fScanner);
  @@ -193,6 +195,182 @@
       } // <init>(SymbolTable,GrammarPool)
   
       //
  +    // XMLParser methods
  +    //
  +
  +    /** 
  +     * Reset all components before parsing. 
  +     *
  +     * @throws SAXException Thrown if an error occurs during initialization.
  +     */
  +    protected void reset() throws SAXException {
  +        super.reset();
  +
  +        // reset every component
  +        fScanner.reset(this);
  +        fDTDScanner.reset(this);
  +        fValidator.reset(this);
  +
  +        // setup document pipeline
  +        /***
  +        fScanner.setDocumentHandler(fValidator);
  +        fValidator.setDocumentHandler(this);
  +        /***/
  +        fScanner.setDocumentHandler(this);
  +        /***/
  +
  +        // setup dtd pipeline
  +        /***
  +        fDTDScanner.setDTDHandler(fValidator);
  +        fValidator.setDTDHandler(this);
  +        /***/
  +        fDTDScanner.setDTDHandler(this);
  +        /***/
  +
  +        // setup dtd content model pipeline
  +        /***
  +        fDTDScanner.setDTDContentModelHandler(fValidator);
  +        fValidator.setDTDContentModelHandler(this);
  +        /***/
  +        fDTDScanner.setDTDContentModelHandler(this);
  +        /***/
  +
  +    } // reset()
  +
  +    //
  +    // XMLComponentManager methods
  +    //
  +
  +    /**
  +     * setFeature
  +     * 
  +     * @param featureId 
  +     * @param state 
  +     */
  +    public void setFeature(String featureId, boolean state)
  +        throws SAXNotRecognizedException, SAXNotSupportedException {
  +
  +        super.setFeature(featureId, state);
  +
  +        // forward to every component
  +        fScanner.setFeature(featureId, state);
  +        fDTDScanner.setFeature(featureId, state);
  +        fValidator.setFeature(featureId, state);
  +
  +    } // setFeature
  +
  +    /**
  +     * setProperty
  +     * 
  +     * @param propertyId 
  +     * @param value 
  +     */
  +    public void setProperty(String propertyId, Object value)
  +        throws SAXNotRecognizedException, SAXNotSupportedException {
  +
  +        super.setProperty(propertyId, value);
  +
  +        // forward to every component
  +        fScanner.setProperty(propertyId, value);
  +        fDTDScanner.setProperty(propertyId, value);
  +        fValidator.setProperty(propertyId, value);
  +
  +    } // setProperty
  +
  +    /**
  +     * Parses the specified input source.
  +     *
  +     * @param source The input source.
  +     *
  +     * @exception org.xml.sax.SAXException Throws exception on SAX error.
  +     * @exception java.io.IOException Throws exception on i/o error.
  +     */
  +    public void parse(InputSource source)
  +        throws SAXException, IOException {
  +
  +        if (fParseInProgress) {
  +            // REVISIT - need to add new error message
  +            throw new SAXException(
  +                              "FWK005 parse may not be called while parsing.");
  +        }
  +
  +        try {
  +            reset();
  +            fEntityManager.setEntityHandler(fScanner);
  +            fEntityManager.startDocumentEntity(new XMLInputSource(source));
  +            fScanner.scanDocument(true);
  +            fParseInProgress = false;
  +        } catch (SAXException ex) {
  +            fParseInProgress = false;
  +            if (PRINT_EXCEPTION_STACK_TRACE)
  +                ex.printStackTrace();
  +            throw ex;
  +        } catch (IOException ex) {
  +            fParseInProgress = false;
  +            if (PRINT_EXCEPTION_STACK_TRACE)
  +                ex.printStackTrace();
  +            throw ex;
  +        } catch (Exception ex) {
  +            fParseInProgress = false;
  +            if (PRINT_EXCEPTION_STACK_TRACE)
  +                ex.printStackTrace();
  +            throw new org.xml.sax.SAXException(ex);
  +        }
  +
  +    } // parse(InputSource)
  +
  +    //
  +    // XMLParser methods
  +    //
  +
  +    /**
  +     * Check a property. If the property is know and supported, this method
  +     * simply returns. Otherwise, the appropriate exception is thrown.
  +     *
  +     * @param propertyId The unique identifier (URI) of the property
  +     *                   being set.
  +     * @exception org.xml.sax.SAXNotRecognizedException If the
  +     *            requested property is not known.
  +     * @exception org.xml.sax.SAXNotSupportedException If the
  +     *            requested property is known, but the requested
  +     *            value is not supported.
  +     * @exception org.xml.sax.SAXException If there is any other
  +     *            problem fulfilling the request.
  +     */
  +    protected void checkProperty(String propertyId)
  +        throws SAXNotRecognizedException, SAXNotSupportedException {
  +
  +        //
  +        // SAX2 Properties
  +        //
  +
  +        if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  +            String property =
  +                propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  +        }
  +
  +        //
  +        // Xerces Properties
  +        //
  +
  +        else if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
  +            String property =
  +                propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
  +            if (property.equals(Constants.DTD_SCANNER_PROPERTY)) {
  +                return;
  +            }
  +            /***
  +            if (property.equals(Constants.ENTITY_RESOLVER_PROPERTY)) {
  +                return;
  +            }   
  +            /***/
  +        }
  +
  +        super.checkProperty(propertyId);
  +
  +    } // checkProperty(String)
  +
  +    //
       // XMLDocumentHandler methods
       //
   
  @@ -735,180 +913,5 @@
        */
       public void endContentModel() throws SAXException {
       } // endContentModel()
  -
  -    //
  -    // Methods inherited from XMLParser that are overriden
  -    //
  -
  -    /**
  -     * setFeature
  -     * 
  -     * @param featureId 
  -     * @param state 
  -     */
  -    public void setFeature(String featureId, boolean state)
  -        throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        super.setFeature(featureId, state);
  -
  -        // forward to every component
  -        fEntityManager.setFeature(featureId, state);
  -        fScanner.setFeature(featureId, state);
  -        fDTDScanner.setFeature(featureId, state);
  -        fValidator.setFeature(featureId, state);
  -
  -    } // setFeature
  -
  -    /**
  -     * setProperty
  -     * 
  -     * @param propertyId 
  -     * @param value 
  -     */
  -    public void setProperty(String propertyId, Object value)
  -        throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        super.setProperty(propertyId, value);
  -
  -        // forward to every component
  -        fEntityManager.setProperty(propertyId, value);
  -        fScanner.setProperty(propertyId, value);
  -        fDTDScanner.setProperty(propertyId, value);
  -        fValidator.setProperty(propertyId, value);
  -
  -    } // setProperty
  -
  -    /**
  -     * Parses the specified input source.
  -     *
  -     * @param source The input source.
  -     *
  -     * @exception org.xml.sax.SAXException Throws exception on SAX error.
  -     * @exception java.io.IOException Throws exception on i/o error.
  -     */
  -    public void parse(InputSource source)
  -        throws SAXException, IOException {
  -
  -        if (fParseInProgress) {
  -            // REVISIT - need to add new error message
  -            throw new SAXException(
  -                              "FWK005 parse may not be called while parsing.");
  -        }
  -
  -        try {
  -            reset();
  -            fEntityManager.setEntityHandler(fScanner);
  -            fEntityManager.startDocumentEntity(new XMLInputSource(source));
  -            fScanner.scanDocument(true);
  -            fParseInProgress = false;
  -        } catch (SAXException ex) {
  -            fParseInProgress = false;
  -            if (PRINT_EXCEPTION_STACK_TRACE)
  -                ex.printStackTrace();
  -            throw ex;
  -        } catch (IOException ex) {
  -            fParseInProgress = false;
  -            if (PRINT_EXCEPTION_STACK_TRACE)
  -                ex.printStackTrace();
  -            throw ex;
  -        } catch (Exception ex) {
  -            fParseInProgress = false;
  -            if (PRINT_EXCEPTION_STACK_TRACE)
  -                ex.printStackTrace();
  -            throw new org.xml.sax.SAXException(ex);
  -        }
  -
  -    } // parse(InputSource)
  -
  -    /** 
  -     * Reset all components before parsing. 
  -     *
  -     * @throws SAXException Thrown if an error occurs during initialization.
  -     */
  -    public void reset() throws SAXException {
  -        super.reset();
  -
  -        // reset every component
  -        fEntityManager.reset(this);
  -        fScanner.reset(this);
  -        fDTDScanner.reset(this);
  -        fValidator.reset(this);
  -
  -        // setup document pipeline
  -        /***
  -        fScanner.setDocumentHandler(fValidator);
  -        fValidator.setDocumentHandler(this);
  -        /***/
  -        fScanner.setDocumentHandler(this);
  -        /***/
  -
  -        // setup dtd pipeline
  -        /***
  -        fDTDScanner.setDTDHandler(fValidator);
  -        fValidator.setDTDHandler(this);
  -        /***/
  -        fDTDScanner.setDTDHandler(this);
  -        /***/
  -
  -        // setup dtd content model pipeline
  -        /***
  -        fDTDScanner.setDTDContentModelHandler(fValidator);
  -        fValidator.setDTDContentModelHandler(this);
  -        /***/
  -        fDTDScanner.setDTDContentModelHandler(this);
  -        /***/
  -
  -    } // reset()
  -
  -    //
  -    // XMLParser methods
  -    //
  -
  -    /**
  -     * Check a property. If the property is know and supported, this method
  -     * simply returns. Otherwise, the appropriate exception is thrown.
  -     *
  -     * @param propertyId The unique identifier (URI) of the property
  -     *                   being set.
  -     * @exception org.xml.sax.SAXNotRecognizedException If the
  -     *            requested property is not known.
  -     * @exception org.xml.sax.SAXNotSupportedException If the
  -     *            requested property is known, but the requested
  -     *            value is not supported.
  -     * @exception org.xml.sax.SAXException If there is any other
  -     *            problem fulfilling the request.
  -     */
  -    protected void checkProperty(String propertyId)
  -        throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        //
  -        // SAX2 Properties
  -        //
  -
  -        if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
  -            String property =
  -                propertyId.substring(Constants.SAX_PROPERTY_PREFIX.length());
  -        }
  -
  -        //
  -        // Xerces Properties
  -        //
  -
  -        else if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
  -            String property =
  -                propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
  -            if (property.equals(Constants.DTD_SCANNER_PROPERTY)) {
  -                return;
  -            }
  -            /***
  -            if (property.equals(Constants.ENTITY_RESOLVER_PROPERTY)) {
  -                return;
  -            }   
  -            /***/
  -        }
  -
  -        super.checkProperty(propertyId);
  -
  -    } // checkProperty(String)
   
   } // class XMLDocumentParser
  
  
  
  1.1.2.13  +204 -190  xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLParser.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- XMLParser.java	2000/10/06 22:21:24	1.1.2.12
  +++ XMLParser.java	2000/10/12 21:53:50	1.1.2.13
  @@ -81,7 +81,9 @@
   /**
    * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
    * @author Arnaud  Le Hors, IBM
  - * @version $Id: XMLParser.java,v 1.1.2.12 2000/10/06 22:21:24 andyc Exp $
  + * @author Andy Clark, IBM
  + *
  + * @version $Id: XMLParser.java,v 1.1.2.13 2000/10/12 21:53:50 andyc Exp $
    */
   public abstract class XMLParser
       implements XMLComponentManager {
  @@ -90,19 +92,25 @@
       // Data
       //
   
  -    /** fSymbolTable */
  +    // components (non-configurable)
  +
  +    /** Symbol table. */
       protected SymbolTable fSymbolTable;
  +
  +    // components (configurable)
   
  -    /** fEntityManager */
  +    /** Entity manager. */
       protected XMLEntityManager fEntityManager;
   
  -    /** fErrorReporter */
  +    /** Error reporter. */
       protected XMLErrorReporter fErrorReporter;
  +
  +    // data
   
  -    /** properties table */
  +    /** Properties. */
       protected Hashtable fProperties;
   
  -    /** features table */
  +    /** Features. */
       protected Hashtable fFeatures;
   
       //
  @@ -112,9 +120,9 @@
       /**
        * Default Constructor. Creates a parser with its own SymbolTable.
        */
  -    public XMLParser() {
  +    protected XMLParser() {
           this(new SymbolTable());
  -    }
  +    } // <init>()
   
       /**
        * Constructor allowing the SymbolTable to be specified.
  @@ -146,10 +154,116 @@
       } // <init>(SymbolTable)
   
       //
  -    // Methods
  +    // Public methods
       //
   
       /**
  +     * Parses the input source specified by the given system identifier.
  +     * <p>
  +     * This method is equivalent to the following:
  +     * <pre>
  +     *     parse(new InputSource(systemId));
  +     * </pre>
  +     *
  +     * @param source The input source.
  +     *
  +     * @exception org.xml.sax.SAXException Throws exception on SAX error.
  +     * @exception java.io.IOException Throws exception on i/o error.
  +     */
  +    public void parse(String systemId)
  +        throws SAXException, IOException {
  +
  +        InputSource source = new InputSource(systemId);
  +        parse(source);
  +        try {
  +            Reader reader = source.getCharacterStream();
  +            if (reader != null) {
  +                reader.close();
  +            }
  +            else {
  +                InputStream is = source.getByteStream();
  +                if (is != null) {
  +                    is.close();
  +                }
  +            }
  +        }
  +        catch (IOException e) {
  +            // ignore
  +        }
  +
  +    } // parse(String)
  +
  +    /**
  +     * parse
  +     *
  +     * @param inputSource
  +     *
  +     * @exception org.xml.sax.SAXException
  +     * @exception java.io.IOException
  +     */
  +    public abstract void parse(InputSource inputSource) 
  +        throws SAXException, IOException;
  +
  +    /**
  +     * Sets the resolver used to resolve external entities. The EntityResolver
  +     * interface supports resolution of public and system identifiers.
  +     *
  +     * @param resolver The new entity resolver. Passing a null value will
  +     *                 uninstall the currently installed resolver.
  +     */
  +    public void setEntityResolver(EntityResolver resolver) {
  +        final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
  +        fProperties.put(ENTITY_RESOLVER, resolver);
  +    } // setEntityResolver(EntityResolver)
  +
  +    /**
  +     * Return the current entity resolver.
  +     *
  +     * @return The current entity resolver, or null if none
  +     *         has been registered.
  +     * @see #setEntityResolver
  +     */
  +    public EntityResolver getEntityResolver() {
  +        final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
  +        return (EntityResolver)fProperties.get(ENTITY_RESOLVER);
  +    } // getEntityResolver():EntityResolver
  +
  +    /**
  +     * Allow an application to register an error event handler.
  +     *
  +     * <p>If the application does not register an error handler, all
  +     * error events reported by the SAX parser will be silently
  +     * ignored; however, normal processing may not continue.  It is
  +     * highly recommended that all SAX applications implement an
  +     * error handler to avoid unexpected bugs.</p>
  +     *
  +     * <p>Applications may register a new or different handler in the
  +     * middle of a parse, and the SAX parser must begin using the new
  +     * handler immediately.</p>
  +     *
  +     * @param errorHandler The error handler.
  +     * @exception java.lang.NullPointerException If the handler 
  +     *            argument is null.
  +     * @see #getErrorHandler
  +     */
  +    public void setErrorHandler(ErrorHandler errorHandler) {
  +        final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  +        fProperties.put(ERROR_HANDLER, errorHandler);
  +    } // setErrorHandler(ErrorHandler)
  +
  +    /**
  +     * Return the current error handler.
  +     *
  +     * @return The current error handler, or null if none
  +     *         has been registered.
  +     * @see #setErrorHandler
  +     */
  +    public ErrorHandler getErrorHandler() {
  +        final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  +        return (ErrorHandler)fProperties.get(ERROR_HANDLER);
  +    } // getErrorHandler():ErrorHandler
  +
  +    /**
        * Set the state of a feature.
        *
        * Set the state of any feature in a SAX2 parser.  The parser
  @@ -178,14 +292,56 @@
           // then store the information
           fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
   
  -    } // setFeature
  +    } // setFeature(String,boolean)
   
       /**
  -     * getFeature
  +     * setProperty
        * 
  -     * @param featureId 
  +     * @param propertyId 
  +     * @param value 
  +     */
  +    public void setProperty(String propertyId, Object value)
  +        throws SAXNotRecognizedException, SAXNotSupportedException {
  +
  +        checkProperty(propertyId);
  +
  +        // forward to every component
  +        fEntityManager.setProperty(propertyId, value);
  +        fErrorReporter.setProperty(propertyId, value);
  +        // then store the information
  +        fProperties.put(propertyId, value);
  +
  +    } // setProperty(String,Object)
  +
  +    /**
  +     * Set the locale to use for messages.
  +     *
  +     * @param locale The locale object to use for localization of messages.
  +     *
  +     * @exception SAXException An exception thrown if the parser does not
  +     *                         support the specified locale.
  +     *
  +     * @see org.xml.sax.Parser
  +     */
  +    public void setLocale(Locale locale) throws SAXException {
  +
  +        fErrorReporter.setLocale(locale);
  +
  +    } // setLocale(Locale)
  +
  +    //
  +    // XMLComponentManager methods
  +    //
  +
  +    /**
  +     * Returns the state of a feature.
  +     * 
  +     * @param featureId The feature identifier.
        * 
  -     * @return 
  +     * @throws SAXNotRecognizedException Thrown if the feature is not 
  +     *                                   recognized.
  +     * @throws SAXNotSupportedException Thrown if the feature is not
  +     *                                  supported.
        */
       public boolean getFeature(String featureId)
           throws SAXNotRecognizedException, SAXNotSupportedException {
  @@ -194,8 +350,42 @@
   
           Boolean state = (Boolean) fFeatures.get(featureId);
           return state.booleanValue();
  +
  +    } // getFeature(String):boolean
  +
  +    /**
  +     * Returns the value of a property.
  +     * 
  +     * @param propertyId The property identifier.
  +     * 
  +     * @throws SAXNotRecognizedException Thrown if the feature is not 
  +     *                                   recognized.
  +     * @throws SAXNotSupportedException Thrown if the feature is not
  +     *                                  supported.
  +     */
  +    public Object getProperty(String propertyId)
  +        throws SAXNotRecognizedException, SAXNotSupportedException {
  +
  +        checkProperty(propertyId);
  +
  +        return fProperties.get(propertyId);
  +
  +    } // getProperty(String):Object
  +
  +    //
  +    // Protected methods
  +    //
  +
  +    /**
  +     * reset all components before parsing
  +     */
  +    protected void reset() throws SAXException {
  +
  +        // reset every component
  +        fEntityManager.reset(this);
  +        fErrorReporter.reset(this);
   
  -    } // getFeature
  +    } // reset()
   
       /**
        * Check a feature. If feature is know and supported, this method simply
  @@ -350,43 +540,7 @@
   
       } // checkFeature(String)
   
  -
       /**
  -     * setProperty
  -     * 
  -     * @param propertyId 
  -     * @param value 
  -     */
  -    public void setProperty(String propertyId, Object value)
  -        throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        checkProperty(propertyId);
  -
  -        // forward to every component
  -        fEntityManager.setProperty(propertyId, value);
  -        fErrorReporter.setProperty(propertyId, value);
  -        // then store the information
  -        fProperties.put(propertyId, value);
  -
  -    } // setProperty
  -
  -    /**
  -     * getProperty
  -     * 
  -     * @param propertyId 
  -     * 
  -     * @return 
  -     */
  -    public Object getProperty(String propertyId)
  -        throws SAXNotRecognizedException, SAXNotSupportedException {
  -
  -        checkProperty(propertyId);
  -
  -        return fProperties.get(propertyId);
  -
  -    } // getProperty
  -
  -    /**
        * Check a property. If the property is know and supported, this method
        * simply returns. Otherwise, the appropriate exception is thrown.
        *
  @@ -468,145 +622,5 @@
           throw new SAXNotRecognizedException(propertyId);
   
       } // checkProperty(String)
  -
  -    /**
  -     * Sets the resolver used to resolve external entities. The EntityResolver
  -     * interface supports resolution of public and system identifiers.
  -     *
  -     * @param resolver The new entity resolver. Passing a null value will
  -     *                 uninstall the currently installed resolver.
  -     */
  -    public void setEntityResolver(EntityResolver resolver) {
  -        final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
  -        fProperties.put(ENTITY_RESOLVER, resolver);
  -    } // setEntityResolver
  -
  -    /**
  -     * Return the current entity resolver.
  -     *
  -     * @return The current entity resolver, or null if none
  -     *         has been registered.
  -     * @see #setEntityResolver
  -     */
  -    public EntityResolver getEntityResolver() {
  -        final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
  -        return (EntityResolver)fProperties.get(ENTITY_RESOLVER);
  -    } // getEntityResolver
  -
  -    /**
  -     * Allow an application to register an error event handler.
  -     *
  -     * <p>If the application does not register an error handler, all
  -     * error events reported by the SAX parser will be silently
  -     * ignored; however, normal processing may not continue.  It is
  -     * highly recommended that all SAX applications implement an
  -     * error handler to avoid unexpected bugs.</p>
  -     *
  -     * <p>Applications may register a new or different handler in the
  -     * middle of a parse, and the SAX parser must begin using the new
  -     * handler immediately.</p>
  -     *
  -     * @param errorHandler The error handler.
  -     * @exception java.lang.NullPointerException If the handler 
  -     *            argument is null.
  -     * @see #getErrorHandler
  -     */
  -    public void setErrorHandler(ErrorHandler errorHandler) {
  -        final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  -        fProperties.put(ERROR_HANDLER, errorHandler);
  -    } // setErrorHandler
  -
  -    /**
  -     * Return the current error handler.
  -     *
  -     * @return The current error handler, or null if none
  -     *         has been registered.
  -     * @see #setErrorHandler
  -     */
  -    public ErrorHandler getErrorHandler() {
  -        final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  -        return (ErrorHandler)fProperties.get(ERROR_HANDLER);
  -    } // getErrorHandler
  -
  -    /**
  -     * Parses the input source specified by the given system identifier.
  -     * <p>
  -     * This method is equivalent to the following:
  -     * <pre>
  -     *     parse(new InputSource(systemId));
  -     * </pre>
  -     *
  -     * @param source The input source.
  -     *
  -     * @exception org.xml.sax.SAXException Throws exception on SAX error.
  -     * @exception java.io.IOException Throws exception on i/o error.
  -     */
  -    public void parse(String systemId)
  -        throws SAXException, IOException {
  -
  -        InputSource source = new InputSource(systemId);
  -        parse(source);
  -        try {
  -            Reader reader = source.getCharacterStream();
  -            if (reader != null) {
  -                reader.close();
  -            }
  -            else {
  -                InputStream is = source.getByteStream();
  -                if (is != null) {
  -                    is.close();
  -                }
  -            }
  -        }
  -        catch (IOException e) {
  -            // ignore
  -        }
  -
  -    } // parse(String)
  -
  -    /**
  -     * parse
  -     *
  -     * @param inputSource
  -     *
  -     * @exception org.xml.sax.SAXException
  -     * @exception java.io.IOException
  -     */
  -    public void parse(InputSource inputSource)
  -        throws SAXException, IOException {
  -    } // parse
  -
  -    /**
  -     * reset all components before parsing
  -     */
  -    public void reset()
  -        throws SAXException {
  -
  -        // reset every component
  -        fEntityManager.reset(this);
  -        fErrorReporter.reset(this);
  -
  -    } // reset
  -
  -    //
  -    // Locale 
  -    //
  -
  -    /**
  -     * Set the locale to use for messages.
  -     *
  -     * @param locale The locale object to use for localization of messages.
  -     *
  -     * @exception SAXException An exception thrown if the parser does not
  -     *                         support the specified locale.
  -     *
  -     * @see org.xml.sax.Parser
  -     */
  -    public void setLocale(Locale locale) throws SAXException {
  -
  -        fErrorReporter.setLocale(locale);
  -
  -    } // setLocale(Locale)
  -
   
   } // class XMLParser