DOMElementNSImpl::DOMElementNSImpl(DOMDocument *ownerDoc, const XMLCh *namespaceURI, const XMLCh *prefix, const XMLCh *localName, const XMLCh *qualifiedName) : DOMElementImpl(ownerDoc, qualifiedName) { this->fSchemaType = 0; DOMDocumentImpl* docImpl = (DOMDocumentImpl*)fParent.fOwnerDocument; if (prefix == 0 || *prefix == 0) { fPrefix = 0; fLocalName = fName; } else { fPrefix = docImpl->getPooledString(prefix); fLocalName = docImpl->getPooledString(localName); } // DOM Level 3: namespace URI is never empty string. // const XMLCh * URI = DOMNodeImpl::mapPrefix ( fPrefix, (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI, DOMNode::ELEMENT_NODE); fNamespaceURI = (URI == 0) ? 0 : docImpl->getPooledString(URI); }
void DOMElementNSImpl::setPrefix(const XMLCh *prefix) { if (fNode.isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); if (fNamespaceURI == 0 || fNamespaceURI[0] == chNull) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); if (prefix == 0 || *prefix == 0) { fPrefix = 0; fName = fLocalName; return; } DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument; if(!doc->isXMLName(prefix)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0, GetDOMNodeMemoryManager); const XMLCh * xml = DOMNodeImpl::getXmlString(); const XMLCh * xmlURI = DOMNodeImpl::getXmlURIString(); if (XMLString::equals(prefix, xml) && !XMLString::equals(fNamespaceURI, xmlURI)) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); if (XMLString::indexOf(prefix, chColon) != -1) { throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); } this-> fPrefix = doc->getPooledString(prefix); XMLSize_t prefixLen = XMLString::stringLen(prefix); XMLSize_t newQualifiedNameLen = prefixLen+1+XMLString::stringLen(fLocalName); XMLCh *newName; XMLCh temp[256]; if (newQualifiedNameLen >= 255) newName = (XMLCh*) doc->getMemoryManager()->allocate ( newQualifiedNameLen * sizeof(XMLCh) );//new XMLCh[newQualifiedNameLen]; else newName = temp; // newName = prefix + chColon + fLocalName; XMLString::copyString(newName, prefix); newName[prefixLen] = chColon; XMLString::copyString(&newName[prefixLen+1], fLocalName); fName = doc->getPooledString(newName); if (newQualifiedNameLen >= 255) doc->getMemoryManager()->deallocate(newName);//delete[] newName; }
void DOMAttrNSImpl::setName(const XMLCh* namespaceURI, const XMLCh* qualifiedName) { DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) getOwnerDocument(); const XMLCh * xmlns = DOMNodeImpl::getXmlnsString(); const XMLCh * xmlnsURI = DOMNodeImpl::getXmlnsURIString(); this->fName = ownerDoc->getPooledString(qualifiedName); int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName); if (index < 0) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); bool xmlnsAlone = false; //true if attribute name is "xmlns" if (index == 0) { //qualifiedName contains no ':' if (XMLString::equals(this->fName, xmlns)) { if (!XMLString::equals(namespaceURI, xmlnsURI)) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); xmlnsAlone = true; } this -> fPrefix = 0; this -> fLocalName = this -> fName; } else { //0 < index < this->name.length()-1 XMLCh* newName; XMLCh temp[4000]; if (index >= 3999) newName = (XMLCh*) ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()->allocate ( (XMLString::stringLen(qualifiedName) + 1) * sizeof(XMLCh) );//new XMLCh[XMLString::stringLen(qualifiedName)+1]; else newName = temp; XMLString::copyNString(newName, fName, index); newName[index] = chNull; this-> fPrefix = ownerDoc->getPooledString(newName); this -> fLocalName = ownerDoc->getPooledString(fName+index+1); if (index >= 3999) ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()->deallocate(newName);//delete[] newName; // Before we carry on, we should check if the prefix or localName are valid XMLName if (!((DOMDocumentImpl *)this->getOwnerDocument())->isXMLName(fPrefix) || !((DOMDocumentImpl *)this->getOwnerDocument())->isXMLName(fLocalName)) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); } // DOM Level 3: namespace URI is never empty string. const XMLCh * URI = xmlnsAlone ? xmlnsURI : DOMNodeImpl::mapPrefix ( fPrefix, (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI, DOMNode::ATTRIBUTE_NODE ); this -> fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI); }
/** * NON-DOM * set the ownerDocument of this node and its children */ void DOMDocumentTypeImpl::setOwnerDocument(DOMDocument *doc) { if (castToNodeImpl(this)->getOwnerDocument()) { fNode.setOwnerDocument(doc); fParent.setOwnerDocument(doc); } else { if (doc) { DOMDocumentImpl *docImpl = (DOMDocumentImpl *)doc; fPublicId = docImpl->cloneString(fPublicId); fSystemId = docImpl->cloneString(fSystemId); fInternalSubset = docImpl->cloneString(fInternalSubset); fName = docImpl->getPooledString(fName); fNode.setOwnerDocument(doc); fParent.setOwnerDocument(doc); DOMNamedNodeMapImpl* entitiesTemp = fEntities->cloneMap(this); DOMNamedNodeMapImpl* notationsTemp = fNotations->cloneMap(this); DOMNamedNodeMapImpl* elementsTemp = fElements->cloneMap(this); fEntities = entitiesTemp; fNotations = notationsTemp; fElements = elementsTemp; } } }
const XMLCh * DOMAttrImpl::getValue() const { if (fParent.fFirstChild == 0) { return XMLUni::fgZeroLenString; // return ""; } // Simple case where attribute value is just a single text node DOMNode *node = castToChildImpl(fParent.fFirstChild)->nextSibling; if (node == 0 && fParent.fFirstChild->getNodeType() == DOMNode::TEXT_NODE) { return fParent.fFirstChild->getNodeValue(); } // // Complicated case where attribute value is a DOM tree // // According to the spec, the child nodes of the Attr node may be either // Text or EntityReference nodes. // // The parser will not create such thing, this is for those created by users. // // In such case, we have to visit each child to retrieve the text // DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument; XMLBuffer buf(1023, doc->getMemoryManager()); for (node = fParent.fFirstChild; node != 0; node = castToChildImpl(node)->nextSibling) getTextValue(node, buf); return doc->getPooledString(buf.getRawBuffer()); }
//DOM Level 2 DOMDeepNodeListImpl::DOMDeepNodeListImpl(const DOMNode *rootNode, const XMLCh *namespaceURI, const XMLCh *localName) : fRootNode(rootNode) , fChanges(0) , fCurrentNode(0) , fCurrentIndexPlus1(0) , fMatchAllURI(false) , fMatchURIandTagname(true) { DOMDocumentImpl* doc = (DOMDocumentImpl *)castToNodeImpl(rootNode)->getOwnerDocument(); fTagName = doc->getPooledString(localName); fMatchAll = XMLString::equals(fTagName, kAstr); fMatchAllURI = XMLString::equals(namespaceURI, kAstr); fNamespaceURI = doc->getPooledString(namespaceURI); }
void DOMElementNSImpl::setName(const XMLCh *namespaceURI, const XMLCh *qualifiedName) { DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) getOwnerDocument(); this->fName = ownerDoc->getPooledString(qualifiedName); int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName); if (index < 0) throw DOMException(DOMException::NAMESPACE_ERR, 0); if (index == 0) { //qualifiedName contains no ':' this -> fPrefix = 0; this -> fLocalName = this -> fName; } else { //0 < index < this->name.length()-1 XMLCh* newName; XMLCh temp[4000]; if (index >= 3999) newName = (XMLCh*) ownerDoc->getMemoryManager()->allocate ( (XMLString::stringLen(qualifiedName) + 1) * sizeof(XMLCh) );//new XMLCh[XMLString::stringLen(qualifiedName)+1]; else newName = temp; XMLString::copyNString(newName, fName, index); newName[index] = chNull; this-> fPrefix = ownerDoc->getPooledString(newName); this -> fLocalName = ownerDoc->getPooledString(fName+index+1); if (index >= 3999) ownerDoc->getMemoryManager()->deallocate(newName);//delete[] newName; // Before we carry on, we should check if the prefix or localName are valid XMLName if (!((DOMDocumentImpl *)this->getOwnerDocument())->isXMLName(fPrefix) || !((DOMDocumentImpl *)this->getOwnerDocument())->isXMLName(fLocalName)) throw DOMException(DOMException::NAMESPACE_ERR, 0); } // DOM Level 3: namespace URI is never empty string. const XMLCh * URI = DOMNodeImpl::mapPrefix ( fPrefix, (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI, DOMNode::ELEMENT_NODE ); this -> fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI); }
XERCES_CPP_NAMESPACE_BEGIN DOMAttrImpl::DOMAttrImpl(DOMDocument *ownerDoc, const XMLCh *aName) : fNode(ownerDoc), fParent (ownerDoc), fSchemaType(0) { DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc; fName = docImpl->getPooledString(aName); fNode.isSpecified(true); }
DOMElementImpl::DOMElementImpl(DOMDocument *ownerDoc, const XMLCh *eName) : fNode(ownerDoc), fParent(ownerDoc), fAttributes(0), fDefaultAttributes(0), fSchemaType(0) { DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc; fName = docImpl->getPooledString(eName); setupDefaultAttributes(); if (!fDefaultAttributes) { fDefaultAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this); fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this); } else { fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this, fDefaultAttributes); } }
DOMNode* DOMElementImpl::rename(const XMLCh* namespaceURI, const XMLCh* name) { DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument; if (!namespaceURI || !*namespaceURI) { fName = doc->getPooledString(name); fAttributes->reconcileDefaultAttributes(getDefaultAttributes()); // and fire user data NODE_RENAMED event castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this); return this; } else { // create a new ElementNS DOMElementNSImpl* newElem = (DOMElementNSImpl*)doc->createElementNS(namespaceURI, name); // transfer the userData doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newElem)); // remove old node from parent if any DOMNode* parent = getParentNode(); DOMNode* nextSib = getNextSibling(); if (parent) { parent->removeChild(this); } // move children to new node DOMNode* child = getFirstChild(); while (child) { removeChild(child); newElem->appendChild(child); child = getFirstChild(); } // insert new node where old one was if (parent) { parent->insertBefore(newElem, nextSib); } // move specified attributes to new node newElem->fAttributes->moveSpecifiedAttributes(fAttributes); // and fire user data NODE_RENAMED event castToNodeImpl(newElem)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newElem); return newElem; } }
void DOMElementNSImpl::setName(const XMLCh *namespaceURI, const XMLCh *qualifiedName) { DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) fParent.fOwnerDocument; this->fName = ownerDoc->getPooledString(qualifiedName); int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName); if (index < 0) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); if (index == 0) { //qualifiedName contains no ':' // fPrefix = 0; fLocalName = fName; } else { //0 < index < this->name.length()-1 // fPrefix = ownerDoc->getPooledNString(qualifiedName, index); fLocalName = ownerDoc->getPooledString(fName+index+1); // Before we carry on, we should check if the prefix or localName are valid XMLName if (!ownerDoc->isXMLName(fPrefix) || !ownerDoc->isXMLName(fLocalName)) throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager); } // DOM Level 3: namespace URI is never empty string. // const XMLCh * URI = DOMNodeImpl::mapPrefix ( fPrefix, (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI, DOMNode::ELEMENT_NODE); fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI); }
DOMNode* DOMAttrImpl::rename(const XMLCh* namespaceURI, const XMLCh* name) { DOMElement* el = getOwnerElement(); DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument; if (el) el->removeAttributeNode(this); if (!namespaceURI || !*namespaceURI) { fName = doc->getPooledString(name); if (el) el->setAttributeNode(this); // and fire user data NODE_RENAMED event castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this); return this; } else { // create a new AttrNS DOMAttr* newAttr = doc->createAttributeNS(namespaceURI, name); // transfer the userData doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newAttr)); // move children to new node DOMNode* child = getFirstChild(); while (child) { removeChild(child); newAttr->appendChild(child); child = getFirstChild(); } // reattach attr to element if (el) el->setAttributeNodeNS(newAttr); // and fire user data NODE_RENAMED event castToNodeImpl(newAttr)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newAttr); return newAttr; } }
const XMLCh * DOMCharacterDataImpl::substringData(const DOMNode *node, XMLSize_t offset, XMLSize_t count) const { // Note: the C++ XMLCh * operation throws the correct DOMExceptions // when parameter values are bad. // XMLSize_t len = fDataBuf->getLen(); if (offset > len) throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMCharacterDataImplMemoryManager); DOMDocumentImpl *doc = (DOMDocumentImpl *)node->getOwnerDocument(); XMLCh* newString; XMLCh temp[4096]; if (len >= 4095) newString = (XMLCh*) doc->getMemoryManager()->allocate ( (len + 1) * sizeof(XMLCh) );//new XMLCh[len+1]; else newString = temp; XMLString::copyNString(newString, fDataBuf->getRawBuffer()+offset, count); newString[count] = chNull; const XMLCh* retString = doc->getPooledString(newString); if (len >= 4095) doc->getMemoryManager()->deallocate(newString);//delete[] newString; return retString; }