You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/05/16 16:30:41 UTC

cvs commit: xml-xerces/c/src/idom IDAttrNSImpl.cpp IDAttrNSImpl.hpp IDElementNSImpl.cpp IDElementNSImpl.hpp

tng         01/05/16 07:30:38

  Modified:    c/src/idom IDAttrNSImpl.cpp IDAttrNSImpl.hpp
                        IDElementNSImpl.cpp IDElementNSImpl.hpp
  Log:
  IDOM: Add namespace support.  By Henry Zongaro.
  
  Revision  Changes    Path
  1.3       +67 -53    xml-xerces/c/src/idom/IDAttrNSImpl.cpp
  
  Index: IDAttrNSImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/idom/IDAttrNSImpl.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDAttrNSImpl.cpp	2001/05/11 13:25:37	1.2
  +++ IDAttrNSImpl.cpp	2001/05/16 14:30:21	1.3
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: IDAttrNSImpl.cpp,v 1.2 2001/05/11 13:25:37 tng Exp $
  + * $Id: IDAttrNSImpl.cpp,v 1.3 2001/05/16 14:30:21 tng Exp $
    */
   
   #include <util/XMLUniDefs.hpp>
  @@ -66,18 +66,17 @@
   
   #include "assert.h"
   
  -static const XMLCh kEmptyString[] = {0};
  -
   IDAttrNSImpl::IDAttrNSImpl(IDOM_Document *ownerDoc, const XMLCh *nam) :
   IDAttrImpl(ownerDoc, nam)
   {
  -    this->namespaceURI=0;	//DOM Level 2
  -    this->localName=0;       //DOM Level 2
  +    this->fNamespaceURI=0;	//DOM Level 2
  +    this->fLocalName=0;       //DOM Level 2
  +    this->fPrefix=0;
   }
   
   //Introduced in DOM Level 2
   IDAttrNSImpl::IDAttrNSImpl(IDOM_Document *ownerDoc,
  -                           const XMLCh *fNamespaceURI,
  +                           const XMLCh *namespaceURI,
                              const XMLCh *qualifiedName) :
   IDAttrImpl(ownerDoc, qualifiedName)
   {
  @@ -86,39 +85,46 @@
       this->fName = ((IDDocumentImpl *)ownerDoc)->getPooledString(qualifiedName);
   
       int index = IDDocumentImpl::indexofQualifiedName(qualifiedName);
  -    const XMLCh * prefix;
       if (index < 0)
           throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
  +
       bool xmlnsAlone = false;	//true if attribute name is "xmlns"
       if (index == 0) {	//qualifiedName contains no ':'
           if (XMLString::compareString(this->fName, xmlns) == 0) {
  -            if (XMLString::compareString(fNamespaceURI, xmlnsURI) != 0)
  +            if (XMLString::compareString(namespaceURI, xmlnsURI) != 0)
                   throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
               xmlnsAlone = true;
           }
  -        prefix = 0;
  -        this -> localName = this -> fName;
  +        this -> fPrefix = 0;
  +        this -> fLocalName = this -> fName;
       } else {	//0 < index < this->name.length()-1
  +        XMLCh* newName;
           XMLCh temp[4000];
  -        assert (index < 4000);   // idom_revisit.  Do a heap allocation if this fails.
  -        XMLString::copyNString(temp, fName, index);
  -        temp[index] = 0;
  -        prefix = ((IDDocumentImpl *)ownerDoc)->getPooledString(temp);
  -        //prefix = this->fName.substringData(0, index);
  -        this -> localName = ((IDDocumentImpl *)ownerDoc)->getPooledString(fName+index+1);
  -         //   this->fName.substringData(index+1, this->fName.length()-index-1);
  +        if (index >= 3999)
  +            newName = new XMLCh[XMLString::stringLen(qualifiedName)+1];
  +        else
  +            newName = temp;
  +
  +        XMLString::copyNString(newName, fName, index);
  +        newName[index] = chNull;
  +        this-> fPrefix = ((IDDocumentImpl *)ownerDoc)->getPooledString(newName);
  +        this -> fLocalName = ((IDDocumentImpl *)ownerDoc)->getPooledString(fName+index+1);
  +
  +        if (index >= 3999)
  +            delete newName;
       }
   
       const XMLCh * URI = xmlnsAlone ?
  -                xmlnsURI : IDNodeImpl::mapPrefix(prefix, fNamespaceURI, IDOM_Node::ATTRIBUTE_NODE);
  -    this -> namespaceURI = URI == 0 ? kEmptyString : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
  +                xmlnsURI : IDNodeImpl::mapPrefix(fPrefix, namespaceURI, IDOM_Node::ATTRIBUTE_NODE);
  +    this -> fNamespaceURI = URI == 0 ? XMLUni::fgZeroLenString : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
   };
   
   IDAttrNSImpl::IDAttrNSImpl(const IDAttrNSImpl &other, bool deep) :
   IDAttrImpl(other, deep)
   {
  -    this->namespaceURI = other.namespaceURI;	//DOM Level 2
  -    this->localName = other.localName;          //DOM Level 2
  +    this->fNamespaceURI = other.fNamespaceURI;	//DOM Level 2
  +    this->fLocalName = other.fLocalName;          //DOM Level 2
  +    this->fPrefix = other.fPrefix;
   };
   
   IDOM_Node * IDAttrNSImpl::cloneNode(bool deep) const
  @@ -128,64 +134,72 @@
   
   const XMLCh * IDAttrNSImpl::getNamespaceURI() const
   {
  -    return namespaceURI;
  +    return fNamespaceURI;
   }
   
   const XMLCh * IDAttrNSImpl::getPrefix() const
   {
  -    //  idom_revisit.  Get fPrefix set correctly at the start of time.
  -    if (fPrefix)
  -        return fPrefix;
  -
  -    int index = IDDocumentImpl::indexofQualifiedName(fName);
  -    if (index == 0)
  -        return 0;
  -
  -    IDAttrNSImpl *This = (IDAttrNSImpl *)this;   // cast off const.
  -    This->fPrefix = new (getOwnerDocument()) XMLCh[index+1];
  -    XMLString::copyNString(fPrefix, fName, index);
  -    fPrefix[index] = 0;
       return fPrefix;
   }
   
   const XMLCh * IDAttrNSImpl::getLocalName() const
   {
  -    return localName;
  +    return fLocalName;
   }
   
   void IDAttrNSImpl::setPrefix(const XMLCh *prefix)
   {
  -#ifdef idom_revist
  -    const XMLCh * xml = IDOM_Node::getXmlString();
  -    const XMLCh * xmlURI = IDOM_Node::getXmlURIString();
  -    const XMLCh * xmlns = IDOM_Node::getXmlnsString();
  -    const XMLCh * xmlnsURI = IDOM_Node::getXmlnsURIString();
  +    const XMLCh * xml = IDNodeImpl::getXmlString();
  +    const XMLCh * xmlURI = IDNodeImpl::getXmlURIString();
  +    const XMLCh * xmlns = IDNodeImpl::getXmlnsString();
  +    const XMLCh * xmlnsURI = IDNodeImpl::getXmlnsURIString();
   
       if (fNode.isReadOnly())
           throw IDOM_DOMException(IDOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
           0);
  -    if (namespaceURI == 0 || localName.equals(xmlns))
  +    if (fNamespaceURI == 0 || XMLString::compareString(fLocalName, xmlns) == 0)
           throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
   
  -    if (prefix != 0 && !DocumentImpl::isXMLName(prefix))
  +    if (prefix != 0 && !IDDocumentImpl::isXMLName(prefix))
           throw IDOM_DOMException(IDOM_DOMException::INVALID_CHARACTER_ERR,0);
   
  -    if (prefix == 0 || prefix.length() == 0) {
  -        name = localName;
  +    if (prefix == 0 || prefix[0] == chNull) {
  +        fName = fLocalName;
  +        fPrefix = 0;
           return;
       }
   
  -    if (prefix.equals(xml) && !namespaceURI.equals(xmlURI) ||
  -        prefix.equals(xmlns) && !namespaceURI.equals(xmlnsURI))
  +    if (XMLString::compareString(prefix, xml) == 0 &&
  +        XMLString::compareString(fNamespaceURI, xmlURI) != 0 ||
  +        XMLString::compareString(prefix, xmlns) == 0 &&
  +        XMLString::compareString(fNamespaceURI, xmlnsURI) != 0)
           throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
   
  -    const XMLCh *p = prefix.rawBuffer();
  -    for (int i = prefix.length(); --i >= 0;) {
  -        if (*p++ == chColon)	//prefix is malformed
  -            throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
  +    if (XMLString::indexOf(prefix, chColon) != -1) {
  +        throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
       }
  +
  +    this-> fPrefix = ((IDDocumentImpl *)this->getOwnerDocument())->getPooledString(prefix);
  +
  +    int prefixLen = XMLString::stringLen(prefix);
  +    XMLCh *newName;
  +    XMLCh temp[1000];
  +    int newQualifiedNameLen = prefixLen+1+XMLString::stringLen(fLocalName);
  +
  +    if (newQualifiedNameLen >= 999)
  +        newName = new XMLCh[newQualifiedNameLen + 1];
  +    else
  +        newName = temp;
  +
  +    // newName = prefix + chColon + fLocalName;
  +    XMLString::copyString(newName, prefix);
  +    newName[prefixLen] = chColon;
  +    XMLString::copyString(&newName[prefixLen+1], fLocalName);
  +
  +    fName = ((IDDocumentImpl *)this->getOwnerDocument())->
  +                                           getPooledString(newName);
  +
  +    if (newQualifiedNameLen < 1000)
  +        delete newName;
   
  -    name = prefix + chColon + localName; //nodeName is changed too
  -#endif
  -    assert(false);  // idom_revisit   setPrefix not implemented yet.
   }
  
  
  
  1.3       +5 -5      xml-xerces/c/src/idom/IDAttrNSImpl.hpp
  
  Index: IDAttrNSImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/idom/IDAttrNSImpl.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDAttrNSImpl.hpp	2001/05/11 13:25:37	1.2
  +++ IDAttrNSImpl.hpp	2001/05/16 14:30:23	1.3
  @@ -58,7 +58,7 @@
    */
   
   /*
  - * $Id: IDAttrNSImpl.hpp,v 1.2 2001/05/11 13:25:37 tng Exp $
  + * $Id: IDAttrNSImpl.hpp,v 1.3 2001/05/16 14:30:23 tng Exp $
    */
   
   //
  @@ -77,9 +77,9 @@
   class CDOM_EXPORT IDAttrNSImpl: public IDAttrImpl {
   protected:
       //Introduced in DOM Level 2
  -    const XMLCh * namespaceURI;     //namespace URI of this node
  -    const XMLCh * localName;        //local part of qualified name
  -          XMLCh * fPrefix;           // prefix part of qualified name
  +    const XMLCh * fNamespaceURI;     //namespace URI of this node
  +    const XMLCh * fLocalName;        //local part of qualified name
  +    const XMLCh * fPrefix;           // prefix part of qualified name
                              // idom_revisit - can return local part
                              //    by pointing into the qualified (L1) name.
   
  @@ -91,7 +91,7 @@
   
       virtual IDOM_Node * cloneNode(bool deep) const;
       //Introduced in DOM Level 2
  -    virtual const XMLCh *	getNamespaceURI() const;
  +    virtual const XMLCh *   getNamespaceURI() const;
       virtual const XMLCh *   getPrefix() const;
       virtual const XMLCh *   getLocalName() const;
       virtual void            setPrefix(const XMLCh *prefix);
  
  
  
  1.3       +44 -48    xml-xerces/c/src/idom/IDElementNSImpl.cpp
  
  Index: IDElementNSImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/idom/IDElementNSImpl.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDElementNSImpl.cpp	2001/05/11 13:25:42	1.2
  +++ IDElementNSImpl.cpp	2001/05/16 14:30:25	1.3
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: IDElementNSImpl.cpp,v 1.2 2001/05/11 13:25:42 tng Exp $
  + * $Id: IDElementNSImpl.cpp,v 1.3 2001/05/16 14:30:25 tng Exp $
    */
   
   #include <util/XMLUniDefs.hpp>
  @@ -68,6 +68,7 @@
   {
       this->fNamespaceURI=0;	  //DOM Level 2
       this->fLocalName=0;       //DOM Level 2
  +    this->fPrefix=0;
   }
   
   //Introduced in DOM Level 2
  @@ -76,38 +77,34 @@
                                const XMLCh *qualifiedName) :
       IDElementImpl(ownerDoc, qualifiedName)
   {
  -    const XMLCh * xmlns = IDNodeImpl::getXmlnsString();
  -    const XMLCh * xmlnsURI = IDNodeImpl::getXmlnsURIString();
  +    this->fName = ((IDDocumentImpl *)ownerDoc)->getPooledString(qualifiedName);
   
  -    //  What the hell is this?  idom_revisit
  -    // this->ownerDocument=ownerDoc;
  -    // this->name = qualifiedName.clone();
  -
       int index = IDDocumentImpl::indexofQualifiedName(qualifiedName);
  -    const XMLCh * prefix;
       if (index < 0)
           throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
  +
       if (index == 0) {	//qualifiedName contains no ':'
  -        prefix = 0;
  +        this -> fPrefix = 0;
           this -> fLocalName = this -> fName;
       } else {	//0 < index < this->name.length()-1
  -        XMLCh *nonConstfName = (XMLCh *)fName;
  -        XMLCh t = fName[index];          // Temporarily put a null in the middle
  -        nonConstfName[index] = 0;        //   of the source string, splitting it in two.
  -
  -        prefix = ((IDDocumentImpl *)ownerDoc)->getPooledString(fName);
  -        // prefix = this->name.substringData(0, index);
  -
  -        fLocalName = ((IDDocumentImpl *)ownerDoc)->getPooledString(&fName[index+1]);
  -        //this -> localName =
  -        //    this->name.substringData(index+1, this->name.length()-index-1);
  +        XMLCh* newName;
  +        XMLCh temp[4000];
  +        if (index >= 3999)
  +            newName = new XMLCh[XMLString::stringLen(qualifiedName)+1];
  +        else
  +            newName = temp;
  +
  +        XMLString::copyNString(newName, fName, index);
  +        newName[index] = chNull;
  +        this-> fPrefix = ((IDDocumentImpl *)ownerDoc)->getPooledString(newName);
  +        this -> fLocalName = ((IDDocumentImpl *)ownerDoc)->getPooledString(fName+index+1);
   
  -        nonConstfName[index] = t;  // put what is probably the ':' back into the
  -                                   //   original name.
  +        if (index >= 3999)
  +            delete newName;
       }
   
  -    const XMLCh *pooledURI = ((IDDocumentImpl *)ownerDoc)->getPooledString(namespaceURI);
  -    fNamespaceURI = IDNodeImpl::mapPrefix(prefix, pooledURI, IDOM_Node::ELEMENT_NODE);
  +    const XMLCh * URI = IDNodeImpl::mapPrefix(fPrefix, namespaceURI, IDOM_Node::ELEMENT_NODE);
  +    this -> fNamespaceURI = URI == 0 ? XMLUni::fgZeroLenString : ((IDDocumentImpl *)ownerDoc)->getPooledString(URI);
   };
   
   IDElementNSImpl::IDElementNSImpl(const IDElementNSImpl &other, bool deep) :
  @@ -115,6 +112,7 @@
   {
       this->fNamespaceURI = other.fNamespaceURI;	        //DOM Level 2
       this->fLocalName = other.fLocalName;                //DOM Level 2
  +    this->fPrefix = other.fPrefix;
   };
   
   IDOM_Node * IDElementNSImpl::cloneNode(bool deep) const {
  @@ -128,20 +126,7 @@
   
   const XMLCh * IDElementNSImpl::getPrefix() const
   {
  -    int index = IDDocumentImpl::indexofQualifiedName(fName);
  -    if (index == 0)
  -        return 0;
  -
  -    // idom_revist.  We should probably add a prefix field to name space nodes.
  -    //               But for now, extract off the prefix from the qname,
  -    //               and then get from the name pool
  -    XMLCh temp[1000];
  -    if (index >= 999) index = 999;  //  idom_revisit.  This can't just fail like this.
  -    XMLString::copyNString(temp, fName, index);
  -    temp[index] = 0;
  -    IDDocumentImpl *doc = (IDDocumentImpl *)this->getOwnerDocument();
  -    const XMLCh *retPtr = doc->getPooledString(temp);
  -    return retPtr;
  +    return fPrefix;
   }
   
   
  @@ -154,8 +139,6 @@
   {
       const XMLCh * xml      = IDNodeImpl::getXmlString();
       const XMLCh * xmlURI   = IDNodeImpl::getXmlURIString();
  -    const XMLCh * xmlns    = IDNodeImpl::getXmlnsString();
  -    const XMLCh * xmlnsURI = IDNodeImpl::getXmlnsURIString();
   
       if (fNode.isReadOnly())
           throw IDOM_DOMException(IDOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
  @@ -179,14 +162,27 @@
       if (XMLString::indexOf(prefix, chColon) != -1) {
           throw IDOM_DOMException(IDOM_DOMException::NAMESPACE_ERR, 0);
       }
  +
  +    this-> fPrefix = ((IDDocumentImpl *)this->getOwnerDocument())->getPooledString(prefix);
  +
  +    int prefixLen = XMLString::stringLen(prefix);
  +    XMLCh *newName;
  +    XMLCh temp[1000];
  +    int newQualifiedNameLen = prefixLen+1+XMLString::stringLen(fLocalName);
  +
  +    if (newQualifiedNameLen >= 999)
  +        newName = new XMLCh[newQualifiedNameLen + 1];
  +    else
  +        newName = temp;
  +
  +    // newName = prefix + chColon + fLocalName;
  +    XMLString::copyString(newName, prefix);
  +    newName[prefixLen] = chColon;
  +    XMLString::copyString(&newName[prefixLen+1], fLocalName);
  +
  +    fName = ((IDDocumentImpl *)this->getOwnerDocument())->
  +                                           getPooledString(newName);
   
  -    // node name is changed too, to be  "newPrefix:localName"
  -    // idom_revisit.  Add code for case when names are too long to be held
  -    //                in the temp stack buffer.
  -    XMLCh   temp[1000];
  -    XMLString::copyString(temp, prefix);
  -    temp[XMLString::stringLen(prefix)] = chColon;
  -    XMLString::catString(temp, fLocalName);
  -    IDDocumentImpl *doc = (IDDocumentImpl *)this->getOwnerDocument();
  -    fName = doc->getPooledString(temp);
  +    if (newQualifiedNameLen < 1000)
  +        delete newName;
   }
  
  
  
  1.3       +2 -1      xml-xerces/c/src/idom/IDElementNSImpl.hpp
  
  Index: IDElementNSImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/idom/IDElementNSImpl.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDElementNSImpl.hpp	2001/05/11 13:25:42	1.2
  +++ IDElementNSImpl.hpp	2001/05/16 14:30:26	1.3
  @@ -58,7 +58,7 @@
    */
   
   /*
  - * $Id: IDElementNSImpl.hpp,v 1.2 2001/05/11 13:25:42 tng Exp $
  + * $Id: IDElementNSImpl.hpp,v 1.3 2001/05/16 14:30:26 tng Exp $
    */
   
   //
  @@ -79,6 +79,7 @@
       //Introduced in DOM Level 2
       const XMLCh * fNamespaceURI;     //namespace URI of this node
       const XMLCh * fLocalName;        //local part of qualified name
  +    const XMLCh * fPrefix;
   
   
   public:
  
  
  

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