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...@apache.org on 2001/12/17 20:03:21 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers AbstractDOMParser.java

lehors      01/12/17 11:03:21

  Modified:    java/src/org/apache/xerces/parsers AbstractDOMParser.java
  Log:
  added setting of some of the new DOM Level 3 attributes:
  encoding, actualEncoding, version.
  
  Revision  Changes    Path
  1.22      +108 -17   xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
  
  Index: AbstractDOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- AbstractDOMParser.java	2001/12/12 22:33:47	1.21
  +++ AbstractDOMParser.java	2001/12/17 19:03:21	1.22
  @@ -102,7 +102,7 @@
    * @author Andy Clark, IBM
    * @author Elena Litani, IBM
    *
  - * @version $Id: AbstractDOMParser.java,v 1.21 2001/12/12 22:33:47 elena Exp $
  + * @version $Id: AbstractDOMParser.java,v 1.22 2001/12/17 19:03:21 lehors Exp $
    */
   public abstract class AbstractDOMParser
       extends AbstractXMLDocumentParser {
  @@ -190,9 +190,6 @@
       protected CDATASection fCurrentCDATASection;
   
   
  -    protected String               fCurrentEntityName;
  -    protected String               fCurrentEntityNode;
  -
       // deferred expansion data
   
       protected boolean              fDeferNodeExpansion;
  @@ -393,6 +390,7 @@
           // REVISIT: investigate fInDTD & fInDocument flags
           // this method now only called by DocumentHandler
           // comment(), endEntity(), processingInstruction(), textDecl()
  +        // REVISIT: need to set the Entity.actualEncoding somehow
           if (fInDocument && !fInDTD && fCreateEntityRefNodes ) {
               if (!fDeferNodeExpansion) {
                   EntityReference er = fDocument.createEntityReference(name);
  @@ -410,6 +408,61 @@
       } // startEntity(String,String,String,String)
   
       /**
  +     * Notifies of the presence of a TextDecl line in an entity. If present,
  +     * this method will be called immediately following the startEntity call.
  +     * <p>
  +     * <strong>Note:</strong> This method will never be called for the
  +     * document entity; it is only called for external general entities
  +     * referenced in document content.
  +     * <p>
  +     * <strong>Note:</strong> This method is not called for entity references
  +     * appearing as part of attribute values.
  +     * 
  +     * @param version  The XML version, or null if not specified.
  +     * @param encoding The IANA encoding name of the entity.
  +     *
  +     * @throws XNIException Thrown by handler to signal an error.
  +     */
  +    public void textDecl(String version, String encoding) throws XNIException {
  +        if (!fDeferNodeExpansion) {
  +            // REVISIT: when DOM Level 3 is REC rely on Document.support
  +            //          instead of specific class
  +            if (fDocumentType != null) {
  +                NamedNodeMap entities = fDocumentType.getEntities();
  +                String name = fCurrentNode.getNodeName();
  +                EntityImpl entity = (EntityImpl) entities.getNamedItem(name);
  +                if (entity != null) {
  +                    entity.setVersion(version);
  +                    entity.setEncoding(encoding);
  +                }
  +            }
  +        }
  +        else {
  +            String name = fDeferredDocumentImpl.getNodeName(fCurrentNodeIndex, false);
  +            if (fDocumentTypeIndex != -1 && name != null) {
  +                // find corresponding Entity decl
  +                boolean found = false;
  +                int node = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
  +                while (node != -1) {
  +                    short nodeType = fDeferredDocumentImpl.getNodeType(node, false);
  +                    if (nodeType == Node.ENTITY_NODE) {
  +                        String nodeName =
  +                            fDeferredDocumentImpl.getNodeName(node, false);
  +                        if (nodeName.equals(name)) {
  +                            found = true;
  +                            break;
  +                        }
  +                    }
  +                    node = fDeferredDocumentImpl.getRealPrevSibling(node, false);
  +                }
  +                if (found) {
  +                    fDeferredDocumentImpl.setEntityInfo(node, version, encoding);
  +                }
  +            }
  +        }
  +    } // textDecl(String,String)
  +
  +    /**
        * A comment.
        *
        * @param text The text in the comment.
  @@ -487,8 +540,12 @@
               if (fDocumentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME)) {
                   fDocument = new DocumentImpl();
                   fDocumentImpl = (DocumentImpl)fDocument;
  +                // REVISIT: when DOM Level 3 is REC rely on Document.support
  +                //          instead of specific class
                   // set DOM error checking off
  -                fDocumentImpl.setErrorChecking(false);
  +                fDocumentImpl.setStrictErrorChecking(false);
  +                // set actual encoding
  +                fDocumentImpl.setActualEncoding(encoding);
               }
               else {
                   // use specified document class
  @@ -500,8 +557,10 @@
                           Class.forName(DEFAULT_DOCUMENT_CLASS_NAME);
                       if (defaultDocClass.isAssignableFrom(documentClass)) {
                           fDocumentImpl = (DocumentImpl)fDocument;
  +                        // REVISIT: when DOM Level 3 is REC rely on
  +                        //          Document.support instead of specific class
                           // set DOM error checking off
  -                        fDocumentImpl.setErrorChecking(false);
  +                        fDocumentImpl.setStrictErrorChecking(false);
                       }
                   }
                   catch (ClassNotFoundException e) {
  @@ -526,6 +585,36 @@
       } // startDocument(String,String)
   
       /**
  +     * Notifies of the presence of an XMLDecl line in the document. If
  +     * present, this method will be called immediately following the
  +     * startDocument call.
  +     * 
  +     * @param version    The XML version.
  +     * @param encoding   The IANA encoding name of the document, or null if
  +     *                   not specified.
  +     * @param standalone The standalone value, or null if not specified.
  +     *
  +     * @throws XNIException Thrown by handler to signal an error.
  +     */
  +    public void xmlDecl(String version, String encoding, String standalone)
  +        throws XNIException {
  +        if (!fDeferNodeExpansion) {
  +            // REVISIT: when DOM Level 3 is REC rely on Document.support
  +            //          instead of specific class
  +            if (fDocumentImpl != null) {
  +                fDocumentImpl.setVersion(version);
  +                fDocumentImpl.setEncoding(encoding);
  +                fDocumentImpl.setStandalone("true".equals(standalone));
  +            }
  +        }
  +        else {
  +            fDeferredDocumentImpl.setVersion(version);
  +            fDeferredDocumentImpl.setEncoding(encoding);
  +            fDeferredDocumentImpl.setStandalone("true".equals(standalone));
  +        }
  +    } // xmlDecl(String,String,String)
  +
  +    /**
        * Notifies of the presence of the DOCTYPE line in the document.
        *
        * @param rootElement The name of the root element.
  @@ -823,9 +912,11 @@
   
           fInDocument = false;
           if (!fDeferNodeExpansion) {
  +            // REVISIT: when DOM Level 3 is REC rely on Document.support
  +            //          instead of specific class
               // set DOM error checking back on
               if (fDocumentImpl != null) {
  -                fDocumentImpl.setErrorChecking(true);
  +                fDocumentImpl.setStrictErrorChecking(true);
               }
               fCurrentNode = null;
           }
  @@ -852,7 +943,7 @@
   
           if (fInDocument && !fInDTD && fCreateEntityRefNodes) {
               if (!fDeferNodeExpansion) {
  -                if (fDocumentImpl != null && fDocumentType != null) {
  +                if (fDocumentType != null) {
                       NamedNodeMap entities = fDocumentType.getEntities();
                       NodeImpl entity = (NodeImpl)entities.getNamedItem(name);
                       if (entity != null && entity.getFirstChild() == null) {
  @@ -945,21 +1036,21 @@
           // create deferred node        
           if (fDocumentTypeIndex != -1) {
               boolean found = false;
  -            int nodeIndex = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
  -            while (nodeIndex != -1) {
  -                short nodeType = fDeferredDocumentImpl.getNodeType(nodeIndex, false);
  +            int node = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
  +            while (node != -1) {
  +                short nodeType = fDeferredDocumentImpl.getNodeType(node, false);
                   if (nodeType == Node.ENTITY_NODE) {
  -                    String nodeName = fDeferredDocumentImpl.getNodeName(nodeIndex, false);
  +                    String nodeName = fDeferredDocumentImpl.getNodeName(node, false);
                       if (nodeName.equals(name)) {
                           found = true;
                           break;
                       }
                   }
  -                nodeIndex = fDeferredDocumentImpl.getRealPrevSibling(nodeIndex, false);
  +                node = fDeferredDocumentImpl.getRealPrevSibling(node, false);
               }
               if (!found) {
  -                int entityIndex = fDeferredDocumentImpl.createDeferredEntity(
  -                                    name, null, null, null);
  +                int entityIndex =
  +                    fDeferredDocumentImpl.createDeferredEntity(name, null, null, null);
                   fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, entityIndex);
               }
           }
  @@ -1003,7 +1094,7 @@
               }
           }
               
  -        // create deferred node        
  +        // create deferred node
           if (fDocumentTypeIndex != -1) {
               boolean found = false;
               int nodeIndex = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
  @@ -1216,7 +1307,7 @@
                           namespaceURI = NamespaceContext.XMLNS_URI;
                       }
                       attr = (AttrImpl)fDocumentImpl.createAttributeNS(namespaceURI,
  -                                                                     attributeName);
  +                                                                attributeName);
                   }
                   else {
                       attr = (AttrImpl)fDocumentImpl.createAttribute(attributeName);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org