/** * 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()
// 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; }
DOMNode *DOMAttrMapImpl::removeNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName) { if (this->readOnly()) throw DOMException( DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager); int i = findNamePoint(namespaceURI, localName); if (i < 0) throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager); DOMNode * removed = fNodes -> elementAt(i); fNodes -> removeElementAt(i); //remove n from nodes castToNodeImpl(removed)->fOwnerNode = fOwnerNode->getOwnerDocument(); castToNodeImpl(removed)->isOwned(false); // 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; }
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; }
// 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; }