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/01/26 00:59:16 UTC

cvs commit: xml-xerces/c/src/parsers DOMParser.cpp DOMParser.hpp

lehors      01/01/25 15:59:16

  Modified:    c/src/dom DocumentImpl.hpp ElementImpl.cpp ElementNSImpl.cpp
                        ParentNode.cpp
               c/src/parsers DOMParser.cpp DOMParser.hpp
  Log:
  added a flag to turn off error checking in the DOM,
  this is primarily used while building the DOM from the parser to
  get better performance.
  
  Revision  Changes    Path
  1.22      +33 -1     xml-xerces/c/src/dom/DocumentImpl.hpp
  
  Index: DocumentImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/DocumentImpl.hpp,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DocumentImpl.hpp	2001/01/17 17:46:01	1.21
  +++ DocumentImpl.hpp	2001/01/25 23:59:11	1.22
  @@ -58,7 +58,7 @@
    */
   
   /*
  - * $Id: DocumentImpl.hpp,v 1.21 2001/01/17 17:46:01 lehors Exp $
  + * $Id: DocumentImpl.hpp,v 1.22 2001/01/25 23:59:11 lehors Exp $
    */
   
   //
  @@ -160,6 +160,9 @@
        */
       int fChanges;
   
  +    /** Bypass error checking. */
  +    bool errorChecking;
  +
       friend class NodeIteratorImpl;
       friend class TreeWalkerImpl;
       friend class RangeImpl;
  @@ -233,6 +236,35 @@
   
       virtual void changed();
       virtual int changes();
  +
  +    /** 
  +     * Sets whether the DOM implementation performs error checking
  +     * upon operations. Turning off error checking only affects
  +     * the following DOM checks:
  +     * <ul>
  +     * <li>Checking strings to make sure that all characters are
  +     *     legal XML characters
  +     * <li>Hierarchy checking such as allowed children, checks for
  +     *     cycles, etc.
  +     * </ul>
  +     * <p>
  +     * Turning off error checking does <em>not</em> turn off the
  +     * following checks:
  +     * <ul>
  +     * <li>Read only checks
  +     * <li>Checks related to DOM events
  +     * </ul>
  +     */
  +    inline void setErrorChecking(bool check) {
  +        errorChecking = check;
  +    }
  +
  +    /**
  +     * Returns true if the DOM implementation performs error checking.
  +     */
  +    inline bool getErrorChecking() {
  +        return errorChecking;
  +    }
   };
   
   #endif
  
  
  
  1.30      +38 -33    xml-xerces/c/src/dom/ElementImpl.cpp
  
  Index: ElementImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/ElementImpl.cpp,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ElementImpl.cpp	2001/01/18 02:49:55	1.29
  +++ ElementImpl.cpp	2001/01/25 23:59:11	1.30
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: ElementImpl.cpp,v 1.29 2001/01/18 02:49:55 lehors Exp $
  + * $Id: ElementImpl.cpp,v 1.30 2001/01/25 23:59:11 lehors Exp $
    */
    
   #include "DeepNodeListImpl.hpp"
  @@ -174,10 +174,10 @@
   
   void ElementImpl::removeAttribute(const DOMString &nam)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -        DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       if (attributes != null)
       {    
       	AttrImpl *att = (AttrImpl *) attributes->getNamedItem(nam);
  @@ -195,10 +195,10 @@
   
   AttrImpl *ElementImpl::removeAttributeNode(AttrImpl *oldAttr)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -        DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       if (attributes != null)
       {
   	    AttrImpl *found = (AttrImpl *) attributes->getNamedItem(oldAttr->getName());
  @@ -220,10 +220,10 @@
   
   AttrImpl *ElementImpl::setAttribute(const DOMString &nam, const DOMString &val)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -        DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       AttrImpl* newAttr = (AttrImpl*)getAttributeNode(nam);
       if (!newAttr)
       {
  @@ -243,10 +243,10 @@
   
   AttrImpl * ElementImpl::setAttributeNode(AttrImpl *newAttr)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -        DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       if (!(newAttr->isAttrImpl()))
           throw DOM_DOMException(DOM_DOMException::WRONG_DOCUMENT_ERR, null);
   	if (attributes == 0)
  @@ -297,10 +297,10 @@
   AttrImpl *ElementImpl::setAttributeNS(const DOMString &fNamespaceURI,
   	const DOMString &qualifiedName, const DOMString &fValue)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -	    DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       AttrImpl *newAttr =
         (AttrImpl *) ownerDocument->createAttributeNS(fNamespaceURI,
                                                       qualifiedName);
  @@ -320,10 +320,10 @@
   void ElementImpl::removeAttributeNS(const DOMString &fNamespaceURI,
   	const DOMString &fLocalName)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -	    DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  - 
  +    if (getOwnerDocument()->getErrorChecking() && isReadOnly()) {
  +        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                               null);
  +    }
       if (attributes != null)
       {   
   		AttrImpl *att =
  @@ -347,14 +347,19 @@
   
   AttrImpl *ElementImpl::setAttributeNodeNS(AttrImpl *newAttr)
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -	    DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  -    if (newAttr -> getOwnerDocument() != this -> getOwnerDocument())
  -        throw DOM_DOMException(DOM_DOMException::WRONG_DOCUMENT_ERR, null);
  -	if (attributes == 0)
  -		attributes = new AttrMapImpl(this, null);
  +    if (getOwnerDocument()->getErrorChecking()) {
  +        if (isReadOnly()) {
  +            throw DOM_DOMException(
  +                                 DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                                 null);
  +        }
  +        if (newAttr->getOwnerDocument() != this->getOwnerDocument()) {
  +            throw DOM_DOMException(DOM_DOMException::WRONG_DOCUMENT_ERR, null);
  +        }
  +    }
  +    if (attributes == 0) {
  +        attributes = new AttrMapImpl(this, null);
  +    }
       AttrImpl *oldAttr = (AttrImpl *) attributes->getNamedItemNS(newAttr->getNamespaceURI(), newAttr->getLocalName());
       
       // This will throw INUSE if necessary
  
  
  
  1.9       +18 -13    xml-xerces/c/src/dom/ElementNSImpl.cpp
  
  Index: ElementNSImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/ElementNSImpl.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ElementNSImpl.cpp	2001/01/25 19:22:55	1.8
  +++ ElementNSImpl.cpp	2001/01/25 23:59:12	1.9
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: ElementNSImpl.cpp,v 1.8 2001/01/25 19:22:55 tng Exp $
  + * $Id: ElementNSImpl.cpp,v 1.9 2001/01/25 23:59:12 lehors Exp $
    */
   
   #include <util/XMLUniDefs.hpp>
  @@ -137,23 +137,28 @@
       DOMString xmlns = NodeImpl::getXmlnsString();
       DOMString xmlnsURI = NodeImpl::getXmlnsURIString();
   
  -    if (isReadOnly())
  -        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  -                               null);
  -    if(prefix != null && !DocumentImpl::isXMLName(prefix))
  -        throw DOM_DOMException(DOM_DOMException::INVALID_CHARACTER_ERR,null);
  -
  -    if (namespaceURI == null)
  -	throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);
  -
  +    if (ownerDocument->getErrorChecking()) {
  +        if (isReadOnly()) {
  +            throw DOM_DOMException(
  +                                 DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                                 null);
  +        }
  +        if (prefix != null && !DocumentImpl::isXMLName(prefix)) {
  +            throw DOM_DOMException(DOM_DOMException::INVALID_CHARACTER_ERR,
  +                                   null);
  +        }
  +        if (namespaceURI == null) {
  +            throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);
  +        }
  +    }
       if (prefix == null || prefix.length() == 0) {
           name = localName;
           return;
       }
  -
  -    if (prefix.equals(xml) && !namespaceURI.equals(xmlURI))
  +    if (ownerDocument->getErrorChecking() &&
  +        (prefix.equals(xml) && !namespaceURI.equals(xmlURI))) {
           throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);
  -
  +    }
       const XMLCh *p = prefix.rawBuffer();
       for (int i = prefix.length(); --i >= 0;)
           if (*p++ == chColon)	//prefix is malformed
  
  
  
  1.9       +53 -38    xml-xerces/c/src/dom/ParentNode.cpp
  
  Index: ParentNode.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/dom/ParentNode.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ParentNode.cpp	2001/01/25 02:01:31	1.8
  +++ ParentNode.cpp	2001/01/25 23:59:12	1.9
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: ParentNode.cpp,v 1.8 2001/01/25 02:01:31 lehors Exp $
  + * $Id: ParentNode.cpp,v 1.9 2001/01/25 23:59:12 lehors Exp $
    *
    * <p><b>WARNING</b>: Some of the code here is partially duplicated in
    * AttrImpl, be careful to keep these two classes in sync!
  @@ -181,7 +181,9 @@
   
   NodeImpl *ParentNode::insertBefore(NodeImpl *newChild, NodeImpl *refChild) {
    
  -   if (newChild->isDocumentFragmentImpl()) {
  +    bool errorChecking = ownerDocument->getErrorChecking();
  +
  +    if (newChild->isDocumentFragmentImpl()) {
           // SLOW BUT SAFE: We could insert the whole subtree without
           // juggling so many next/previous pointers. (Wipe out the
           // parent's child-list, patch the parent pointers, set the
  @@ -199,12 +201,15 @@
   
           // No need to check kids for right-document; if they weren't,
           // they wouldn't be kids of that DocFrag.
  -        for (NodeImpl *kid = newChild->getFirstChild(); // Prescan
  -             kid != null; kid = kid->getNextSibling()) {
  -
  -            if (!DocumentImpl::isKidOK(this, kid)) {
  -                throw DOM_DOMException(DOM_DOMException::HIERARCHY_REQUEST_ERR,
  +        if (errorChecking) {
  +            for (NodeImpl *kid = newChild->getFirstChild(); // Prescan
  +                 kid != null; kid = kid->getNextSibling()) {
  +
  +                if (!DocumentImpl::isKidOK(this, kid)) {
  +                    throw DOM_DOMException(
  +                                       DOM_DOMException::HIERARCHY_REQUEST_ERR,
                                          null);
  +                }
               }
           }                       
   
  @@ -218,30 +223,37 @@
       if (refChild == newChild) {
           return newChild;
       }
  -
  -    if (isReadOnly()) {
  -        throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  -                               null);
  -    }
  -    if (newChild->getOwnerDocument() != ownerDocument) {
  -        throw DOM_DOMException(DOM_DOMException::WRONG_DOCUMENT_ERR, null);
  -    }
  -    if (!DocumentImpl::isKidOK(this, newChild)) {
  -        throw DOM_DOMException(DOM_DOMException::HIERARCHY_REQUEST_ERR, null);
  -    }
  -    // refChild must be a child of this node (or null)
  -    if (refChild != null && refChild->getParentNode() != this) {
  -        throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  -    }
   
  -    // Prevent cycles in the tree
  -    // newChild cannot be ancestor of this Node, and actually cannot be this
  -    bool treeSafe = true;
  -    for (NodeImpl *a = this; treeSafe && a != null; a = a->getParentNode()) {
  -        treeSafe = (newChild != a);
  -    }
  -    if (!treeSafe) {
  -        throw DOM_DOMException(DOM_DOMException::HIERARCHY_REQUEST_ERR, null);
  +    if (errorChecking) {
  +        if (isReadOnly()) {
  +            throw DOM_DOMException(
  +                                 DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                                 null);
  +        }
  +        if (newChild->getOwnerDocument() != ownerDocument) {
  +            throw DOM_DOMException(DOM_DOMException::WRONG_DOCUMENT_ERR, null);
  +        }
  +        if (!DocumentImpl::isKidOK(this, newChild)) {
  +            throw DOM_DOMException(DOM_DOMException::HIERARCHY_REQUEST_ERR,
  +                                   null);
  +        }
  +        // refChild must be a child of this node (or null)
  +        if (refChild != null && refChild->getParentNode() != this) {
  +            throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  +        }
  +
  +        // Prevent cycles in the tree
  +        // newChild cannot be ancestor of this Node,
  +        // and actually cannot be this
  +        bool treeSafe = true;
  +        for (NodeImpl *a = this; treeSafe && a != null; a = a->getParentNode())
  +        {
  +            treeSafe = (newChild != a);
  +        }
  +        if (!treeSafe) {
  +            throw DOM_DOMException(DOM_DOMException::HIERARCHY_REQUEST_ERR,
  +                                   null);
  +        }
       }
   
       // Convert to internal type, to avoid repeated casting  
  @@ -361,15 +373,18 @@
     
   NodeImpl *ParentNode::removeChild(NodeImpl *oldChild) 
   {
  -    if (isReadOnly())
  -        throw DOM_DOMException(
  -        DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null);
  -    
  -    if (oldChild != null && oldChild->getParentNode() != this)
  -        throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  -    
  +    if (ownerDocument->getErrorChecking()) {
  +        if (isReadOnly()) {
  +            throw DOM_DOMException(
  +                                 DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  +                                 null);
  +        }
  +        if (oldChild != null && oldChild->getParentNode() != this) {
  +            throw DOM_DOMException(DOM_DOMException::NOT_FOUND_ERR, null);
  +        }
  +    }
       //fix other ranges for change before deleting the node
  -    if (this->getOwnerDocument() !=  null  ) {
  +    if (getOwnerDocument() !=  null) {
           typedef RefVectorOf<RangeImpl> RangeImpls;
           RangeImpls* ranges = this->getOwnerDocument()->getRanges();
           if (ranges != null) {
  
  
  
  1.37      +10 -1     xml-xerces/c/src/parsers/DOMParser.cpp
  
  Index: DOMParser.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/parsers/DOMParser.cpp,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- DOMParser.cpp	2000/10/20 22:06:27	1.36
  +++ DOMParser.cpp	2001/01/25 23:59:15	1.37
  @@ -59,7 +59,7 @@
   *  handler with the scanner. In these handler methods, appropriate DOM nodes
   *  are created and added to the DOM tree.
   *
  -* $Id: DOMParser.cpp,v 1.36 2000/10/20 22:06:27 andyh Exp $
  +* $Id: DOMParser.cpp,v 1.37 2001/01/25 23:59:15 lehors Exp $
   * 
   */
   
  @@ -566,6 +566,15 @@
       // Just set the document as the current parent and current node
       fCurrentParent = fDocument;
       fCurrentNode   = fDocument;
  +    // set DOM error checking off
  +    fDocument.setErrorChecking(false);
  +}
  +
  +
  +void DOMParser::endDocument()
  +{
  +    // set DOM error checking back on
  +    fDocument.setErrorChecking(true);
   }
   
   
  
  
  
  1.15      +1 -11     xml-xerces/c/src/parsers/DOMParser.hpp
  
  Index: DOMParser.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/parsers/DOMParser.hpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DOMParser.hpp	2001/01/12 21:23:38	1.14
  +++ DOMParser.hpp	2001/01/25 23:59:15	1.15
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: DOMParser.hpp,v 1.14 2001/01/12 21:23:38 tng Exp $
  + * $Id: DOMParser.hpp,v 1.15 2001/01/25 23:59:15 lehors Exp $
    *
    */
   
  @@ -1307,16 +1307,6 @@
   {
       // The DOM entity resolver doesn't handle this
   }
  -
  -
  -// ---------------------------------------------------------------------------
  -//  DOMParser: Handlers for the XMLDocumentHandler interface
  -// ---------------------------------------------------------------------------
  -inline void DOMParser::endDocument()
  -{
  -    // Not used in DOM at this time
  -}
  -
   
   
   // ---------------------------------------------------------------------------