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 2002/07/04 17:34:42 UTC

cvs commit: xml-xerces/c/src/xercesc/dom/impl DOMAttrMapImpl.cpp DOMAttrMapImpl.hpp

tng         2002/07/04 08:34:42

  Modified:    c/src/xercesc/dom/impl DOMAttrMapImpl.cpp DOMAttrMapImpl.hpp
  Log:
  DOM L3: add DOMDocument::renameNode
  
  Revision  Changes    Path
  1.2       +91 -30    xml-xerces/c/src/xercesc/dom/impl/DOMAttrMapImpl.cpp
  
  Index: DOMAttrMapImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMAttrMapImpl.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMAttrMapImpl.cpp	21 May 2002 20:29:32 -0000	1.1
  +++ DOMAttrMapImpl.cpp	4 Jul 2002 15:34:42 -0000	1.2
  @@ -60,6 +60,7 @@
    */
   
   #include "DOMAttrMapImpl.hpp"
  +#include "DOMAttrImpl.hpp"
   #include "DOMNamedNodeMapImpl.hpp"
   #include "DOMNodeImpl.hpp"
   #include "DOMElementImpl.hpp"
  @@ -101,40 +102,100 @@
   
   DOMNode *DOMAttrMapImpl::removeNamedItem(const XMLCh *name)
   {
  -	DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItem(name);
  +    DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItem(name);
   
  -	// Replace it if it had a default value
  -	// (DOM spec level 1 - Element Interface)
  -	if (hasDefaults() && (removed != 0))
  -	{
  -		DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
  -		DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItem(name));
  -		if (attr != 0)
  -		{
  -			DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
  -			setNamedItem(newAttr);
  -		}
  -	}
  +    // Replace it if it had a default value
  +    // (DOM spec level 1 - Element Interface)
  +    if (hasDefaults() && (removed != 0))
  +    {
  +        DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
  +        DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItem(name));
  +        if (attr != 0)
  +        {
  +            DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
  +            setNamedItem(newAttr);
  +        }
  +    }
   
  -	return removed;
  +    return removed;
   }
   
   DOMNode *DOMAttrMapImpl::removeNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName)
   {
  -	DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItemNS(namespaceURI, localName);
  +    DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItemNS(namespaceURI, localName);
   
  -	// Replace it if it had a default value
  -	// (DOM spec level 2 - Element Interface)
  -	if (hasDefaults() && (removed != 0))
  -	{
  -		DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
  -		DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItemNS(namespaceURI, localName));
  -		if (attr != 0)
  -		{
  -			DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
  -			setNamedItem(newAttr);
  -		}
  -	}
  +    // Replace it if it had a default value
  +    // (DOM spec level 2 - Element Interface)
  +
  +    if (hasDefaults() && (removed != 0))
  +    {
  +        DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes();
  +        DOMAttr* attr = (DOMAttr*)(defAttrs->getNamedItemNS(namespaceURI, localName));
  +        if (attr != 0)
  +        {
  +            DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
  +            setNamedItemNS(newAttr);
  +        }
  +    }
  +
  +    return removed;
  +}
  +
  +/**
  + * Get this AttributeMap in sync with the given "defaults" map.
  + * @param defaults The default attributes map to sync with.
  + */
  +void DOMAttrMapImpl::reconcileDefaultAttributes(const DOMAttrMapImpl* defaults) {
  +
  +    // remove any existing default
  +    XMLSize_t nsize = getLength();
  +    for (XMLSSize_t i = nsize - 1; i >= 0; i--) {
  +        DOMAttr* attr = (DOMAttr*)item(i);
  +        if (!attr->getSpecified()) {
  +            removeNamedItemAt(i);
  +        }
  +    }
  +
  +    hasDefaults(false);
  +
  +    // add the new defaults
  +    if (defaults) {
  +        hasDefaults(true);
  +
  +        if (nsize == 0) {
  +            cloneContent(defaults);
  +        }
  +        else {
  +            XMLSize_t dsize = defaults->getLength();
  +            for (XMLSize_t n = 0; n < dsize; n++) {
  +                DOMAttr* attr = (DOMAttr*)defaults->item(n);
  +
  +                DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true);
  +                setNamedItemNS(newAttr);
  +                DOMAttrImpl* newAttrImpl = (DOMAttrImpl*) newAttr;
  +                newAttrImpl->setSpecified(false);
  +            }
  +        }
  +    }
  +} // reconcileDefaults()
  +
  +
  +/**
  + * Move specified attributes from the given map to this one
  + */
  +void DOMAttrMapImpl::moveSpecifiedAttributes(DOMAttrMapImpl* srcmap) {
  +    XMLSize_t nsize = srcmap->getLength();
  +
  +    for (XMLSSize_t i = nsize - 1; i >= 0; i--) {
  +        DOMAttr* attr = (DOMAttr*)srcmap->item(i);
  +        if (attr->getSpecified()) {
  +            srcmap->removeNamedItemAt(i);
  +        }
  +
  +        if (attr->getLocalName())
  +            setNamedItemNS(attr);
  +        else
  +            setNamedItem(attr);
  +    }
  +} // moveSpecifiedAttributes(AttributeMap):void
   
  -	return removed;
  -}
  
  
  
  1.2       +13 -13    xml-xerces/c/src/xercesc/dom/impl/DOMAttrMapImpl.hpp
  
  Index: DOMAttrMapImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMAttrMapImpl.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMAttrMapImpl.hpp	21 May 2002 20:29:32 -0000	1.1
  +++ DOMAttrMapImpl.hpp	4 Jul 2002 15:34:42 -0000	1.2
  @@ -80,24 +80,27 @@
   class CDOM_EXPORT DOMAttrMapImpl : public DOMNamedNodeMapImpl
   {
   private:
  -	//  bool attrDefaults;    // revisit.  Move up to the owning element level.
  +    bool attrDefaults;
   
   public:
  -	DOMAttrMapImpl(DOMNode *ownerNod);
  +    DOMAttrMapImpl(DOMNode *ownerNod);
   
       // revisit.  This "copy" constructor is used for cloning an Element with Attributes,
       //                and for setting up default attributes.  It's probably not right
       //                for one or the other or both.
  -	DOMAttrMapImpl(DOMNode *ownerNod, const DOMNamedNodeMapImpl *defaults);
  -	DOMAttrMapImpl();
  +    DOMAttrMapImpl(DOMNode *ownerNod, const DOMNamedNodeMapImpl *defaults);
  +    DOMAttrMapImpl();
   
       virtual ~DOMAttrMapImpl();
  -	virtual DOMAttrMapImpl *cloneAttrMap(DOMNode *ownerNode);
  -	virtual bool hasDefaults();
  -	virtual void hasDefaults(bool value);
  +    virtual DOMAttrMapImpl *cloneAttrMap(DOMNode *ownerNode);
  +    virtual bool hasDefaults();
  +    virtual void hasDefaults(bool value);
   
       virtual DOMNode *removeNamedItem(const XMLCh *name);
       virtual DOMNode *removeNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName);
  +
  +    void reconcileDefaultAttributes(const DOMAttrMapImpl* defaults);
  +    void moveSpecifiedAttributes(DOMAttrMapImpl* srcmap);
   };
   
   // ---------------------------------------------------------------------------
  @@ -106,15 +109,12 @@
   
   inline bool DOMAttrMapImpl::hasDefaults()
   {
  -    //   revisit.   Put a flag on the element for this value.
  -	// return attrDefaults;
  -    return false;
  +    return attrDefaults;
   }
   
   inline void DOMAttrMapImpl::hasDefaults(bool value)
   {
  -    //   revisit.  Put a flag on the Element for this value.
  -	//  attrDefaults = value;
  +    attrDefaults = value;
   }
   
   
  
  
  

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