DOMNode *DOMAttrMapImpl::removeNamedItem(const XMLCh *name) { if (this->readOnly()) throw DOMException( DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager); int i=findNamePoint(name); DOMNode *removed = 0; if(i<0) throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager); removed = fNodes->elementAt(i); fNodes->removeElementAt(i); castToNodeImpl(removed)->fOwnerNode = fOwnerNode->getOwnerDocument(); castToNodeImpl(removed)->isOwned(false); // 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; }
// remove the name using index // avoid calling findNamePoint again if the index is already known DOMNode * DOMAttrMapImpl::removeNamedItemAt(XMLSize_t index) { DOMNode* removed = DOMNamedNodeMapImpl::removeNamedItemAt(index); // Replace it if it had a default value // (DOM spec level 1 - Element Interface) if (hasDefaults() && (removed != 0)) { DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes(); const XMLCh* localName = removed->getLocalName(); DOMAttr* attr = 0; if (localName) attr = (DOMAttr*)(defAttrs->getNamedItemNS(removed->getNamespaceURI(), localName)); else attr = (DOMAttr*)(defAttrs->getNamedItem(((DOMAttr*)removed)->getName())); if (attr != 0) { DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true); setNamedItem(newAttr); } } return removed; }
/** * 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
// // setNamedItemNS() Put the item into the NamedNodeList by name. // If an item with the same name already was // in the list, replace it. Return the old // item, if there was one. // Caller is responsible for arranging for // deletion of the old item if its ref count is // zero. // DOMNode * DOMNamedNodeMapImpl::setNamedItemNS(DOMNode *arg) { DOMDocument *doc = fOwnerNode->getOwnerDocument(); DOMNodeImpl *argImpl = castToNodeImpl(arg); if (argImpl->getOwnerDocument() != doc) throw DOMException(DOMException::WRONG_DOCUMENT_ERR,0, GetDOMNamedNodeMapMemoryManager); if (this->readOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager); if (argImpl->isOwned()) throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR,0, GetDOMNamedNodeMapMemoryManager); argImpl->fOwnerNode = fOwnerNode; argImpl->isOwned(true); const XMLCh* namespaceURI=arg->getNamespaceURI(); const XMLCh* localName=arg->getLocalName(); // the map is indexed using the full name of nodes; to search given a namespace and a local name // we have to do a linear search for (int index = 0; index < MAP_SIZE; index++) { if(fBuckets[index]==0) continue; int i = 0; int size = fBuckets[index]->size(); for (i = 0; i < size; ++i) { DOMNode *n=fBuckets[index]->elementAt(i); const XMLCh * nNamespaceURI = n->getNamespaceURI(); const XMLCh * nLocalName = n->getLocalName(); if (!XMLString::equals(nNamespaceURI, namespaceURI)) //URI not match continue; else { if (XMLString::equals(localName, nLocalName) || (nLocalName == 0 && XMLString::equals(localName, n->getNodeName()))) { fBuckets[index]->setElementAt(arg,i); castToNodeImpl(n)->fOwnerNode = fOwnerNode->getOwnerDocument(); castToNodeImpl(n)->isOwned(false); return n; } } } } // if not found, add it using the full name as key return setNamedItem(arg); }
DOMNode *DOMAttrMapImpl::removeNamedItem(const XMLCh *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); } } return removed; }
NodeImpl *AttrMapImpl::removeNamedItemNS(const DOMString &namespaceURI, const DOMString &localName) { NodeImpl* removed = NamedNodeMapImpl::removeNamedItemNS(namespaceURI, localName); // Replace it if it had a default value // (DOM spec level 2 - Element Interface) if (hasDefaults() && (removed != null)) { AttrMapImpl* defAttrs = ((ElementImpl*)ownerNode)->getDefaultAttributes(); AttrImpl* attr = (AttrImpl*)(defAttrs->getNamedItemNS(namespaceURI, localName)); if (attr != null) { AttrImpl* newAttr = (AttrImpl*)attr->cloneNode(true); setNamedItem(newAttr); } } return removed; }
// remove the name using index // avoid calling findNamePoint again if the index is already known DOMNode * DOMAttrMapImpl::removeNamedItemAt(XMLSize_t index) { if (this->readOnly()) throw DOMException( DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager); DOMNode *removed = item(index); if(!removed) throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager); fNodes->removeElementAt(index); castToNodeImpl(removed)->fOwnerNode = fOwnerNode->getOwnerDocument(); castToNodeImpl(removed)->isOwned(false); // Replace it if it had a default value // (DOM spec level 1 - Element Interface) if (hasDefaults() && (removed != 0)) { DOMAttrMapImpl* defAttrs = ((DOMElementImpl*)fOwnerNode)->getDefaultAttributes(); const XMLCh* localName = removed->getLocalName(); DOMAttr* attr = 0; if (localName) attr = (DOMAttr*)(defAttrs->getNamedItemNS(removed->getNamespaceURI(), localName)); else attr = (DOMAttr*)(defAttrs->getNamedItem(((DOMAttr*)removed)->getName())); if (attr != 0) { DOMAttr* newAttr = (DOMAttr*)attr->cloneNode(true); setNamedItem(newAttr); } } return removed; }
Attr * setNamedAttr(Attr * arg) throw(DOMException) { return dynamic_cast<Attr*>(setNamedItem(arg)); }