Added Xerces-C++ 3.1.2

This commit is contained in:
sippeangelo
2015-12-01 10:23:50 +01:00
parent 65d3f3bc31
commit 1b478d3159
815 changed files with 262638 additions and 0 deletions
+362
View File
@@ -0,0 +1,362 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrImpl.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMException.hpp>
#include "DOMAttrImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMTypeInfoImpl.hpp"
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);
}
DOMAttrImpl::DOMAttrImpl(const DOMAttrImpl &other, bool /*deep*/)
: DOMAttr(other)
, fNode(other.fNode)
, fParent (other.fParent)
, fName(other.fName)
, fSchemaType(other.fSchemaType)
{
if (other.fNode.isSpecified())
fNode.isSpecified(true);
else
fNode.isSpecified(false);
if (other.fNode.isIdAttr())
{
fNode.isIdAttr(true);
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
doc->getNodeIDMap()->add(this);
}
fParent.cloneChildren(&other);
}
DOMAttrImpl::~DOMAttrImpl() {
}
DOMNode * DOMAttrImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (fParent.fOwnerDocument, DOMDocumentImpl::ATTR_OBJECT) DOMAttrImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMAttrImpl::getNodeName() const{
return fName;
}
DOMNode::NodeType DOMAttrImpl::getNodeType() const {
return DOMNode::ATTRIBUTE_NODE;
}
const XMLCh * DOMAttrImpl::getName() const {
return fName;
}
const XMLCh * DOMAttrImpl::getNodeValue() const
{
return getValue();
}
bool DOMAttrImpl::getSpecified() const
{
return fNode.isSpecified();
}
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());
}
void DOMAttrImpl::getTextValue(DOMNode* node, XMLBuffer& buf) const
{
if (node->getNodeType() == DOMNode::TEXT_NODE)
buf.append(node->getNodeValue());
else if (node->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE)
{
for (node = node->getFirstChild(); node != 0; node = castToChildImpl(node)->nextSibling)
{
getTextValue(node, buf);
}
}
return;
}
void DOMAttrImpl::setNodeValue(const XMLCh *val)
{
setValue(val);
}
void DOMAttrImpl::setSpecified(bool arg)
{
fNode.isSpecified(arg);
}
void DOMAttrImpl::setValue(const XMLCh *val)
{
if (fNode.isReadOnly())
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
// If this attribute was of type ID and in the map, take it out,
// then put it back in with the new name. For now, we don't worry
// about what happens if the new name conflicts
//
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
if (fNode.isIdAttr())
doc->getNodeIDMap()->remove(this);
DOMNode *kid;
while ((kid = fParent.fFirstChild) != 0) // Remove existing kids
{
DOMNode* node = removeChild(kid);
if (node)
node->release();
}
if (val != 0) // Create and add the new one
fParent.appendChildFast(doc->createTextNode(val));
fNode.isSpecified(true);
fParent.changed();
if (fNode.isIdAttr())
doc->getNodeIDMap()->add(this);
}
void DOMAttrImpl::setValueFast(const XMLCh *val)
{
if (val != 0)
fParent.appendChildFast(fParent.fOwnerDocument->createTextNode(val));
fNode.isSpecified (true);
}
//Introduced in DOM Level 2
DOMElement *DOMAttrImpl::getOwnerElement() const
{
// if we have an owner, ownerNode is our ownerElement, otherwise it's
// our ownerDocument and we don't have an ownerElement
return (DOMElement *) (fNode.isOwned() ? fNode.fOwnerNode : 0);
}
//internal use by parser only
void DOMAttrImpl::setOwnerElement(DOMElement *ownerElem)
{
fNode.fOwnerNode = ownerElem;
// revisit. Is this backwards? isOwned(true)?
fNode.isOwned(false);
}
//For DOM Level 3
void DOMAttrImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ATTR_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
bool DOMAttrImpl::isId() const {
return fNode.isIdAttr();
}
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 DOMTypeInfo *DOMAttrImpl::getSchemaTypeInfo() const
{
if(!fSchemaType)
return &DOMTypeInfoImpl::g_DtdNotValidatedAttribute;
return fSchemaType;
}
void DOMAttrImpl::setSchemaTypeInfo(const DOMTypeInfoImpl* typeInfo)
{
fSchemaType = typeInfo;
}
bool DOMAttrImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{
// check for '+DOMPSVITypeInfo'
if(feature && *feature=='+' && XMLString::equals(feature+1, XMLUni::fgXercescInterfacePSVITypeInfo))
return true;
return fNode.isSupported (feature, version);
}
void* DOMAttrImpl::getFeature(const XMLCh* feature, const XMLCh* version) const
{
if(XMLString::equals(feature, XMLUni::fgXercescInterfacePSVITypeInfo))
return (DOMPSVITypeInfo*)fSchemaType;
return fNode.getFeature(feature, version);
}
DOMNode* DOMAttrImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
DOMNamedNodeMap* DOMAttrImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMAttrImpl::getChildNodes() const {return fParent.getChildNodes (); }
DOMNode* DOMAttrImpl::getFirstChild() const {return fParent.getFirstChild (); }
DOMNode* DOMAttrImpl::getLastChild() const {return fParent.getLastChild (); }
const XMLCh* DOMAttrImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMAttrImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMAttrImpl::getNextSibling() const {return fNode.getNextSibling (); }
DOMDocument* DOMAttrImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMAttrImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMAttrImpl::getParentNode() const {return fNode.getParentNode (); }
DOMNode* DOMAttrImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }
bool DOMAttrImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
DOMNode* DOMAttrImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); }
void DOMAttrImpl::normalize() {fParent.normalize (); }
DOMNode* DOMAttrImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
DOMNode* DOMAttrImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); }
void DOMAttrImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMAttrImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMAttrImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMAttrImpl::isEqualNode(const DOMNode* arg) const {return fParent.isEqualNode(arg); }
void* DOMAttrImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMAttrImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMAttrImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMAttrImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMAttrImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMAttrImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMAttrImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMAttrImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMAttrImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
XERCES_CPP_NAMESPACE_END
+137
View File
@@ -0,0 +1,137 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMATTRIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMATTRIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include "DOMParentNode.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include "DOMNodeIDMap.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMElementImpl;
class DOMTypeInfoImpl;
class CDOM_EXPORT DOMAttrImpl: public DOMAttr {
public:
DOMNodeImpl fNode;
DOMParentNode fParent;
const XMLCh *fName;
protected:
const DOMTypeInfoImpl *fSchemaType;
public:
DOMAttrImpl(DOMDocument *ownerDocument, const XMLCh *aName);
DOMAttrImpl(const DOMAttrImpl &other, bool deep=false);
virtual ~DOMAttrImpl();
public:
// Add all functions that are pure virtual in DOMNODE
DOMNODE_FUNCTIONS;
public:
virtual const XMLCh * getName() const;
virtual bool getSpecified() const;
virtual const XMLCh * getValue() const;
virtual void setSpecified(bool arg);
virtual void setValue(const XMLCh * value);
virtual DOMElement * getOwnerElement() const;
virtual bool isId() const;
virtual const DOMTypeInfo* getSchemaTypeInfo() const;
void setOwnerElement(DOMElement *ownerElem); //internal use only
// helper function for DOM Level 3 renameNode
virtual DOMNode* rename(const XMLCh* namespaceURI, const XMLCh* name);
//helper function for DOM Level 3 TypeInfo
virtual void setSchemaTypeInfo(const DOMTypeInfoImpl* typeInfo);
// helper method that sets this attr to an idnode and places it into the document map
virtual void addAttrToIDNodeMap();
// helper to remove this attr from from the id map if it is in there
virtual void removeAttrFromIDNodeMap();
public:
// Set attribute value fast. Assumptions:
//
// - node is not read-only
// - no ID management is performed
// - this attribute does not have a value
//
virtual void setValueFast (const XMLCh * value);
protected:
void getTextValue(DOMNode* node, XMLBuffer& buf) const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMAttrImpl& operator=(const DOMAttrImpl&);
};
inline void DOMAttrImpl::removeAttrFromIDNodeMap()
{
if (fNode.isIdAttr()) {
((DOMDocumentImpl *)fParent.fOwnerDocument)->getNodeIDMap()->remove(this);
fNode.isIdAttr(false);
}
}
inline void DOMAttrImpl::addAttrToIDNodeMap()
{
if (fNode.isIdAttr())
return;
fNode.isIdAttr(true);
// REVIST For now, we don't worry about what happens if the new
// name conflicts as per setValue
DOMDocumentImpl *doc = (DOMDocumentImpl *)(fParent.fOwnerDocument);
if (doc->fNodeIDMap == 0)
doc->fNodeIDMap = new (doc) DOMNodeIDMap(500, doc);
doc->getNodeIDMap()->add(this);
}
XERCES_CPP_NAMESPACE_END
#endif
+494
View File
@@ -0,0 +1,494 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrMapImpl.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
#include "DOMCasts.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMNodeVector.hpp"
#include "DOMAttrMapImpl.hpp"
#include "DOMAttrImpl.hpp"
#include "DOMElementImpl.hpp"
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMAttrMapImpl::DOMAttrMapImpl(DOMNode *ownerNod)
{
this->fOwnerNode=ownerNod;
this->fNodes = 0;
hasDefaults(false);
}
DOMAttrMapImpl::DOMAttrMapImpl(DOMNode *ownerNod, const DOMAttrMapImpl *defaults)
{
this->fOwnerNode=ownerNod;
this->fNodes = 0;
hasDefaults(false);
if (defaults != 0)
{
if (defaults->getLength() > 0)
{
hasDefaults(true);
cloneContent(defaults);
}
}
}
DOMAttrMapImpl::~DOMAttrMapImpl()
{
}
void DOMAttrMapImpl::cloneContent(const DOMAttrMapImpl *srcmap)
{
if ((srcmap != 0) && (srcmap->fNodes != 0))
{
if (fNodes != 0)
fNodes->reset();
else
{
XMLSize_t size = srcmap->fNodes->size();
if(size > 0) {
DOMDocumentImpl *doc = (DOMDocumentImpl*)fOwnerNode->getOwnerDocument();
fNodes = new (doc) DOMNodeVector(doc, size);
}
}
for (XMLSize_t i = 0; i < srcmap->fNodes->size(); i++)
{
DOMNode *n = srcmap->fNodes->elementAt(i);
DOMNode *clone = n->cloneNode(true);
castToNodeImpl(clone)->isSpecified(castToNodeImpl(n)->isSpecified());
castToNodeImpl(clone)->fOwnerNode = fOwnerNode;
castToNodeImpl(clone)->isOwned(true);
fNodes->addElement(clone);
}
}
}
DOMAttrMapImpl *DOMAttrMapImpl::cloneAttrMap(DOMNode *ownerNode_p)
{
DOMAttrMapImpl *newmap = new (castToNodeImpl(ownerNode_p)->getOwnerDocument()) DOMAttrMapImpl(ownerNode_p);
newmap->cloneContent(this);
// newmap->attrDefaults = this->attrDefaults; // revisit
return newmap;
}
void DOMAttrMapImpl::setReadOnly(bool readOnl, bool deep)
{
// this->fReadOnly=readOnl;
if(deep && fNodes!=0)
{
XMLSize_t sz = fNodes->size();
for (XMLSize_t i=0; i<sz; ++i) {
castToNodeImpl(fNodes->elementAt(i))->setReadOnly(readOnl, deep);
}
}
}
bool DOMAttrMapImpl::readOnly() {
return castToNodeImpl(fOwnerNode)->isReadOnly();
}
int DOMAttrMapImpl::findNamePoint(const XMLCh *name) const
{
// Binary search
int i=0;
if(fNodes!=0)
{
int first=0,last=(int)fNodes->size()-1;
while(first<=last)
{
i=(first+last)/2;
int test = XMLString::compareString(name, fNodes->elementAt(i)->getNodeName());
if(test==0)
return i; // Name found
else if(test<0)
last=i-1;
else
first=i+1;
}
if(first>i) i=first;
}
/********************
// Linear search
int i = 0;
if (fNodes != 0)
for (i = 0; i < fNodes.size(); ++i)
{
int test = name.compareTo(((NodeImpl *) (fNodes.elementAt(i))).getNodeName());
if (test == 0)
return i;
else
if (test < 0)
{
break; // Found insertpoint
}
}
*******************/
return -1 - i; // not-found has to be encoded.
}
DOMNode * DOMAttrMapImpl::getNamedItem(const XMLCh *name) const
{
int i=findNamePoint(name);
return (i<0) ? 0 : fNodes->elementAt(i);
}
DOMNode *DOMAttrMapImpl::setNamedItem(DOMNode *arg)
{
if (arg->getNodeType() != DOMNode::ATTRIBUTE_NODE)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR, 0, GetDOMNamedNodeMapMemoryManager);
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 ((arg->getNodeType() == DOMNode::ATTRIBUTE_NODE) && argImpl->isOwned() && (argImpl->fOwnerNode != fOwnerNode))
throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR,0, GetDOMNamedNodeMapMemoryManager);
argImpl->fOwnerNode = fOwnerNode;
argImpl->isOwned(true);
int i=findNamePoint(arg->getNodeName());
DOMNode * previous=0;
if(i>=0)
{
previous = fNodes->elementAt(i);
fNodes->setElementAt(arg,i);
}
else
{
i=-1-i; // Insert point (may be end of list)
if(0==fNodes)
{
fNodes=new ((DOMDocumentImpl*)doc) DOMNodeVector(doc);
}
fNodes->insertElementAt(arg,i);
}
if (previous != 0) {
castToNodeImpl(previous)->fOwnerNode = doc;
castToNodeImpl(previous)->isOwned(false);
}
return previous;
}
//Introduced in DOM Level 2
int DOMAttrMapImpl::findNamePoint(const XMLCh *namespaceURI,
const XMLCh *localName) const
{
if (fNodes == 0)
return -1;
// This is a linear search through the same fNodes Vector.
// The Vector is sorted on the DOM Level 1 nodename.
// The DOM Level 2 NS keys are namespaceURI and Localname,
// so we must linear search thru it.
// In addition, to get this to work with fNodes without any namespace
// (namespaceURI and localNames are both 0) we then use the nodeName
// as a secondary key.
const XMLSize_t len = fNodes -> size();
for (XMLSize_t i = 0; i < len; ++i) {
DOMNode *node = fNodes -> elementAt(i);
const XMLCh * nNamespaceURI = node->getNamespaceURI();
const XMLCh * nLocalName = node->getLocalName();
if (!XMLString::equals(nNamespaceURI, namespaceURI)) //URI not match
continue;
else {
if (XMLString::equals(localName, nLocalName)
||
(nLocalName == 0 && XMLString::equals(localName, node->getNodeName())))
return (int)i;
}
}
return -1; //not found
}
DOMNode *DOMAttrMapImpl::getNamedItemNS(const XMLCh *namespaceURI,
const XMLCh *localName) const
{
int i = findNamePoint(namespaceURI, localName);
return i < 0 ? 0 : fNodes -> elementAt(i);
}
DOMNode *DOMAttrMapImpl::setNamedItemNS(DOMNode* arg)
{
if (arg->getNodeType() != DOMNode::ATTRIBUTE_NODE)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR, 0, GetDOMNamedNodeMapMemoryManager);
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);
int i=findNamePoint(arg->getNamespaceURI(), arg->getLocalName());
DOMNode *previous=0;
if(i>=0) {
previous = fNodes->elementAt(i);
fNodes->setElementAt(arg,i);
} else {
i=findNamePoint(arg->getNodeName()); // Insert point (may be end of list)
if (i<0)
i = -1 - i;
if(0==fNodes)
fNodes=new ((DOMDocumentImpl*)doc) DOMNodeVector(doc);
fNodes->insertElementAt(arg,i);
}
if (previous != 0) {
castToNodeImpl(previous)->fOwnerNode = doc;
castToNodeImpl(previous)->isOwned(false);
}
return previous;
}
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;
}
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;
}
// 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;
}
/**
* 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 (XMLSize_t i = nsize; i > 0; i--) {
DOMAttr* attr = (DOMAttr*)item(i-1);
if (!attr->getSpecified()) {
removeNamedItemAt(i-1);
}
}
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 (XMLSize_t i = nsize; i > 0; i--) {
DOMAttr* attr = (DOMAttr*)srcmap->item(i-1);
if (attr->getSpecified()) {
srcmap->removeNamedItemAt(i-1);
}
if (attr->getLocalName())
setNamedItemNS(attr);
else
setNamedItem(attr);
}
} // moveSpecifiedAttributes(AttributeMap):void
XMLSize_t DOMAttrMapImpl::getLength() const
{
return (fNodes != 0) ? fNodes->size() : 0;
}
DOMNode * DOMAttrMapImpl::item(XMLSize_t index) const
{
return (fNodes != 0 && index < fNodes->size()) ?
fNodes->elementAt(index) : 0;
}
void DOMAttrMapImpl::setNamedItemFast(DOMNode *arg)
{
DOMNodeImpl *argImpl = castToNodeImpl(arg);
argImpl->fOwnerNode = fOwnerNode;
argImpl->isOwned(true);
int i = findNamePoint(arg->getNodeName());
if(i >= 0)
fNodes->setElementAt(arg, i);
else
{
i= -1 -i;
fNodes->insertElementAt(arg, i);
}
}
void DOMAttrMapImpl::setNamedItemNSFast(DOMNode* arg)
{
DOMNodeImpl *argImpl = castToNodeImpl(arg);
argImpl->fOwnerNode = fOwnerNode;
argImpl->isOwned(true);
int i=findNamePoint(arg->getNamespaceURI(), arg->getLocalName());
if(i >= 0)
{
fNodes->setElementAt(arg,i);
}
else
{
i = findNamePoint(arg->getNodeName());
if (i < 0)
i = -1 - i;
fNodes->insertElementAt(arg,i);
}
}
void DOMAttrMapImpl::reserve (XMLSize_t n)
{
if (fNodes == 0)
{
DOMDocumentImpl* doc = (DOMDocumentImpl*)fOwnerNode->getOwnerDocument();
fNodes = new (doc) DOMNodeVector(doc, n);
}
}
XERCES_CPP_NAMESPACE_END
+125
View File
@@ -0,0 +1,125 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrMapImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMATTRMAPIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMATTRMAPIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class DOMNodeVector;
class CDOM_EXPORT DOMAttrMapImpl : public DOMNamedNodeMap
{
protected:
DOMNodeVector* fNodes;
DOMNode* fOwnerNode; // the node this map belongs to
bool attrDefaults;
virtual void cloneContent(const DOMAttrMapImpl *srcmap);
bool readOnly(); // revisit. Look at owner node read-only.
public:
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 DOMAttrMapImpl *defaults);
DOMAttrMapImpl();
virtual ~DOMAttrMapImpl();
virtual DOMAttrMapImpl *cloneAttrMap(DOMNode *ownerNode);
virtual bool hasDefaults();
virtual void hasDefaults(bool value);
virtual int findNamePoint(const XMLCh *name) const;
virtual int findNamePoint(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual DOMNode* removeNamedItemAt(XMLSize_t index);
virtual void setReadOnly(bool readOnly, bool deep);
virtual XMLSize_t getLength() const;
virtual DOMNode* item(XMLSize_t index) const;
virtual DOMNode* getNamedItem(const XMLCh *name) const;
virtual DOMNode* setNamedItem(DOMNode *arg);
virtual DOMNode* removeNamedItem(const XMLCh *name);
virtual DOMNode* getNamedItemNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual DOMNode* setNamedItemNS(DOMNode *arg);
virtual DOMNode* removeNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName);
// Fast versions of the above functions which bypass validity checks.
// It also assumes that fNode is not 0 (call reserve) and that there
// is no previous node with this name. These are used in parsing.
//
void setNamedItemFast(DOMNode *arg);
void setNamedItemNSFast(DOMNode *arg);
// Tries to reserve space for the specified number of elements.
// Currently only works on newly-created instances (fNodes == 0).
//
void reserve (XMLSize_t);
void reconcileDefaultAttributes(const DOMAttrMapImpl* defaults);
void moveSpecifiedAttributes(DOMAttrMapImpl* srcmap);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMAttrMapImpl(const DOMAttrMapImpl &);
DOMAttrMapImpl & operator = (const DOMAttrMapImpl &);
};
// ---------------------------------------------------------------------------
// DOMAttrMapImpl: Getters & Setters
// ---------------------------------------------------------------------------
inline bool DOMAttrMapImpl::hasDefaults()
{
return attrDefaults;
}
inline void DOMAttrMapImpl::hasDefaults(bool value)
{
attrDefaults = value;
}
XERCES_CPP_NAMESPACE_END
#endif
+247
View File
@@ -0,0 +1,247 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrNSImpl.cpp 901107 2010-01-20 08:45:02Z borisk $
*/
#include <xercesc/util/XMLUniDefs.hpp>
#include "DOMAttrNSImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMException.hpp>
#include "assert.h"
XERCES_CPP_NAMESPACE_BEGIN
DOMAttrNSImpl::DOMAttrNSImpl(DOMDocument *ownerDoc, const XMLCh *nam) :
DOMAttrImpl(ownerDoc, nam)
{
this->fNamespaceURI=0; //DOM Level 2
this->fLocalName=0; //DOM Level 2
this->fPrefix=0;
}
//Introduced in DOM Level 2
DOMAttrNSImpl::DOMAttrNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *qualifiedName) :
DOMAttrImpl(ownerDoc, qualifiedName)
{
setName(namespaceURI, qualifiedName);
}
DOMAttrNSImpl::
DOMAttrNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *prefix,
const XMLCh *localName,
const XMLCh *qualifiedName)
: DOMAttrImpl(ownerDoc, qualifiedName)
{
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::ATTRIBUTE_NODE
);
this -> fNamespaceURI = (URI == 0) ? 0 : docImpl->getPooledString(URI);
}
DOMAttrNSImpl::DOMAttrNSImpl(const DOMAttrNSImpl &other, bool deep) :
DOMAttrImpl(other, deep)
{
this->fNamespaceURI = other.fNamespaceURI; //DOM Level 2
this->fLocalName = other.fLocalName; //DOM Level 2
this->fPrefix = other.fPrefix;
}
DOMNode * DOMAttrNSImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ATTR_NS_OBJECT) DOMAttrNSImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMAttrNSImpl::getNamespaceURI() const
{
return fNamespaceURI;
}
const XMLCh * DOMAttrNSImpl::getPrefix() const
{
return fPrefix;
}
const XMLCh * DOMAttrNSImpl::getLocalName() const
{
return fLocalName;
}
void DOMAttrNSImpl::setPrefix(const XMLCh *prefix)
{
const XMLCh * xmlns = DOMNodeImpl::getXmlnsString();
if (fNode.isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
if (fNamespaceURI == 0 || fNamespaceURI[0] == chNull || XMLString::equals(fLocalName, xmlns))
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
if (prefix == 0 || prefix[0] == chNull) {
fName = fLocalName;
fPrefix = 0;
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();
const XMLCh * xmlnsURI = DOMNodeImpl::getXmlnsURIString();
if ((XMLString::equals(prefix, xml) &&
!XMLString::equals(fNamespaceURI, xmlURI))
|| (XMLString::equals(prefix, xmlns) &&
!XMLString::equals(fNamespaceURI, xmlnsURI)))
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::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ATTR_NS_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
DOMNode* DOMAttrNSImpl::rename(const XMLCh* namespaceURI, const XMLCh* name)
{
DOMElement* el = getOwnerElement();
if (el)
el->removeAttributeNode(this);
setName(namespaceURI, name);
if (el)
el->setAttributeNodeNS(this);
return this;
}
void DOMAttrNSImpl::setName(const XMLCh* namespaceURI, const XMLCh* qualifiedName)
{
DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *)fParent.fOwnerDocument;
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;
}
fPrefix = 0;
fLocalName = fName;
}
else
{
fPrefix = ownerDoc->getPooledNString(fName, 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 = xmlnsAlone ? xmlnsURI
: DOMNodeImpl::mapPrefix
(
fPrefix,
(!namespaceURI || !*namespaceURI) ? 0 : namespaceURI,
DOMNode::ATTRIBUTE_NODE
);
this -> fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAttrNSImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMATTRNSIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMATTRNSIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include "DOMAttrImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMAttrNSImpl: public DOMAttrImpl {
protected:
//Introduced in DOM Level 2
const XMLCh * fNamespaceURI; //namespace URI of this node
const XMLCh * fLocalName; //local part of qualified name
const XMLCh * fPrefix; // prefix part of qualified name
// revisit - can return local part
// by pointing into the qualified (L1) name.
public:
DOMAttrNSImpl(DOMDocument *ownerDoc, const XMLCh *name);
DOMAttrNSImpl(DOMDocument *ownerDoc, //DOM Level 2
const XMLCh *namespaceURI, const XMLCh *qualifiedName);
DOMAttrNSImpl(const DOMAttrNSImpl &other, bool deep=false);
// Fast construction without any checks for name validity. Used in
// parsing. Note that if prefix is not specified and localName is
// 'xmlns', this constructor expects proper namespaceURI.
//
DOMAttrNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *prefix, // Null or empty - no prefix.
const XMLCh *localName,
const XMLCh *qualifiedName);
virtual DOMNode * cloneNode(bool deep) const;
//Introduced in DOM Level 2
virtual const XMLCh * getNamespaceURI() const;
virtual const XMLCh * getPrefix() const;
virtual const XMLCh * getLocalName() const;
virtual void setPrefix(const XMLCh *prefix);
virtual void release();
// helper function for DOM Level 3 renameNode
virtual DOMNode* rename(const XMLCh* namespaceURI, const XMLCh* name);
void setName(const XMLCh* namespaceURI, const XMLCh* name);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMAttrNSImpl & operator = (const DOMAttrNSImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,321 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCDATASectionImpl.cpp 1027995 2010-10-27 15:09:39Z amassari $
*/
#include "DOMCDATASectionImpl.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMRangeImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMStringPool.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNodeFilter.hpp>
#include <xercesc/dom/DOMTreeWalker.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMCDATASectionImpl::DOMCDATASectionImpl(DOMDocument *ownerDoc,
const XMLCh *dat)
: fNode(ownerDoc), fCharacterData(ownerDoc, dat)
{
fNode.setIsLeafNode(true);
}
DOMCDATASectionImpl::
DOMCDATASectionImpl(DOMDocument *ownerDoc, const XMLCh* data, XMLSize_t n)
: fNode(ownerDoc), fCharacterData(ownerDoc, data, n)
{
fNode.setIsLeafNode(true);
}
DOMCDATASectionImpl::DOMCDATASectionImpl(const DOMCDATASectionImpl &other, bool /*deep*/)
: DOMCDATASection(other),
fNode(*castToNodeImpl(&other)),
fChild(*castToChildImpl(&other)),
fCharacterData(other.fCharacterData)
{
// revisit. Something nees to make "deep" work.
}
DOMCDATASectionImpl::~DOMCDATASectionImpl()
{
}
DOMNode *DOMCDATASectionImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (this->getOwnerDocument(), DOMMemoryManager::CDATA_SECTION_OBJECT) DOMCDATASectionImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMCDATASectionImpl::getNodeName() const {
static const XMLCh gcdata_section[] = {chPound, chLatin_c, chLatin_d, chLatin_a, chLatin_t, chLatin_a,
chDash, chLatin_s, chLatin_e, chLatin_c, chLatin_t, chLatin_i, chLatin_o, chLatin_n, 0};
return gcdata_section;
}
DOMNode::NodeType DOMCDATASectionImpl::getNodeType() const {
return DOMNode::CDATA_SECTION_NODE;
}
bool DOMCDATASectionImpl::isIgnorableWhitespace() const
{
return fNode.ignorableWhitespace();
}
//
// splitText. revist - factor into a common function for use
// here and in DOMTextImpl
//
DOMText *DOMCDATASectionImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
DOMText *newText =
doc->createCDATASection(this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
}
bool DOMCDATASectionImpl::getIsElementContentWhitespace() const
{
return isIgnorableWhitespace();
}
const XMLCh* DOMCDATASectionImpl::getWholeText() const
{
DOMDocument *doc = getOwnerDocument();
if (!doc) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
return 0;
}
DOMNode* root=doc->getDocumentElement();
DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
}
XMLBuffer buff(1023, GetDOMNodeMemoryManager);
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==TEXT_NODE || nextNode->getNodeType()==CDATA_SECTION_NODE)
buff.append(nextNode->getNodeValue());
}
pWalker->release();
XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
XMLString::copyString(wholeString, buff.getRawBuffer());
return wholeString;
}
DOMText* DOMCDATASectionImpl::replaceWholeText(const XMLCh* newText)
{
DOMDocument *doc = getOwnerDocument();
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* pFirstTextNode=this;
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
pFirstTextNode=prevNode;
}
// before doing any change we need to check if we are going to remove an entity reference that doesn't contain just text
DOMNode* pCurrentNode=pWalker->getCurrentNode();
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==ENTITY_REFERENCE_NODE)
{
DOMTreeWalker* pInnerWalker=doc->createTreeWalker(nextNode, DOMNodeFilter::SHOW_ALL, NULL, true);
while(pInnerWalker->nextNode())
{
short nodeType=pInnerWalker->getCurrentNode()->getNodeType();
if(nodeType!=ENTITY_REFERENCE_NODE && nodeType!=TEXT_NODE && nodeType!=CDATA_SECTION_NODE)
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
pInnerWalker->release();
}
}
DOMText* retVal=NULL;
// if the first node in the chain is a text node, replace its content, otherwise create a new node
if(newText && *newText)
{
if(!castToNodeImpl(pFirstTextNode)->isReadOnly() && (pFirstTextNode->getNodeType()==TEXT_NODE || pFirstTextNode->getNodeType()==CDATA_SECTION_NODE))
{
pFirstTextNode->setNodeValue(newText);
retVal=(DOMText*)pFirstTextNode;
}
else
{
if(getNodeType()==TEXT_NODE)
retVal=doc->createTextNode(newText);
else
retVal=doc->createCDATASection(newText);
pFirstTextNode->getParentNode()->insertBefore(retVal, pFirstTextNode);
}
}
// now delete all the following text nodes
pWalker->setCurrentNode(pCurrentNode);
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode!=retVal)
{
// keep the tree walker valid
pWalker->previousNode();
nextNode->getParentNode()->removeChild(nextNode);
nextNode->release();
}
}
pWalker->release();
return retVal;
}
void DOMCDATASectionImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fCharacterData.releaseBuffer();
doc->release(this, DOMMemoryManager::CDATA_SECTION_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
//
// Delegation stubs for other DOM_Node inherited functions.
//
DOMNode* DOMCDATASectionImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
DOMNamedNodeMap* DOMCDATASectionImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMCDATASectionImpl::getChildNodes() const {return fNode.getChildNodes (); }
DOMNode* DOMCDATASectionImpl::getFirstChild() const {return fNode.getFirstChild (); }
DOMNode* DOMCDATASectionImpl::getLastChild() const {return fNode.getLastChild (); }
const XMLCh* DOMCDATASectionImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMCDATASectionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMCDATASectionImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMCDATASectionImpl::getNodeValue() const {return fCharacterData.getNodeValue (); }
DOMDocument* DOMCDATASectionImpl::getOwnerDocument() const {return fNode.getOwnerDocument(); }
const XMLCh* DOMCDATASectionImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMCDATASectionImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMCDATASectionImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMCDATASectionImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
DOMNode* DOMCDATASectionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fNode.insertBefore (newChild, refChild); }
void DOMCDATASectionImpl::normalize() {fNode.normalize (); }
DOMNode* DOMCDATASectionImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
DOMNode* DOMCDATASectionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fNode.replaceChild (newChild, oldChild); }
bool DOMCDATASectionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMCDATASectionImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMCDATASectionImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMCDATASectionImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMCDATASectionImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
void* DOMCDATASectionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMCDATASectionImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMCDATASectionImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMCDATASectionImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMCDATASectionImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMCDATASectionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMCDATASectionImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMCDATASectionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMCDATASectionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMCDATASectionImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
//
// Delegation of CharacerData functions.
//
const XMLCh* DOMCDATASectionImpl::getData() const {return fCharacterData.getData();}
XMLSize_t DOMCDATASectionImpl::getLength() const {return fCharacterData.getLength();}
const XMLCh* DOMCDATASectionImpl::substringData(XMLSize_t offset, XMLSize_t count) const
{return fCharacterData.substringData(this, offset, count);}
void DOMCDATASectionImpl::appendData(const XMLCh *arg) {fCharacterData.appendData(this, arg);}
void DOMCDATASectionImpl::insertData(XMLSize_t offset, const XMLCh *arg)
{fCharacterData.insertData(this, offset, arg);}
void DOMCDATASectionImpl::deleteData(XMLSize_t offset, XMLSize_t count)
{fCharacterData.deleteData(this, offset, count);}
void DOMCDATASectionImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
{fCharacterData.replaceData(this, offset, count, arg);}
void DOMCDATASectionImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);}
void DOMCDATASectionImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCDATASectionImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMCDATASECTIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCDATASECTIONIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMCDATASection.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp"
#include "DOMParentNode.hpp"
#include "DOMCharacterDataImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMCDATASectionImpl: public DOMCDATASection {
protected:
DOMNodeImpl fNode;
DOMChildNode fChild;
DOMCharacterDataImpl fCharacterData;
public:
DOMCDATASectionImpl(DOMDocument *ownerDoc, const XMLCh* data);
DOMCDATASectionImpl(DOMDocument *ownerDoc, const XMLCh* data, XMLSize_t n);
DOMCDATASectionImpl(const DOMCDATASectionImpl &other, bool deep = false);
virtual ~DOMCDATASectionImpl();
// Functions inherited from TEXT
virtual DOMText* splitText(XMLSize_t offset);
// DOM Level 3
virtual bool getIsElementContentWhitespace() const;
virtual const XMLCh* getWholeText() const;
virtual DOMText* replaceWholeText(const XMLCh* content);
// non-standard extension
virtual bool isIgnorableWhitespace() const;
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
// Functions introduced by DOMCharacterData
virtual const XMLCh* getData() const;
virtual XMLSize_t getLength() const;
virtual const XMLCh* substringData(XMLSize_t offset,
XMLSize_t count) const;
virtual void appendData(const XMLCh *arg);
virtual void insertData(XMLSize_t offset, const XMLCh *arg);
virtual void deleteData(XMLSize_t offset,
XMLSize_t count);
virtual void replaceData(XMLSize_t offset,
XMLSize_t count,
const XMLCh *arg);
virtual void setData(const XMLCh *data);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMCDATASectionImpl & operator = (const DOMCDATASectionImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
+146
View File
@@ -0,0 +1,146 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCasts.hpp 673975 2008-07-04 09:23:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMCASTS_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCASTS_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
//
// Define inline casting functions to convert from
// (DOMNode *) to DOMParentNode or DOMChildNode *.
//
// This requires knowledge of the structure of the fields of
// for all node types. There are three categories -
//
// Nodetypes that can have children and can be a child themselves.
// e.g. Elements
//
// Object
// DOMNodeImpl fNode;
// DOMParentNode fParent;
// DOMChildNode fChild;
// ... // other fields, depending on node type.
//
// Nodetypes that can not have children, e.g. TEXT
//
// Object
// DOMNodeImpl fNode;
// DOMChildNode fChild;
// ... // other fields, depending on node type
//
// Nodetypes that can not be a child of other nodes, but that can
// have children (are a parent) e.g. ATTR
// Object
// DOMNodeImpl fNode;
// DOMParentNode fParent
// ... // other fields, depending on node type
//
// The casting functions make these assumptions:
// 1. The cast is possible. Using code will not attempt to
// cast to something that does not exist, such as the child
// part of an ATTR
//
// 2. The nodes belong to this implementation.
//
// Some of the casts use the LEAFNODE flag in the common fNode part to
// determine whether an fParent field exists, and thus the
// position of the fChild part within the node.
//
// These functions also cast off const. It was either do that, or make
// a second overloaded set that took and returned const arguements.
//
//
// Note that using offsetof, or taking the offset of an object member at
// a 0 address, is now undefined in C++. And gcc now warns about this behavior.
// This is because doing do so is unreliable for some types of objects.
// See: http://gcc.gnu.org/ml/gcc/2004-06/msg00227.html
// : http://gcc.gnu.org/ml/gcc-bugs/2000-03/msg00805.html
// The casting code below works around gcc's warnings by using a dummy
// pointer, which the compiler cannot tell is null. The defeats the warning,
// but also masks the potential problem.
// The gcc option -Wno-invalid-offsetof may also be used to turn off this warning.
//
#include "DOMElementImpl.hpp"
#include "DOMTextImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
static inline DOMNodeImpl *castToNodeImpl(const DOMNode *p)
{
DOMElementImpl *pE = (DOMElementImpl *)p;
return &(pE->fNode);
}
static inline DOMParentNode *castToParentImpl(const DOMNode *p) {
DOMElementImpl *pE = (DOMElementImpl *)p;
return &(pE->fParent);
}
static inline DOMChildNode *castToChildImpl(const DOMNode *p) {
DOMElementImpl *pE = (DOMElementImpl *)p;
if (pE->fNode.isLeafNode()) {
DOMTextImpl *pT = (DOMTextImpl *)p;
return &(pT->fChild);
}
return &(pE->fChild);
}
static inline DOMNode *castToNode(const DOMParentNode *p ) {
DOMElementImpl* dummy = 0;
XMLSize_t parentOffset = (char *)&(dummy->fParent) - (char *)dummy;
char *retPtr = (char *)p - parentOffset;
return (DOMNode *)retPtr;
}
static inline DOMNode *castToNode(const DOMNodeImpl *p) {
DOMElementImpl* dummy = 0;
XMLSize_t nodeImplOffset = (char *)&(dummy->fNode) - (char *)dummy;
char *retPtr = (char *)p - nodeImplOffset;
return (DOMNode *)retPtr;
}
static inline DOMNodeImpl *castToNodeImpl(const DOMParentNode *p)
{
DOMElementImpl* dummy = 0;
XMLSize_t nodeImplOffset = (char *)&(dummy->fNode) - (char *)dummy;
XMLSize_t parentOffset = (char *)&(dummy->fParent) - (char *)dummy;
char *retPtr = (char *)p - parentOffset + nodeImplOffset;
return (DOMNodeImpl *)retPtr;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,318 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCharacterDataImpl.cpp 678766 2008-07-22 14:00:16Z borisk $
*/
#include "DOMCharacterDataImpl.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include "DOMRangeImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMStringPool.hpp"
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMCharacterDataImpl::DOMCharacterDataImpl(DOMDocument *doc, const XMLCh *dat)
{
fDoc = (DOMDocumentImpl*)doc;
XMLSize_t len=XMLString::stringLen(dat);
fDataBuf = fDoc->popBuffer(len+1);
if (!fDataBuf)
fDataBuf = new (fDoc) DOMBuffer(fDoc, len+15);
fDataBuf->set(dat, len);
}
DOMCharacterDataImpl::
DOMCharacterDataImpl(DOMDocument *doc, const XMLCh* dat, XMLSize_t len)
{
fDoc = (DOMDocumentImpl*)doc;
fDataBuf = fDoc->popBuffer(len+1);
if (!fDataBuf)
fDataBuf = new (fDoc) DOMBuffer(fDoc, len+15);
fDataBuf->set(dat, len);
}
DOMCharacterDataImpl::DOMCharacterDataImpl(const DOMCharacterDataImpl &other)
{
fDoc = (DOMDocumentImpl*)other.fDoc;
XMLSize_t len=other.getLength();
fDataBuf = fDoc->popBuffer(len+1);
if (!fDataBuf)
fDataBuf = new (fDoc) DOMBuffer(fDoc, len+15);
fDataBuf->set(other.fDataBuf->getRawBuffer(), len);
}
DOMCharacterDataImpl::~DOMCharacterDataImpl() {
}
const XMLCh * DOMCharacterDataImpl::getNodeValue() const
{
return fDataBuf->getRawBuffer();
}
void DOMCharacterDataImpl::setNodeValue(const DOMNode *node, const XMLCh *value)
{
if (castToNodeImpl(node)->isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
fDataBuf->set(value);
DOMDocumentImpl *doc = (DOMDocumentImpl *)node->getOwnerDocument();
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->receiveReplacedText((DOMNode*)node);
}
}
}
}
}
void DOMCharacterDataImpl::appendData(const DOMNode *node, const XMLCh *dat)
{
if(castToNodeImpl(node)->isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
fDataBuf->append(dat);
}
void DOMCharacterDataImpl::appendData(const DOMNode *node, const XMLCh *dat, XMLSize_t n)
{
if(castToNodeImpl(node)->isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
fDataBuf->append(dat, n);
}
void DOMCharacterDataImpl::deleteData(const DOMNode *node, XMLSize_t offset, XMLSize_t count)
{
if (castToNodeImpl(node)->isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
// Note: the C++ XMLCh * operation throws the correct DOMExceptions
// when parameter values are bad.
//
XMLSize_t len = this->fDataBuf->getLen();
if (offset > len)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMCharacterDataImplMemoryManager);
// Cap the value of delLength to avoid trouble with overflows
// in the following length computations.
if (count > len)
count = len;
// If the length of data to be deleted would extend off the end
// of the string, cut it back to stop at the end of string.
if (offset + count >= len)
count = len - offset;
XMLSize_t newLen = len - count;
XMLCh* newString;
XMLCh temp[4096];
if (newLen >= 4095)
newString = (XMLCh*) XMLPlatformUtils::fgMemoryManager->allocate
(
(newLen+1) * sizeof(XMLCh)
);//new XMLCh[newLen+1];
else
newString = temp;
XMLString::copyNString(newString, fDataBuf->getRawBuffer(), offset);
XMLString::copyString(newString+offset, fDataBuf->getRawBuffer()+offset+count);
fDataBuf->set(newString);
if (newLen >= 4095)
XMLPlatformUtils::fgMemoryManager->deallocate(newString);//delete[] newString;
// We don't delete the old string (doesn't work), or alter
// the old string (may be shared)
// It just hangs around, possibly orphaned.
DOMDocumentImpl *doc = (DOMDocumentImpl *)node->getOwnerDocument();
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateRangeForDeletedText( (DOMNode*)node, offset, count);
}
}
}
}
}
const XMLCh *DOMCharacterDataImpl::getData() const
{
return fDataBuf->getRawBuffer();
}
//
// getCharDataLength - return the length of the character data string.
//
XMLSize_t DOMCharacterDataImpl::getLength() const
{
return fDataBuf->getLen();
}
void DOMCharacterDataImpl::insertData(const DOMNode *node, XMLSize_t offset, const XMLCh *dat)
{
if (castToNodeImpl(node)->isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
// 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);
XMLSize_t datLen = XMLString::stringLen(dat);
XMLSize_t newLen = len + datLen;
XMLCh* newString;
XMLCh temp[4096];
if (newLen >= 4095)
newString = (XMLCh*) XMLPlatformUtils::fgMemoryManager->allocate
(
(newLen + 1) * sizeof(XMLCh)
);//new XMLCh[newLen+1];
else
newString = temp;
XMLString::copyNString(newString, fDataBuf->getRawBuffer(), offset);
XMLString::copyNString(newString+offset, dat, datLen);
XMLString::copyString(newString+offset+datLen, fDataBuf->getRawBuffer()+offset);
fDataBuf->set(newString);
if (newLen >= 4095)
XMLPlatformUtils::fgMemoryManager->deallocate(newString);//delete[] newString;
DOMDocumentImpl *doc = (DOMDocumentImpl *)node->getOwnerDocument();
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateRangeForInsertedText( (DOMNode*)node, offset, datLen);
}
}
}
}
}
void DOMCharacterDataImpl::replaceData(const DOMNode *node, XMLSize_t offset, XMLSize_t count,
const XMLCh *dat)
{
if (castToNodeImpl(node)->isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMCharacterDataImplMemoryManager);
deleteData(node, offset, count);
insertData(node, offset, dat);
}
void DOMCharacterDataImpl::setData(const DOMNode *node, const XMLCh *arg)
{
setNodeValue(node, arg);
}
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;
}
void DOMCharacterDataImpl::releaseBuffer() {
fDoc->releaseBuffer(fDataBuf);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCharacterDataImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMCHARACTERDATAIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCHARACTERDATAIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class DOMDocument;
class DOMDocumentImpl;
class DOMBuffer;
// Instances of DOMCharacterDataImpl appear as members of node types
// that implement the DOMCharacterData interfaces.
// Operations in those classes are delegated to this class.
//
class CDOM_EXPORT DOMCharacterDataImpl
{
public:
DOMBuffer* fDataBuf;
// for the buffer bid
DOMDocumentImpl* fDoc;
public:
DOMCharacterDataImpl(DOMDocument *doc, const XMLCh *dat);
DOMCharacterDataImpl(DOMDocument *doc, const XMLCh* data, XMLSize_t n);
DOMCharacterDataImpl(const DOMCharacterDataImpl &other);
~DOMCharacterDataImpl();
const XMLCh * getNodeValue() const;
void setNodeValue(const XMLCh * value);
void appendData(const DOMNode *node, const XMLCh *data);
void appendData(const DOMNode *node, const XMLCh *data, XMLSize_t n);
void deleteData(const DOMNode *node, XMLSize_t offset, XMLSize_t count);
const XMLCh* getData() const;
XMLSize_t getLength() const;
void insertData(const DOMNode *node, XMLSize_t offset, const XMLCh * data);
void replaceData(const DOMNode *node, XMLSize_t offset, XMLSize_t count, const XMLCh * data);
void setData(const DOMNode *node, const XMLCh * arg);
void setNodeValue(const DOMNode *node, const XMLCh *value);
const XMLCh* substringData(const DOMNode *node, XMLSize_t offset, XMLSize_t count) const;
void releaseBuffer();
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMCharacterDataImpl & operator = (const DOMCharacterDataImpl &);
};
#define GetDOMCharacterDataImplMemoryManager GET_DIRECT_MM(fDoc)
XERCES_CPP_NAMESPACE_END
#endif
+78
View File
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMChildNode.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// This class only adds the ability to have siblings
#include <xercesc/util/XercesDefs.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp"
#include "DOMCasts.hpp"
XERCES_CPP_NAMESPACE_BEGIN
DOMChildNode::DOMChildNode()
{
this->previousSibling = 0;
this->nextSibling = 0;
}
// This only makes a shallow copy, cloneChildren must also be called for a
// deep clone
DOMChildNode::DOMChildNode(const DOMChildNode &)
{
// Need to break the association w/ original siblings and parent
this->previousSibling = 0;
this->nextSibling = 0;
}
DOMChildNode::~DOMChildNode() {
}
DOMNode * DOMChildNode::getNextSibling() const {
return nextSibling;
}
//
// Note: for getParentNode and getPreviousSibling(), below, an
// extra paramter "thisNode" is required. This is because there
// is no way to cast from a DOMChildNode pointer back to the
// DOMNodeImpl that it is part of. Our "this" may or may not
// be preceded by a fParent in the object layout, and there's no
// practical way to tell, so we just take an extra parameter instead.
DOMNode * DOMChildNode::getParentNode(const DOMNode *thisNode) const
{
// if we have an owner, ownerNode is our parent, otherwise it's
// our ownerDocument and we don't have a parent
DOMNodeImpl *thisNodeImpl = castToNodeImpl(thisNode);
return thisNodeImpl->isOwned() ? thisNodeImpl->fOwnerNode : 0;
}
DOMNode * DOMChildNode::getPreviousSibling(const DOMNode *thisNode) const {
// if we are the firstChild, previousSibling actually refers to our
// parent's lastChild, but we hide that
return castToNodeImpl(thisNode)->isFirstChild() ? 0 : previousSibling;
}
XERCES_CPP_NAMESPACE_END
+72
View File
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMChildNode.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMCHILDNODE_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCHILDNODE_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
/**
* ChildNode adds to NodeImpl the capability of being a child, this is having
* siblings.
**/
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMDocument;
class DOMNode;
class CDOM_EXPORT DOMChildNode {
public:
DOMNode *previousSibling;
DOMNode *nextSibling;
DOMChildNode();
DOMChildNode(const DOMChildNode &other);
~DOMChildNode();
DOMNode * getNextSibling() const;
DOMNode * getParentNode(const DOMNode *thisNode) const;
DOMNode * getPreviousSibling(const DOMNode *thisNode) const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMChildNode & operator = (const DOMChildNode &);
};
XERCES_CPP_NAMESPACE_END
#endif
+189
View File
@@ -0,0 +1,189 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCommentImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include "DOMCommentImpl.hpp"
#include "DOMCharacterDataImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMCasts.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMRangeImpl.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMCommentImpl::DOMCommentImpl(DOMDocument *ownerDoc, const XMLCh *dat)
: fNode(ownerDoc), fCharacterData(ownerDoc, dat)
{
fNode.setIsLeafNode(true);
}
DOMCommentImpl::DOMCommentImpl(const DOMCommentImpl &other, bool)
: fNode(other.fNode),
fChild(other.fChild),
fCharacterData(other.fCharacterData)
{
fNode.setIsLeafNode(true);
}
DOMCommentImpl::~DOMCommentImpl() {
}
DOMNode * DOMCommentImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::COMMENT_OBJECT) DOMCommentImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMCommentImpl::getNodeName() const {
static const XMLCh gComment[] =
{chPound, chLatin_c, chLatin_o, chLatin_m, chLatin_m, chLatin_e,chLatin_n, chLatin_t, 0};
return gComment;
}
DOMNode::NodeType DOMCommentImpl::getNodeType() const {
return DOMNode::COMMENT_NODE;
}
void DOMCommentImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fCharacterData.releaseBuffer();
doc->release(this, DOMMemoryManager::COMMENT_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
// Non standard extension for the range to work
DOMComment *DOMCommentImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
DOMComment *newText =
doc->createComment(this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
}
DOMNode* DOMCommentImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
DOMNamedNodeMap* DOMCommentImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMCommentImpl::getChildNodes() const {return fNode.getChildNodes (); }
DOMNode* DOMCommentImpl::getFirstChild() const {return fNode.getFirstChild (); }
DOMNode* DOMCommentImpl::getLastChild() const {return fNode.getLastChild (); }
const XMLCh* DOMCommentImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMCommentImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMCommentImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMCommentImpl::getNodeValue() const {return fCharacterData.getNodeValue (); }
DOMDocument* DOMCommentImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }
const XMLCh* DOMCommentImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMCommentImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMCommentImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMCommentImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
DOMNode* DOMCommentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fNode.insertBefore (newChild, refChild); }
void DOMCommentImpl::normalize() {fNode.normalize (); }
DOMNode* DOMCommentImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
DOMNode* DOMCommentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fNode.replaceChild (newChild, oldChild); }
bool DOMCommentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMCommentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMCommentImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMCommentImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMCommentImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
void* DOMCommentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMCommentImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMCommentImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMCommentImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMCommentImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMCommentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMCommentImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMCommentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMCommentImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMCommentImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
//
// Delegation of CharacerData functions.
//
const XMLCh* DOMCommentImpl::getData() const {return fCharacterData.getData();}
XMLSize_t DOMCommentImpl::getLength() const {return fCharacterData.getLength();}
const XMLCh* DOMCommentImpl::substringData(XMLSize_t offset, XMLSize_t count) const
{return fCharacterData.substringData(this, offset, count);}
void DOMCommentImpl::appendData(const XMLCh *arg) {fCharacterData.appendData(this, arg);}
void DOMCommentImpl::insertData(XMLSize_t offset, const XMLCh *arg)
{fCharacterData.insertData(this, offset, arg);}
void DOMCommentImpl::deleteData(XMLSize_t offset, XMLSize_t count)
{fCharacterData.deleteData(this, offset, count);}
void DOMCommentImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
{fCharacterData.replaceData(this, offset, count, arg);}
void DOMCommentImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);}
void DOMCommentImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMCommentImpl.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMCOMMENTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCOMMENTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMComment.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp"
#include "DOMCharacterDataImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMCommentImpl: public DOMComment {
public:
DOMNodeImpl fNode;
DOMChildNode fChild;
DOMCharacterDataImpl fCharacterData;
public:
DOMCommentImpl(DOMDocument *, const XMLCh *);
DOMCommentImpl(const DOMCommentImpl &other, bool deep);
virtual ~DOMCommentImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
// Functions from DOMCharacterData
virtual void appendData(const XMLCh *data);
virtual void deleteData(XMLSize_t offset, XMLSize_t count);
virtual const XMLCh * getData() const;
virtual XMLSize_t getLength() const;
virtual void insertData(XMLSize_t offset, const XMLCh * data);
virtual void replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh * data);
virtual void setData(const XMLCh * arg);
virtual const XMLCh * substringData(XMLSize_t offset, XMLSize_t count) const;
// Non standard extension for the range to work
DOMComment* splitText(XMLSize_t offset);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMCommentImpl & operator = (const DOMCommentImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,271 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DOMConfigurationImpl.hpp"
#include "DOMStringListImpl.hpp"
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOMException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
const unsigned short DOMConfigurationImpl::fDEFAULT_VALUES = 0x2596;
DOMConfigurationImpl::DOMConfigurationImpl(MemoryManager* const manager): featureValues(fDEFAULT_VALUES),
fErrorHandler(0), fSchemaType(0), fSchemaLocation(0),
fSupportedParameters(0), fMemoryManager(manager)
{
fSupportedParameters=new (fMemoryManager) DOMStringListImpl(17, fMemoryManager);
fSupportedParameters->add(XMLUni::fgDOMErrorHandler);
fSupportedParameters->add(XMLUni::fgDOMSchemaType);
fSupportedParameters->add(XMLUni::fgDOMSchemaLocation);
fSupportedParameters->add(XMLUni::fgDOMCanonicalForm);
fSupportedParameters->add(XMLUni::fgDOMCDATASections);
fSupportedParameters->add(XMLUni::fgDOMComments);
fSupportedParameters->add(XMLUni::fgDOMDatatypeNormalization);
fSupportedParameters->add(XMLUni::fgDOMWRTDiscardDefaultContent);
fSupportedParameters->add(XMLUni::fgDOMEntities);
fSupportedParameters->add(XMLUni::fgDOMInfoset);
fSupportedParameters->add(XMLUni::fgDOMNamespaces);
fSupportedParameters->add(XMLUni::fgDOMNamespaceDeclarations);
fSupportedParameters->add(XMLUni::fgDOMNormalizeCharacters);
fSupportedParameters->add(XMLUni::fgDOMSplitCDATASections);
fSupportedParameters->add(XMLUni::fgDOMValidate);
fSupportedParameters->add(XMLUni::fgDOMValidateIfSchema);
fSupportedParameters->add(XMLUni::fgDOMElementContentWhitespace);
}
DOMConfigurationImpl::~DOMConfigurationImpl() {
delete fSupportedParameters;
}
void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) {
if(!canSetParameter(name, value)) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
}
if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
fErrorHandler = (DOMErrorHandler*)value;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
fSchemaType = (XMLCh*)value;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
fSchemaLocation = (XMLCh*)value;
} else { // canSetParameter above should take care of this case
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
}
}
void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) {
if(!canSetParameter(name, value)) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
}
DOMConfigurationFeature whichFlag = getFeatureFlag(name);
if(value) {
featureValues |= whichFlag;
} else {
featureValues &= ~whichFlag;
}
}
// --------------------------------------
// Getter Methods
// --------------------------------------
const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const {
DOMConfigurationFeature whichFlag;
try {
whichFlag = getFeatureFlag(name);
if(featureValues & whichFlag) {
return (void*)true;
} else {
return (void*)false;
}
} catch (DOMException&) {
// must not be a boolean parameter
if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
return fErrorHandler;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
return fSchemaType;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
return fSchemaLocation;
} else {
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
}
}
}
// -----------------------------------------
// Query Methods
// -----------------------------------------
bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, const void* /*value*/) const {
/**
* canSetParameter(name, value) returns false in two conditions:
* 1) if a [required] feature has no supporting code, then return false in
* both the true and false outcomes (This is in order to be either fully
* spec compliant, or not at all)
* 2) if an [optional] feature has no supporting code, then return false
**/
if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
return true; // required //
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
return false; // optional //
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
return false; // optional //
}
return false;
}
bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, bool booleanValue) const {
/**
* canSetParameter(name, value) returns false in two conditions:
* 1) if a [required] feature has no supporting code, then return false in
* both the true and false outcomes (This is in order to be either fully
* spec compliant, or not at all)
* 2) if an [optional] feature has no supporting code, then return false
**/
DOMConfigurationFeature whichFlag = getFeatureFlag(name);
switch (whichFlag) {
case FEATURE_CANONICAL_FORM:
if(booleanValue) return false; // optional //
else return true; // required //
case FEATURE_CDATA_SECTIONS:
return true;
case FEATURE_COMMENTS:
return true;
case FEATURE_DATATYPE_NORMALIZATION:
if(booleanValue) return false; // required //
else return true; // required //
case FEATURE_DISCARD_DEFAULT_CONTENT:
if(booleanValue) return false; // required //
else return true; // required //
case FEATURE_ENTITIES:
if(booleanValue) return true; // required //
else return true; // required //
case FEATURE_INFOSET:
if(booleanValue) return false; // required //
else return true; // no effect//
case FEATURE_NAMESPACES:
return true;
case FEATURE_NAMESPACE_DECLARATIONS:
if(booleanValue) return true; // optional //
else return false; // required //
case FEATURE_NORMALIZE_CHARACTERS:
if(booleanValue) return false; // optional //
else return true; // required //
case FEATURE_SPLIT_CDATA_SECTIONS:
//we dont report an error in the false case so we cant claim we do it
if(booleanValue) return false; // required //
else return false; // required //
case FEATURE_VALIDATE:
if(booleanValue) return false; // optional //
else return true; // required //
case FEATURE_VALIDATE_IF_SCHEMA:
if(booleanValue) return false; // optional //
else return true; // required //
case FEATURE_ELEMENT_CONTENT_WHITESPACE:
if(booleanValue) return true; // required //
else return false; // optional //
}
// should never be here
return false;
}
const DOMStringList* DOMConfigurationImpl::getParameterNames() const
{
return fSupportedParameters;
}
// -------------------------------------------
// Impl methods
// -------------------------------------------
DOMConfigurationImpl::DOMConfigurationFeature DOMConfigurationImpl::getFeatureFlag(const XMLCh* name) const {
if(XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm)==0) {
return FEATURE_CANONICAL_FORM;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections )==0) {
return FEATURE_CDATA_SECTIONS;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMComments)==0) {
return FEATURE_COMMENTS;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization)==0) {
return FEATURE_DATATYPE_NORMALIZATION;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMWRTDiscardDefaultContent)==0) {
return FEATURE_DISCARD_DEFAULT_CONTENT;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities)==0) {
return FEATURE_ENTITIES;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset)==0) {
return FEATURE_INFOSET;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces)==0) {
return FEATURE_NAMESPACES;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations)==0) {
return FEATURE_NAMESPACE_DECLARATIONS;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters)==0) {
return FEATURE_NORMALIZE_CHARACTERS;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections)==0) {
return FEATURE_SPLIT_CDATA_SECTIONS;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate)==0) {
return FEATURE_VALIDATE;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema)==0) {
return FEATURE_VALIDATE_IF_SCHEMA;
} else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace)==0) {
return FEATURE_ELEMENT_CONTENT_WHITESPACE;
} else {
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
}
}
DOMErrorHandler* DOMConfigurationImpl::getErrorHandler() const {
return fErrorHandler;
}
const XMLCh* DOMConfigurationImpl::getSchemaType() const {
return fSchemaType;
}
const XMLCh* DOMConfigurationImpl::getSchemaLocation() const {
return fSchemaLocation;
}
void DOMConfigurationImpl::setErrorHandler(DOMErrorHandler *erHandler) {
fErrorHandler = erHandler;
}
void DOMConfigurationImpl::setSchemaType(const XMLCh* st) {
fSchemaType = st;
}
void DOMConfigurationImpl::setSchemaLocation(const XMLCh* sl) {
fSchemaLocation = sl;
}
XERCES_CPP_NAMESPACE_END
/**
* End of file DOMConfigurationImpl.cpp
*/
@@ -0,0 +1,150 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#if !defined(XERCESC_INCLUDE_GUARD_DOMCONFIGURATIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMCONFIGURATIONIMPL_HPP
//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#include <xercesc/dom/DOMConfiguration.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMDocumentImpl;
class DOMStringListImpl;
class CDOM_EXPORT DOMConfigurationImpl : public DOMConfiguration
{
private:
//unimplemented
DOMConfigurationImpl(const DOMConfiguration &);
DOMConfigurationImpl & operator = (const DOMConfiguration &);
public:
//-----------------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------------
DOMConfigurationImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMConfigurationImpl();
enum DOMConfigurationFeature {
FEATURE_CANONICAL_FORM = 0x0001,
FEATURE_CDATA_SECTIONS = 0x0002,
FEATURE_COMMENTS = 0x0004,
FEATURE_DATATYPE_NORMALIZATION = 0x0008,
FEATURE_DISCARD_DEFAULT_CONTENT = 0x0010,
FEATURE_ENTITIES = 0x0020,
FEATURE_INFOSET = 0x0040,
FEATURE_NAMESPACES = 0x0080,
FEATURE_NAMESPACE_DECLARATIONS = 0x0100,
FEATURE_NORMALIZE_CHARACTERS = 0x0200,
FEATURE_SPLIT_CDATA_SECTIONS = 0x0400,
FEATURE_VALIDATE = 0x0800,
FEATURE_VALIDATE_IF_SCHEMA = 0x1000,
FEATURE_ELEMENT_CONTENT_WHITESPACE = 0x2000
};
unsigned short featureValues;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
virtual void setParameter(const XMLCh* name, const void* value);
virtual void setParameter(const XMLCh* name, bool value);
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
virtual const void* getParameter(const XMLCh* name) const;
// -----------------------------------------------------------------------
// Query methods
// -----------------------------------------------------------------------
virtual bool canSetParameter(const XMLCh* name, const void* value) const;
virtual bool canSetParameter(const XMLCh* name, bool value) const;
virtual const DOMStringList* getParameterNames() const;
// ---------------------------------------------------------------------------
// Impl specific methods
// ---------------------------------------------------------------------------
/* specific get and set methods for non-boolean parameters
* */
DOMErrorHandler* getErrorHandler() const;
const XMLCh* getSchemaType() const;
const XMLCh* getSchemaLocation() const;
void setErrorHandler(DOMErrorHandler *erHandler);
void setSchemaType(const XMLCh* st);
void setSchemaLocation(const XMLCh* sl);
// The default values for the boolean parameters
// from CANONICAL_FORM to ELEMENT_CONTENT_WHITESPACE
// 10010110010110 = 0x2596
static const unsigned short fDEFAULT_VALUES;
protected:
// implements a simple map between the name and its enum value
DOMConfigurationFeature getFeatureFlag(const XMLCh* name) const;
// the error handler
DOMErrorHandler* fErrorHandler;
// the schema type
const XMLCh* fSchemaType;
// the schema location
const XMLCh* fSchemaLocation;
// the list of supported parameters
DOMStringListImpl* fSupportedParameters;
MemoryManager* fMemoryManager;
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file DOMConfigurationImpl.hpp
*/
@@ -0,0 +1,219 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDeepNodeListImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include "DOMDeepNodeListImpl.hpp"
#include "DOMElementImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMNodeImpl.hpp"
#include <xercesc/util/XMLUniDefs.hpp>
#include <limits.h>
XERCES_CPP_NAMESPACE_BEGIN
static const XMLCh kAstr[] = {chAsterisk, chNull};
DOMDeepNodeListImpl::DOMDeepNodeListImpl(const DOMNode *rootNode,
const XMLCh *tagName)
: fRootNode(rootNode)
, fChanges(0)
, fCurrentNode(0)
, fCurrentIndexPlus1(0)
, fNamespaceURI(0)
, fMatchAllURI(false)
, fMatchURIandTagname(false)
{
fTagName = ((DOMDocumentImpl *)(castToNodeImpl(rootNode)->getOwnerDocument()))->getPooledString(tagName);
fMatchAll = XMLString::equals(fTagName, kAstr);
}
//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);
}
DOMDeepNodeListImpl::~DOMDeepNodeListImpl()
{
}
XMLSize_t DOMDeepNodeListImpl::getLength() const
{
// Reset cache to beginning of list
item(0);
// Preload all matching elements. (Stops when we run out of subtree!)
item(INT_MAX);
return fCurrentIndexPlus1;
}
DOMNode *DOMDeepNodeListImpl::item(XMLSize_t index) const
{
return ((DOMDeepNodeListImpl*)this)->cacheItem(index);
}
// Start from the first child and count forward, 0-based. index>length-1
// should return 0.
//
// Attempts to do only work actually requested, cache work already
// done, and to flush that cache when the tree has changed.
//
// LIMITATION: ????? Unable to tell relevant tree-changes from
// irrelevant ones. Doing so in a really useful manner would seem
// to involve a tree-walk in its own right, or maintaining our data
// in a parallel tree.
DOMNode *DOMDeepNodeListImpl::cacheItem(XMLSize_t index)
{
XMLSize_t currentIndexPlus1 = fCurrentIndexPlus1;
DOMNode *currentNode = fCurrentNode;
if (castToParentImpl(fRootNode)->changes() != fChanges)
{
// Tree changed. Do it all from scratch!
currentIndexPlus1 = 0;
currentNode = (DOMNode *)fRootNode;
fChanges = castToParentImpl(fRootNode)->changes();
}
else if (currentIndexPlus1 > index+1)
{
// Interested in something before cached node. Do it all from scratch!
currentIndexPlus1 = 0;
currentNode = (DOMNode *)fRootNode;
}
else if (index+1 == currentIndexPlus1)
{
// What luck! User is interested in cached node.
return currentNode;
}
DOMNode *nextNode = 0;
// revisit - ???? How efficient is this loop? ????
// Start at the place in the tree at which we're
// currently pointing and count off nodes until we
// reach the node of interest or the end of the tree.
while (currentIndexPlus1 < index+1 && currentNode != 0)
{
nextNode = nextMatchingElementAfter(currentNode);
if (nextNode == 0)
break;
currentNode = nextNode;
currentIndexPlus1++;
}
fCurrentNode = currentNode;
fCurrentIndexPlus1 = currentIndexPlus1;
// If we found a node at the requested index, make that the current node
if (nextNode != 0)
{
return currentNode;
}
// If we didn't find a node at the requested index, return 0
return 0;
}
/* Iterative tree-walker. When you have a Parent link, there's often no
need to resort to recursion. NOTE THAT only Element nodes are matched
since we're specifically supporting getElementsByTagName().
*/
DOMNode *DOMDeepNodeListImpl::nextMatchingElementAfter(DOMNode *current)
{
DOMNode *next;
while (current != 0)
{
// Look down to first child.
if (current->hasChildNodes())
{
current = current->getFirstChild();
}
// Look right to sibling (but not from root!)
else
{
if (current != fRootNode && 0 != (next = current->getNextSibling()))
{
current = next;
}
// Look up and right (but not past root!)
else
{
next = 0;
for (;
current != fRootNode; // Stop on return to starting point
current = current->getParentNode())
{
next = current->getNextSibling();
if (next != 0)
break;
}
current = next;
}
}
// Have we found an Element with the right tagName?
// ("*" matches anything.)
if (current != 0 && current != fRootNode &&
current->getNodeType() == DOMNode::ELEMENT_NODE) {
DOMElement *currElement = (DOMElement *)current;
if (!fMatchURIandTagname) { //DOM Level 1
if (fMatchAll ||
XMLString::equals(currElement->getTagName(), fTagName))
return current;
} else { //DOM Level 2
if (!fMatchAllURI &&
!XMLString::equals(current->getNamespaceURI(), fNamespaceURI))
continue;
if (fMatchAll ||
XMLString::equals(current->getLocalName(), fTagName))
return current;
}
}
// Otherwise continue walking the tree
}
// Fell out of tree-walk; no more instances found
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDeepNodeListImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class CDOM_EXPORT DOMDeepNodeListImpl: public DOMNodeList {
protected:
const DOMNode* fRootNode;
const XMLCh* fTagName;
bool fMatchAll;
int fChanges;
DOMNode* fCurrentNode;
XMLSize_t fCurrentIndexPlus1;
//DOM Level 2
const XMLCh* fNamespaceURI;
bool fMatchAllURI;
bool fMatchURIandTagname; //match both namespaceURI and tagName
public:
DOMDeepNodeListImpl(const DOMNode *rootNode, const XMLCh *tagName);
DOMDeepNodeListImpl(const DOMNode *rootNode, //DOM Level 2
const XMLCh *namespaceURI,
const XMLCh *localName);
virtual ~DOMDeepNodeListImpl();
virtual XMLSize_t getLength() const;
virtual DOMNode* item(XMLSize_t index) const;
DOMNode* cacheItem(XMLSize_t index);
protected:
DOMNode* nextMatchingElementAfter(DOMNode *current);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMDeepNodeListImpl(const DOMDeepNodeListImpl &);
DOMDeepNodeListImpl & operator = (const DOMDeepNodeListImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,428 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* $Id: DOMDeepNodeListPool.c 883368 2009-11-23 15:28:19Z amassari $
*/
// ---------------------------------------------------------------------------
// Include
// ---------------------------------------------------------------------------
#include <xercesc/util/XercesDefs.hpp>
#if defined(XERCES_TMPLSINC)
#include <xercesc/dom/impl/DOMDeepNodeListPool.hpp>
#endif
#include <assert.h>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DOMDeepNodeListPool: Constructors and Destructor
// ---------------------------------------------------------------------------
template <class TVal, class THasher>
DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus
, const bool adoptElems
, const XMLSize_t initSize) :
fAdoptedElems(adoptElems)
, fBucketList(0)
, fHashModulus(modulus)
, fIdPtrs(0)
, fIdPtrsCount(initSize)
, fIdCounter(0)
, fMemoryManager(XMLPlatformUtils::fgMemoryManager)
{
initialize(modulus);
//
// Allocate the initial id pointers array. We don't have to zero them
// out since the fIdCounter value tells us which ones are valid. The
// zeroth element is never used (and represents an invalid pool id.)
//
if (!fIdPtrsCount)
fIdPtrsCount = 256;
fIdPtrs = (TVal**) fMemoryManager->allocate(fIdPtrsCount * sizeof(TVal*));//new TVal*[fIdPtrsCount];
fIdPtrs[0] = 0;
}
template <class TVal, class THasher>
DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus
, const bool adoptElems
, const THasher& hasher
, const XMLSize_t initSize) :
fAdoptedElems(adoptElems)
, fBucketList(0)
, fHashModulus(modulus)
, fIdPtrs(0)
, fIdPtrsCount(initSize)
, fIdCounter(0)
, fMemoryManager(XMLPlatformUtils::fgMemoryManager)
, fHasher(hasher)
{
initialize(modulus);
//
// Allocate the initial id pointers array. We don't have to zero them
// out since the fIdCounter value tells us which ones are valid. The
// zeroth element is never used (and represents an invalid pool id.)
//
if (!fIdPtrsCount)
fIdPtrsCount = 256;
fIdPtrs = (TVal**) fMemoryManager->allocate(fIdPtrsCount * sizeof(TVal*));//new TVal*[fIdPtrsCount];
fIdPtrs[0] = 0;
}
template <class TVal, class THasher>
DOMDeepNodeListPool<TVal, THasher>::DOMDeepNodeListPool( const XMLSize_t modulus
, const XMLSize_t initSize) :
fAdoptedElems(true)
, fBucketList(0)
, fHashModulus(modulus)
, fIdPtrs(0)
, fIdPtrsCount(initSize)
, fIdCounter(0)
, fMemoryManager(XMLPlatformUtils::fgMemoryManager)
{
initialize(modulus);
//
// Allocate the initial id pointers array. We don't have to zero them
// out since the fIdCounter value tells us which ones are valid. The
// zeroth element is never used (and represents an invalid pool id.)
//
if (!fIdPtrsCount)
fIdPtrsCount = 256;
fIdPtrs = (TVal**) fMemoryManager->allocate(fIdPtrsCount * sizeof(TVal*));//new TVal*[fIdPtrsCount];
fIdPtrs[0] = 0;
}
template <class TVal, class THasher>
void DOMDeepNodeListPool<TVal, THasher>::initialize(const XMLSize_t modulus)
{
if (modulus == 0)
ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::HshTbl_ZeroModulus, fMemoryManager);
// Allocate the bucket list and zero them
fBucketList = (DOMDeepNodeListPoolTableBucketElem<TVal>**)
fMemoryManager->allocate
(
fHashModulus * sizeof(DOMDeepNodeListPoolTableBucketElem<TVal>*)
);//new DOMDeepNodeListPoolTableBucketElem<TVal>*[fHashModulus];
for (XMLSize_t index = 0; index < fHashModulus; index++)
fBucketList[index] = 0;
}
template <class TVal, class THasher>
DOMDeepNodeListPool<TVal, THasher>::~DOMDeepNodeListPool()
{
removeAll();
// Then delete the bucket list & hasher & id pointers list
fMemoryManager->deallocate(fIdPtrs);//delete [] fIdPtrs;
fMemoryManager->deallocate(fBucketList);//delete [] fBucketList;
}
// ---------------------------------------------------------------------------
// DOMDeepNodeListPool: Element management
// ---------------------------------------------------------------------------
template <class TVal, class THasher>
bool DOMDeepNodeListPool<TVal, THasher>::isEmpty() const
{
// Just check the bucket list for non-empty elements
for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++)
{
if (fBucketList[buckInd] != 0)
return false;
}
return true;
}
template <class TVal, class THasher>
bool DOMDeepNodeListPool<TVal, THasher>::containsKey( const void* const key1
, const XMLCh* const key2
, const XMLCh* const key3) const
{
XMLSize_t hashVal;
const DOMDeepNodeListPoolTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal);
return (findIt != 0);
}
template <class TVal, class THasher>
void DOMDeepNodeListPool<TVal, THasher>::removeAll()
{
if (fIdCounter == 0) return;
// Clean up the buckets first
for (XMLSize_t buckInd = 0; buckInd < fHashModulus; buckInd++)
{
// Get the bucket list head for this entry
DOMDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[buckInd];
DOMDeepNodeListPoolTableBucketElem<TVal>* nextElem;
while (curElem)
{
// Save the next element before we hose this one
nextElem = curElem->fNext;
// If we adopted the data, then delete it too
// (Note: the userdata hash table instance has data type of void *.
// This will generate compiler warnings here on some platforms, but they
// can be ignored since fAdoptedElements is false.
if (fAdoptedElems)
delete curElem->fData;
// Then delete the current element and move forward
fMemoryManager->deallocate(curElem->fKey2);//delete [] curElem->fKey2;
fMemoryManager->deallocate(curElem->fKey3);//delete [] curElem->fKey3;
delete curElem;
curElem = nextElem;
}
// Clean out this entry
fBucketList[buckInd] = 0;
}
// Reset the id counter
fIdCounter = 0;
}
template <class TVal, class THasher>
void DOMDeepNodeListPool<TVal, THasher>::cleanup()
{
removeAll();
// Then delete the bucket list & hasher & id pointers list
fMemoryManager->deallocate(fIdPtrs);//delete [] fIdPtrs;
fMemoryManager->deallocate(fBucketList);//delete [] fBucketList;
}
// ---------------------------------------------------------------------------
// DOMDeepNodeListPool: Getters
// ---------------------------------------------------------------------------
template <class TVal, class THasher>
TVal*
DOMDeepNodeListPool<TVal, THasher>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3)
{
XMLSize_t hashVal;
DOMDeepNodeListPoolTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal);
if (!findIt)
return 0;
return findIt->fData;
}
template <class TVal, class THasher>
const TVal*
DOMDeepNodeListPool<TVal, THasher>::getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const
{
XMLSize_t hashVal;
const DOMDeepNodeListPoolTableBucketElem<TVal>* findIt = findBucketElem(key1, key2, key3, hashVal);
if (!findIt)
return 0;
return findIt->fData;
}
template <class TVal, class THasher>
TVal*
DOMDeepNodeListPool<TVal, THasher>::getById(const XMLSize_t elemId)
{
// If its either zero or beyond our current id, its an error
if (!elemId || (elemId > fIdCounter))
ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Pool_InvalidId, fMemoryManager);
return fIdPtrs[elemId];
}
template <class TVal, class THasher>
const TVal*
DOMDeepNodeListPool<TVal, THasher>::getById(const XMLSize_t elemId) const
{
// If its either zero or beyond our current id, its an error
if (!elemId || (elemId > fIdCounter))
ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Pool_InvalidId, fMemoryManager);
return fIdPtrs[elemId];
}
// ---------------------------------------------------------------------------
// DOMDeepNodeListPool: Putters
// ---------------------------------------------------------------------------
template <class TVal, class THasher>
XMLSize_t
DOMDeepNodeListPool<TVal, THasher>::put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt)
{
// First see if the key exists already
XMLSize_t hashVal;
DOMDeepNodeListPoolTableBucketElem<TVal>* newBucket = findBucketElem(key1, key2, key3, hashVal);
//
// If so,then update its value. If not, then we need to add it to
// the right bucket
//
if (newBucket)
{
if (fAdoptedElems)
delete newBucket->fData;
fMemoryManager->deallocate(newBucket->fKey2);//delete[] newBucket->fKey2;
fMemoryManager->deallocate(newBucket->fKey3);//delete[] newBucket->fKey3;
newBucket->fData = valueToAdopt;
newBucket->fKey1 = key1;
newBucket->fKey2 = XMLString::replicate(key2, fMemoryManager);
newBucket->fKey3 = XMLString::replicate(key3, fMemoryManager);
}
else
{
// Revisit: the gcc compiler 2.95.x is generating an
// internal compiler error message. So we use the default
// memory manager for now.
#if defined (XML_GCC_VERSION) && (XML_GCC_VERSION < 29600)
newBucket = new DOMDeepNodeListPoolTableBucketElem<TVal>
(
key1
, key2
, key3
, valueToAdopt
, fBucketList[hashVal]
, fMemoryManager
);
#else
newBucket = new (fMemoryManager) DOMDeepNodeListPoolTableBucketElem<TVal>
(
key1
, key2
, key3
, valueToAdopt
, fBucketList[hashVal]
, fMemoryManager
);
#endif
fBucketList[hashVal] = newBucket;
}
//
// Give this new one the next available id and add to the pointer list.
// Expand the list if that is now required.
//
if (fIdCounter + 1 == fIdPtrsCount)
{
// Create a new count 1.5 times larger and allocate a new array
XMLSize_t newCount = (XMLSize_t)(fIdPtrsCount * 1.5);
TVal** newArray = (TVal**) fMemoryManager->allocate
(
newCount * sizeof(TVal*)
);//new TVal*[newCount];
// Copy over the old contents to the new array
memcpy(newArray, fIdPtrs, fIdPtrsCount * sizeof(TVal*));
// Ok, toss the old array and store the new data
fMemoryManager->deallocate(fIdPtrs); //delete [] fIdPtrs;
fIdPtrs = newArray;
fIdPtrsCount = newCount;
}
const XMLSize_t retId = ++fIdCounter;
fIdPtrs[retId] = valueToAdopt;
// Return the id that we gave to this element
return retId;
}
// ---------------------------------------------------------------------------
// DOMDeepNodeListPool: Private methods
// ---------------------------------------------------------------------------
template <class TVal, class THasher>
DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal, THasher>::
findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal)
{
// Hash the key
hashVal = fHasher.getHashVal(key1, fHashModulus);
assert(hashVal < fHashModulus);
// Search that bucket for the key
DOMDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
while (curElem)
{
//key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same
//but we need them to be treated as different keys in this case
if (fHasher.equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) {
if (!key2 || !curElem->fKey2) {
if (key2 || curElem->fKey2) {
curElem = curElem->fNext;
continue;
}
}
if (!key3 || !curElem->fKey3) {
if (key3 || curElem->fKey3) {
curElem = curElem->fNext;
continue;
}
}
return curElem;
}
curElem = curElem->fNext;
}
return 0;
}
template <class TVal, class THasher>
const DOMDeepNodeListPoolTableBucketElem<TVal>* DOMDeepNodeListPool<TVal, THasher>::
findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const
{
// Hash the key
hashVal = fHasher.getHashVal(key1, fHashModulus);
assert(hashVal < fHashModulus);
// Search that bucket for the key
const DOMDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
while (curElem)
{
//key2 and key3 are XMLCh*, compareString takes null pointer vs zero len string the same
//but we need them to be treated as different keys in this case
if (fHasher.equals(key1, curElem->fKey1) && (XMLString::equals(key2, curElem->fKey2)) && (XMLString::equals(key3, curElem->fKey3))) {
if (!key2 || !curElem->fKey2) {
if (key2 || curElem->fKey2) {
curElem = curElem->fNext;
continue;
}
}
if (!key3 || !curElem->fKey3) {
if (key3 || curElem->fKey3) {
curElem = curElem->fNext;
continue;
}
}
return curElem;
}
curElem = curElem->fNext;
}
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,200 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDeepNodeListPool.hpp 883368 2009-11-23 15:28:19Z amassari $
*/
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#if !defined(XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMDEEPNODELISTPOOL_HPP
#include <xercesc/util/Hashers.hpp>
#include <xercesc/util/IllegalArgumentException.hpp>
#include <xercesc/util/NoSuchElementException.hpp>
#include <xercesc/util/RuntimeException.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/XMLEnumerator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This should really be a nested class, but some of the compilers we
// have to support cannot deal with that!
//
template <class TVal>
struct DOMDeepNodeListPoolTableBucketElem : public XMemory
{
DOMDeepNodeListPoolTableBucketElem
(
void* key1
, XMLCh* key2
, XMLCh* key3
, TVal* const value
, DOMDeepNodeListPoolTableBucketElem<TVal>* next
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
) :
fData(value)
, fNext(next)
, fKey1(key1)
, fKey2(0)
, fKey3(0)
{
if (key2)
fKey2 = XMLString::replicate(key2, manager);
if (key3)
fKey3 = XMLString::replicate(key3, manager);
}
TVal* fData;
DOMDeepNodeListPoolTableBucketElem<TVal>* fNext;
void* fKey1;
XMLCh* fKey2;
XMLCh* fKey3;
~DOMDeepNodeListPoolTableBucketElem() {};
};
template <class TVal, class THasher = PtrHasher>
class DOMDeepNodeListPool
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DOMDeepNodeListPool
(
const XMLSize_t modulus
, const XMLSize_t initSize = 128
);
DOMDeepNodeListPool
(
const XMLSize_t modulus
, const bool adoptElems
, const XMLSize_t initSize = 128
);
DOMDeepNodeListPool
(
const XMLSize_t modulus
, const bool adoptElems
, const THasher& hasher
, const XMLSize_t initSize = 128
);
~DOMDeepNodeListPool();
// -----------------------------------------------------------------------
// Element management
// -----------------------------------------------------------------------
bool isEmpty() const;
bool containsKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
void removeAll();
void cleanup();
// -----------------------------------------------------------------------
// Getters
// -----------------------------------------------------------------------
TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3);
const TVal* getByKey(const void* const key1, const XMLCh* const key2, const XMLCh* const key3) const;
TVal* getById(const XMLSize_t elemId);
const TVal* getById(const XMLSize_t elemId) const;
// -----------------------------------------------------------------------
// Putters
// -----------------------------------------------------------------------
XMLSize_t put(void* key1, XMLCh* key2, XMLCh* key3, TVal* const valueToAdopt);
private:
// -----------------------------------------------------------------------
// Private methods
// -----------------------------------------------------------------------
DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal);
const DOMDeepNodeListPoolTableBucketElem<TVal>* findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* const key3, XMLSize_t& hashVal) const;
void initialize(const XMLSize_t modulus);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMDeepNodeListPool(const DOMDeepNodeListPool<TVal, THasher> &);
DOMDeepNodeListPool<TVal, THasher> & operator = (const DOMDeepNodeListPool<TVal, THasher> &);
// -----------------------------------------------------------------------
// Data members
//
// fAdoptedElems
// Indicates whether the values added are adopted or just referenced.
// If adopted, then they are deleted when they are removed from the
// hash table.
//
// fBucketList
// This is the array that contains the heads of all of the list
// buckets, one for each possible hash value.
//
// fHashModulus
// The modulus used for this hash table, to hash the keys. This is
// also the number of elements in the bucket list.
//
// fHash
// The hasher for the key1 data type.
//
// fIdPtrs
// fIdPtrsCount
// This is the array of pointers to the bucket elements in order of
// their assigned ids. So taking id N and referencing this array
// gives you the element with that id. The count field indicates
// the current size of this list. When fIdCounter+1 reaches this
// value the list must be expanded.
//
// fIdCounter
// This is used to give out unique ids to added elements. It starts
// at zero (which means empty), and is bumped up for each newly added
// element. So the first element is 1, the next is 2, etc... This
// means that this value is set to the top index of the fIdPtrs array.
// -----------------------------------------------------------------------
bool fAdoptedElems;
DOMDeepNodeListPoolTableBucketElem<TVal>** fBucketList;
XMLSize_t fHashModulus;
TVal** fIdPtrs;
XMLSize_t fIdPtrsCount;
XMLSize_t fIdCounter;
MemoryManager* fMemoryManager;
THasher fHasher;
};
XERCES_CPP_NAMESPACE_END
#if !defined(XERCES_TMPLSINC)
#include <xercesc/dom/impl/DOMDeepNodeListPool.c>
#endif
#endif
@@ -0,0 +1,137 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDocumentFragmentImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMDocumentFragmentImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMDocumentFragmentImpl::DOMDocumentFragmentImpl(DOMDocument *masterDoc)
: fNode(masterDoc), fParent(masterDoc)
{
}
DOMDocumentFragmentImpl::DOMDocumentFragmentImpl(const DOMDocumentFragmentImpl &other,
bool deep)
: fNode(other.fNode), fParent(other.fParent)
{
if (deep)
castToParentImpl(this)->cloneChildren(&other);
}
DOMDocumentFragmentImpl::~DOMDocumentFragmentImpl()
{
}
DOMNode *DOMDocumentFragmentImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (castToNodeImpl(this)->getOwnerDocument(), DOMMemoryManager::DOCUMENT_FRAGMENT_OBJECT) DOMDocumentFragmentImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMDocumentFragmentImpl::getNodeName() const {
static const XMLCh name[] = {chPound, chLatin_d, chLatin_o, chLatin_c, chLatin_u, chLatin_m,
chLatin_e, chLatin_n, chLatin_t, chDash,
chLatin_f, chLatin_r, chLatin_a, chLatin_g, chLatin_m, chLatin_e, chLatin_n, chLatin_t, 0};
return name;
}
DOMNode::NodeType DOMDocumentFragmentImpl::getNodeType() const {
return DOMNode::DOCUMENT_FRAGMENT_NODE;
}
void DOMDocumentFragmentImpl::setNodeValue(const XMLCh *x)
{
fNode.setNodeValue(x);
}
void DOMDocumentFragmentImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::DOCUMENT_FRAGMENT_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
//
// Delegation stubs for inherited functions.
//
DOMNode* DOMDocumentFragmentImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
DOMNamedNodeMap* DOMDocumentFragmentImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMDocumentFragmentImpl::getChildNodes() const {return fParent.getChildNodes (); }
DOMNode* DOMDocumentFragmentImpl::getFirstChild() const {return fParent.getFirstChild (); }
DOMNode* DOMDocumentFragmentImpl::getLastChild() const {return fParent.getLastChild (); }
const XMLCh* DOMDocumentFragmentImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMDocumentFragmentImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMDocumentFragmentImpl::getNextSibling() const {return fNode.getNextSibling (); }
const XMLCh* DOMDocumentFragmentImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMDocumentFragmentImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMDocumentFragmentImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMDocumentFragmentImpl::getParentNode() const {return fNode.getParentNode (); }
DOMNode* DOMDocumentFragmentImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }
bool DOMDocumentFragmentImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
DOMNode* DOMDocumentFragmentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); }
void DOMDocumentFragmentImpl::normalize() {fParent.normalize (); }
DOMNode* DOMDocumentFragmentImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
DOMNode* DOMDocumentFragmentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); }
bool DOMDocumentFragmentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMDocumentFragmentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMDocumentFragmentImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMDocumentFragmentImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMDocumentFragmentImpl::isEqualNode(const DOMNode* arg) const {return fParent.isEqualNode(arg); }
void* DOMDocumentFragmentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMDocumentFragmentImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMDocumentFragmentImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMDocumentFragmentImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMDocumentFragmentImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMDocumentFragmentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMDocumentFragmentImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMDocumentFragmentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMDocumentFragmentImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMDocumentFragmentImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDocumentFragmentImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMDOCUMENTFRAGMENTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMDOCUMENTFRAGMENTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMDocumentFragment.hpp>
#include "DOMParentNode.hpp"
#include "DOMNodeImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMDocumentFragmentImpl: public DOMDocumentFragment {
protected:
DOMNodeImpl fNode;
DOMParentNode fParent;
protected:
DOMDocumentFragmentImpl(DOMDocument *);
DOMDocumentFragmentImpl(const DOMDocumentFragmentImpl &other, bool deep);
friend class DOMDocumentImpl;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMDocumentFragmentImpl & operator = (const DOMDocumentFragmentImpl &);
public:
virtual ~DOMDocumentFragmentImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
};
XERCES_CPP_NAMESPACE_END
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,507 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDocumentImpl.hpp 1662888 2015-02-28 02:26:43Z scantor $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMDOCUMENTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMDOCUMENTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/RefArrayOf.hpp>
#include <xercesc/util/RefStackOf.hpp>
#include <xercesc/util/RefHash2KeysTableOf.hpp>
#include <xercesc/util/StringPool.hpp>
#include <xercesc/util/KeyRefPair.hpp>
#include <xercesc/util/XMLChar.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMUserDataHandler.hpp>
#include <xercesc/dom/DOMMemoryManager.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMParentNode.hpp"
#include "DOMDeepNodeListPool.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMAttrImpl;
class DOMCDATASectionImpl;
class DOMCommentImpl;
class DOMConfiguration;
class DOMDeepNodeListImpl;
class DOMDocumentFragmentImpl;
class DOMDocumentTypeImpl;
class DOMElementImpl;
class DOMEntityImpl;
class DOMEntityReferenceImpl;
class DOMNotationImpl;
class DOMProcessingInstructionImpl;
class DOMTextImpl;
class DOMNodeIteratorImpl;
class DOMNormalizer;
class DOMTreeWalkerImpl;
class DOMNodeFilter;
class DOMNodeFilterImpl;
class DOMImplementation;
class DOMNodeIDMap;
class DOMRangeImpl;
class DOMBuffer;
class MemoryManager;
class XPathNSResolver;
class XPathExpression;
typedef RefVectorOf<DOMRangeImpl> Ranges;
typedef RefVectorOf<DOMNodeIteratorImpl> NodeIterators;
typedef KeyRefPair<void, DOMUserDataHandler> DOMUserDataRecord;
typedef RefStackOf<DOMNode> DOMNodePtr;
class CDOM_EXPORT DOMDocumentImpl: public XMemory, public DOMMemoryManager, public DOMDocument {
public:
// -----------------------------------------------------------------------
// data
// -----------------------------------------------------------------------
DOMNodeImpl fNode; // Implements common node functionality.
DOMParentNode fParent; // Implements common parent node functionality
DOMNodeIDMap* fNodeIDMap; // for use by GetElementsById().
public:
DOMDocumentImpl(DOMImplementation* domImpl, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
DOMDocumentImpl(const XMLCh* namespaceURI, //DOM Level 2
const XMLCh* qualifiedName,
DOMDocumentType* doctype,
DOMImplementation* domImpl,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual ~DOMDocumentImpl();
void setDocumentType(DOMDocumentType *doctype);
public:
// Add all functions that are pure virtual in DOMNODE
DOMNODE_FUNCTIONS;
public:
// Add all functions that are pure virtual in DOMDocument
virtual DOMAttr* createAttribute(const XMLCh *name);
virtual DOMCDATASection* createCDATASection(const XMLCh *data);
virtual DOMComment* createComment(const XMLCh *data);
virtual DOMDocumentFragment* createDocumentFragment();
virtual DOMDocumentType* createDocumentType(const XMLCh *name);
virtual DOMDocumentType* createDocumentType(const XMLCh *qName,
const XMLCh *publicId,
const XMLCh *systemId);
virtual DOMElement* createElement(const XMLCh * tagName);
virtual DOMElement* createElementNoCheck(const XMLCh *tagName);
virtual DOMEntity* createEntity(const XMLCh * name);
virtual DOMEntityReference* createEntityReference(const XMLCh * name);
virtual DOMNotation* createNotation(const XMLCh * name);
virtual DOMProcessingInstruction* createProcessingInstruction(const XMLCh * target, const XMLCh * data);
virtual DOMText* createTextNode(const XMLCh * data);
virtual DOMDocumentType* getDoctype() const;
virtual DOMElement* getDocumentElement() const;
virtual DOMNodeList* getElementsByTagName(const XMLCh * tagname) const;
virtual DOMImplementation* getImplementation() const;
bool isXMLName(const XMLCh * s);
virtual DOMNodeIterator* createNodeIterator(DOMNode *root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* filter,
bool entityReferenceExpansion);
virtual DOMTreeWalker* createTreeWalker(DOMNode *root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* filter,
bool entityReferenceExpansion);
virtual DOMRange* createRange();
virtual Ranges* getRanges() const; //non-standard api
virtual NodeIterators* getNodeIterators() const; //non-standard api
virtual void removeRange(DOMRangeImpl* range); //non-standard api
virtual void removeNodeIterator(DOMNodeIteratorImpl* nodeIterator); //non-standard api
virtual DOMXPathExpression* createExpression(const XMLCh *expression,
const DOMXPathNSResolver *resolver);
virtual DOMXPathNSResolver* createNSResolver(const DOMNode *nodeResolver);
virtual DOMXPathResult* evaluate(const XMLCh *expression,
const DOMNode *contextNode,
const DOMXPathNSResolver *resolver,
DOMXPathResult::ResultType type,
DOMXPathResult* result);
// Extension to be called by the Parser
DOMEntityReference* createEntityReferenceByParser(const XMLCh * name);
// Add all functions that are pure virtual in DOMMemoryManager
virtual XMLSize_t getMemoryAllocationBlockSize() const;
virtual void setMemoryAllocationBlockSize(XMLSize_t size);
virtual void* allocate(XMLSize_t amount);
virtual void* allocate(XMLSize_t amount, DOMMemoryManager::NodeObjectType type);
virtual void release(DOMNode* object, DOMMemoryManager::NodeObjectType type);
virtual XMLCh* cloneString(const XMLCh *src);
//
// Functions to keep track of document mutations, so that node list chached
// information can be invalidated. One global changes counter per document.
//
virtual void changed();
virtual int changes() const;
/**
* Sets whether the DOM implementation performs error checking
* upon operations. Turning off error checking only affects
* the following DOM checks:
* <ul>
* <li>Checking strings to make sure that all characters are
* legal XML characters
* <li>Hierarchy checking such as allowed children, checks for
* cycles, etc.
* </ul>
* <p>
* Turning off error checking does <em>not</em> turn off the
* following checks:
* <ul>
* <li>Read only checks
* <li>Checks related to DOM events
* </ul>
*/
inline void setErrorChecking(bool check) {
errorChecking = check;
}
/**
* Returns true if the DOM implementation performs error checking.
*/
inline bool getErrorChecking() const {
return errorChecking;
}
//Introduced in DOM Level 2
virtual DOMNode* importNode(const DOMNode *source, bool deep);
virtual DOMElement* createElementNS(const XMLCh *namespaceURI,
const XMLCh *qualifiedName);
virtual DOMElement* createElementNS(const XMLCh *namespaceURI,
const XMLCh *qualifiedName,
const XMLFileLoc lineNo,
const XMLFileLoc columnNo);
virtual DOMAttr* createAttributeNS(const XMLCh *namespaceURI,
const XMLCh *qualifiedName);
virtual DOMNodeList* getElementsByTagNameNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual DOMElement* getElementById(const XMLCh *elementId) const;
//Introduced in DOM Level 3
virtual const XMLCh* getInputEncoding() const;
virtual const XMLCh* getXmlEncoding() const;
virtual bool getXmlStandalone() const;
virtual void setXmlStandalone(bool standalone);
virtual const XMLCh* getXmlVersion() const;
virtual void setXmlVersion(const XMLCh* version);
virtual const XMLCh* getDocumentURI() const;
virtual void setDocumentURI(const XMLCh* documentURI);
virtual bool getStrictErrorChecking() const;
virtual void setStrictErrorChecking(bool strictErrorChecking);
virtual DOMNode* adoptNode(DOMNode* source);
virtual void normalizeDocument();
virtual DOMConfiguration* getDOMConfig() const;
void setInputEncoding(const XMLCh* actualEncoding);
void setXmlEncoding(const XMLCh* encoding);
// helper functions to prevent storing userdata pointers on every node.
void* setUserData(DOMNodeImpl* n,
const XMLCh* key,
void* data,
DOMUserDataHandler* handler);
void* getUserData(const DOMNodeImpl* n,
const XMLCh* key) const;
void callUserDataHandlers(const DOMNodeImpl* n,
DOMUserDataHandler::DOMOperationType operation,
const DOMNode* src,
DOMNode* dst) const;
void transferUserData(DOMNodeImpl* n1, DOMNodeImpl* n2);
DOMNode* renameNode(DOMNode* n,
const XMLCh* namespaceURI,
const XMLCh* name);
//Return the index > 0 of ':' in the given qualified name qName="prefix:localName".
//Return 0 if there is no ':', or -1 if qName is malformed such as ":abcd".
static int indexofQualifiedName(const XMLCh * qName);
static bool isKidOK(DOMNode *parent, DOMNode *child);
inline DOMNodeIDMap* getNodeIDMap() {return fNodeIDMap;};
//
// Memory Management Functions. All memory is allocated by and owned by
// a document, and is not recovered until the
// document itself is deleted.
//
const XMLCh* getPooledString(const XMLCh*);
const XMLCh* getPooledNString(const XMLCh*, XMLSize_t);
void deleteHeap();
void releaseDocNotifyUserData(DOMNode* object);
void releaseBuffer(DOMBuffer* buffer);
DOMBuffer* popBuffer(XMLSize_t nMinSize);
MemoryManager* getMemoryManager() const;
// Factory methods for getting/creating node lists.
// Because nothing is ever deleted, the implementation caches and recycles
// previously used instances of DOMDeepNodeList
//
DOMNodeList* getDeepNodeList(const DOMNode *rootNode, const XMLCh *tagName);
DOMNodeList* getDeepNodeList(const DOMNode *rootNode, //DOM Level 2
const XMLCh *namespaceURI,
const XMLCh *localName);
protected:
//Internal helper functions
virtual DOMNode* importNode(const DOMNode *source, bool deep, bool cloningNode);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMDocumentImpl(const DOMDocumentImpl &);
DOMDocumentImpl & operator = (const DOMDocumentImpl &);
protected:
// -----------------------------------------------------------------------
// data
// -----------------------------------------------------------------------
// New data introduced in DOM Level 3
const XMLCh* fInputEncoding;
const XMLCh* fXmlEncoding;
bool fXmlStandalone;
const XMLCh* fXmlVersion;
const XMLCh* fDocumentURI;
DOMConfiguration* fDOMConfiguration;
XMLStringPool fUserDataTableKeys;
RefHash2KeysTableOf<DOMUserDataRecord, PtrHasher>* fUserDataTable;
// Per-Document heap Variables.
// The heap consists of one or more biggish blocks which are
// sub-allocated for individual allocations of nodes, strings, etc.
// The big blocks form a linked list, allowing them to be located for deletion.
//
// There is no provision for deleting suballocated blocks, other than
// deleting the entire heap when the document is deleted.
//
// There is no header on individual sub-allocated blocks.
// The header on big blocks consists only of a single back pointer to
// the previously allocated big block (our linked list of big blocks)
//
//
// revisit - this heap should be encapsulated into its own
// class, rather than hanging naked on Document.
//
void* fCurrentBlock;
char* fFreePtr;
XMLSize_t fFreeBytesRemaining,
fHeapAllocSize;
// To recycle the DOMNode pointer
RefArrayOf<DOMNodePtr>* fRecycleNodePtr;
// To recycle DOMBuffer pointer
RefStackOf<DOMBuffer>* fRecycleBufferPtr;
// Pool of DOMNodeList for getElementsByTagName
DOMDeepNodeListPool<DOMDeepNodeListImpl>* fNodeListPool;
// Other data
DOMDocumentType* fDocType;
DOMElement* fDocElement;
DOMStringPoolEntry** fNameTable;
XMLSize_t fNameTableSize;
DOMNormalizer* fNormalizer;
Ranges* fRanges;
NodeIterators* fNodeIterators;
MemoryManager* fMemoryManager; // configurable memory manager
DOMImplementation* fDOMImplementation;
int fChanges;
bool errorChecking; // Bypass error checking.
};
inline MemoryManager* DOMDocumentImpl::getMemoryManager() const
{
return fMemoryManager;
}
inline const XMLCh* DOMDocumentImpl::getPooledString(const XMLCh *in)
{
if (in == 0)
return 0;
DOMStringPoolEntry **pspe;
DOMStringPoolEntry *spe;
XMLSize_t inHash = XMLString::hash(in, fNameTableSize);
pspe = &fNameTable[inHash];
while (*pspe != 0)
{
if (XMLString::equals((*pspe)->fString, in))
return (*pspe)->fString;
pspe = &((*pspe)->fNext);
}
// This string hasn't been seen before. Add it to the pool.
//
// Compute size to allocate. Note that there's 1 char of string
// declared in the struct, so we don't need to add one again to
// account for the trailing null.
//
XMLSize_t n = XMLString::stringLen(in);
XMLSize_t sizeToAllocate = sizeof(DOMStringPoolEntry) + n*sizeof(XMLCh);
*pspe = spe = (DOMStringPoolEntry *)allocate(sizeToAllocate);
spe->fNext = 0;
XMLString::copyString((XMLCh*)spe->fString, in);
return spe->fString;
}
inline const XMLCh* DOMDocumentImpl::getPooledNString(const XMLCh *in, XMLSize_t n)
{
if (in == 0)
return 0;
DOMStringPoolEntry **pspe;
DOMStringPoolEntry *spe;
XMLSize_t inHash = XMLString::hashN(in, n, fNameTableSize);
pspe = &fNameTable[inHash];
while (*pspe != 0)
{
if (XMLString::stringLen((*pspe)->fString) == n && XMLString::equalsN((*pspe)->fString, in, n))
return (*pspe)->fString;
pspe = &((*pspe)->fNext);
}
// This string hasn't been seen before. Add it to the pool.
//
// Compute size to allocate. Note that there's 1 char of string
// declared in the struct, so we don't need to add one again to
// account for the trailing null.
//
XMLSize_t sizeToAllocate = sizeof(DOMStringPoolEntry) + n*sizeof(XMLCh);
*pspe = spe = (DOMStringPoolEntry *)allocate(sizeToAllocate);
spe->fNext = 0;
XMLString::copyNString((XMLCh*)spe->fString, in, n);
return spe->fString;
}
inline int DOMDocumentImpl::indexofQualifiedName(const XMLCh* name)
{
int i = 0;
int colon = -1;
int colon_count = 0;
for (; *name != 0; ++i, ++name)
{
if (*name == chColon)
{
++colon_count;
colon = i;
}
}
if (i == 0 || colon == 0 || colon == (i - 1) || colon_count > 1)
return -1;
return colon != -1 ? colon : 0;
}
XERCES_CPP_NAMESPACE_END
// ---------------------------------------------------------------------------
//
// Operator new. Global overloaded version, lets any object be allocated on
// the heap owned by a document.
//
// ---------------------------------------------------------------------------
inline void * operator new(size_t amt, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocumentImpl *doc, XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager::NodeObjectType type)
{
void *p = doc->allocate(amt, type);
return p;
}
inline void * operator new(size_t amt, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager::NodeObjectType type)
{
XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager* mgr=(XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager*)doc->getFeature(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgXercescInterfaceDOMMemoryManager,0);
void* p=0;
if(mgr)
p = mgr->allocate(amt, type);
return p;
}
inline void * operator new(size_t amt, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocumentImpl *doc)
{
void* p = doc->allocate(amt);
return p;
}
inline void * operator new(size_t amt, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc)
{
XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager* mgr=(XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager*)doc->getFeature(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgXercescInterfaceDOMMemoryManager,0);
void* p=0;
if(mgr)
p = mgr->allocate(amt);
return p;
}
// ---------------------------------------------------------------------------
// For DOM:
// Bypass compiler warning:
// no matching operator delete found; memory will not be freed if initialization throws an exception
// ---------------------------------------------------------------------------
#if !defined(XERCES_NO_MATCHING_DELETE_OPERATOR)
inline void operator delete(void* /*ptr*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocumentImpl * /*doc*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager::NodeObjectType /*type*/)
{
return;
}
inline void operator delete(void* /*ptr*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * /*doc*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMMemoryManager::NodeObjectType /*type*/)
{
return;
}
inline void operator delete(void* /*ptr*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocumentImpl * /*doc*/)
{
return;
}
inline void operator delete(void* /*ptr*/, XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * /*doc*/)
{
return;
}
#endif
#endif
@@ -0,0 +1,555 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDocumentTypeImpl.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
#include "DOMDocumentTypeImpl.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLChar.hpp>
#include <xercesc/util/Mutexes.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include "DOMNamedNodeMapImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMCasts.hpp"
XERCES_CPP_NAMESPACE_BEGIN
static DOMDocument* sDocument = 0;
static XMLMutex* sDocumentMutex = 0;
void XMLInitializer::initializeDOMDocumentTypeImpl()
{
sDocumentMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager);
static const XMLCh gCoreStr[] = { chLatin_C, chLatin_o, chLatin_r, chLatin_e, chNull };
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gCoreStr);
sDocument = impl->createDocument(); // document type object (DTD).
}
void XMLInitializer::terminateDOMDocumentTypeImpl()
{
sDocument->release();
sDocument = 0;
delete sDocumentMutex;
sDocumentMutex = 0;
}
DOMDocumentTypeImpl::DOMDocumentTypeImpl(DOMDocument *ownerDoc,
const XMLCh *dtName,
bool heap)
: fNode(ownerDoc),
fParent(ownerDoc),
fName(0),
fEntities(0),
fNotations(0),
fElements(0),
fPublicId(0),
fSystemId(0),
fInternalSubset(0),
fIntSubsetReading(false),
fIsCreatedFromHeap(heap)
{
if (ownerDoc)
{
fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(dtName);
fEntities = new (ownerDoc) DOMNamedNodeMapImpl(this);
fNotations= new (ownerDoc) DOMNamedNodeMapImpl(this);
fElements = new (ownerDoc) DOMNamedNodeMapImpl(this);
}
else
{
XMLMutexLock lock(sDocumentMutex);
DOMDocument* doc = sDocument;
fName = ((DOMDocumentImpl *)doc)->getPooledString(dtName);
fEntities = new (doc) DOMNamedNodeMapImpl(this);
fNotations= new (doc) DOMNamedNodeMapImpl(this);
fElements = new (doc) DOMNamedNodeMapImpl(this);
}
}
//Introduced in DOM Level 2
DOMDocumentTypeImpl::DOMDocumentTypeImpl(DOMDocument *ownerDoc,
const XMLCh *qualifiedName,
const XMLCh *pubId,
const XMLCh *sysId,
bool heap)
: fNode(ownerDoc),
fParent(ownerDoc),
fName(0),
fEntities(0),
fNotations(0),
fElements(0),
fPublicId(0),
fSystemId(0),
fInternalSubset(0),
fIntSubsetReading(false),
fIsCreatedFromHeap(heap)
{
int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);
if (index < 0)
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
else if (index > 0)
{
// we have to make sure the qualifiedName has correct prefix and localName
// although we don't really to store them separately
XMLCh* newName;
XMLCh temp[256];
if (index >= 255)
newName = (XMLCh*) XMLPlatformUtils::fgMemoryManager->allocate
(
(XMLString::stringLen(qualifiedName)+1) * sizeof(XMLCh)
);//new XMLCh[XMLString::stringLen(qualifiedName)+1];
else
newName = temp;
XMLString::copyNString(newName, qualifiedName, index);
newName[index] = chNull;
// Before we carry on, we should check if the prefix or localName are valid XMLName
if (ownerDoc) {
if (!((DOMDocumentImpl*)ownerDoc)->isXMLName(newName) || !((DOMDocumentImpl*)ownerDoc)->isXMLName(qualifiedName+index+1))
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
}
else {
// document is not there yet, so assume XML 1.0
if (!XMLChar1_0::isValidName(newName) || !XMLChar1_0::isValidName(qualifiedName+index+1))
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
}
if (index >= 255)
XMLPlatformUtils::fgMemoryManager->deallocate(newName);//delete[] newName;
}
if (ownerDoc)
{
DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc;
fPublicId = docImpl->cloneString(pubId);
fSystemId = docImpl->cloneString(sysId);
fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(qualifiedName);
fEntities = new (ownerDoc) DOMNamedNodeMapImpl(this);
fNotations= new (ownerDoc) DOMNamedNodeMapImpl(this);
fElements = new (ownerDoc) DOMNamedNodeMapImpl(this);
}
else
{
XMLMutexLock lock(sDocumentMutex);
DOMDocument* doc = sDocument;
fPublicId = ((DOMDocumentImpl*) doc)->cloneString(pubId);
fSystemId = ((DOMDocumentImpl*) doc)->cloneString(sysId);
fName = ((DOMDocumentImpl*) doc)->getPooledString(qualifiedName);
fEntities = new (doc) DOMNamedNodeMapImpl(this);
fNotations= new (doc) DOMNamedNodeMapImpl(this);
fElements = new (doc) DOMNamedNodeMapImpl(this);
}
}
DOMDocumentTypeImpl::DOMDocumentTypeImpl(const DOMDocumentTypeImpl &other, bool heap, bool deep)
: fNode(other.fNode),
fParent(other.fParent),
fChild(other.fChild),
fName(0),
fEntities(0),
fNotations(0),
fElements(0),
fPublicId(0),
fSystemId(0),
fInternalSubset(0),
fIntSubsetReading(other.fIntSubsetReading),
fIsCreatedFromHeap(heap)
{
fName = other.fName;
//DOM Level 2
fPublicId = other.fPublicId;
fSystemId = other.fSystemId;
fInternalSubset = other.fInternalSubset;
if ((DOMDocumentImpl *)this->fNode.getOwnerDocument() && deep)
fParent.cloneChildren(&other);
fEntities = other.fEntities->cloneMap(this);
fNotations= other.fNotations->cloneMap(this);
fElements = other.fElements->cloneMap(this);
}
DOMDocumentTypeImpl::~DOMDocumentTypeImpl()
{
}
DOMNode *DOMDocumentTypeImpl::cloneNode(bool deep) const
{
DOMNode* newNode = 0;
DOMDocument* doc = castToNodeImpl(this)->getOwnerDocument();
if (doc != 0)
newNode = new (doc, DOMMemoryManager::DOCUMENT_TYPE_OBJECT) DOMDocumentTypeImpl(*this, false, deep);
else
{
XMLMutexLock lock(sDocumentMutex);
newNode = new (sDocument, DOMMemoryManager::DOCUMENT_TYPE_OBJECT) DOMDocumentTypeImpl(*this, false, deep);
}
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
/**
* 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 * DOMDocumentTypeImpl::getNodeName() const
{
return fName;
}
DOMNode::NodeType DOMDocumentTypeImpl::getNodeType() const {
return DOMNode::DOCUMENT_TYPE_NODE;
}
DOMNamedNodeMap *DOMDocumentTypeImpl::getEntities() const
{
return fEntities;
}
const XMLCh * DOMDocumentTypeImpl::getName() const
{
return fName;
}
DOMNamedNodeMap *DOMDocumentTypeImpl::getNotations() const
{
return fNotations;
}
DOMNamedNodeMap *DOMDocumentTypeImpl::getElements() const
{
return fElements;
}
void DOMDocumentTypeImpl::setNodeValue(const XMLCh *val)
{
fNode.setNodeValue(val);
}
void DOMDocumentTypeImpl::setReadOnly(bool readOnl, bool deep)
{
fNode.setReadOnly(readOnl,deep);
if (fEntities)
fEntities->setReadOnly(readOnl,true);
if (fNotations)
fNotations->setReadOnly(readOnl,true);
}
//Introduced in DOM Level 2
const XMLCh * DOMDocumentTypeImpl::getPublicId() const
{
return fPublicId;
}
const XMLCh * DOMDocumentTypeImpl::getSystemId() const
{
return fSystemId;
}
const XMLCh * DOMDocumentTypeImpl::getInternalSubset() const
{
return fInternalSubset;
}
bool DOMDocumentTypeImpl::isIntSubsetReading() const
{
return fIntSubsetReading;
}
//set functions
void DOMDocumentTypeImpl::setPublicId(const XMLCh *value)
{
// revist. Why shouldn't 0 be assigned like any other value?
if (value == 0)
return;
DOMDocumentImpl* doc = (DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument();
if (doc != 0)
fPublicId = doc->cloneString(value);
else {
XMLMutexLock lock(sDocumentMutex);
fPublicId = ((DOMDocumentImpl *)sDocument)->cloneString(value);
}
}
void DOMDocumentTypeImpl::setSystemId(const XMLCh *value)
{
DOMDocumentImpl* doc = (DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument();
if (doc != 0)
fSystemId = doc->cloneString(value);
else {
XMLMutexLock lock(sDocumentMutex);
fSystemId = ((DOMDocumentImpl *)sDocument)->cloneString(value);
}
}
void DOMDocumentTypeImpl::setInternalSubset(const XMLCh *value)
{
DOMDocumentImpl* doc = (DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument();
if (doc != 0)
fInternalSubset = doc->cloneString(value);
else {
XMLMutexLock lock(sDocumentMutex);
fInternalSubset = ((DOMDocumentImpl *)sDocument)->cloneString(value);
}
}
void DOMDocumentTypeImpl::release()
{
if (fNode.isOwned()) {
if (fNode.isToBeReleased()) {
// we are calling from documnet.release() which will notify the user data handler
if (fIsCreatedFromHeap) {
DOMDocumentType* docType = this;
delete docType;
}
}
else
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
else {
if (fIsCreatedFromHeap) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
DOMDocumentType* docType = this;
delete docType;
}
else {
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
doc->release(this, DOMMemoryManager::DOCUMENT_TYPE_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
}
}
//
// Delegation for functions inherited from Node
//
DOMNode* DOMDocumentTypeImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
DOMNamedNodeMap* DOMDocumentTypeImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMDocumentTypeImpl::getChildNodes() const {return fParent.getChildNodes (); }
DOMNode* DOMDocumentTypeImpl::getFirstChild() const {return fParent.getFirstChild (); }
DOMNode* DOMDocumentTypeImpl::getLastChild() const {return fParent.getLastChild (); }
const XMLCh* DOMDocumentTypeImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMDocumentTypeImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMDocumentTypeImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMDocumentTypeImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMDocumentTypeImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMDocumentTypeImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMDocumentTypeImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMDocumentTypeImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMDocumentTypeImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
DOMNode* DOMDocumentTypeImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); }
void DOMDocumentTypeImpl::normalize() {fParent.normalize (); }
DOMNode* DOMDocumentTypeImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
DOMNode* DOMDocumentTypeImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); }
void DOMDocumentTypeImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMDocumentTypeImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMDocumentTypeImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
void* DOMDocumentTypeImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMDocumentTypeImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMDocumentTypeImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMDocumentTypeImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMDocumentTypeImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMDocumentTypeImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMDocumentTypeImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMDocumentTypeImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMDocumentTypeImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
bool DOMDocumentTypeImpl::isEqualNode(const DOMNode* arg) const
{
if (isSameNode(arg)) {
return true;
}
if (!fNode.isEqualNode(arg)) {
return false;
}
DOMDocumentType* argDT = (DOMDocumentType*) arg;
// check the string values
if (!getPublicId()) {
if (argDT->getPublicId()) {
return false;
}
}
else if (!XMLString::equals(getPublicId(), argDT->getPublicId())) {
return false;
}
if (!getSystemId()) {
if (argDT->getSystemId()) {
return false;
}
}
else if (!XMLString::equals(getSystemId(), argDT->getSystemId())) {
return false;
}
if (!getInternalSubset()) {
if (argDT->getInternalSubset()) {
return false;
}
}
else if (!XMLString::equals(getInternalSubset(), argDT->getInternalSubset())) {
return false;
}
// check the notations
if (getNotations()) {
if (!argDT->getNotations())
return false;
DOMNamedNodeMap* map1 = getNotations();
DOMNamedNodeMap* map2 = argDT->getNotations();
XMLSize_t len = map1->getLength();
if (len != map2->getLength()) {
return false;
}
for (XMLSize_t i = 0; i < len; i++) {
DOMNode* n1 = map1->item(i);
DOMNode* n2 = map2->getNamedItem(n1->getNodeName());
if (!n2 || !n1->isEqualNode(n2)) {
return false;
}
}
}
else {
if (argDT->getNotations())
return false;
}
// check the entities
if (getEntities()) {
if (!argDT->getEntities())
return false;
DOMNamedNodeMap* map1 = getEntities();
DOMNamedNodeMap* map2 = argDT->getEntities();
XMLSize_t len = map1->getLength();
if (len != map2->getLength()) {
return false;
}
for (XMLSize_t i = 0; i < len; i++) {
DOMNode* n1 = map1->item(i);
DOMNode* n2 = map2->getNamedItem(n1->getNodeName());
if (!n2 || !n1->isEqualNode(n2)) {
return false;
}
}
}
else {
if (argDT->getEntities())
return false;
}
return fParent.isEqualNode(arg);
}
bool DOMDocumentTypeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{
// check for 'DOMDocumentTypeImpl' or '+DOMDocumentTypeImpl'
if(feature && *feature)
{
if((*feature==chPlus && XMLString::equals(feature+1, XMLUni::fgXercescInterfaceDOMDocumentTypeImpl)) ||
XMLString::equals(feature, XMLUni::fgXercescInterfaceDOMDocumentTypeImpl))
return true;
}
return fNode.isSupported (feature, version);
}
void* DOMDocumentTypeImpl::getFeature(const XMLCh* feature, const XMLCh* version) const
{
if(XMLString::equals(feature, XMLUni::fgXercescInterfaceDOMDocumentTypeImpl))
return (DOMDocumentTypeImpl*)this;
return fNode.getFeature(feature,version);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMDocumentTypeImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMDOCUMENTTYPEIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMDOCUMENTTYPEIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp"
#include "DOMParentNode.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMNamedNodeMapImpl;
class CDOM_EXPORT DOMDocumentTypeImpl: public DOMDocumentType {
protected:
DOMNodeImpl fNode;
DOMParentNode fParent;
DOMChildNode fChild;
const XMLCh * fName;
DOMNamedNodeMapImpl* fEntities;
DOMNamedNodeMapImpl* fNotations;
DOMNamedNodeMapImpl* fElements;
const XMLCh * fPublicId;
const XMLCh * fSystemId;
const XMLCh * fInternalSubset;
bool fIntSubsetReading;
bool fIsCreatedFromHeap;
virtual void setPublicId(const XMLCh * value);
virtual void setSystemId(const XMLCh * value);
virtual void setInternalSubset(const XMLCh *value);
bool isIntSubsetReading() const;
friend class AbstractDOMParser;
friend class DOMDocumentImpl;
public:
DOMDocumentTypeImpl(DOMDocument *, const XMLCh *, bool);
DOMDocumentTypeImpl(DOMDocument *,
const XMLCh *qualifiedName, //DOM Level 2
const XMLCh *publicId, const XMLCh *systemId, bool);
DOMDocumentTypeImpl(const DOMDocumentTypeImpl &other, bool heap, bool deep=false);
virtual ~DOMDocumentTypeImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
virtual void setOwnerDocument(DOMDocument *doc);
virtual DOMNamedNodeMap * getEntities() const;
virtual const XMLCh * getName() const;
virtual DOMNamedNodeMap * getNotations() const;
virtual DOMNamedNodeMap * getElements() const;
virtual void setReadOnly(bool readOnly, bool deep);
//Introduced in DOM Level 2
virtual const XMLCh * getPublicId() const;
virtual const XMLCh * getSystemId() const;
virtual const XMLCh * getInternalSubset() const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMDocumentTypeImpl & operator = (const DOMDocumentTypeImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
+880
View File
@@ -0,0 +1,880 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMElementImpl.cpp 901107 2010-01-20 08:45:02Z borisk $
*/
#include "DOMElementImpl.hpp"
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUri.hpp>
#include "DOMAttrMapImpl.hpp"
#include "DOMAttrImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMParentNode.hpp"
#include "DOMCasts.hpp"
#include "DOMElementNSImpl.hpp"
#include "DOMTypeInfoImpl.hpp"
#include "DOMDocumentTypeImpl.hpp"
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMAttr;
DOMElementImpl::DOMElementImpl(DOMDocument *ownerDoc, const XMLCh *eName)
: fNode(ownerDoc), fParent(ownerDoc), fAttributes(0), fDefaultAttributes(0)
{
DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc;
fName = docImpl->getPooledString(eName);
setupDefaultAttributes();
if (!fDefaultAttributes) {
fDefaultAttributes = new (docImpl) DOMAttrMapImpl(this);
fAttributes = new (docImpl) DOMAttrMapImpl(this);
}
else {
fAttributes = new (docImpl) DOMAttrMapImpl(this, fDefaultAttributes);
}
}
DOMElementImpl::DOMElementImpl(const DOMElementImpl &other, bool deep)
: DOMElement(other),
fNode (other.fParent.fOwnerDocument),
fParent (other.fParent.fOwnerDocument),
fAttributes(0),
fDefaultAttributes(0)
{
fName = other.fName;
if (deep)
fParent.cloneChildren(&other);
if (other.getAttributes())
{
fAttributes = ((DOMAttrMapImpl *)other.getAttributes())->cloneAttrMap(this);
}
if (other.getDefaultAttributes())
{
fDefaultAttributes = ((DOMAttrMapImpl *)other.getDefaultAttributes())->cloneAttrMap(this);
}
if (!fDefaultAttributes)
setupDefaultAttributes();
if (!fDefaultAttributes)
fDefaultAttributes = new (fParent.fOwnerDocument) DOMAttrMapImpl(this);
if (!fAttributes) {
if (!fDefaultAttributes) {
fAttributes = new (fParent.fOwnerDocument) DOMAttrMapImpl(this);
}
else {
fAttributes = new (fParent.fOwnerDocument) DOMAttrMapImpl(this, fDefaultAttributes);
}
}
}
DOMElementImpl::~DOMElementImpl()
{
}
DOMNode *DOMElementImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ELEMENT_OBJECT) DOMElementImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMElementImpl::getNodeName() const {
return fName;
}
DOMNode::NodeType DOMElementImpl::getNodeType() const {
return DOMNode::ELEMENT_NODE;
}
const XMLCh * DOMElementImpl::getAttribute(const XMLCh *nam) const
{
DOMNode * attr = fAttributes->getNamedItem(nam);
if (attr)
return attr->getNodeValue();
return XMLUni::fgZeroLenString;
}
DOMAttr *DOMElementImpl::getAttributeNode(const XMLCh *nam) const
{
return (DOMAttr *)fAttributes->getNamedItem(nam);
}
DOMNamedNodeMap *DOMElementImpl::getAttributes() const
{
DOMElementImpl *ncThis = (DOMElementImpl *)this; // cast off const
return ncThis->fAttributes;
}
DOMNodeList *DOMElementImpl::getElementsByTagName(const XMLCh *tagname) const
{
DOMDocumentImpl *docImpl = (DOMDocumentImpl *)fParent.fOwnerDocument;
return docImpl->getDeepNodeList(this,tagname);
}
const XMLCh * DOMElementImpl::getTagName() const
{
return fName;
}
void DOMElementImpl::removeAttribute(const XMLCh *nam)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
int i = fAttributes->findNamePoint(nam);
if (i >= 0)
{
DOMNode *att = fAttributes->removeNamedItemAt(i);
((DOMAttrImpl *)att)->removeAttrFromIDNodeMap();
att->release();
}
}
DOMAttr *DOMElementImpl::removeAttributeNode(DOMAttr *oldAttr)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
DOMNode* found = 0;
// Since there is no removeAttributeNodeNS, check if this oldAttr has NS or not
const XMLCh* localName = oldAttr->getLocalName();
int i = 0;
if (localName)
i = fAttributes->findNamePoint(oldAttr->getNamespaceURI(), localName);
else
i = fAttributes->findNamePoint(oldAttr->getName());
if (i >= 0) {
// If it is in fact the right object, remove it.
found = fAttributes->item(i);
if (found == oldAttr) {
fAttributes->removeNamedItemAt(i);
((DOMAttrImpl *)oldAttr)->removeAttrFromIDNodeMap();
}
else
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
}
else
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
return (DOMAttr *)found;
}
void DOMElementImpl::setAttribute(const XMLCh *nam, const XMLCh *val)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
DOMAttr* newAttr = getAttributeNode(nam);
if (!newAttr)
{
newAttr = fParent.fOwnerDocument->createAttribute(nam);
fAttributes->setNamedItem(newAttr);
}
newAttr->setNodeValue(val);
}
void DOMElementImpl::setIdAttribute(const XMLCh* name, bool isId)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
DOMAttr *attr = getAttributeNode(name);
if (!attr)
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
if(isId)
((DOMAttrImpl *)attr)->addAttrToIDNodeMap();
else
((DOMAttrImpl *)attr)->removeAttrFromIDNodeMap();
}
void DOMElementImpl::setIdAttributeNS(const XMLCh* namespaceURI, const XMLCh* localName, bool isId) {
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
DOMAttr *attr = getAttributeNodeNS(namespaceURI, localName);
if (!attr)
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
if(isId)
((DOMAttrImpl *)attr)->addAttrToIDNodeMap();
else
((DOMAttrImpl *)attr)->removeAttrFromIDNodeMap();
}
void DOMElementImpl::setIdAttributeNode(const DOMAttr *idAttr, bool isId) {
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
DOMAttr *attr;
const XMLCh* localName = idAttr->getLocalName();
if (localName)
attr = getAttributeNodeNS(idAttr->getNamespaceURI(), idAttr->getLocalName());
else
attr = getAttributeNode(idAttr->getName());
if(!attr)
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
if(isId)
((DOMAttrImpl *)attr)->addAttrToIDNodeMap();
else
((DOMAttrImpl *)attr)->removeAttrFromIDNodeMap();
}
DOMAttr * DOMElementImpl::setAttributeNode(DOMAttr *newAttr)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
if (newAttr->getNodeType() != DOMNode::ATTRIBUTE_NODE)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0, GetDOMNodeMemoryManager);
// revisit. Exception doesn't match test.
// This will throw INUSE if necessary
DOMAttr *oldAttr = (DOMAttr *) fAttributes->setNamedItem(newAttr);
return oldAttr;
}
void DOMElementImpl::setNodeValue(const XMLCh *x)
{
fNode.setNodeValue(x);
}
void DOMElementImpl::setReadOnly(bool readOnl, bool deep)
{
fNode.setReadOnly(readOnl,deep);
fAttributes->setReadOnly(readOnl,true);
}
//Introduced in DOM Level 2
const XMLCh * DOMElementImpl::getAttributeNS(const XMLCh *fNamespaceURI,
const XMLCh *fLocalName) const
{
DOMAttr * attr=
(DOMAttr *)(fAttributes->getNamedItemNS(fNamespaceURI, fLocalName));
return (attr==0) ? XMLUni::fgZeroLenString : attr->getValue();
}
void DOMElementImpl::setAttributeNS(const XMLCh *fNamespaceURI,
const XMLCh *qualifiedName, const XMLCh *fValue)
{
if (fNode.isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);
if (index < 0)
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
DOMAttr* newAttr = getAttributeNodeNS(fNamespaceURI, qualifiedName+index);
if (!newAttr)
{
newAttr = fParent.fOwnerDocument->createAttributeNS(fNamespaceURI, qualifiedName);
fAttributes->setNamedItemNS(newAttr);
}
newAttr->setNodeValue(fValue);
}
void DOMElementImpl::removeAttributeNS(const XMLCh *fNamespaceURI,
const XMLCh *fLocalName)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
int i = fAttributes->findNamePoint(fNamespaceURI, fLocalName);
if (i >= 0)
{
DOMNode *att = fAttributes->removeNamedItemAt(i);
att->release();
}
}
DOMAttr *DOMElementImpl::getAttributeNodeNS(const XMLCh *fNamespaceURI,
const XMLCh *fLocalName) const
{
return (DOMAttr *)fAttributes->getNamedItemNS(fNamespaceURI, fLocalName);
}
DOMAttr *DOMElementImpl::setAttributeNodeNS(DOMAttr *newAttr)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
if (newAttr -> getOwnerDocument() != fParent.fOwnerDocument)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0, GetDOMNodeMemoryManager);
// This will throw INUSE if necessary
DOMAttr *oldAttr = (DOMAttr *) fAttributes->setNamedItemNS(newAttr);
return oldAttr;
}
DOMNodeList *DOMElementImpl::getElementsByTagNameNS(const XMLCh *namespaceURI,
const XMLCh *localName) const
{
DOMDocumentImpl *docImpl = (DOMDocumentImpl *)fParent.fOwnerDocument;
return docImpl->getDeepNodeList(this, namespaceURI, localName);
}
bool DOMElementImpl::hasAttributes() const
{
return (fAttributes != 0 && fAttributes->getLength() != 0);
}
bool DOMElementImpl::hasAttribute(const XMLCh *name) const
{
return (getAttributeNode(name) != 0);
}
bool DOMElementImpl::hasAttributeNS(const XMLCh *namespaceURI,
const XMLCh *localName) const
{
return (getAttributeNodeNS(namespaceURI, localName) != 0);
}
// util functions for default attributes
// returns the default attribute map for this node from the owner document
DOMAttrMapImpl *DOMElementImpl::getDefaultAttributes() const
{
return fDefaultAttributes;
}
// initially set up the default attribute information based on doctype information
void DOMElementImpl::setupDefaultAttributes()
{
DOMDocument *tmpdoc = fParent.fOwnerDocument;
if ((fNode.fOwnerNode == 0) || (tmpdoc == 0) || (tmpdoc->getDoctype() == 0))
return;
DOMNode *eldef = ((DOMDocumentTypeImpl*)tmpdoc->getDoctype())->getElements()->getNamedItem(getNodeName());
DOMAttrMapImpl* defAttrs = (eldef == 0) ? 0 : (DOMAttrMapImpl *)(eldef->getAttributes());
if (defAttrs)
fDefaultAttributes = new (tmpdoc) DOMAttrMapImpl(this, defAttrs);
}
DOMAttr * DOMElementImpl::setDefaultAttributeNode(DOMAttr *newAttr)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
if (newAttr->getNodeType() != DOMNode::ATTRIBUTE_NODE)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0, GetDOMNodeMemoryManager);
// revisit. Exception doesn't match test.
// This will throw INUSE if necessary
DOMAttr *oldAttr = (DOMAttr *) fDefaultAttributes->setNamedItem(newAttr);
fAttributes->hasDefaults(true);
return oldAttr;
}
DOMAttr *DOMElementImpl::setDefaultAttributeNodeNS(DOMAttr *newAttr)
{
if (fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
if (newAttr -> getOwnerDocument() != fParent.fOwnerDocument)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0, GetDOMNodeMemoryManager);
// This will throw INUSE if necessary
DOMAttr *oldAttr = (DOMAttr *) fDefaultAttributes->setNamedItemNS(newAttr);
fAttributes->hasDefaults(true);
return oldAttr;
}
void DOMElementImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
// release children
fParent.release();
// release attributes
fAttributes->hasDefaults(false);
XMLSize_t count;
while((count = fAttributes->getLength()) != 0)
{
DOMNode* attr = fAttributes->removeNamedItemAt(count-1);
attr->release();
}
doc->release(this, DOMMemoryManager::ELEMENT_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
const XMLCh* DOMElementImpl::getBaseURI() const
{
const XMLCh* baseURI = fNode.fOwnerNode->getBaseURI();
if (fAttributes) {
const XMLCh baseString[] =
{
chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull
};
DOMNode* attrNode = fAttributes->getNamedItemNS(DOMNodeImpl::getXmlURIString(), baseString);
if (attrNode==NULL) {
const XMLCh xmlBaseString[] =
{
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull
};
attrNode = fAttributes->getNamedItem(xmlBaseString);
}
if (attrNode) {
const XMLCh* uri = attrNode->getNodeValue();
if (uri && *uri) {// attribute value is always empty string
// if there is a base URI for the parent node, use it to resolve relative URI
if(baseURI)
{
try {
DOMDocumentImpl* doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
XMLUri temp(baseURI, doc->getMemoryManager());
XMLUri temp2(&temp, uri, doc->getMemoryManager());
uri = doc->cloneString(temp2.getUriText());
}
catch(const OutOfMemoryException&)
{
throw;
}
catch (...){
// REVISIT: what should happen in this case?
return 0;
}
}
return uri;
}
}
}
return baseURI;
}
//
// Functions inherited from Node
//
DOMNode* DOMElementImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
DOMNodeList* DOMElementImpl::getChildNodes() const {return fParent.getChildNodes (); }
DOMNode* DOMElementImpl::getFirstChild() const {return fParent.getFirstChild (); }
DOMNode* DOMElementImpl::getLastChild() const {return fParent.getLastChild (); }
const XMLCh* DOMElementImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMElementImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMElementImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMElementImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMElementImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMElementImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMElementImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMElementImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMElementImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
DOMNode* DOMElementImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); }
void DOMElementImpl::normalize() {fParent.normalize (); }
DOMNode* DOMElementImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
DOMNode* DOMElementImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); }
bool DOMElementImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMElementImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMElementImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
void* DOMElementImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMElementImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
short DOMElementImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMElementImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMElementImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMElementImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMElementImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMElementImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMElementImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
bool DOMElementImpl::isEqualNode(const DOMNode* arg) const
{
if (isSameNode(arg)) {
return true;
}
if (!fNode.isEqualNode(arg)) {
return false;
}
bool hasAttrs = hasAttributes();
if (hasAttrs != arg->hasAttributes()) {
return false;
}
if (hasAttrs) {
DOMNamedNodeMap* map1 = getAttributes();
DOMNamedNodeMap* map2 = arg->getAttributes();
XMLSize_t len = map1->getLength();
if (len != map2->getLength()) {
return false;
}
for (XMLSize_t i = 0; i < len; i++) {
DOMNode* n1 = map1->item(i);
if (!n1->getLocalName()) { // DOM Level 1 Node
DOMNode* n2 = map2->getNamedItem(n1->getNodeName());
if (!n2 || !n1->isEqualNode(n2)) {
return false;
}
}
else {
DOMNode* n2 = map2->getNamedItemNS(n1->getNamespaceURI(),
n1->getLocalName());
if (!n2 || !n1->isEqualNode(n2)) {
return false;
}
}
}
}
return fParent.isEqualNode(arg);
}
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;
}
}
const DOMTypeInfo *DOMElementImpl::getSchemaTypeInfo() const
{
return &DOMTypeInfoImpl::g_DtdValidatedElement;
}
// DOMElementTraversal
DOMElement * DOMElementImpl::getFirstElementChild() const
{
DOMNode* n = getFirstChild();
while (n != NULL) {
switch (n->getNodeType()) {
case DOMNode::ELEMENT_NODE:
return (DOMElement*) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getFirstElementChild(n);
if (e != NULL)
return e;
}
break;
default:
break;
}
n = n->getNextSibling();
}
return NULL;
}
DOMElement * DOMElementImpl::getLastElementChild() const
{
DOMNode* n = getLastChild();
while (n != NULL) {
switch (n->getNodeType()) {
case DOMNode::ELEMENT_NODE:
return (DOMElement*) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getLastElementChild(n);
if (e != NULL)
return e;
}
break;
default:
break;
}
n = n->getPreviousSibling();
}
return NULL;
}
DOMElement * DOMElementImpl::getNextElementSibling() const
{
DOMNode* n = getNextLogicalSibling(this);
while (n != NULL) {
switch (n->getNodeType()) {
case DOMNode::ELEMENT_NODE:
return (DOMElement*) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getFirstElementChild(n);
if (e != NULL)
return e;
}
break;
default:
break;
}
n = getNextLogicalSibling(n);
}
return NULL;
}
DOMElement * DOMElementImpl::getPreviousElementSibling() const
{
DOMNode* n = getPreviousLogicalSibling(this);
while (n != NULL) {
switch (n->getNodeType()) {
case DOMNode::ELEMENT_NODE:
return (DOMElement*) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getLastElementChild(n);
if (e != NULL)
return e;
}
break;
default:
break;
}
n = getPreviousLogicalSibling(n);
}
return NULL;
}
XMLSize_t DOMElementImpl::getChildElementCount() const
{
XMLSize_t count = 0;
DOMElement* child = getFirstElementChild();
while (child != NULL) {
++count;
child = child->getNextElementSibling();
}
return count;
}
// Returns the first element node found from a
// non-recursive in order traversal of the given node.
DOMElement* DOMElementImpl::getFirstElementChild(const DOMNode* n) const
{
const DOMNode* top = n;
while (n != NULL) {
if (n->getNodeType() == DOMNode::ELEMENT_NODE) {
return (DOMElement*) n;
}
DOMNode* next = n->getFirstChild();
while (next == NULL) {
if (top == n) {
break;
}
next = n->getNextSibling();
if (next == NULL) {
n = n->getParentNode();
if (n == NULL || top == n) {
return NULL;
}
}
}
n = next;
}
return NULL;
}
// Returns the first element node found from a
// non-recursive reverse order traversal of the given node.
DOMElement* DOMElementImpl::getLastElementChild(const DOMNode* n) const
{
const DOMNode* top = n;
while (n != NULL) {
if (n->getNodeType() == DOMNode::ELEMENT_NODE) {
return (DOMElement*) n;
}
DOMNode* next = n->getLastChild();
while (next == NULL) {
if (top == n) {
break;
}
next = n->getPreviousSibling();
if (next == NULL) {
n = n->getParentNode();
if (n == NULL || top == n) {
return NULL;
}
}
}
n = next;
}
return NULL;
}
// Returns the next logical sibling with respect to the given node.
DOMNode* DOMElementImpl::getNextLogicalSibling(const DOMNode* n) const
{
DOMNode* next = n->getNextSibling();
// If "n" has no following sibling and its parent is an entity reference node we
// need to continue the search through the following siblings of the entity
// reference as these are logically siblings of the given node.
if (next == NULL) {
DOMNode* parent = n->getParentNode();
while (parent != NULL && parent->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) {
next = parent->getNextSibling();
if (next != NULL) {
break;
}
parent = parent->getParentNode();
}
}
return next;
}
// Returns the previous logical sibling with respect to the given node.
DOMNode* DOMElementImpl::getPreviousLogicalSibling(const DOMNode* n) const
{
DOMNode* prev = n->getPreviousSibling();
// If "n" has no previous sibling and its parent is an entity reference node we
// need to continue the search through the previous siblings of the entity
// reference as these are logically siblings of the given node.
if (prev == NULL) {
DOMNode* parent = n->getParentNode();
while (parent != NULL && parent->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) {
prev = parent->getPreviousSibling();
if (prev != NULL) {
break;
}
parent = parent->getParentNode();
}
}
return prev;
}
XERCES_CPP_NAMESPACE_END
+143
View File
@@ -0,0 +1,143 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMElementImpl.hpp 792236 2009-07-08 17:22:35Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMELEMENTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMELEMENTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include "DOMChildNode.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMParentNode.hpp"
#include "DOMAttrMapImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMTypeInfo;
class DOMNodeList;
class DOMAttrMapImpl;
class DOMDocument;
class CDOM_EXPORT DOMElementImpl: public DOMElement {
public:
DOMNodeImpl fNode;
DOMParentNode fParent;
DOMChildNode fChild;
DOMAttrMapImpl *fAttributes;
DOMAttrMapImpl *fDefaultAttributes;
const XMLCh *fName;
public:
DOMElementImpl(DOMDocument *ownerDoc, const XMLCh *name);
DOMElementImpl(const DOMElementImpl &other, bool deep=false);
virtual ~DOMElementImpl();
public:
// Declare functions from DOMNode. They all must be implemented by this class
DOMNODE_FUNCTIONS;
public:
// Functions introduced on Element...
virtual const XMLCh* getAttribute(const XMLCh *name) const;
virtual DOMAttr* getAttributeNode(const XMLCh *name) const;
virtual DOMNodeList* getElementsByTagName(const XMLCh *tagname) const;
virtual const XMLCh* getTagName() const;
virtual void removeAttribute(const XMLCh *name);
virtual DOMAttr* removeAttributeNode(DOMAttr * oldAttr);
virtual void setAttribute(const XMLCh *name, const XMLCh *value);
virtual DOMAttr* setAttributeNode(DOMAttr *newAttr);
virtual void setReadOnly(bool readOnly, bool deep);
//Introduced in DOM Level 2
virtual const XMLCh* getAttributeNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual void setAttributeNS(const XMLCh *namespaceURI,
const XMLCh *qualifiedName,
const XMLCh *value);
virtual void removeAttributeNS(const XMLCh *namespaceURI,
const XMLCh *localName);
virtual DOMAttr* getAttributeNodeNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual DOMAttr* setAttributeNodeNS(DOMAttr *newAttr);
virtual DOMNodeList* getElementsByTagNameNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual bool hasAttribute(const XMLCh *name) const;
virtual bool hasAttributeNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
//Introduced in DOM level 3
virtual void setIdAttribute(const XMLCh* name, bool isId);
virtual void setIdAttributeNS(const XMLCh* namespaceURI, const XMLCh* localName, bool isId);
virtual void setIdAttributeNode(const DOMAttr *idAttr, bool isId);
virtual const DOMTypeInfo * getSchemaTypeInfo() const;
// for handling of default attribute
virtual DOMAttr* setDefaultAttributeNode(DOMAttr *newAttr);
virtual DOMAttr* setDefaultAttributeNodeNS(DOMAttr *newAttr);
virtual DOMAttrMapImpl* getDefaultAttributes() const;
// helper function for DOM Level 3 renameNode
virtual DOMNode* rename(const XMLCh* namespaceURI, const XMLCh* name);
// DOMElementTraversal
virtual DOMElement * getFirstElementChild() const;
virtual DOMElement * getLastElementChild() const;
virtual DOMElement * getPreviousElementSibling() const;
virtual DOMElement * getNextElementSibling() const;
virtual XMLSize_t getChildElementCount() const;
protected:
// default attribute helper functions
virtual void setupDefaultAttributes();
// helper function for DOMElementTraversal methods
DOMElement* getFirstElementChild(const DOMNode* n) const;
DOMElement* getLastElementChild(const DOMNode* n) const;
DOMNode* getNextLogicalSibling(const DOMNode* n) const;
DOMNode* getPreviousLogicalSibling(const DOMNode* n) const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMElementImpl & operator = (const DOMElementImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,264 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMElementNSImpl.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
#include <xercesc/util/XMLUniDefs.hpp>
#include "DOMElementNSImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMTypeInfoImpl.hpp"
#include "DOMCasts.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUri.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMElementNSImpl::DOMElementNSImpl(DOMDocument *ownerDoc, const XMLCh *nam) :
DOMElementImpl(ownerDoc, nam)
{
this->fNamespaceURI=0; //DOM Level 2
this->fLocalName=0; //DOM Level 2
this->fPrefix=0;
this->fSchemaType = 0;
}
//Introduced in DOM Level 2
DOMElementNSImpl::DOMElementNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *qualifiedName) :
DOMElementImpl(ownerDoc, qualifiedName)
{
setName(namespaceURI, qualifiedName);
this->fSchemaType = 0;
}
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);
}
DOMElementNSImpl::DOMElementNSImpl(const DOMElementNSImpl &other, bool deep) :
DOMElementImpl(other, deep)
{
this->fNamespaceURI = other.fNamespaceURI; //DOM Level 2
this->fLocalName = other.fLocalName; //DOM Level 2
this->fPrefix = other.fPrefix;
this->fSchemaType = other.fSchemaType;
}
DOMNode * DOMElementNSImpl::cloneNode(bool deep) const {
DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ELEMENT_NS_OBJECT) DOMElementNSImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMElementNSImpl::getNamespaceURI() const
{
return fNamespaceURI;
}
const XMLCh * DOMElementNSImpl::getPrefix() const
{
return fPrefix;
}
const XMLCh * DOMElementNSImpl::getLocalName() const
{
return fLocalName;
}
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 DOMElementNSImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ELEMENT_NS_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
DOMNode* DOMElementNSImpl::rename(const XMLCh* namespaceURI, const XMLCh* name)
{
setName(namespaceURI, name);
fAttributes->reconcileDefaultAttributes(getDefaultAttributes());
// and fire user data NODE_RENAMED event
castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this);
return this;
}
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);
}
const DOMTypeInfo *DOMElementNSImpl::getSchemaTypeInfo() const
{
if(!fSchemaType)
return &DOMTypeInfoImpl::g_DtdValidatedElement;
return fSchemaType;
}
void DOMElementNSImpl::setSchemaTypeInfo(const DOMTypeInfoImpl* typeInfo)
{
fSchemaType = typeInfo;
}
bool DOMElementNSImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{
// check for '+DOMPSVITypeInfo'
if(feature && *feature=='+' && XMLString::equals(feature+1, XMLUni::fgXercescInterfacePSVITypeInfo))
return true;
return fNode.isSupported (feature, version);
}
void* DOMElementNSImpl::getFeature(const XMLCh* feature, const XMLCh* version) const
{
if(XMLString::equals(feature, XMLUni::fgXercescInterfacePSVITypeInfo))
return (DOMPSVITypeInfo*)fSchemaType;
return DOMElementImpl::getFeature(feature, version);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMElementNSImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMELEMENTNSIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMELEMENTNSIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include "DOMElementImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMTypeInfoImpl;
class CDOM_EXPORT DOMElementNSImpl: public DOMElementImpl {
protected:
//Introduced in DOM Level 2
const XMLCh * fNamespaceURI; //namespace URI of this node
const XMLCh * fLocalName; //local part of qualified name
const XMLCh * fPrefix;
const DOMTypeInfoImpl *fSchemaType;
public:
DOMElementNSImpl(DOMDocument *ownerDoc, const XMLCh *name);
DOMElementNSImpl(DOMDocument *ownerDoc, //DOM Level 2
const XMLCh *namespaceURI,
const XMLCh *qualifiedName);
DOMElementNSImpl(const DOMElementNSImpl &other, bool deep=false);
// Fast construction without any checks for name validity. Used in
// parsing.
//
DOMElementNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *prefix, // Null or empty - no prefix.
const XMLCh *localName,
const XMLCh *qualifiedName);
virtual DOMNode * cloneNode(bool deep) const;
virtual bool isSupported(const XMLCh *feature, const XMLCh *version) const;
virtual void* getFeature(const XMLCh* feature, const XMLCh* version) const;
//Introduced in DOM Level 2
virtual const XMLCh *getNamespaceURI() const;
virtual const XMLCh *getPrefix() const;
virtual const XMLCh *getLocalName() const;
virtual void setPrefix(const XMLCh *prefix);
virtual void release();
//Introduced in DOM Level 3
virtual const DOMTypeInfo * getSchemaTypeInfo() const;
// helper function for DOM Level 3 renameNode
virtual DOMNode* rename(const XMLCh* namespaceURI, const XMLCh* name);
void setName(const XMLCh* namespaceURI, const XMLCh* name);
//helper function for DOM Level 3 TypeInfo
virtual void setSchemaTypeInfo(const DOMTypeInfoImpl* typeInfo);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMElementNSImpl & operator = (const DOMElementNSImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
+295
View File
@@ -0,0 +1,295 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMEntityImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMEntityReference.hpp>
#include "DOMEntityImpl.hpp"
#include "DOMDocumentImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
DOMEntityImpl::DOMEntityImpl(DOMDocument *ownerDoc, const XMLCh *eName)
: fNode(ownerDoc),
fParent(ownerDoc),
fPublicId(0),
fSystemId(0),
fNotationName(0),
fRefEntity(0),
fInputEncoding(0),
fXmlEncoding(0),
fXmlVersion(0),
fBaseURI(0),
fEntityRefNodeCloned(false)
{
fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(eName);
fNode.setReadOnly(true, true);
}
DOMEntityImpl::DOMEntityImpl(const DOMEntityImpl &other, bool deep)
: DOMEntity(other),
fNode(other.fNode),
fParent(other.fParent),
fName(other.fName),
fPublicId(other.fPublicId),
fSystemId(other.fSystemId),
fNotationName(other.fNotationName),
fRefEntity(other.fRefEntity),
fInputEncoding(other.fInputEncoding),
fXmlEncoding(other.fXmlEncoding),
fXmlVersion(other.fXmlVersion),
fBaseURI(other.fBaseURI),
fEntityRefNodeCloned(false)
{
if (deep)
fParent.cloneChildren(&other);
fNode.setReadOnly(true, true);
}
DOMEntityImpl::~DOMEntityImpl() {
}
DOMNode *DOMEntityImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ENTITY_OBJECT) DOMEntityImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMEntityImpl::getNodeName() const {
return fName;
}
DOMNode::NodeType DOMEntityImpl::getNodeType() const {
return DOMNode::ENTITY_NODE;
}
const XMLCh * DOMEntityImpl::getNotationName() const
{
return fNotationName;
}
const XMLCh * DOMEntityImpl::getPublicId() const {
return fPublicId;
}
const XMLCh * DOMEntityImpl::getSystemId() const
{
return fSystemId;
}
const XMLCh* DOMEntityImpl::getBaseURI() const
{
return fBaseURI;
}
void DOMEntityImpl::setNodeValue(const XMLCh *arg)
{
fNode.setNodeValue(arg);
}
void DOMEntityImpl::setNotationName(const XMLCh *arg)
{
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fNotationName = doc->cloneString(arg);
}
void DOMEntityImpl::setPublicId(const XMLCh *arg)
{
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fPublicId = doc->cloneString(arg);
}
void DOMEntityImpl::setSystemId(const XMLCh *arg)
{
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fSystemId = doc->cloneString(arg);
}
void DOMEntityImpl::setBaseURI(const XMLCh* baseURI) {
if (baseURI && *baseURI) {
XMLCh* temp = (XMLCh*) ((DOMDocumentImpl *)fParent.fOwnerDocument)->allocate((XMLString::stringLen(baseURI) + 9)*sizeof(XMLCh));
XMLString::fixURI(baseURI, temp);
fBaseURI = temp;
}
else
fBaseURI = 0;
}
void DOMEntityImpl::setEntityRef(DOMEntityReference* other)
{
fRefEntity = other;
}
DOMEntityReference* DOMEntityImpl::getEntityRef() const
{
return fRefEntity;
}
void DOMEntityImpl::cloneEntityRefTree() const
{
if (fEntityRefNodeCloned)
return;
// cast off const. This method is const because it is
// called from a bunch of logically const methods, like
// getFirstChild().
DOMEntityImpl *ncThis = (DOMEntityImpl *)this;
//lazily clone the entityRef tree to this entity
if (fParent.fFirstChild != 0)
return;
if (!fRefEntity)
return;
ncThis->fEntityRefNodeCloned = true;
ncThis->fNode.setReadOnly(false, true);
ncThis->fParent.cloneChildren(fRefEntity);
ncThis->fNode.setReadOnly(true, true);
}
DOMNode * DOMEntityImpl::getFirstChild() const
{
cloneEntityRefTree();
return fParent.fFirstChild;
}
DOMNode * DOMEntityImpl::getLastChild() const
{
cloneEntityRefTree();
return fParent.getLastChild();
}
DOMNodeList* DOMEntityImpl::getChildNodes() const
{
cloneEntityRefTree();
return this->fParent.getChildNodes();
}
bool DOMEntityImpl::hasChildNodes() const
{
cloneEntityRefTree();
return fParent.fFirstChild!=0;
}
void DOMEntityImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ENTITY_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
//
// Functions inherited from Node
//
DOMNode* DOMEntityImpl::appendChild(DOMNode *newChild) {cloneEntityRefTree(); return fParent.appendChild (newChild); }
DOMNamedNodeMap* DOMEntityImpl::getAttributes() const {return fNode.getAttributes (); }
const XMLCh* DOMEntityImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMEntityImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMEntityImpl::getNextSibling() const {return fNode.getNextSibling (); }
const XMLCh* DOMEntityImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMEntityImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMEntityImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMEntityImpl::getParentNode() const {return fNode.getParentNode (); }
DOMNode* DOMEntityImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }
DOMNode* DOMEntityImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{cloneEntityRefTree(); return fParent.insertBefore (newChild, refChild); }
void DOMEntityImpl::normalize() {cloneEntityRefTree(); fParent.normalize (); }
DOMNode* DOMEntityImpl::removeChild(DOMNode *oldChild) {cloneEntityRefTree(); return fParent.removeChild (oldChild); }
DOMNode* DOMEntityImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{cloneEntityRefTree(); return fParent.replaceChild (newChild, oldChild); }
bool DOMEntityImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMEntityImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMEntityImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMEntityImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMEntityImpl::isEqualNode(const DOMNode* arg) const {cloneEntityRefTree(); return fParent.isEqualNode(arg); }
void* DOMEntityImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMEntityImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
short DOMEntityImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMEntityImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMEntityImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMEntityImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMEntityImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMEntityImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMEntityImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
//Introduced in DOM Level 3
const XMLCh* DOMEntityImpl::getInputEncoding() const {
return fInputEncoding;
}
void DOMEntityImpl::setInputEncoding(const XMLCh* actualEncoding){
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fInputEncoding = doc->cloneString(actualEncoding);
}
const XMLCh* DOMEntityImpl::getXmlEncoding() const {
return fXmlEncoding;
}
void DOMEntityImpl::setXmlEncoding(const XMLCh* encoding){
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fXmlEncoding = doc->cloneString(encoding);
}
const XMLCh* DOMEntityImpl::getXmlVersion() const {
return fXmlVersion;
}
void DOMEntityImpl::setXmlVersion(const XMLCh* version){
DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
fXmlVersion = doc->cloneString(version);
}
XERCES_CPP_NAMESPACE_END
+107
View File
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMEntityImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMENTITYIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMENTITYIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include "DOMNodeImpl.hpp"
#include "DOMParentNode.hpp"
#include <xercesc/dom/DOMEntity.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMEntityReference;
class CDOM_EXPORT DOMEntityImpl: public DOMEntity {
protected:
DOMNodeImpl fNode;
DOMParentNode fParent;
const XMLCh * fName;
const XMLCh * fPublicId;
const XMLCh * fSystemId;
const XMLCh * fNotationName;
DOMEntityReference* fRefEntity;
// New data introduced in DOM Level 3
const XMLCh* fInputEncoding;
const XMLCh* fXmlEncoding;
const XMLCh* fXmlVersion;
const XMLCh* fBaseURI;
bool fEntityRefNodeCloned;
// helper function
void cloneEntityRefTree() const;
friend class XercesDOMParser;
public:
DOMEntityImpl(DOMDocument *doc, const XMLCh *eName);
DOMEntityImpl(const DOMEntityImpl &other, bool deep=false);
virtual ~DOMEntityImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
virtual const XMLCh * getPublicId() const;
virtual const XMLCh * getSystemId() const;
virtual const XMLCh * getNotationName() const;
virtual void setNotationName(const XMLCh *arg);
virtual void setPublicId(const XMLCh *arg);
virtual void setSystemId(const XMLCh *arg);
//DOM Level 2 additions. Non standard functions
virtual void setEntityRef(DOMEntityReference *);
virtual DOMEntityReference* getEntityRef() const;
//Introduced in DOM Level 3
virtual const XMLCh* getInputEncoding() const;
virtual const XMLCh* getXmlEncoding() const;
virtual const XMLCh* getXmlVersion() const;
virtual void setBaseURI(const XMLCh *arg);
void setInputEncoding(const XMLCh* actualEncoding);
void setXmlEncoding(const XMLCh* encoding);
void setXmlVersion(const XMLCh* version);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMEntityImpl & operator = (const DOMEntityImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,223 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMEntityReferenceImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include "DOMDocumentImpl.hpp"
#include "DOMDocumentTypeImpl.hpp"
#include "DOMEntityImpl.hpp"
#include "DOMEntityReferenceImpl.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMEntityReferenceImpl::DOMEntityReferenceImpl(DOMDocument *ownerDoc,
const XMLCh *entityName)
: fNode(ownerDoc), fParent(ownerDoc), fBaseURI(0)
{
fName = ((DOMDocumentImpl*)fParent.fOwnerDocument)->getPooledString(entityName);
// EntityReference behaves as a read-only node, since its contents
// reflect the Entity it refers to -- but see setNodeName().
//retrieve the corresponding entity content
if (ownerDoc) {
if (ownerDoc->getDoctype()) {
if (ownerDoc->getDoctype()->getEntities()) {
DOMEntityImpl* entity = (DOMEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
if (entity) {
fBaseURI = entity->getBaseURI();
DOMEntityReference* refEntity = entity->getEntityRef();
if (refEntity) {
fParent.cloneChildren(refEntity);
}
}
}
}
}
fNode.setReadOnly(true, true);
}
DOMEntityReferenceImpl::DOMEntityReferenceImpl(DOMDocument *ownerDoc,
const XMLCh *entityName,
bool cloneChild)
: fNode(ownerDoc), fParent(ownerDoc), fBaseURI(0)
{
fName = ((DOMDocumentImpl*)fParent.fOwnerDocument)->getPooledString(entityName);
// EntityReference behaves as a read-only node, since its contents
// reflect the Entity it refers to -- but see setNodeName().
//retrieve the corresponding entity content
if (ownerDoc) {
if (ownerDoc->getDoctype()) {
if (ownerDoc->getDoctype()->getEntities()) {
DOMEntityImpl* entity = (DOMEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
if (entity) {
fBaseURI = entity->getBaseURI();
if (cloneChild) {
DOMEntityReference* refEntity = entity->getEntityRef();
if (refEntity) {
fParent.cloneChildren(refEntity);
}
}
}
}
}
}
fNode.setReadOnly(true, true);
}
DOMEntityReferenceImpl::DOMEntityReferenceImpl(const DOMEntityReferenceImpl &other,
bool deep)
: DOMEntityReference(other),
fNode(other.fNode),
fParent(other.fParent),
fChild(other.fChild),
fName(other.fName),
fBaseURI(other.fBaseURI)
{
if (deep)
fParent.cloneChildren(&other);
fNode.setReadOnly(true, true);
}
DOMEntityReferenceImpl::~DOMEntityReferenceImpl()
{
}
DOMNode *DOMEntityReferenceImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ENTITY_REFERENCE_OBJECT) DOMEntityReferenceImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMEntityReferenceImpl::getNodeName() const
{
return fName;
}
DOMNode::NodeType DOMEntityReferenceImpl::getNodeType() const {
return DOMNode::ENTITY_REFERENCE_NODE;
}
/**
* EntityReferences never have a nodeValue.
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
*/
void DOMEntityReferenceImpl::setNodeValue(const XMLCh *x)
{
fNode.setNodeValue(x);
}
/**
* EntityRef is already, and must be, a read-only node. Attempts to change
* that will throw a NO_MODIFICATION_ALLOWED_ERR DOMException.
* <P>
* If you want to alter its contents, edit the Entity definition.
*
* @param readOnly boolean
*/
void DOMEntityReferenceImpl::setReadOnly(bool readOnl,bool deep)
{
if(((DOMDocumentImpl *)fParent.fOwnerDocument)->getErrorChecking() && readOnl==false)
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
fNode.setReadOnly(readOnl,deep);
}
void DOMEntityReferenceImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ENTITY_REFERENCE_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
const XMLCh* DOMEntityReferenceImpl::getBaseURI() const
{
return fBaseURI;
}
//
// Delegate functions from Node to the appropriate implementation.
//
DOMNode* DOMEntityReferenceImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
DOMNamedNodeMap* DOMEntityReferenceImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMEntityReferenceImpl::getChildNodes() const {return fParent.getChildNodes (); }
DOMNode* DOMEntityReferenceImpl::getFirstChild() const {return fParent.getFirstChild (); }
DOMNode* DOMEntityReferenceImpl::getLastChild() const {return fParent.getLastChild (); }
const XMLCh* DOMEntityReferenceImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMEntityReferenceImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMEntityReferenceImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMEntityReferenceImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMEntityReferenceImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
const XMLCh* DOMEntityReferenceImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMEntityReferenceImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMEntityReferenceImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMEntityReferenceImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
DOMNode* DOMEntityReferenceImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); }
void DOMEntityReferenceImpl::normalize() {fParent.normalize (); }
DOMNode* DOMEntityReferenceImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
DOMNode* DOMEntityReferenceImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); }
bool DOMEntityReferenceImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMEntityReferenceImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMEntityReferenceImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMEntityReferenceImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMEntityReferenceImpl::isEqualNode(const DOMNode* arg) const {return fParent.isEqualNode(arg); }
void* DOMEntityReferenceImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMEntityReferenceImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
short DOMEntityReferenceImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMEntityReferenceImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMEntityReferenceImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMEntityReferenceImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMEntityReferenceImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMEntityReferenceImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMEntityReferenceImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMEntityReferenceImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMENTITYREFERENCEIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMENTITYREFERENCEIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMEntityReference.hpp>
#include "DOMParentNode.hpp"
#include "DOMChildNode.hpp"
#include "DOMNodeImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMEntityReferenceImpl: public DOMEntityReference
{
protected:
DOMNodeImpl fNode;
DOMParentNode fParent;
DOMChildNode fChild;
const XMLCh *fName;
const XMLCh *fBaseURI;
friend class XercesDOMParser;
public:
DOMEntityReferenceImpl(DOMDocument *ownerDoc, const XMLCh *entityName);
DOMEntityReferenceImpl(DOMDocument *ownerDoc, const XMLCh *entityName, bool cloneChild);
DOMEntityReferenceImpl(const DOMEntityReferenceImpl &other, bool deep=false);
virtual ~DOMEntityReferenceImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
virtual void setReadOnly(bool readOnly,bool deep);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMEntityReferenceImpl & operator = (const DOMEntityReferenceImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
+90
View File
@@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMErrorImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMErrorImpl.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMLocator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DOMErrorImpl: Constructors and Destructor
// ---------------------------------------------------------------------------
DOMErrorImpl::DOMErrorImpl(const ErrorSeverity severity) :
fAdoptLocation(false)
, fSeverity(severity)
, fMessage(0)
, fLocation(0)
, fType(0)
, fRelatedData(0)
{
}
DOMErrorImpl::DOMErrorImpl(const ErrorSeverity severity,
const XMLCh* const message,
DOMLocator* const location) :
fAdoptLocation(false)
, fSeverity(severity)
, fMessage(message)
, fLocation(location)
, fType(0)
, fRelatedData(0)
{
}
DOMErrorImpl::DOMErrorImpl(const ErrorSeverity severity,
const XMLCh* type,
const XMLCh* message,
void* relatedData) :
fAdoptLocation(false)
, fSeverity(severity)
, fMessage(message)
, fLocation(0)
, fType(type)
, fRelatedData(relatedData)
{
}
DOMErrorImpl::~DOMErrorImpl()
{
if (fAdoptLocation)
delete fLocation;
}
// ---------------------------------------------------------------------------
// DOMErrorImpl: Setter methods
// ---------------------------------------------------------------------------
void DOMErrorImpl::setLocation(DOMLocator* const location)
{
if (fAdoptLocation)
delete fLocation;
fLocation = location;
}
void DOMErrorImpl::setRelatedException(void*) const
{
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
}
XERCES_CPP_NAMESPACE_END
+188
View File
@@ -0,0 +1,188 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMErrorImpl.hpp 676853 2008-07-15 09:58:05Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMERRORIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMERRORIMPL_HPP
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/**
* Introduced in DOM Level 3
* Implementation of a DOMError interface.
*
* @see DOMError#DOMError
*/
class CDOM_EXPORT DOMErrorImpl : public DOMError
{
public:
/** @name Constructors and Destructor */
//@{
/** Constructors */
DOMErrorImpl(const ErrorSeverity severity);
DOMErrorImpl
(
const ErrorSeverity severity
, const XMLCh* const message
, DOMLocator* const location
);
DOMErrorImpl
(
const ErrorSeverity severity
, const XMLCh* type
, const XMLCh* message
, void* relatedData
);
/** Desctructor */
virtual ~DOMErrorImpl();
//@}
// DOMError interface
virtual ErrorSeverity getSeverity() const;
virtual const XMLCh* getMessage() const;
virtual DOMLocator* getLocation() const;
virtual void* getRelatedException() const;
virtual const XMLCh* getType() const;
virtual void* getRelatedData() const;
// Setters
void setSeverity(const ErrorSeverity severity);
void setMessage(const XMLCh* const message);
void setLocation(DOMLocator* const location);
void setAdoptLocation(const bool value);
void setRelatedException(void* exc) const;
void setType(const XMLCh* type);
void setRelatedData(void* relatedData);
private:
/* Unimplemented constructors and operators */
/* Copy constructor */
DOMErrorImpl(const DOMErrorImpl&);
/* Assignment operator */
DOMErrorImpl& operator=(const DOMErrorImpl&);
protected:
// -----------------------------------------------------------------------
// Private data members
//
// fAdoptLocation
// Indicates whether we own the DOMLocator object or not.
//
// fSeverity
// The type of the error.
//
// fMessage
// The error message.
//
// fLocation
// The location info of the error.
//
// fType
// The type of the error.
//
// fRelatedData
// The data related to this error.
//
// -----------------------------------------------------------------------
bool fAdoptLocation;
ErrorSeverity fSeverity;
const XMLCh* fMessage;
DOMLocator* fLocation;
const XMLCh* fType;
void* fRelatedData;
};
// ---------------------------------------------------------------------------
// DOMErrorImpl: Getter methods
// ---------------------------------------------------------------------------
inline DOMError::ErrorSeverity DOMErrorImpl::getSeverity() const
{
return fSeverity;
}
inline const XMLCh* DOMErrorImpl::getMessage() const
{
return fMessage;
}
inline DOMLocator* DOMErrorImpl::getLocation() const
{
return fLocation;
}
inline void* DOMErrorImpl::getRelatedException() const
{
return 0;
}
inline const XMLCh* DOMErrorImpl::getType() const
{
return fType;
}
inline void* DOMErrorImpl::getRelatedData() const
{
return fRelatedData;
}
// ---------------------------------------------------------------------------
// DOMErrorImpl: Setter methods
// ---------------------------------------------------------------------------
inline void DOMErrorImpl::setSeverity(const ErrorSeverity severity)
{
fSeverity = severity;
}
inline void DOMErrorImpl::setMessage(const XMLCh* const message)
{
fMessage = message;
}
inline void DOMErrorImpl::setAdoptLocation(const bool value)
{
fAdoptLocation = value;
}
inline void DOMErrorImpl::setType(const XMLCh* type)
{
fType = type;
}
inline void DOMErrorImpl::setRelatedData(void* relatedData)
{
fRelatedData = relatedData;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,291 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMImplementationImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMImplementationImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMDocumentTypeImpl.hpp"
#include "DOMLSSerializerImpl.hpp"
#include "DOMLSInputImpl.hpp"
#include "DOMLSOutputImpl.hpp"
#include "DOMImplementationListImpl.hpp"
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLChar.hpp>
#include <xercesc/util/XMLStringTokenizer.hpp>
#include <xercesc/util/XMLDOMMsg.hpp>
#include <xercesc/util/XMLMsgLoader.hpp>
#include <xercesc/parsers/DOMLSParserImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ------------------------------------------------------------
// Static constants
// ------------------------------------------------------------
static const XMLCh g1_0[] = // Points to "1.0"
{chDigit_1, chPeriod, chDigit_0, chNull};
static const XMLCh g2_0[] = // Points to "2.0"
{chDigit_2, chPeriod, chDigit_0, chNull};
static const XMLCh g3_0[] = // Points to "3.0"
{chDigit_3, chPeriod, chDigit_0, chNull};
static const XMLCh gTrav[] = // Points to "Traversal"
{chLatin_T, chLatin_r, chLatin_a, chLatin_v, chLatin_e, chLatin_r,
chLatin_s, chLatin_a, chLatin_l, chNull};
static const XMLCh gCore[] = // Points to "Core"
{chLatin_C, chLatin_o, chLatin_r, chLatin_e, chNull};
static const XMLCh gRange[] = // Points to "Range"
{chLatin_R, chLatin_a, chLatin_n, chLatin_g, chLatin_e, chNull};
static const XMLCh gLS[] = // Points to "LS"
{chLatin_L, chLatin_S, chNull};
static const XMLCh gXPath[] = // Points to "XPath"
{chLatin_X, chLatin_P, chLatin_a, chLatin_t, chLatin_h, chNull};
static XMLMsgLoader *sMsgLoader = 0;
static DOMImplementationImpl *gDomimp = 0;
void XMLInitializer::initializeDOMImplementationImpl()
{
sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLDOMMsgDomain);
if (!sMsgLoader)
XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
gDomimp = new DOMImplementationImpl;
}
void XMLInitializer::terminateDOMImplementationImpl()
{
delete gDomimp;
gDomimp = 0;
delete sMsgLoader;
sMsgLoader = 0;
}
//
//
XMLMsgLoader* DOMImplementationImpl::getMsgLoader4DOM()
{
return sMsgLoader;
}
DOMImplementationImpl *DOMImplementationImpl::getDOMImplementationImpl()
{
return gDomimp;
}
// ------------------------------------------------------------
// DOMImplementation Virtual interface
// ------------------------------------------------------------
bool DOMImplementationImpl::hasFeature(const XMLCh * feature, const XMLCh * version) const
{
if (!feature)
return false;
// ignore the + modifier
if(*feature==chPlus)
feature++;
bool anyVersion = (version == 0 || !*version);
bool version1_0 = XMLString::equals(version, g1_0);
bool version2_0 = XMLString::equals(version, g2_0);
bool version3_0 = XMLString::equals(version, g3_0);
// Currently, we support only XML Level 1 version 1.0
if (XMLString::compareIStringASCII(feature, XMLUni::fgXMLString) == 0
&& (anyVersion || version1_0 || version2_0))
return true;
if (XMLString::compareIStringASCII(feature, gCore) == 0
&& (anyVersion || version1_0 || version2_0 || version3_0))
return true;
if (XMLString::compareIStringASCII(feature, gTrav) == 0
&& (anyVersion || version2_0))
return true;
if (XMLString::compareIStringASCII(feature, gRange) == 0
&& (anyVersion || version2_0))
return true;
if (XMLString::compareIStringASCII(feature, gLS) == 0
&& (anyVersion || version3_0))
return true;
if (XMLString::compareIStringASCII(feature, gXPath) == 0
&& (anyVersion || version3_0))
return true;
return false;
}
//Introduced in DOM Level 2
DOMDocumentType *DOMImplementationImpl::createDocumentType(const XMLCh *qualifiedName,
const XMLCh * publicId, const XMLCh *systemId)
{
// assume XML 1.0 since we do not know its version yet.
if(!XMLChar1_0::isValidName(qualifiedName))
throw DOMException(DOMException::INVALID_CHARACTER_ERR, 0);
//to do: do we need to create with user's memorymanager???
DOMDocumentTypeImpl* docType = new DOMDocumentTypeImpl(0, qualifiedName, publicId, systemId, true);
return docType;
}
DOMDocument *DOMImplementationImpl::createDocument(const XMLCh *namespaceURI,
const XMLCh *qualifiedName, DOMDocumentType *doctype,
MemoryManager* const manager)
{
return new (manager) DOMDocumentImpl(namespaceURI, qualifiedName, doctype, this, manager);
}
//Introduced in DOM Level 3
void* DOMImplementationImpl::getFeature(const XMLCh*, const XMLCh*) const {
return 0;
}
// Non-standard extension
DOMDocument *DOMImplementationImpl::createDocument(MemoryManager* const manager)
{
return new (manager) DOMDocumentImpl(this, manager);
}
//
// DOMImplementation::getImplementation. DOMImplementation is supposed to
// be a pure interface class. This one static
// function is the hook that lets things get started.
DOMImplementation *DOMImplementation::getImplementation()
{
return (DOMImplementation*) DOMImplementationImpl::getDOMImplementationImpl();
}
bool DOMImplementation::loadDOMExceptionMsg
(
const short msgToLoad
, XMLCh* const toFill
, const XMLSize_t maxChars
)
{
// Figure out which exception range this code is and load the corresponding
// message.
//
if (msgToLoad <= 50)
{
// DOMException
return sMsgLoader->loadMsg(XMLDOMMsg::DOMEXCEPTION_ERRX+msgToLoad, toFill, maxChars);
}
else if (msgToLoad <= 80)
{
// DOMXPathException
return sMsgLoader->loadMsg(XMLDOMMsg::DOMXPATHEXCEPTION_ERRX+msgToLoad-DOMXPathException::INVALID_EXPRESSION_ERR+1, toFill, maxChars);
}
else if (msgToLoad <= 110)
{
// DOMXLSException
return sMsgLoader->loadMsg(XMLDOMMsg::DOMLSEXCEPTION_ERRX+msgToLoad-DOMLSException::PARSE_ERR+1, toFill, maxChars);
}
else
{
// DOMRangeException
return sMsgLoader->loadMsg(XMLDOMMsg::DOMRANGEEXCEPTION_ERRX+msgToLoad-DOMRangeException::BAD_BOUNDARYPOINTS_ERR+1, toFill, maxChars);
}
}
// ------------------------------------------------------------
// DOMImplementationLS Virtual interface
// ------------------------------------------------------------
//Introduced in DOM Level 3
DOMLSParser* DOMImplementationImpl::createLSParser( const DOMImplementationLSMode mode,
const XMLCh* const /*schemaType*/,
MemoryManager* const manager,
XMLGrammarPool* const gramPool)
{
if (mode == DOMImplementationLS::MODE_ASYNCHRONOUS)
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, manager);
// TODO: schemaType
return new (manager) DOMLSParserImpl(0, manager, gramPool);
}
DOMLSSerializer* DOMImplementationImpl::createLSSerializer(MemoryManager* const manager)
{
return new (manager) DOMLSSerializerImpl(manager);
}
DOMLSInput* DOMImplementationImpl::createLSInput(MemoryManager* const manager)
{
return new (manager) DOMLSInputImpl(manager);
}
DOMLSOutput* DOMImplementationImpl::createLSOutput(MemoryManager* const manager)
{
return new (manager) DOMLSOutputImpl(manager);
}
// ------------------------------------------------------------
// DOMImplementationSource Virtual interface
// ------------------------------------------------------------
DOMImplementation* DOMImplementationImpl::getDOMImplementation(const XMLCh* features) const
{
DOMImplementation* impl = DOMImplementation::getImplementation();
XMLStringTokenizer tokenizer(features, XMLPlatformUtils::fgMemoryManager);
const XMLCh* feature = 0;
while (feature || tokenizer.hasMoreTokens()) {
if (!feature)
feature = tokenizer.nextToken();
const XMLCh* version = 0;
const XMLCh* token = tokenizer.nextToken();
if (token && XMLString::isDigit(token[0]))
version = token;
if (!impl->hasFeature(feature, version))
return 0;
if (!version)
feature = token;
}
return impl;
}
DOMImplementationList* DOMImplementationImpl::getDOMImplementationList(const XMLCh* features) const
{
DOMImplementationListImpl* list = new DOMImplementationListImpl;
DOMImplementation* myImpl=getDOMImplementation(features);
if(myImpl)
list->add(myImpl);
return list;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,102 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMImplementationImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMIMPLEMENTATIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMIMPLEMENTATIONIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationSource.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLMsgLoader;
class DOMImplementationImpl: public XMemory,
public DOMImplementation,
public DOMImplementationSource
{
private:
DOMImplementationImpl(const DOMImplementationImpl &);
DOMImplementationImpl & operator = (const DOMImplementationImpl &);
friend class XMLInitializer;
protected:
DOMImplementationImpl() {};
public:
virtual ~DOMImplementationImpl() {};
static DOMImplementationImpl* getDOMImplementationImpl();
static XMLMsgLoader* getMsgLoader4DOM();
// ------------------------------------------------------------
// DOMImplementation Virtual interface
// ------------------------------------------------------------
virtual bool hasFeature(const XMLCh * feature, const XMLCh * version) const;
// Introduced in DOM Level 2
virtual DOMDocumentType* createDocumentType(const XMLCh *qualifiedName,
const XMLCh * publicId,
const XMLCh *systemId);
virtual DOMDocument* createDocument(const XMLCh *namespaceURI,
const XMLCh *qualifiedName,
DOMDocumentType *doctype,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// DOM Level 3
virtual void* getFeature(const XMLCh* feature, const XMLCh* version) const;
// Non-standard extension
virtual DOMDocument* createDocument(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// ------------------------------------------------------------
// DOMImplementationLS Virtual interface
// ------------------------------------------------------------
// Introduced in DOM Level 3
virtual DOMLSParser* createLSParser(const DOMImplementationLSMode mode,
const XMLCh* const schemaType,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager,
XMLGrammarPool* const gramPool = 0);
virtual DOMLSSerializer* createLSSerializer(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual DOMLSInput* createLSInput(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual DOMLSOutput* createLSOutput(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// ------------------------------------------------------------
// DOMImplementationSource Virtual interface
// ------------------------------------------------------------
virtual DOMImplementation* getDOMImplementation(const XMLCh* features) const;
virtual DOMImplementationList* getDOMImplementationList(const XMLCh* features) const;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMImplementationListImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMImplementationListImpl.hpp"
#include <xercesc/dom/DOMImplementation.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMImplementationListImpl::DOMImplementationListImpl()
{
fList=new RefVectorOf<DOMImplementation>(3, false);
}
DOMImplementationListImpl:: ~DOMImplementationListImpl()
{
delete fList;
}
void DOMImplementationListImpl::add(DOMImplementation* impl) {
fList->addElement(impl);
}
XMLSize_t DOMImplementationListImpl::getLength() const{
return fList->size();
}
DOMImplementation *DOMImplementationListImpl::item(XMLSize_t index) const
{
if(index<fList->size())
return fList->elementAt(index);
return 0;
}
void DOMImplementationListImpl::release() {
delete this;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMImplementationListImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMIMPLEMENTATIONLISTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMIMPLEMENTATIONLISTIMPL_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/dom/DOMImplementationList.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMImplementation;
class CDOM_EXPORT DOMImplementationListImpl: public DOMImplementationList
{
protected:
RefVectorOf<DOMImplementation> *fList;
private:
// Unused, and unimplemented constructors, operators, etc.
DOMImplementationListImpl(const DOMImplementationListImpl & other);
DOMImplementationListImpl & operator = (const DOMImplementationListImpl & other);
public:
DOMImplementationListImpl();
void add(DOMImplementation* impl);
virtual ~DOMImplementationListImpl();
virtual DOMImplementation * item(XMLSize_t index) const;
virtual XMLSize_t getLength() const;
virtual void release();
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,117 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMImplementationRegistry.cpp 676911 2008-07-15 13:27:32Z amassari $
*/
#include <xercesc/util/Mutexes.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMImplementationSource.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include "DOMImplementationImpl.hpp"
#include "DOMImplementationListImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
// Points to the singleton instance of a registry of DOMImplementationSource.
//
static RefVectorOf<DOMImplementationSource>* gDOMImplSrcVector = 0;
// Global mutex that is used to synchronize access to the vector.
//
static XMLMutex* gDOMImplSrcVectorMutex = 0;
void XMLInitializer::initializeDOMImplementationRegistry()
{
gDOMImplSrcVectorMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager);
gDOMImplSrcVector = new RefVectorOf<DOMImplementationSource>(3, false);
}
void XMLInitializer::terminateDOMImplementationRegistry()
{
delete gDOMImplSrcVector;
gDOMImplSrcVector = 0;
delete gDOMImplSrcVectorMutex;
gDOMImplSrcVectorMutex = 0;
}
// -----------------------------------------------------------------------
// DOMImplementationRegistry Functions
// -----------------------------------------------------------------------
DOMImplementation *DOMImplementationRegistry::getDOMImplementation(const XMLCh* features) {
XMLMutexLock lock(gDOMImplSrcVectorMutex);
XMLSize_t len = gDOMImplSrcVector->size();
// Put our defined source there
if (len == 0) {
gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl());
len = gDOMImplSrcVector->size();
}
for (XMLSize_t i = len; i > 0; i--) {
DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1);
DOMImplementation* impl = source->getDOMImplementation(features);
if (impl)
return impl;
}
return 0;
}
DOMImplementationList* DOMImplementationRegistry::getDOMImplementationList(const XMLCh* features) {
DOMImplementationListImpl* list = new DOMImplementationListImpl;
XMLMutexLock lock(gDOMImplSrcVectorMutex);
XMLSize_t len = gDOMImplSrcVector->size();
// Put our defined source there
if (len == 0)
gDOMImplSrcVector->addElement((DOMImplementationSource*)DOMImplementationImpl::getDOMImplementationImpl());
len = gDOMImplSrcVector->size();
for (XMLSize_t i = len; i > 0; i--) {
DOMImplementationSource* source = gDOMImplSrcVector->elementAt(i-1);
DOMImplementationList* oneList = source->getDOMImplementationList(features);
XMLSize_t oneListLen=oneList->getLength();
for(XMLSize_t j=0; j<oneListLen; j++)
list->add(oneList->item(j));
oneList->release();
}
return list;
}
void DOMImplementationRegistry::addSource (DOMImplementationSource* source)
{
XMLMutexLock lock(gDOMImplSrcVectorMutex);
gDOMImplSrcVector->addElement(source);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLSInputImpl.cpp 752848 2009-03-12 12:44:40Z amassari $
*/
#include "DOMLSInputImpl.hpp"
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMLSInputImpl::DOMLSInputImpl(MemoryManager* const manager /*= XMLPlatformUtils::fgMemoryManager*/)
:fStringData(0)
,fByteStream(0)
,fEncoding(0)
,fPublicId(0)
,fSystemId(0)
,fBaseURI(0)
,fIssueFatalErrorIfNotFound(true)
,fMemoryManager(manager)
{
}
DOMLSInputImpl::~DOMLSInputImpl()
{
fMemoryManager->deallocate(fEncoding);
fMemoryManager->deallocate(fPublicId);
fMemoryManager->deallocate(fSystemId);
fMemoryManager->deallocate(fBaseURI);
}
void DOMLSInputImpl::setStringData(const XMLCh* data)
{
fStringData=data;
setEncoding(XMLUni::fgXMLChEncodingString);
}
void DOMLSInputImpl::setByteStream(InputSource* stream)
{
fByteStream=stream;
}
void DOMLSInputImpl::setEncoding(const XMLCh* const encodingStr)
{
fMemoryManager->deallocate(fEncoding);
fEncoding = XMLString::replicate(encodingStr, fMemoryManager);
}
void DOMLSInputImpl::setPublicId(const XMLCh* const publicId)
{
fMemoryManager->deallocate(fPublicId);
fPublicId = XMLString::replicate(publicId, fMemoryManager);
}
void DOMLSInputImpl::setSystemId(const XMLCh* const systemId)
{
fMemoryManager->deallocate(fSystemId);
fSystemId = XMLString::replicate(systemId, fMemoryManager);
}
void DOMLSInputImpl::setBaseURI(const XMLCh* const baseURI)
{
fMemoryManager->deallocate(fBaseURI);
fBaseURI = XMLString::replicate(baseURI, fMemoryManager);
}
void DOMLSInputImpl::setIssueFatalErrorIfNotFound(bool flag)
{
fIssueFatalErrorIfNotFound=flag;
}
void DOMLSInputImpl::release()
{
delete this;
}
XERCES_CPP_NAMESPACE_END
+134
View File
@@ -0,0 +1,134 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLSInputImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMLSINPUTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMLSINPUTIMPL_HPP
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMLSInput.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMLSInputImpl : public XMemory, public DOMLSInput
{
public:
DOMLSInputImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMLSInputImpl();
virtual const XMLCh* getStringData() const;
virtual InputSource* getByteStream() const;
virtual const XMLCh* getEncoding() const;
virtual const XMLCh* getPublicId() const;
virtual const XMLCh* getSystemId() const;
virtual const XMLCh* getBaseURI() const;
virtual void setStringData(const XMLCh* data);
virtual void setByteStream(InputSource* stream);
virtual void setEncoding(const XMLCh* const encodingStr);
virtual void setPublicId(const XMLCh* const publicId);
virtual void setSystemId(const XMLCh* const systemId);
virtual void setBaseURI(const XMLCh* const baseURI);
virtual void setIssueFatalErrorIfNotFound(bool flag);
virtual bool getIssueFatalErrorIfNotFound() const;
virtual void release();
private:
/** unimplemented copy ctor and assignment operator */
DOMLSInputImpl(const DOMLSInputImpl&);
DOMLSInputImpl & operator = (const DOMLSInputImpl&);
protected:
// -----------------------------------------------------------------------
// Private data members
//
// fStringData
// We don't own it
//
// fByteStream
// We don't own it
//
// fEncoding
// We own it
//
// fPublicId
// We own it
//
// fSystemId
// We own it
//
// fBaseURI
// We own it
//
// -----------------------------------------------------------------------
const XMLCh *fStringData;
InputSource *fByteStream;
XMLCh *fEncoding;
XMLCh *fPublicId;
XMLCh *fSystemId;
XMLCh *fBaseURI;
bool fIssueFatalErrorIfNotFound;
MemoryManager* fMemoryManager;
};
inline const XMLCh* DOMLSInputImpl::getStringData() const
{
return fStringData;
}
inline InputSource* DOMLSInputImpl::getByteStream() const
{
return fByteStream;
}
inline const XMLCh* DOMLSInputImpl::getEncoding() const
{
return fEncoding;
}
inline const XMLCh* DOMLSInputImpl::getPublicId() const
{
return fPublicId;
}
inline const XMLCh* DOMLSInputImpl::getSystemId() const
{
return fSystemId;
}
inline const XMLCh* DOMLSInputImpl::getBaseURI() const
{
return fBaseURI;
}
inline bool DOMLSInputImpl::getIssueFatalErrorIfNotFound() const
{
return fIssueFatalErrorIfNotFound;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLSOutputImpl.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
#include "DOMLSOutputImpl.hpp"
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMLSOutputImpl::DOMLSOutputImpl(MemoryManager* const manager /*= XMLPlatformUtils::fgMemoryManager*/)
:fByteStream(0)
,fEncoding(0)
,fSystemId(0)
,fMemoryManager(manager)
{
}
DOMLSOutputImpl::~DOMLSOutputImpl()
{
fMemoryManager->deallocate(fEncoding);
fMemoryManager->deallocate(fSystemId);
}
void DOMLSOutputImpl::setByteStream(XMLFormatTarget* stream)
{
fByteStream=stream;
}
void DOMLSOutputImpl::setEncoding(const XMLCh* const encodingStr)
{
fMemoryManager->deallocate(fEncoding);
fEncoding = XMLString::replicate(encodingStr, fMemoryManager);
}
void DOMLSOutputImpl::setSystemId(const XMLCh* const systemId)
{
fMemoryManager->deallocate(fSystemId);
fSystemId = XMLString::replicate(systemId, fMemoryManager);
}
void DOMLSOutputImpl::release()
{
delete this;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLSOutputImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMLSOUTPUTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMLSOUTPUTIMPL_HPP
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMLSOutput.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMLSOutputImpl : public XMemory, public DOMLSOutput
{
public:
DOMLSOutputImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMLSOutputImpl();
virtual XMLFormatTarget* getByteStream() const;
virtual const XMLCh* getEncoding() const;
virtual const XMLCh* getSystemId() const;
virtual void setByteStream(XMLFormatTarget* stream);
virtual void setEncoding(const XMLCh* const encodingStr);
virtual void setSystemId(const XMLCh* const systemId);
virtual void release();
private:
/** unimplemented copy ctor and assignment operator */
DOMLSOutputImpl(const DOMLSOutputImpl&);
DOMLSOutputImpl & operator = (const DOMLSOutputImpl&);
protected:
// -----------------------------------------------------------------------
// Private data members
//
// fByteStream
// We don't own it
//
// fEncoding
// We own it
//
// fSystemId
// We own it
//
// -----------------------------------------------------------------------
XMLFormatTarget *fByteStream;
XMLCh *fEncoding;
XMLCh *fSystemId;
MemoryManager* fMemoryManager;
};
inline XMLFormatTarget* DOMLSOutputImpl::getByteStream() const
{
return fByteStream;
}
inline const XMLCh* DOMLSOutputImpl::getEncoding() const
{
return fEncoding;
}
inline const XMLCh* DOMLSOutputImpl::getSystemId() const
{
return fSystemId;
}
XERCES_CPP_NAMESPACE_END
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,232 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLSSerializerImpl.hpp 695856 2008-09-16 12:52:32Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMLSSerializer.hpp>
#include <xercesc/util/XMLDOMMsg.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/framework/XMLFormatter.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMStringListImpl;
class CDOM_EXPORT DOMLSSerializerImpl : public XMemory,
public DOMLSSerializer,
public DOMConfiguration
{
public:
/** @name Constructor and Destructor */
//@{
/**
* Constructor.
*/
DOMLSSerializerImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
/**
* Destructor.
*/
~DOMLSSerializerImpl();
//@}
/** @name Implementation of DOMLSSerializer interface */
//@{
virtual DOMConfiguration* getDomConfig();
virtual void setNewLine(const XMLCh* const newLine);
virtual const XMLCh* getNewLine() const;
virtual void setFilter(DOMLSSerializerFilter *filter);
virtual DOMLSSerializerFilter* getFilter() const;
virtual bool write(const DOMNode* nodeToWrite,
DOMLSOutput* const destination);
virtual bool writeToURI(const DOMNode* nodeToWrite,
const XMLCh* uri);
/**
* The caller is responsible for the release of the returned string
*/
virtual XMLCh* writeToString(const DOMNode* nodeToWrite, MemoryManager* manager = NULL);
virtual void release();
//@}
/** @name Implementation of DOMConfiguration interface */
//@{
virtual void setParameter(const XMLCh* name, const void* value);
virtual void setParameter(const XMLCh* name, bool value);
virtual const void* getParameter(const XMLCh* name) const;
virtual bool canSetParameter(const XMLCh* name, const void* value) const;
virtual bool canSetParameter(const XMLCh* name, bool value) const;
virtual const DOMStringList* getParameterNames() const;
//@}
private:
/** unimplemented copy ctor and assignment operator */
DOMLSSerializerImpl(const DOMLSSerializerImpl&);
DOMLSSerializerImpl & operator = (const DOMLSSerializerImpl&);
protected:
/** helper **/
void processNode(const DOMNode* const);
void procCdataSection(const XMLCh* const nodeValue
, const DOMNode* const nodeToWrite);
void procUnrepCharInCdataSection(const XMLCh* const nodeValue
, const DOMNode* const nodeToWrite);
protected:
/**
* Overidden by derived classes to extend the abilities of the standard writer
* always returns false in the default implementation
* @return true if the method deals with nodeToWrite
*/
virtual bool customNodeSerialize(const DOMNode* const nodeToWrite, int level);
DOMNodeFilter::FilterAction checkFilter(const DOMNode* const) const;
bool checkFeature(const XMLCh* const featName
, bool state
, int& featureId) const;
bool reportError(const DOMNode* const errorNode
, DOMError::ErrorSeverity errorType
, const XMLCh* const errorMsg);
bool reportError(const DOMNode* const errorNode
, DOMError::ErrorSeverity errorType
, XMLDOMMsg::Codes toEmit);
bool canSetFeature(const int featureId
, bool val) const;
void setFeature(const int featureId
, bool val);
bool getFeature(const int featureId) const;
void printNewLine();
void setURCharRef();
bool isDefaultNamespacePrefixDeclared() const;
bool isNamespaceBindingActive(const XMLCh* prefix, const XMLCh* uri) const;
void printIndent(unsigned int level);
//does the actual work for processNode while keeping track of the level
void processNode(const DOMNode* const nodeToWrite, int level);
void processBOM();
// -----------------------------------------------------------------------
// Private data members
//
// fFeatures
//
// fNewLine
// own it
//
// fErrorHandler
// don't own it
//
// fFilter
// don't own it
//
// fDocumentVersion
// The XML Version of the document to be serialized.
//
// fSupportedParameters
// A list of the parameters that can be set, including the ones
// specific of Xerces
//
// fEncodingUsed (session var)
// the actual encoding used in write(),
// it does not own any data(memory).
//
// fNewLineUsed (session var)
// the actual "end of line" sequence used in write(),
// it does not own any data(memory).
//
// fFormatter (session var)
// the formatter used in write()
//
// fErrorCount
// the count of error encountered in the serialization,
// which neither the error handler, nor the serializer itself,
// treat as fatal. And the serializer will return true/false
// based on this value.
//
// fCurrentLine
// the current line. Used to track the line number the current
// node begins on
//
// -----------------------------------------------------------------------
int fFeatures;
XMLCh *fNewLine;
DOMErrorHandler *fErrorHandler;
DOMLSSerializerFilter *fFilter;
const XMLCh *fDocumentVersion;
DOMStringListImpl *fSupportedParameters;
//session vars
const XMLCh *fEncodingUsed;
const XMLCh *fNewLineUsed;
XMLFormatter *fFormatter;
int fErrorCount;
int fCurrentLine;
bool fLineFeedInTextNodePrinted;
unsigned int fLastWhiteSpaceInTextNode;
RefVectorOf< RefHashTableOf<XMLCh> >* fNamespaceStack;
MemoryManager* fMemoryManager;
};
inline DOMConfiguration* DOMLSSerializerImpl::getDomConfig()
{
return this;
}
inline void DOMLSSerializerImpl::setFeature(const int featureId
, bool val)
{
(val)? fFeatures |= (1<<featureId) : fFeatures &= ~(1<<featureId);
}
inline bool DOMLSSerializerImpl::getFeature(const int featureId) const
{
return ((fFeatures & ( 1<<featureId )) != 0) ? true : false;
}
inline void DOMLSSerializerImpl::setURCharRef()
{
fFormatter->setUnRepFlags(XMLFormatter::UnRep_CharRef);
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLocatorImpl.cpp 676853 2008-07-15 09:58:05Z borisk $
*/
#include "DOMLocatorImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DOMLocatorImpl: Constructors and Destructor
// ---------------------------------------------------------------------------
DOMLocatorImpl::DOMLocatorImpl() :
fLineNum(0)
, fColumnNum(0)
, fByteOffset(~(XMLFilePos(0)))
, fUtf16Offset(~(XMLFilePos(0)))
, fRelatedNode(0)
, fURI(0)
{
}
DOMLocatorImpl::DOMLocatorImpl(const XMLFileLoc lineNum,
const XMLFileLoc columnNum,
DOMNode* const errorNode,
const XMLCh* const uri,
const XMLFilePos byteOffset,
const XMLFilePos utf16Offset) :
fLineNum(lineNum)
, fColumnNum(columnNum)
, fByteOffset(byteOffset)
, fUtf16Offset(utf16Offset)
, fRelatedNode(errorNode)
, fURI(uri)
{
}
DOMLocatorImpl::~DOMLocatorImpl()
{
}
XERCES_CPP_NAMESPACE_END
+187
View File
@@ -0,0 +1,187 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMLocatorImpl.hpp 676853 2008-07-15 09:58:05Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMLOCATORIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMLOCATORIMPL_HPP
#include <xercesc/dom/DOMLocator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/**
* Introduced in DOM Level 3
*
* Implementation of a DOMLocator interface.
*
* @see DOMLocator#DOMLocator
*/
class CDOM_EXPORT DOMLocatorImpl : public DOMLocator
{
public:
/** @name Constructors and Destructor */
//@{
/** Constructor */
DOMLocatorImpl();
DOMLocatorImpl
(
const XMLFileLoc lineNum
, const XMLFileLoc columnNum
, DOMNode* const errorNode
, const XMLCh* const uri
, const XMLFilePos offset = ~(XMLFilePos(0))
, const XMLFilePos utf16Offset = ~(XMLFilePos(0))
);
/** Desctructor */
virtual ~DOMLocatorImpl();
//@}
// DOMLocator interface
virtual XMLFileLoc getLineNumber() const;
virtual XMLFileLoc getColumnNumber() const;
virtual XMLFilePos getByteOffset() const;
virtual XMLFilePos getUtf16Offset() const;
virtual DOMNode* getRelatedNode() const;
virtual const XMLCh* getURI() const;
// Setter functions
void setLineNumber(const XMLFileLoc lineNumber);
void setColumnNumber(const XMLFileLoc columnNumber);
void setByteOffset(const XMLFilePos offset);
void setUtf16Offset(const XMLFilePos offset);
void setRelatedNode(DOMNode* const errorNode);
void setURI(const XMLCh* const uri);
private :
/* Unimplemented constructors and operators */
/* Copy constructor */
DOMLocatorImpl(const DOMLocatorImpl&);
/* Assignment operator */
DOMLocatorImpl& operator=(const DOMLocatorImpl&);
protected:
// -----------------------------------------------------------------------
// Private data members
//
// fLineNum
// fColumnNum
// Track line/column number of where the error occured
//
// fByteOffset
// Track byte offset in the input source where the error
// occured
//
// fUtf16Offset
// Track character offset in the input source where the error
// occured
//
// fRelatedNode
// Current node where the error occured
//
// fURI
// The uri where the error occured
// -----------------------------------------------------------------------
XMLFileLoc fLineNum;
XMLFileLoc fColumnNum;
XMLFilePos fByteOffset;
XMLFilePos fUtf16Offset;
DOMNode* fRelatedNode;
const XMLCh* fURI;
};
// ---------------------------------------------------------------------------
// DOMLocatorImpl: Getter methods
// ---------------------------------------------------------------------------
inline XMLFileLoc DOMLocatorImpl::getLineNumber() const
{
return fLineNum;
}
inline XMLFileLoc DOMLocatorImpl::getColumnNumber() const
{
return fColumnNum;
}
inline XMLFilePos DOMLocatorImpl::getByteOffset() const
{
return fByteOffset;
}
inline XMLFilePos DOMLocatorImpl::getUtf16Offset() const
{
return fUtf16Offset;
}
inline DOMNode* DOMLocatorImpl::getRelatedNode() const
{
return fRelatedNode;
}
inline const XMLCh* DOMLocatorImpl::getURI() const
{
return fURI;
}
// ---------------------------------------------------------------------------
// DOMLocatorImpl: Setter methods
// ---------------------------------------------------------------------------
inline void DOMLocatorImpl::setLineNumber(const XMLFileLoc lineNumber)
{
fLineNum = lineNumber;
}
inline void DOMLocatorImpl::setColumnNumber(const XMLFileLoc columnNumber)
{
fColumnNum = columnNumber;
}
inline void DOMLocatorImpl::setByteOffset(const XMLFilePos offset)
{
fByteOffset = offset;
}
inline void DOMLocatorImpl::setUtf16Offset(const XMLFilePos offset)
{
fUtf16Offset = offset;
}
inline void DOMLocatorImpl::setRelatedNode(DOMNode* const errorNode)
{
fRelatedNode = errorNode;
}
inline void DOMLocatorImpl::setURI(const XMLCh* const uri)
{
fURI = uri;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,340 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNamedNodeMapImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include "DOMNodeVector.hpp"
#include "DOMNamedNodeMapImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMNodeImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
DOMNamedNodeMapImpl::DOMNamedNodeMapImpl(DOMNode *ownerNod)
{
fOwnerNode=ownerNod;
memset(fBuckets,0,MAP_SIZE*sizeof(DOMNodeVector*));
}
DOMNamedNodeMapImpl::~DOMNamedNodeMapImpl()
{
}
bool DOMNamedNodeMapImpl::readOnly()
{
return castToNodeImpl(fOwnerNode)->isReadOnly();
}
DOMNamedNodeMapImpl *DOMNamedNodeMapImpl::cloneMap(DOMNode *ownerNod)
{
DOMDocumentImpl *doc = (DOMDocumentImpl *)(castToNodeImpl(ownerNod)->getOwnerDocument());
DOMNamedNodeMapImpl *newmap = new (doc) DOMNamedNodeMapImpl(ownerNod);
for(XMLSize_t index=0;index<MAP_SIZE;index++)
if (fBuckets[index] != 0) {
XMLSize_t size=fBuckets[index]->size();
newmap->fBuckets[index] = new (doc) DOMNodeVector(doc, size);
for (XMLSize_t i = 0; i < size; ++i) {
DOMNode *s = fBuckets[index]->elementAt(i);
DOMNode *n = s->cloneNode(true);
castToNodeImpl(n)->isSpecified(castToNodeImpl(s)->isSpecified());
castToNodeImpl(n)->fOwnerNode = ownerNod;
castToNodeImpl(n)->isOwned(true);
newmap->fBuckets[index]->addElement(n);
}
}
return newmap;
}
XMLSize_t DOMNamedNodeMapImpl::getLength() const
{
XMLSize_t count=0;
for(XMLSize_t index=0;index<MAP_SIZE;index++)
count+=(fBuckets[index]==0?0:fBuckets[index]->size());
return count;
}
DOMNode * DOMNamedNodeMapImpl::item(XMLSize_t index) const
{
XMLSize_t count=0;
for(XMLSize_t i=0;i<MAP_SIZE;i++) {
if(fBuckets[i]==0)
continue;
XMLSize_t thisBucket=fBuckets[i]->size();
if(index>=count && index<(count+thisBucket))
return fBuckets[i]->elementAt(index-count);
count+=thisBucket;
}
return NULL;
}
DOMNode * DOMNamedNodeMapImpl::getNamedItem(const XMLCh *name) const
{
XMLSize_t hash=XMLString::hash(name,MAP_SIZE);
if(fBuckets[hash]==0)
return 0;
XMLSize_t i = 0;
XMLSize_t size = fBuckets[hash]->size();
for (i = 0; i < size; ++i) {
DOMNode *n=fBuckets[hash]->elementAt(i);
if(XMLString::equals(name,n->getNodeName()))
return n;
}
return 0;
}
//
// removeNamedItem() - Remove the named item, and return it.
// The caller can release the
// returned item if it's not used
// we can't do it here because the caller would
// never see the returned node.
//
DOMNode * DOMNamedNodeMapImpl::removeNamedItem(const XMLCh *name)
{
if (this->readOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager);
XMLSize_t hash=XMLString::hash(name,MAP_SIZE);
if(fBuckets[hash]==0)
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager);
DOMDocument *doc = fOwnerNode->getOwnerDocument();
XMLSize_t i = 0;
XMLSize_t size = fBuckets[hash]->size();
for (i = 0; i < size; ++i) {
DOMNode *n=fBuckets[hash]->elementAt(i);
if(XMLString::equals(name,n->getNodeName())) {
fBuckets[hash]->removeElementAt(i);
castToNodeImpl(n)->fOwnerNode = doc;
castToNodeImpl(n)->isOwned(false);
return n;
}
}
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager);
return 0;
}
//
// setNamedItem() 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::setNamedItem(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 ((arg->getNodeType() == DOMNode::ATTRIBUTE_NODE) && argImpl->isOwned() && (argImpl->fOwnerNode != fOwnerNode))
throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR,0, GetDOMNamedNodeMapMemoryManager);
argImpl->fOwnerNode = fOwnerNode;
argImpl->isOwned(true);
const XMLCh* name=arg->getNodeName();
XMLSize_t hash=XMLString::hash(name,MAP_SIZE);
if(fBuckets[hash]==0)
fBuckets[hash] = new (doc) DOMNodeVector(doc, 3);
XMLSize_t i = 0;
XMLSize_t size = fBuckets[hash]->size();
for (i = 0; i < size; ++i) {
DOMNode *n=fBuckets[hash]->elementAt(i);
if(XMLString::equals(name,n->getNodeName())) {
fBuckets[hash]->setElementAt(arg,i);
castToNodeImpl(n)->fOwnerNode = doc;
castToNodeImpl(n)->isOwned(false);
return n;
}
}
fBuckets[hash]->addElement(arg);
return 0;
}
void DOMNamedNodeMapImpl::setReadOnly(bool readOnl, bool deep)
{
// this->fReadOnly=readOnl;
if(deep) {
for (XMLSize_t index = 0; index < MAP_SIZE; index++) {
if(fBuckets[index]==0)
continue;
XMLSize_t sz = fBuckets[index]->size();
for (XMLSize_t i=0; i<sz; ++i)
castToNodeImpl(fBuckets[index]->elementAt(i))->setReadOnly(readOnl, deep);
}
}
}
//Introduced in DOM Level 2
DOMNode *DOMNamedNodeMapImpl::getNamedItemNS(const XMLCh *namespaceURI, const XMLCh *localName) const
{
// 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 (XMLSize_t index = 0; index < MAP_SIZE; index++) {
if(fBuckets[index]==0)
continue;
XMLSize_t i = 0;
XMLSize_t 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())))
return n;
}
}
}
return 0;
}
//
// 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 (XMLSize_t index = 0; index < MAP_SIZE; index++) {
if(fBuckets[index]==0)
continue;
XMLSize_t i = 0;
XMLSize_t 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 = doc;
castToNodeImpl(n)->isOwned(false);
return n;
}
}
}
}
// if not found, add it using the full name as key
return setNamedItem(arg);
}
// removeNamedItemNS() - Remove the named item, and return it.
// The caller can release the
// returned item if it's not used
// we can't do it here because the caller would
// never see the returned node.
DOMNode *DOMNamedNodeMapImpl::removeNamedItemNS(const XMLCh *namespaceURI,
const XMLCh *localName)
{
if (this->readOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNamedNodeMapMemoryManager);
// 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 (XMLSize_t index = 0; index < MAP_SIZE; index++) {
if(fBuckets[index]==0)
continue;
DOMDocument *doc = fOwnerNode->getOwnerDocument();
XMLSize_t i = 0;
XMLSize_t 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]->removeElementAt(i);
castToNodeImpl(n)->fOwnerNode = doc;
castToNodeImpl(n)->isOwned(false);
return n;
}
}
}
}
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNamedNodeMapMemoryManager);
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNamedNodeMapImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNAMEDNODEMAPIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNAMEDNODEMAPIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNodeVector;
class DOMNode;
#define MAP_SIZE 193
class CDOM_EXPORT DOMNamedNodeMapImpl: public DOMNamedNodeMap {
protected:
DOMNodeVector* fBuckets[MAP_SIZE];
DOMNode* fOwnerNode; // the node this map belongs to
//bool fReadOnly; // revisit - flag on owner node instead?
bool readOnly(); // revisit. Look at owner node read-only.
public:
DOMNamedNodeMapImpl(DOMNode *ownerNode);
virtual ~DOMNamedNodeMapImpl();
virtual DOMNamedNodeMapImpl *cloneMap(DOMNode *ownerNode);
virtual void setReadOnly(bool readOnly, bool deep);
virtual XMLSize_t getLength() const;
virtual DOMNode* item(XMLSize_t index) const;
virtual DOMNode* getNamedItem(const XMLCh *name) const;
virtual DOMNode* setNamedItem(DOMNode *arg);
virtual DOMNode* removeNamedItem(const XMLCh *name);
//Introduced in DOM Level 2
virtual DOMNode* getNamedItemNS(const XMLCh *namespaceURI,
const XMLCh *localName) const;
virtual DOMNode* setNamedItemNS(DOMNode *arg);
virtual DOMNode* removeNamedItemNS(const XMLCh *namespaceURI,
const XMLCh *localName);
private:
// unimplemented
DOMNamedNodeMapImpl(const DOMNamedNodeMapImpl &);
DOMNamedNodeMapImpl & operator = (const DOMNamedNodeMapImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
+230
View File
@@ -0,0 +1,230 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeIDMap.cpp 678144 2008-07-19 12:08:55Z borisk $
*/
#include "DOMAttrImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMNodeIDMap.hpp"
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/RuntimeException.hpp>
#include <stdio.h>
XERCES_CPP_NAMESPACE_BEGIN
static const XMLSize_t gPrimes[] = {997, 9973, 99991, 999983, 0 }; // To do - add a few more.
static const float gMaxFill = 0.8f; // The maximum fraction of the total
// table entries to consume before exanding.
DOMNodeIDMap::DOMNodeIDMap(XMLSize_t initialSize, DOMDocument *doc)
: fNumEntries(0)
, fDoc(doc)
{
for (fSizeIndex = 0; gPrimes[fSizeIndex] < initialSize; fSizeIndex++)
{
if (gPrimes[fSizeIndex] == 0)
{
// We need a bigger size than the largest available one.
// Big trouble.
fSizeIndex--;
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::NodeIDMap_GrowErr, ((DOMDocumentImpl *)fDoc)->getMemoryManager());
}
}
fSize = gPrimes[fSizeIndex];
fMaxEntries = (XMLSize_t)(float(fSize) * gMaxFill);
//fTable = new (fDoc) DOMAttr*[fSize];
fTable = (DOMAttr**) ((DOMDocumentImpl *)fDoc)->allocate(sizeof(DOMAttr*) * fSize);
XMLSize_t i;
for (i=0; i<fSize; i++)
fTable[i] = 0;
}
DOMNodeIDMap::~DOMNodeIDMap()
{
// don't delete - the document owns the storage.
fTable = 0;
}
void DOMNodeIDMap::add(DOMAttr *attr)
{
//
// If the table is getting too full, grow it. We arbitrarily limit
// the table to 80 full, which should limit the average number of
// rehashes to a reasonable value.
//
if (fNumEntries >= fMaxEntries)
growTable();
fNumEntries++;
//
// Hash the value string from the ID attribute being added to the table
// 0 < Initial hash value < table size.
// An initial hash of zero would cause the rehash to fail.
//
const XMLCh *id=attr->getValue();
XMLSize_t initalHash = XMLString::hash(id, fSize-1);
initalHash++;
XMLSize_t currentHash = initalHash;
//
// Loop looking for an empty slot for this ID.
// Don't even bother checking to see if the ID is already there -
// the table is only filled by the parser from valid documents, which
// can not have duplicates. Behavior of invalid docs is not defined.
//
while (fTable[currentHash]!=0 && fTable[currentHash]!=(DOMAttr *)-1)
{
currentHash += initalHash; // rehash
if (currentHash >= fSize)
currentHash = currentHash % fSize;
}
//
// We've found our slot. Stick the pointer to the attr into it.
//
fTable[currentHash] = attr;
}
void DOMNodeIDMap::remove(DOMAttr *attr)
{
//
// Hash the value string from the ID attribute being added to the table
// 0 < Initial hash value < table size.
// An initial hash of zero would cause the rehash to fail.
//
const XMLCh *id=attr->getValue();
XMLSize_t initalHash = XMLString::hash(id, fSize-1);
initalHash++;
XMLSize_t currentHash = initalHash;
//
// Loop looking for a slot pointing to an attr with this id.
//
DOMAttr *tableSlot;
while ((tableSlot= fTable[currentHash])!=0)
{
if (tableSlot == attr)
{
// Found the attribute. Set the slot to -1 to indicate
// that it was once used, meaning that lookups, while never
// matching here, can not stop either, but must rehash again
// and continue searching.
fTable[currentHash] = (DOMAttr *)-1;
return;
}
currentHash += initalHash; // rehash.
if (currentHash >= fSize)
currentHash = currentHash % fSize;
}
// There is no matching entry in the table
}
DOMAttr *DOMNodeIDMap::find(const XMLCh *id)
{
//
// Get the hashcode for the supplied string.
//
XMLSize_t initalHash = XMLString::hash(id, fSize-1);
initalHash++;
XMLSize_t currentHash = initalHash;
//
// Loop looking for a slot pointing to an attr with this id.
//
DOMAttr *tableSlot;
while ((tableSlot= fTable[currentHash])!=0)
{
if ((tableSlot != (DOMAttr *)-1) && XMLString::equals(tableSlot->getValue(), id))
return tableSlot;
currentHash += initalHash; // rehash
if (currentHash >= fSize)
currentHash = currentHash % fSize;
}
// There is no matching entry in the table
return 0;
}
//
// Grow the table to the next larger size.
// It has gotten too full for efficient operation.
// (We never fill it all the way)
//
void DOMNodeIDMap::growTable()
{
DOMAttr **oldTable = fTable;
XMLSize_t oldSize = fSize;
//
// Figure the new table size.
//
#if defined(XERCES_DEBUG)
fprintf(stderr, "growing...\n");
#endif
fSizeIndex++;
fSize = gPrimes[fSizeIndex];
if (fSize == 0)
{
// We need to grow bigger than the largest available size.
// Big trouble.
fSizeIndex--;
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::NodeIDMap_GrowErr, ((DOMDocumentImpl *)fDoc)->getMemoryManager());
}
//
// Allocate the new table.
//
//fTable = new (fDoc) DOMAttr *[fSize];
fTable = (DOMAttr**) ((DOMDocumentImpl *)fDoc)->allocate(sizeof(DOMAttr*) * fSize);
XMLSize_t i;
for (i=0; i<fSize; i++)
fTable[i] = 0;
fMaxEntries = (XMLSize_t)(float(fSize) * gMaxFill);
//
// Move entries over from the old table to the new one.
//
for (i=0; i<oldSize; i++)
{
if ((oldTable[i] != 0) && (oldTable[i] != (DOMAttr *)-1))
add(oldTable[i]);
}
// delete [] oldTable; (The document owns the storage. The old table will just
// need to leak until until the document is discarded.)
}
XERCES_CPP_NAMESPACE_END
+86
View File
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeIDMap.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNODEIDMAP_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNODEIDMAP_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// Class DOMNodeIDMap is a hash table that is used in the implementation of
// of DOM_Document::getElementsByID().
//
// Why Yet Another HashTable implementation? Becuase it can be significantly
// smaller when tuned for this exact usage, and the generic RefHashTableOf
// from the xerces utils project is not a paricularly good fit.
//
class DOMAttr;
class DOMDocument;
class DOMNodeIDMap {
public:
DOMNodeIDMap(XMLSize_t initialSize, DOMDocument *doc); // Create a new hash table, sized to hold "initialSize"
// Entries. It will automatically grow if need be.
~DOMNodeIDMap();
private:
DOMNodeIDMap(const DOMNodeIDMap &other); // No copy, assignement, comparison.
DOMNodeIDMap &operator = (const DOMNodeIDMap &other);
bool operator == (const DOMNodeIDMap &other);
public:
void add(DOMAttr *attr); // Add the specified attribute to the table.
void remove(DOMAttr *other); // Remove the specified attribute.
// Does nothing if the node is not in the table.
DOMAttr *find(const XMLCh *ID); // Find the attribute node in the table with this ID
private:
void growTable();
private:
DOMAttr **fTable;
XMLSize_t fSizeIndex; // Index of the current table size in the
// array of possible table sizes.
XMLSize_t fSize; // The current size of the table array
// (number of slots, not bytes.)
XMLSize_t fNumEntries; // The number of entries used.
XMLSize_t fMaxEntries; // The max number of entries to use before
// growing the table.
DOMDocument *fDoc; // The owning document.
};
XERCES_CPP_NAMESPACE_END
#endif
File diff suppressed because it is too large Load Diff
+382
View File
@@ -0,0 +1,382 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNODEIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNODEIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
/**
* A DOMNodeImpl doesn't have any children, and can therefore only be directly
* inherited by classes of nodes that never have any, such as Text nodes. For
* other types, such as Element, classes must inherit from ParentNode.
* <P>
* All nodes in a single document must originate
* in that document. (Note that this is much tighter than "must be
* same implementation") Nodes are all aware of their ownerDocument,
* and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
* <P>
* However, to save memory not all nodes always have a direct reference
* to their ownerDocument. When a node is owned by another node it relies
* on its owner to store its ownerDocument. Parent nodes always store it
* though, so there is never more than one level of indirection.
* And when a node doesn't have an owner, ownerNode refers to its
* ownerDocument.
**/
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMUserDataHandler.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNamedNodeMap;
class DOMNodeList;
class DOMNode;
class DOMDocument;
class DOMElement;
class CDOM_EXPORT DOMNodeImpl {
public:
// data
DOMNode *fOwnerNode; // typically the parent but not always!
unsigned short flags;
static const unsigned short READONLY;
static const unsigned short SYNCDATA;
static const unsigned short SYNCCHILDREN;
static const unsigned short OWNED;
static const unsigned short FIRSTCHILD;
static const unsigned short SPECIFIED;
static const unsigned short IGNORABLEWS;
static const unsigned short SETVALUE;
static const unsigned short ID_ATTR;
static const unsigned short USERDATA;
static const unsigned short LEAFNODETYPE;
static const unsigned short CHILDNODE;
static const unsigned short TOBERELEASED;
public:
DOMNodeImpl(DOMNode *ownerDocument);
DOMNodeImpl(const DOMNodeImpl &other);
~DOMNodeImpl();
DOMNode * appendChild(DOMNode *newChild);
DOMNamedNodeMap * getAttributes() const;
DOMNodeList * getChildNodes() const;
DOMNode * getFirstChild() const;
DOMNode * getLastChild() const;
const XMLCh * getLocalName() const;
const XMLCh * getNamespaceURI() const;
DOMNode * getNextSibling() const;
const XMLCh * getNodeValue() const;
DOMDocument * getOwnerDocument() const;
DOMNode * getParentNode() const;
const XMLCh * getPrefix() const;
DOMNode * getPreviousSibling() const;
bool hasChildNodes() const;
DOMNode * insertBefore(DOMNode *newChild, DOMNode *refChild);
void normalize();
DOMNode * removeChild(DOMNode *oldChild);
DOMNode * replaceChild(DOMNode *newChild, DOMNode *oldChild);
void setNodeValue(const XMLCh *value);
void setPrefix(const XMLCh *fPrefix);
void setReadOnly(bool readOnly, bool deep);
bool isSupported(const XMLCh *feature, const XMLCh *version) const;
bool hasAttributes() const;
// Introduced in DOM Level 3
void* setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler);
void* getUserData(const XMLCh* key) const;
bool isSameNode(const DOMNode* other) const;
bool isEqualNode(const DOMNode* arg) const;
const XMLCh* getBaseURI() const ;
short compareDocumentPosition(const DOMNode* other) const;
const XMLCh* getTextContent() const ;
const XMLCh* getTextContent(XMLCh* pzBuffer, XMLSize_t& rnBufferLength) const;
void setTextContent(const XMLCh* textContent) ;
const XMLCh* lookupPrefix(const XMLCh* namespaceURI) const ;
bool isDefaultNamespace(const XMLCh* namespaceURI) const ;
const XMLCh* lookupNamespaceURI(const XMLCh* prefix) const ;
void* getFeature(const XMLCh* feature, const XMLCh* version) const;
// Helper functions for DOM Level 3
void release();
void callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
const DOMNode* src,
DOMNode* dst) const;
//reverses the bit pattern given by compareDocumentPosition
short reverseTreeOrderBitPattern(short pattern) const;
const DOMNode* getTreeParentNode(const DOMNode* node) const;
//Utility, not part of DOM Level 2 API
static bool isKidOK(DOMNode *parent, DOMNode *child);
static const XMLCh *mapPrefix(const XMLCh *prefix,
const XMLCh *namespaceURI, short nType);
static const XMLCh *getXmlnsString();
static const XMLCh *getXmlnsURIString();
static const XMLCh *getXmlString();
static const XMLCh *getXmlURIString();
public: // should really be protected - ALH
DOMNode* getElementAncestor (const DOMNode* currentNode) const;
const XMLCh* lookupPrefix(const XMLCh* const namespaceURI, DOMElement *el) const ;
void setOwnerDocument(DOMDocument *doc);
/*
* Flags setters and getters
*/
inline bool isReadOnly() const {
return (flags & READONLY) != 0;
}
inline void isReadOnly(bool value) {
flags = (value ? flags | READONLY : flags & ~READONLY);
}
inline bool needsSyncData() const {
return (flags & SYNCDATA) != 0;
}
inline void needsSyncData(bool value) {
flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA);
}
inline bool needsSyncChildren() const {
return (flags & SYNCCHILDREN) != 0;
}
inline void needsSyncChildren(bool value) {
flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
}
// For Attributes, true if the attr node is attached to an element.
// For all other node types, true if the node has a parent node.
inline bool isOwned() const {
return (flags & OWNED) != 0;
}
inline void isOwned(bool value) {
flags = (value ? flags | OWNED : flags & ~OWNED);
}
inline bool isFirstChild() const {
return (flags & FIRSTCHILD) != 0;
}
inline void isFirstChild(bool value) {
flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
}
inline bool isSpecified() const {
return (flags & SPECIFIED) != 0;
}
inline void isSpecified(bool value) {
flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED);
}
inline bool ignorableWhitespace() const {
return (flags & IGNORABLEWS) != 0;
}
inline void ignorableWhitespace(bool value) {
flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
}
inline bool setValue() const {
return (flags & SETVALUE) != 0;
}
inline void setValue(bool value) {
flags = (value ? flags | SETVALUE : flags & ~SETVALUE);
}
inline bool isIdAttr() const {
return (flags & ID_ATTR) != 0;
}
inline void isIdAttr(bool value) {
flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR);
}
inline bool hasUserData() const {
return (flags & USERDATA) != 0;
}
inline void hasUserData(bool value) {
flags = (value ? flags | USERDATA : flags & ~USERDATA);
}
//
// LeafNode is set true for node types that can not be ParentNodes (can't have children)
// This knowledge is used to allow casting from any unknown node type to the
// IDParentImpl or IDChildImpl parts of the node.
//
inline bool isLeafNode() const {
return (flags & LEAFNODETYPE) != 0;
}
inline void setIsLeafNode(bool value) {
flags = (value ? flags | LEAFNODETYPE : flags & ~LEAFNODETYPE);
}
//
// ChildNode is set true for node types that can be children of other nodes, and
// therefore include a DOMChildNode data member. Note that all of the leaf
// node types (above flag) are also ChildNodes, but not all ChildNodes are
// leaf nodes.
inline bool isChildNode() const {
return (flags & CHILDNODE) != 0;
}
inline void setIsChildNode(bool value) {
flags = (value ? flags | CHILDNODE : flags & ~CHILDNODE);
}
// True if this node has to be released regardless if it has a owner or not
// This is true if called from fParent->release()
inline bool isToBeReleased() const {
return (flags & TOBERELEASED) != 0;
}
inline void isToBeReleased(bool value) {
flags = (value ? flags | TOBERELEASED : flags & ~TOBERELEASED);
}
};
// This macro lists all of the pure virtual functions declared in DOMNode that must
// be implemented by all node types. Since there is no inheritance of implementation,
// using this macro in the class declaration of the node types make it easier to
// accurately get all of the functions declared.
//
#define DOMNODE_FUNCTIONS \
virtual DOMNode* appendChild(DOMNode *newChild) ;\
virtual DOMNode* cloneNode(bool deep) const ;\
virtual DOMNamedNodeMap* getAttributes() const ;\
virtual DOMNodeList* getChildNodes() const ;\
virtual DOMNode* getFirstChild() const ;\
virtual DOMNode* getLastChild() const ;\
virtual const XMLCh* getLocalName() const ;\
virtual const XMLCh* getNamespaceURI() const ;\
virtual DOMNode* getNextSibling() const ;\
virtual const XMLCh* getNodeName() const ;\
virtual NodeType getNodeType() const ;\
virtual const XMLCh* getNodeValue() const ;\
virtual DOMDocument* getOwnerDocument() const ;\
virtual const XMLCh* getPrefix() const ;\
virtual DOMNode* getParentNode() const ;\
virtual DOMNode* getPreviousSibling() const ;\
virtual bool hasChildNodes() const ;\
virtual DOMNode* insertBefore(DOMNode *newChild, DOMNode *refChild) ;\
virtual void normalize() ;\
virtual DOMNode* removeChild(DOMNode *oldChild) ;\
virtual DOMNode* replaceChild(DOMNode *newChild, DOMNode *oldChild) ;\
virtual void setNodeValue(const XMLCh *nodeValue) ;\
virtual bool isSupported(const XMLCh *feature, const XMLCh *version) const ;\
virtual bool hasAttributes() const ;\
virtual void setPrefix(const XMLCh * prefix) ;\
virtual void* setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler) ;\
virtual void* getUserData(const XMLCh* key) const ;\
virtual bool isSameNode(const DOMNode* other) const;\
virtual bool isEqualNode(const DOMNode* arg) const;\
virtual const XMLCh* getBaseURI() const ;\
virtual short compareDocumentPosition(const DOMNode* other) const ;\
virtual const XMLCh* getTextContent() const ;\
const XMLCh* getTextContent(XMLCh* pzBuffer, unsigned int& rnBufferLength) const;\
virtual void setTextContent(const XMLCh* textContent) ;\
virtual const XMLCh* lookupPrefix(const XMLCh* namespaceURI) const ;\
virtual bool isDefaultNamespace(const XMLCh* namespaceURI) const;\
virtual const XMLCh* lookupNamespaceURI(const XMLCh* prefix) const ;\
virtual void* getFeature(const XMLCh* feature, const XMLCh* version) const ;\
virtual void release()
/*
* Here are dummy stubs for most of the functions introduced by DOMNode.
* Each subclass of DOMNode will have something like this that delegates each
* function to the appropriate implementation.
* Functions that must be supplied by every node class are omitted.
*
DOMNode* xxx::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); };
DOMNamedNodeMap* xxx::getAttributes() const {return fNode.getAttributes (); };
DOMNodeList* xxx::getChildNodes() const {return fParent.getChildNodes (); };
DOMNode* xxx::getFirstChild() const {return fParent.getFirstChild (); };
DOMNode* xxx::getLastChild() const {return fParent.getLastChild (); };
const XMLCh* xxx::getLocalName() const {return fNode.getLocalName (); };
const XMLCh* xxx::getNamespaceURI() const {return fNode.getNamespaceURI (); };
DOMNode* xxx::getNextSibling() const {return fChild.getNextSibling (); };
const XMLCh* xxx::getNodeValue() const {return fNode.getNodeValue (); };
DOMDocument* xxx::getOwnerDocument() const {return fNode.getOwnerDocument (); };
const XMLCh* xxx::getPrefix() const {return fNode.getPrefix (); };
DOMNode* xxx::getParentNode() const {return fChild.getParentNode (this); };
DOMNode* xxx::getPreviousSibling() const {return fChild.getPreviousSibling (this); };
bool xxx::hasChildNodes() const {return fParent.hasChildNodes (); };
DOMNode* xxx::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fParent.insertBefore (newChild, refChild); };
void xxx::normalize() {fParent.normalize(); };
DOMNode* xxx::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); };
DOMNode* xxx::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fParent.replaceChild (newChild, oldChild); };
bool xxx::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); };
void xxx::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); };
bool xxx::hasAttributes() const {return fNode.hasAttributes(); };
bool xxx::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); };
bool xxx::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); };
void* xxx::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); };
void* xxx::getUserData(const XMLCh* key) const {return fNode.getUserData(key); };
const XMLCh* xxx::getBaseURI() const {return fNode.getBaseURI(); };
short xxx::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); };
const XMLCh* xxx::getTextContent() const {return fNode.getTextContent(); };
void xxx::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
const XMLCh* xxx::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); };
bool xxx::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
const XMLCh* xxx::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); };
void* xxx::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); };
*/
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,365 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeIteratorImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
//////////////////////////////////////////////////////////////////////
// DOMNodeIteratorImpl.cpp: implementation of the DOMNodeIteratorImpl class.
//
//////////////////////////////////////////////////////////////////////
#include "DOMNodeIteratorImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DOMNodeIteratorImpl::DOMNodeIteratorImpl (DOMDocument* doc,
DOMNode* root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* nodeFilter,
bool expandEntityRef)
: fRoot(root),
fDocument(doc),
fWhatToShow(whatToShow),
fNodeFilter(nodeFilter),
fExpandEntityReferences(expandEntityRef),
fDetached(false),
fCurrentNode(0),
fForward(true)
{
}
DOMNodeIteratorImpl::DOMNodeIteratorImpl ( const DOMNodeIteratorImpl& toCopy)
: DOMNodeIterator(toCopy),
fRoot(toCopy.fRoot),
fDocument(toCopy.fDocument),
fWhatToShow(toCopy.fWhatToShow),
fNodeFilter(toCopy.fNodeFilter),
fExpandEntityReferences(toCopy.fExpandEntityReferences),
fDetached(toCopy.fDetached),
fCurrentNode(toCopy.fCurrentNode),
fForward(toCopy.fForward)
{
}
DOMNodeIteratorImpl& DOMNodeIteratorImpl::operator= (const DOMNodeIteratorImpl& other) {
fRoot = other.fRoot;
fCurrentNode = other.fRoot;
fWhatToShow = other.fWhatToShow;
fNodeFilter = other.fNodeFilter;
fForward = other.fForward;
fDetached = other.fDetached;
fExpandEntityReferences = other.fExpandEntityReferences;
fDocument = other.fDocument;
return *this;
}
DOMNodeIteratorImpl::~DOMNodeIteratorImpl ()
{
fDetached = false;
}
void DOMNodeIteratorImpl::detach ()
{
fDetached = true;
((DOMDocumentImpl *)fDocument)->removeNodeIterator(this);
}
DOMNode* DOMNodeIteratorImpl::getRoot() {
return fRoot;
}
// Implementation Note: Note that the iterator looks at whatToShow
// and filter values at each call, and therefore one _could_ add
// setters for these values and alter them while iterating!
/** Return the whatToShow value */
DOMNodeFilter::ShowType DOMNodeIteratorImpl::getWhatToShow () {
return fWhatToShow;
}
/** Return the filter */
DOMNodeFilter* DOMNodeIteratorImpl::getFilter () {
return fNodeFilter;
}
/** Get the expandEntity reference flag. */
bool DOMNodeIteratorImpl::getExpandEntityReferences()
{
return fExpandEntityReferences;
}
/** Return the next DOMNode* in the Iterator. The node is the next node in
* depth-first order which also passes the filter, and whatToShow.
* A 0 return means either that
*/
DOMNode* DOMNodeIteratorImpl::nextNode () {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
// if root is 0 there is no next node->
if (!fRoot)
return 0;
DOMNode* aNextNode = fCurrentNode;
bool accepted = false; // the next node has not been accepted.
while (!accepted) {
// if last direction is not forward, repeat node->
if (!fForward && (aNextNode != 0)) {
//System.out.println("nextNode():!fForward:"+fCurrentNode.getNodeName());
aNextNode = fCurrentNode;
} else {
// else get the next node via depth-first
aNextNode = nextNode(aNextNode, true);
}
fForward = true; //REVIST: should direction be set forward before 0 check?
// nothing in the list. return 0.
if (!aNextNode) return 0;
// does node pass the filters and whatToShow?
accepted = acceptNode(aNextNode);
if (accepted) {
// if so, then the node is the current node->
fCurrentNode = aNextNode;
return fCurrentNode;
}
}
// no nodes, or no accepted nodes.
return 0;
}
/** Return the previous Node in the Iterator. The node is the next node in
* _backwards_ depth-first order which also passes the filter, and whatToShow.
*/
DOMNode* DOMNodeIteratorImpl::previousNode () {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
// if the root is 0, or the current node is 0, return 0.
if (!fRoot || !fCurrentNode) return 0;
DOMNode* aPreviousNode = fCurrentNode;
bool accepted = false;
while (!accepted) {
if (fForward && (aPreviousNode != 0)) {
//repeat last node->
aPreviousNode = fCurrentNode;
} else {
// get previous node in backwards depth first order.
aPreviousNode = previousNode(aPreviousNode);
}
// we are going backwards
fForward = false;
// if the new previous node is 0, we're at head or past the root,
// so return 0.
if (!aPreviousNode) return 0;
// check if node passes filters and whatToShow.
accepted = acceptNode(aPreviousNode);
if (accepted) {
// if accepted, update the current node, and return it.
fCurrentNode = aPreviousNode;
return fCurrentNode;
}
}
// there are no nodes?
return 0;
}
/** The node is accepted if it passes the whatToShow and the filter. */
bool DOMNodeIteratorImpl::acceptNode (DOMNode* node) {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
if (fNodeFilter == 0) {
return ((fWhatToShow & (1 << (node->getNodeType() - 1))) != 0);
} else {
return ((fWhatToShow & (1 << (node->getNodeType() - 1))) != 0)
&& fNodeFilter->acceptNode(node) == DOMNodeFilter::FILTER_ACCEPT;
}
}
/** Return node, if matches or any parent if matches. */
DOMNode* DOMNodeIteratorImpl::matchNodeOrParent (DOMNode* node) {
for (DOMNode* n = fCurrentNode; n != fRoot; n = n->getParentNode()) {
if (node == n) return n;
}
return 0;
}
/** The method nextNode(DOMNode, bool) returns the next node
* from the actual DOM tree.
*
* The bool visitChildren determines whether to visit the children.
* The result is the nextNode.
*/
DOMNode* DOMNodeIteratorImpl::nextNode (DOMNode* node, bool visitChildren) {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
if (!node) return fRoot;
DOMNode* result = 0;
// only check children if we visit children.
if (visitChildren) {
//if hasChildren, return 1st child.
if ((fExpandEntityReferences || node->getNodeType()!=DOMNode::ENTITY_REFERENCE_NODE) &&
node->hasChildNodes()) {
result = node->getFirstChild();
return result;
}
}
// if hasSibling, return sibling
if (node != fRoot) {
result = node->getNextSibling();
if (result != 0) return result;
// return parent's 1st sibling.
DOMNode* parent = node->getParentNode();
while ((parent != 0) && parent != fRoot) {
result = parent->getNextSibling();
if (result != 0) {
return result;
} else {
parent = parent->getParentNode();
}
} // while (parent != 0 && parent != fRoot) {
}
// end of list, return 0
return 0;
}
/** The method previousNode(DOMNode) returns the previous node
* from the actual DOM tree.
*/
DOMNode* DOMNodeIteratorImpl::previousNode (DOMNode* node) {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
DOMNode* result = 0;
// if we're at the root, return 0.
if (node == fRoot)
return 0;
// get sibling
result = node->getPreviousSibling();
if (!result) {
//if 1st sibling, return parent
result = node->getParentNode();
return result;
}
// if sibling has children, keep getting last child of child.
if (result->hasChildNodes()) {
while ((fExpandEntityReferences || result->getNodeType()!=DOMNode::ENTITY_REFERENCE_NODE) &&
result->hasChildNodes()) {
result = result->getLastChild();
}
}
return result;
}
/** Fix-up the iterator on a remove. Called by DOM or otherwise,
* before an actual DOM remove.
*/
void DOMNodeIteratorImpl::removeNode (DOMNode* node) {
if (fDetached)
throw DOMException(DOMException::INVALID_STATE_ERR, 0, GetDOMNodeIteratorMemoryManager);
// Implementation note: Fix-up means setting the current node properly
// after a remove.
if (!node) return;
DOMNode* deleted = matchNodeOrParent(node);
if (!deleted) return;
if (fForward) {
fCurrentNode = previousNode(deleted);
} else
// if (!fForward)
{
DOMNode* next = nextNode(deleted, false);
if (next != 0) {
// normal case: there _are_ nodes following this in the iterator.
fCurrentNode = next;
} else {
// the last node in the iterator is to be removed,
// so we set the current node to be the previous one.
fCurrentNode = previousNode(deleted);
fForward = true;
}
}
}
void DOMNodeIteratorImpl::release()
{
detach();
// for performance reason, do not recycle pointer
// chance that this is allocated again and again is not usual
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,122 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeIteratorImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNODEITERATORIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNODEITERATORIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
//////////////////////////////////////////////////////////////////////
// DOMNodeIteratorImpl.hpp: interface for the DOMNodeIteratorImpl class.
//
//////////////////////////////////////////////////////////////////////
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMNodeIteratorImpl : public DOMNodeIterator {
protected:
//
// Data
//
// The root.
DOMNode* fRoot;
// The Document used to create this iterator
DOMDocument* fDocument;
// The whatToShow mask.
DOMNodeFilter::ShowType fWhatToShow;
// The NodeFilter reference.
DOMNodeFilter* fNodeFilter;
// The expandEntity reference flag.
bool fExpandEntityReferences;
bool fDetached;
//
// Iterator state - current node and direction.
//
// Note: The current node and direction are sufficient to implement
// the desired behaviour of the current pointer being _between_
// two nodes. The fCurrentNode is actually the last node returned,
// and the
// direction is whether the pointer is in front or behind this node.
// (usually akin to whether the node was returned via nextNode())
// (eg fForward = true) or previousNode() (eg fForward = false).
// The last Node returned.
DOMNode* fCurrentNode;
// The direction of the iterator on the fCurrentNode.
// <code>
// nextNode() == fForward = true;<br>
// previousNode() == fForward = false;<br>
// </code>
bool fForward;
public:
virtual ~DOMNodeIteratorImpl ();
DOMNodeIteratorImpl (
DOMDocument* fDocument,
DOMNode* root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* nodeFilter,
bool expandEntityRef);
DOMNodeIteratorImpl ( const DOMNodeIteratorImpl& toCopy);
DOMNodeIteratorImpl& operator= (const DOMNodeIteratorImpl& other);
virtual DOMNode* getRoot ();
virtual DOMNodeFilter::ShowType getWhatToShow ();
virtual DOMNodeFilter* getFilter ();
// Get the expandEntity reference flag.
virtual bool getExpandEntityReferences();
virtual DOMNode* nextNode ();
virtual DOMNode* previousNode ();
virtual void detach ();
virtual void release();
void removeNode (DOMNode* node);
protected:
DOMNode* matchNodeOrParent (DOMNode* node);
DOMNode* nextNode (DOMNode* node, bool visitChildren);
DOMNode* previousNode (DOMNode* node);
bool acceptNode (DOMNode* node);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeListImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include <xercesc/util/XercesDefs.hpp>
#include "DOMNodeListImpl.hpp"
#include "DOMCasts.hpp"
XERCES_CPP_NAMESPACE_BEGIN
// revisit
// this implementation is too stupid - needs a cache of some kind.
//
DOMNodeListImpl::DOMNodeListImpl(DOMParentNode *node)
: fNode(node)
{
}
DOMNodeListImpl:: ~DOMNodeListImpl()
{
}
XMLSize_t DOMNodeListImpl::getLength() const{
XMLSize_t count = 0;
if (fNode) {
DOMNode *node = fNode->fFirstChild;
while(node != 0){
++count;
node = castToChildImpl(node)->nextSibling;
}
}
return count;
}
DOMNode *DOMNodeListImpl::item(XMLSize_t index) const{
if (fNode) {
DOMNode *node = fNode->fFirstChild;
for(XMLSize_t i=0; i<index && node!=0; ++i)
node = castToChildImpl(node)->nextSibling;
return node;
}
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeListImpl.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNODELISTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNODELISTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
// NodeList implementation class -
// This is for NodeLists returned by GetChildNodes only, not for
// node lists returned by GetElementsByTagName
//
// Every node type capable of having children has (as an embedded member)
// an instance of this class. To hold down the size overhead on each node, a
// cache of extended data for active node lists is maintained
// separately.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMParentNode;
class DOMNode;
class CDOM_EXPORT DOMNodeListImpl: public DOMNodeList
{
protected:
DOMParentNode *fNode;
private:
// Unused, and unimplemented constructors, operators, etc.
DOMNodeListImpl();
DOMNodeListImpl(const DOMNodeListImpl & other);
DOMNodeListImpl & operator = (const DOMNodeListImpl & other);
public:
DOMNodeListImpl(DOMParentNode *node);
virtual ~DOMNodeListImpl();
virtual DOMNode * item(XMLSize_t index) const;
virtual XMLSize_t getLength() const;
};
XERCES_CPP_NAMESPACE_END
#endif
+123
View File
@@ -0,0 +1,123 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeVector.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
//
// file: DOMNodeVector.cpp
// Implementation of class DOMNodeVector.
// (Use of STL vector, or equivalent, would have been nice,
// but is not available. 'DOMNode *' is the only type
// kept in Vectors in this DOM implementation, so this is
// a hardwired implementation for that type.
//
#include "DOMNodeVector.hpp"
#include "DOMDocumentImpl.hpp"
#include <assert.h>
XERCES_CPP_NAMESPACE_BEGIN
DOMNodeVector::DOMNodeVector(DOMDocument *doc)
{
init(doc, 10);
}
DOMNodeVector::DOMNodeVector(DOMDocument *doc, XMLSize_t size) {
init(doc, size);
}
void DOMNodeVector::init(DOMDocument *doc, XMLSize_t size) {
assert(size > 0);
data = (DOMNode**) ((DOMDocumentImpl *)doc)->allocate(sizeof(DOMNode*) * size);
assert(data != 0);
for (XMLSize_t i=0; i<size; i++)
data[i] = 0;
allocatedSize = size;
nextFreeSlot = 0;
}
DOMNodeVector::~DOMNodeVector() {
}
void DOMNodeVector::addElement(DOMNode *elem) {
checkSpace();
data[nextFreeSlot] = elem;
++nextFreeSlot;
}
void DOMNodeVector::checkSpace() {
if (nextFreeSlot == allocatedSize) {
XMLSize_t grow = allocatedSize/2;
if (grow < 10) grow = 10;
const XMLSize_t newAllocatedSize = allocatedSize + grow;
DOMDocument *doc = data[0]->getOwnerDocument();
//DOMNode **newData = new (doc) DOMNode *[newAllocatedSize];
DOMNode **newData = (DOMNode**) ((DOMDocumentImpl *)doc)->allocate(sizeof(DOMNode*) * newAllocatedSize);
assert(newData != 0);
for (XMLSize_t i=0; i<allocatedSize; i++) {
newData[i] = data[i];
}
// delete [] data; // revisit. Can't delete! Recycle?
allocatedSize = newAllocatedSize;
data = newData;
}
}
void DOMNodeVector::insertElementAt(DOMNode *elem, XMLSize_t index) {
assert(index <= nextFreeSlot);
checkSpace();
for (XMLSize_t i=nextFreeSlot; i>index; --i) {
data[i] = data[i-1];
}
data[index] = elem;
++nextFreeSlot;
}
void DOMNodeVector::removeElementAt(XMLSize_t index) {
assert(index < nextFreeSlot);
for (XMLSize_t i=index; i<nextFreeSlot-1; ++i) {
data[i] = data[i+1];
}
--nextFreeSlot;
}
void DOMNodeVector::reset() {
nextFreeSlot = 0;
}
void DOMNodeVector::setElementAt(DOMNode *elem, XMLSize_t index) {
assert(index < nextFreeSlot);
data[index] = elem;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNodeVector.hpp 676796 2008-07-15 05:04:13Z dbertoni $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNODEVECTOR_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNODEVECTOR_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class DOMDocument;
class DOMNodeVector {
private:
DOMNode **data;
XMLSize_t allocatedSize;
XMLSize_t nextFreeSlot;
void init(DOMDocument *doc, XMLSize_t size);
void checkSpace();
// unimplemented
DOMNodeVector ( const DOMNodeVector& toCopy);
DOMNodeVector& operator= (const DOMNodeVector& other);
public:
DOMNodeVector(DOMDocument *doc);
DOMNodeVector(DOMDocument *doc, XMLSize_t size);
~DOMNodeVector();
XMLSize_t size();
DOMNode* elementAt(XMLSize_t index);
DOMNode* lastElement();
void addElement(DOMNode *);
void insertElementAt(DOMNode *, XMLSize_t index);
void setElementAt(DOMNode *val, XMLSize_t index);
void removeElementAt(XMLSize_t index);
void reset();
};
inline DOMNode *DOMNodeVector::elementAt(XMLSize_t index) {
if (index >= nextFreeSlot)
return 0;
return data[index];
}
inline DOMNode *DOMNodeVector::lastElement() {
if (nextFreeSlot == 0)
return 0;
return data[nextFreeSlot-1];
}
inline XMLSize_t DOMNodeVector::size() {
return nextFreeSlot;
}
XERCES_CPP_NAMESPACE_END
#endif
+500
View File
@@ -0,0 +1,500 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMText.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/Mutexes.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/util/XMLMsgLoader.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include "DOMConfigurationImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMElementImpl.hpp"
#include "DOMErrorImpl.hpp"
#include "DOMEntityReferenceImpl.hpp"
#include "DOMNormalizer.hpp"
#include "DOMTextImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
static XMLMsgLoader* gMsgLoader = 0;
void XMLInitializer::initializeDOMNormalizer()
{
gMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain);
if (!gMsgLoader)
XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
}
void XMLInitializer::terminateDOMNormalizer()
{
delete gMsgLoader;
gMsgLoader = 0;
}
//
//
DOMNormalizer::DOMNormalizer(MemoryManager* const manager)
: fDocument(0)
, fConfiguration(0)
, fErrorHandler(0)
, fNSScope(0)
, fNewNamespaceCount(1)
, fMemoryManager(manager)
{
fNSScope = new (fMemoryManager) InScopeNamespaces(fMemoryManager);
}
DOMNormalizer::~DOMNormalizer() {
delete fNSScope;
}
void DOMNormalizer::normalizeDocument(DOMDocumentImpl *doc) {
fDocument = doc;
fConfiguration = (DOMConfigurationImpl*)doc->getDOMConfig();
DOMConfigurationImpl *dci = (DOMConfigurationImpl*)fDocument->getDOMConfig();
if(dci)
fErrorHandler = dci->getErrorHandler();
else
fErrorHandler = 0;
DOMNode *child = 0;
DOMNode *next = 0;
((DOMNormalizer *)this)->fNewNamespaceCount = 1;
for(child = doc->getFirstChild();child != 0; child = next) {
next = child->getNextSibling();
child = normalizeNode(child);
if(child != 0) {
next = child;
}
}
}
DOMNode * DOMNormalizer::normalizeNode(DOMNode *node) const {
switch(node->getNodeType()) {
case DOMNode::ELEMENT_NODE: {
fNSScope->addScope(fMemoryManager);
DOMNamedNodeMap *attrMap = node->getAttributes();
if(fConfiguration->featureValues & DOMConfigurationImpl::FEATURE_NAMESPACES) {
namespaceFixUp((DOMElementImpl*)node);
}
else {
//this is done in namespace fixup so no need to do it if namespace is on
if(attrMap) {
for(XMLSize_t i = 0; i < attrMap->getLength(); i++) {
attrMap->item(i)->normalize();
}
}
}
DOMNode *child = node->getFirstChild();
DOMNode *next = 0;
for (; child != 0; child = next) {
next = child->getNextSibling();
child = normalizeNode(child);
if(child != 0) {
next = child;
}
}
fNSScope->removeScope();
break;
}
case DOMNode::COMMENT_NODE: {
if (!(fConfiguration->featureValues & DOMConfigurationImpl::FEATURE_COMMENTS)) {
DOMNode *prevSibling = node->getPreviousSibling();
DOMNode *parent = node->getParentNode();
// remove the comment node
parent->removeChild(node);
if (prevSibling != 0 && prevSibling->getNodeType() == DOMNode::TEXT_NODE) {
DOMNode *nextSibling = prevSibling->getNextSibling();
if (nextSibling != 0 && nextSibling->getNodeType() == DOMNode::TEXT_NODE) {
((DOMTextImpl*)nextSibling)->insertData(0, prevSibling->getNodeValue());
parent->removeChild(prevSibling);
return nextSibling;
}
}
}
break;
}
case DOMNode::CDATA_SECTION_NODE: {
if (!(fConfiguration->featureValues & DOMConfigurationImpl::FEATURE_CDATA_SECTIONS)) {
// convert CDATA to TEXT nodes
DOMText *text = fDocument->createTextNode(node->getNodeValue());
DOMNode *parent = node->getParentNode();
DOMNode *prevSibling = node->getPreviousSibling();
node = parent->replaceChild(text, node);
if (prevSibling != 0 && prevSibling->getNodeType() == DOMNode::TEXT_NODE) {
text->insertData(0, prevSibling->getNodeValue());
parent->removeChild(prevSibling);
}
return text; // Don't advance;
}
break;
}
case DOMNode::TEXT_NODE: {
DOMNode *next = node->getNextSibling();
if(next != 0 && next->getNodeType() == DOMNode::TEXT_NODE) {
((DOMText*)node)->appendData(next->getNodeValue());
node->getParentNode()->removeChild(next);
return node;
} else {
const XMLCh* nv = node->getNodeValue();
if (nv == 0 || *nv == 0) {
node->getParentNode()->removeChild(node);
}
}
}
default:
break;
}
return 0;
}
void DOMNormalizer::namespaceFixUp(DOMElementImpl *ele) const {
DOMAttrMapImpl *attrMap = ele->fAttributes;
XMLSize_t len = attrMap->getLength();
//get the ns info from the attrs
for(XMLSize_t i = 0; i < len; i++) {
DOMAttr *at = (DOMAttr*)attrMap->item(i);
//normalize the attr whatever happens
at->normalize();
const XMLCh *uri = at->getNamespaceURI();
const XMLCh *value = at->getNodeValue();
if(XMLString::equals(XMLUni::fgXMLNSURIName, uri)) {
if(XMLString::equals(XMLUni::fgXMLNSURIName, value)) {
error(XMLErrs::NSDeclInvalid, ele);
}
else {
const XMLCh *prefix = at->getPrefix();
if(XMLString::equals(prefix, XMLUni::fgXMLNSString)) {
fNSScope->addOrChangeBinding(at->getLocalName(), value, fMemoryManager);
}
else {
fNSScope->addOrChangeBinding(XMLUni::fgZeroLenString, value, fMemoryManager);
}
}
}
}
const XMLCh* prefix = ele->getPrefix();
prefix ? prefix : prefix = XMLUni::fgZeroLenString;
const XMLCh* uri = ele->getNamespaceURI();
uri ? uri : uri = XMLUni::fgZeroLenString;
if(!XMLString::equals(uri, XMLUni::fgZeroLenString)) {
if(!fNSScope->isValidBinding(prefix, uri)) {
addOrChangeNamespaceDecl(prefix, uri, ele);
fNSScope->addOrChangeBinding(prefix, uri, fMemoryManager);
}
}
else {
if(ele->getLocalName() == 0) {
error(XMLErrs::DOMLevel1Node, ele);
}
else if(!fNSScope->isValidBinding(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString)) {
addOrChangeNamespaceDecl(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, ele);
fNSScope->addOrChangeBinding(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, fMemoryManager);
}
}
//fix up non ns attrs
len = attrMap->getLength();
// hp aCC complains this i is a redefinition of the i on line 283
for(XMLSize_t j = 0; j < len; j++) {
DOMAttr *at = (DOMAttr*)attrMap->item(j);
const XMLCh *uri = at->getNamespaceURI();
const XMLCh* prefix = at->getPrefix();
if(!XMLString::equals(XMLUni::fgXMLNSURIName, uri)) {
if(uri != 0) {
if(prefix == 0 || !fNSScope->isValidBinding(prefix, uri)) {
const XMLCh* newPrefix = fNSScope->getPrefix(uri);
if(newPrefix != 0) {
at->setPrefix(newPrefix);
}
else {
if(prefix != 0 && !fNSScope->getUri(prefix)) {
fNSScope->addOrChangeBinding(prefix, uri, fMemoryManager);
addOrChangeNamespaceDecl(prefix, uri, ele);
}
else {
newPrefix = addCustomNamespaceDecl(uri, ele);
fNSScope->addOrChangeBinding(newPrefix, uri, fMemoryManager);
at->setPrefix(newPrefix);
}
}
}
}
else if(at->getLocalName() == 0) {
error(XMLErrs::DOMLevel1Node, at);
}
}
}
}
const XMLCh * DOMNormalizer::integerToXMLCh(unsigned int i) const {
XMLCh *buf = (XMLCh*) fMemoryManager->allocate(15 * sizeof(XMLCh));//new XMLCh[15];
XMLCh *pos = buf + sizeof(buf) - sizeof(XMLCh);
*pos = chNull;
do {
switch(i % 10) {
case 0 : *--pos = chDigit_0;break;
case 1 : *--pos = chDigit_1;break;
case 2 : *--pos = chDigit_2;break;
case 3 : *--pos = chDigit_3;break;
case 4 : *--pos = chDigit_4;break;
case 5 : *--pos = chDigit_5;break;
case 6 : *--pos = chDigit_6;break;
case 7 : *--pos = chDigit_7;break;
case 8 : *--pos = chDigit_8;break;
case 9 : *--pos = chDigit_9;break;
default:;
}
i /= 10;
} while (i);
const XMLCh *copy = fDocument->getPooledString(pos);
fMemoryManager->deallocate(buf);//delete[] buf;
return copy;
}
void DOMNormalizer::addOrChangeNamespaceDecl(const XMLCh* prefix, const XMLCh* uri, DOMElementImpl* element) const {
if (XMLString::equals(prefix, XMLUni::fgZeroLenString)) {
element->setAttributeNS(XMLUni::fgXMLNSURIName, XMLUni::fgXMLNSString, uri);
} else {
XMLBuffer buf(1023, fMemoryManager);
buf.set(XMLUni::fgXMLNSString);
buf.append(chColon);
buf.append(prefix);
element->setAttributeNS(XMLUni::fgXMLNSURIName, buf.getRawBuffer(), uri);
}
}
const XMLCh* DOMNormalizer::addCustomNamespaceDecl(const XMLCh* uri, DOMElementImpl *element) const {
XMLBuffer preBuf(1023, fMemoryManager);
preBuf.append(chLatin_N);
preBuf.append(chLatin_S);
preBuf.append(integerToXMLCh(fNewNamespaceCount));
((DOMNormalizer *)this)->fNewNamespaceCount++;
while(fNSScope->getUri(preBuf.getRawBuffer())) {
preBuf.reset();
preBuf.append(chLatin_N);
preBuf.append(chLatin_S);
preBuf.append(integerToXMLCh(fNewNamespaceCount));
((DOMNormalizer *)this)->fNewNamespaceCount++;
}
XMLBuffer buf(1023, fMemoryManager);
buf.set(XMLUni::fgXMLNSString);
buf.append(chColon);
buf.append(preBuf.getRawBuffer());
element->setAttributeNS(XMLUni::fgXMLNSURIName, buf.getRawBuffer(), uri);
return element->getAttributeNodeNS(XMLUni::fgXMLNSURIName, preBuf.getRawBuffer())->getLocalName();
}
XMLSize_t DOMNormalizer::InScopeNamespaces::size() {
return fScopes->size();
}
DOMNormalizer::InScopeNamespaces::InScopeNamespaces(MemoryManager* const manager)
: lastScopeWithBindings(0)
{
fScopes = new (manager) RefVectorOf<Scope>(10, true, manager);
}
DOMNormalizer::InScopeNamespaces::~InScopeNamespaces() {
delete fScopes;
}
void DOMNormalizer::InScopeNamespaces::addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
MemoryManager* const manager) {
XMLSize_t s = fScopes->size();
if(!s)
addScope(manager);
Scope *curScope = fScopes->elementAt(s - 1);
curScope->addOrChangeBinding(prefix, uri, manager);
lastScopeWithBindings = curScope;
}
void DOMNormalizer::InScopeNamespaces::addScope(MemoryManager* const manager) {
Scope *s = new (manager) Scope(lastScopeWithBindings);
fScopes->addElement(s);
}
void DOMNormalizer::InScopeNamespaces::removeScope() {
lastScopeWithBindings = fScopes->elementAt(fScopes->size() - 1)->fBaseScopeWithBindings;
Scope *s = fScopes->orphanElementAt(fScopes->size() - 1);
delete s;
}
bool DOMNormalizer::InScopeNamespaces::isValidBinding(const XMLCh* prefix, const XMLCh* uri) const {
const XMLCh* actual = fScopes->elementAt(fScopes->size() - 1)->getUri(prefix);
if(actual == 0 || !XMLString::equals(actual, uri))
return false;
return true;
}
const XMLCh* DOMNormalizer::InScopeNamespaces::getPrefix(const XMLCh* uri) const {
return fScopes->elementAt(fScopes->size() - 1)->getPrefix(uri);
}
const XMLCh* DOMNormalizer::InScopeNamespaces::getUri(const XMLCh* prefix) const {
return fScopes->elementAt(fScopes->size() - 1)->getUri(prefix);
}
DOMNormalizer::InScopeNamespaces::Scope::Scope(Scope *baseScopeWithBindings) : fBaseScopeWithBindings(baseScopeWithBindings), fPrefixHash(0), fUriHash(0)
{
}
DOMNormalizer::InScopeNamespaces::Scope::~Scope() {
delete fPrefixHash;
delete fUriHash;
}
void DOMNormalizer::InScopeNamespaces::Scope::addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
MemoryManager* const manager) {
//initialize and copy forward now we need to
if(!fUriHash) {
fPrefixHash = new (manager) RefHashTableOf<XMLCh>(10, (bool) false, manager);
fUriHash = new (manager) RefHashTableOf<XMLCh>(10, (bool) false, manager);
if(fBaseScopeWithBindings) {
RefHashTableOfEnumerator<XMLCh> preEnumer(fBaseScopeWithBindings->fPrefixHash, false, manager);
while(preEnumer.hasMoreElements()) {
const XMLCh* prefix = (XMLCh*) preEnumer.nextElementKey();
const XMLCh* uri = fBaseScopeWithBindings->fPrefixHash->get((void*)prefix);
//have to cast here because otherwise we have delete problems under windows :(
fPrefixHash->put((void *)prefix, (XMLCh*)uri);
}
RefHashTableOfEnumerator<XMLCh> uriEnumer(fBaseScopeWithBindings->fUriHash, false, manager);
while(uriEnumer.hasMoreElements()) {
const XMLCh* uri = (XMLCh*) uriEnumer.nextElementKey();
const XMLCh* prefix = fBaseScopeWithBindings->fUriHash->get((void*)uri);
//have to cast here because otherwise we have delete problems under windows :(
fUriHash->put((void *)uri, (XMLCh*)prefix);
}
}
}
const XMLCh *oldUri = fPrefixHash->get(prefix);
if(oldUri) {
fUriHash->removeKey(oldUri);
}
fPrefixHash->put((void *)prefix, (XMLCh*)uri);
fUriHash->put((void *)uri, (XMLCh*)prefix);
}
const XMLCh* DOMNormalizer::InScopeNamespaces::Scope::getUri(const XMLCh *prefix) const {
const XMLCh* uri = 0;
if(fPrefixHash) {
uri = fPrefixHash->get(prefix);
}
else if(fBaseScopeWithBindings) {
uri = fBaseScopeWithBindings->getUri(prefix);
}
return uri ? uri : 0;
}
const XMLCh* DOMNormalizer::InScopeNamespaces::Scope::getPrefix(const XMLCh* uri) const {
const XMLCh* prefix = 0;
if(fUriHash) {
prefix = fUriHash->get(uri);
}
else if(fBaseScopeWithBindings) {
prefix = fBaseScopeWithBindings->getPrefix(uri);
}
return prefix ? prefix : 0;
}
void DOMNormalizer::error(const XMLErrs::Codes code, const DOMNode *node) const
{
if (fErrorHandler) {
// Load the message into alocal and replace any tokens found in
// the text.
const XMLSize_t maxChars = 2047;
XMLCh errText[maxChars + 1];
if (!gMsgLoader->loadMsg(code, errText, maxChars))
{
// <TBD> Should probably load a default message here
}
DOMErrorImpl domError(
XMLErrs::DOMErrorType (code), 0, errText, (void*)node);
bool toContinueProcess = true;
try
{
toContinueProcess = fErrorHandler->handleError(domError);
}
catch(...)
{
}
if (!toContinueProcess)
throw (XMLErrs::Codes) code;
}
}
XERCES_CPP_NAMESPACE_END
+166
View File
@@ -0,0 +1,166 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNormalizer.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNORMALIZER_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNORMALIZER_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/framework/XMLErrorCodes.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMConfigurationImpl;
class DOMErrorHandler;
class DOMDocumentImpl;
class DOMNode;
class DOMElementImpl;
class DOMAttr;
class DOMNamedNodeMap;
class DOMNormalizer : public XMemory {
//the following are the data structures maintain the stack of namespace information
class InScopeNamespaces : public XMemory {
class Scope : public XMemory {
public:
Scope(Scope *baseScopeWithBindings);
~Scope();
void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
const XMLCh* getUri(const XMLCh *prefix) const;
const XMLCh* getPrefix(const XMLCh* uri) const;
Scope *fBaseScopeWithBindings;
private:
RefHashTableOf<XMLCh> *fPrefixHash;
RefHashTableOf<XMLCh> *fUriHash;
// unimplemented
Scope ( const Scope& toCopy);
Scope& operator= (const Scope& other);
};
public:
InScopeNamespaces(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~InScopeNamespaces();
void addOrChangeBinding(const XMLCh *prefix, const XMLCh *uri,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
void addScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
void removeScope();
bool isValidBinding(const XMLCh* prefix, const XMLCh* uri) const;
const XMLCh* getOrDeclarePrefix(const XMLCh* uri);
const XMLCh* getPrefix(const XMLCh* uri) const;
const XMLCh* getUri(const XMLCh* prefix) const;
XMLSize_t size();
private:
RefVectorOf<Scope> *fScopes;
Scope *lastScopeWithBindings;
// unimplemented
InScopeNamespaces ( const InScopeNamespaces& toCopy);
InScopeNamespaces& operator= (const InScopeNamespaces& other);
};
public:
DOMNormalizer(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMNormalizer();
/**
* Main entry method to normalize a document
*/
void normalizeDocument(DOMDocumentImpl *doc);
private:
// unimplemented
DOMNormalizer ( const DOMNormalizer& toCopy);
DOMNormalizer& operator= (const DOMNormalizer& other);
protected:
/**
* Recursively normalizes a node
*/
DOMNode * normalizeNode(DOMNode *node) const;
/**
* Helper method that fixes up the namespace declarations according to the
* DOM Level 3 psydocode
*/
void namespaceFixUp(DOMElementImpl *ele) const;
/**
* Converts an integer to an XMLCh - max 15 digits long.
*/
const XMLCh * integerToXMLCh(unsigned int i) const;
/**
* Adds a namespace attribute or replaces the value of existing namespace
* attribute with the given prefix and value for URI.
* In case prefix is empty will add/update default namespace declaration.
*/
void addOrChangeNamespaceDecl(const XMLCh* prefix, const XMLCh* uri, DOMElementImpl *element) const;
/**
* Adds a custom namespace in the form "NSx" where x is an integer that
* has not yet used in the document
*/
const XMLCh* addCustomNamespaceDecl(const XMLCh* uri, DOMElementImpl *element) const;
/**
* Report an error
*/
void error(const XMLErrs::Codes code, const DOMNode *node) const;
//
// fDocument - the document we are operating on
//
// fDOMConfiguration - the configuration from the document
//
// fErrorHandler - the errorhandler to be used when reporting errors during normalization
//
// fNSScope - the data stucture that holds the prefix-uri information
//
// fNewNamespaceCount - the number of custom namespace declarations we have created
//
DOMDocumentImpl *fDocument;
DOMConfigurationImpl *fConfiguration;
DOMErrorHandler *fErrorHandler;
InScopeNamespaces *fNSScope;
unsigned int fNewNamespaceCount;
MemoryManager* fMemoryManager;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,179 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNotationImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMDocumentImpl.hpp"
#include "DOMNotationImpl.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMNotationImpl::DOMNotationImpl(DOMDocument *ownerDoc, const XMLCh *nName)
: fNode(ownerDoc), fName(0), fPublicId(0), fSystemId(0), fBaseURI(0)
{
fNode.setIsLeafNode(true);
fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(nName);
}
DOMNotationImpl::DOMNotationImpl(const DOMNotationImpl &other, bool /*deep*/)
: DOMNotation(other),
fNode(other.fNode),
fName(other.fName),
fPublicId(other.fPublicId),
fSystemId(other.fSystemId),
fBaseURI(other.fBaseURI)
{
fNode.setIsLeafNode(true);
}
DOMNotationImpl::~DOMNotationImpl()
{
}
DOMNode *DOMNotationImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::NOTATION_OBJECT) DOMNotationImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMNotationImpl::getNodeName() const {
return fName;
}
DOMNode::NodeType DOMNotationImpl::getNodeType() const {
return DOMNode::NOTATION_NODE;
}
const XMLCh * DOMNotationImpl::getPublicId() const
{
return fPublicId;
}
const XMLCh * DOMNotationImpl::getSystemId() const
{
return fSystemId;
}
void DOMNotationImpl::setNodeValue(const XMLCh *arg)
{
fNode.setNodeValue(arg);
}
void DOMNotationImpl::setPublicId(const XMLCh *arg)
{
if(fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR,0, GetDOMNodeMemoryManager);
fPublicId = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(arg);
}
void DOMNotationImpl::setSystemId(const XMLCh *arg)
{
if(fNode.isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR,0, GetDOMNodeMemoryManager);
fSystemId = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(arg);
}
void DOMNotationImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
doc->release(this, DOMMemoryManager::NOTATION_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
void DOMNotationImpl::setBaseURI(const XMLCh* baseURI) {
if (baseURI && *baseURI) {
XMLCh* temp = (XMLCh*) ((DOMDocumentImpl *)getOwnerDocument())->allocate((XMLString::stringLen(baseURI) + 9)*sizeof(XMLCh));
XMLString::fixURI(baseURI, temp);
fBaseURI = temp;
}
else
fBaseURI = 0;
}
const XMLCh* DOMNotationImpl::getBaseURI() const
{
return fBaseURI;
}
DOMNode* DOMNotationImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
DOMNamedNodeMap* DOMNotationImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMNotationImpl::getChildNodes() const {return fNode.getChildNodes (); }
DOMNode* DOMNotationImpl::getFirstChild() const {return fNode.getFirstChild (); }
DOMNode* DOMNotationImpl::getLastChild() const {return fNode.getLastChild (); }
const XMLCh* DOMNotationImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMNotationImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMNotationImpl::getNextSibling() const {return fNode.getNextSibling (); }
const XMLCh* DOMNotationImpl::getNodeValue() const {return fNode.getNodeValue (); }
DOMDocument* DOMNotationImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }
const XMLCh* DOMNotationImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMNotationImpl::getParentNode() const {return fNode.getParentNode (); }
DOMNode* DOMNotationImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }
bool DOMNotationImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
DOMNode* DOMNotationImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fNode.insertBefore (newChild, refChild); }
void DOMNotationImpl::normalize() {fNode.normalize (); }
DOMNode* DOMNotationImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
DOMNode* DOMNotationImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fNode.replaceChild (newChild, oldChild); }
bool DOMNotationImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMNotationImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMNotationImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMNotationImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMNotationImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
void* DOMNotationImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMNotationImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
short DOMNotationImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMNotationImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMNotationImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMNotationImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMNotationImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMNotationImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMNotationImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMNotationImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMNOTATIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMNOTATIONIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMNotation.hpp>
XERCES_CPP_NAMESPACE_BEGIN
#include "DOMNodeImpl.hpp"
class DOMDocument;
class CDOM_EXPORT DOMNotationImpl: public DOMNotation {
public:
DOMNodeImpl fNode;
const XMLCh * fName;
const XMLCh * fPublicId;
const XMLCh * fSystemId;
const XMLCh * fBaseURI;
public:
DOMNotationImpl(DOMDocument *ownerDoc, const XMLCh *);
DOMNotationImpl(const DOMNotationImpl &other, bool deep=false);
virtual ~DOMNotationImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
//
// The Public Identifier for this Notation. If no public identifier
// was specified, this will be null.
virtual const XMLCh * getPublicId() const;
// The System Identifier for this Notation. If no system identifier
// was specified, this will be null.
virtual const XMLCh * getSystemId() const;
// NON-DOM: The Public Identifier for this Notation. If no public
// identifier was specified, this will be null.
virtual void setPublicId(const XMLCh *arg);
// NON-DOM: The System Identifier for this Notation. If no system
// identifier was specified, this will be null.
virtual void setSystemId(const XMLCh *arg);
// NON-DOM: set base uri
virtual void setBaseURI(const XMLCh *arg);
private:
// unimplemented
DOMNotationImpl& operator= (const DOMNotationImpl& other);
};
XERCES_CPP_NAMESPACE_END
#endif
+464
View File
@@ -0,0 +1,464 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMParentNode.cpp 678709 2008-07-22 10:56:56Z borisk $
*/
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include "DOMDocumentImpl.hpp"
#include "DOMRangeImpl.hpp"
#include "DOMNodeIteratorImpl.hpp"
#include "DOMParentNode.hpp"
#include "DOMCasts.hpp"
XERCES_CPP_NAMESPACE_BEGIN
DOMParentNode::DOMParentNode(DOMDocument *ownerDoc)
: fOwnerDocument(ownerDoc), fFirstChild(0), fChildNodeList(this)
{
}
// This only makes a shallow copy, cloneChildren must also be called for a
// deep clone
DOMParentNode::DOMParentNode(const DOMParentNode &other) :
fChildNodeList(this)
{
this->fOwnerDocument = other.fOwnerDocument;
// Need to break the association w/ original kids
this->fFirstChild = 0;
}
void DOMParentNode::changed()
{
((DOMDocumentImpl*)fOwnerDocument)->changed();
}
int DOMParentNode::changes() const
{
return ((DOMDocumentImpl*)fOwnerDocument)->changes();
}
DOMNode * DOMParentNode::appendChild(DOMNode *newChild)
{
return insertBefore(newChild, 0);
}
void DOMParentNode::cloneChildren(const DOMNode *other) {
// for (DOMNode *mykid = other.getFirstChild();
for (DOMNode *mykid = other->getFirstChild();
mykid != 0;
mykid = mykid->getNextSibling())
{
appendChild(mykid->cloneNode(true));
}
}
DOMDocument * DOMParentNode::getOwnerDocument() const {
return fOwnerDocument;
}
// unlike getOwnerDocument this is not overriden by DocumentImpl to return 0
DOMDocument * DOMParentNode::getDocument() const {
return fOwnerDocument;
}
void DOMParentNode::setOwnerDocument(DOMDocument* doc) {
fOwnerDocument = doc;
}
DOMNodeList *DOMParentNode::getChildNodes() const {
const DOMNodeList *ret = &fChildNodeList;
return (DOMNodeList *)ret; // cast off const.
}
DOMNode * DOMParentNode::getFirstChild() const {
return fFirstChild;
}
DOMNode * DOMParentNode::getLastChild() const
{
return lastChild();
}
DOMNode * DOMParentNode::lastChild() const
{
// last child is stored as the previous sibling of first child
if (fFirstChild == 0) {
return 0;
}
DOMChildNode *firstChild = castToChildImpl(fFirstChild);
DOMNode *ret = firstChild->previousSibling;
return ret;
}
//
// revisit. Is this function used anywhere? I don't see it.
//
void DOMParentNode::lastChild(DOMNode *node) {
// store lastChild as previous sibling of first child
if (fFirstChild != 0) {
DOMChildNode *firstChild = castToChildImpl(fFirstChild);
firstChild->previousSibling = node;
}
}
bool DOMParentNode::hasChildNodes() const
{
return fFirstChild!=0;
}
DOMNode *DOMParentNode::insertBefore(DOMNode *newChild, DOMNode *refChild) {
//not really in the specs, but better than nothing
if(newChild==NULL)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMParentNodeMemoryManager);
DOMNodeImpl *thisNodeImpl = castToNodeImpl(this);
if (thisNodeImpl->isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMParentNodeMemoryManager);
if (newChild->getOwnerDocument() != fOwnerDocument)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0, GetDOMParentNodeMemoryManager);
// Prevent cycles in the tree
//only need to do this if the node has children
if(newChild->hasChildNodes()) {
bool treeSafe=true;
for(DOMNode *a=castToNode(this)->getParentNode();
treeSafe && a!=0;
a=a->getParentNode())
treeSafe=(newChild!=a);
if(!treeSafe)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMParentNodeMemoryManager);
}
// refChild must in fact be a child of this node (or 0)
if (refChild!=0 && refChild->getParentNode() != castToNode(this))
throw DOMException(DOMException::NOT_FOUND_ERR,0, GetDOMParentNodeMemoryManager);
// if the new node has to be placed before itself, we don't have to do anything
// (even worse, we would crash if we continue, as we assume they are two distinct nodes)
if (refChild!=0 && newChild->isSameNode(refChild))
return newChild;
if (newChild->getNodeType() == DOMNode::DOCUMENT_FRAGMENT_NODE)
{
// SLOW BUT SAFE: We could insert the whole subtree without
// juggling so many next/previous pointers. (Wipe out the
// parent's child-list, patch the parent pointers, set the
// ends of the list.) But we know some subclasses have special-
// case behavior they add to insertBefore(), so we don't risk it.
// This approch also takes fewer bytecodes.
// NOTE: If one of the children is not a legal child of this
// node, throw HIERARCHY_REQUEST_ERR before _any_ of the children
// have been transferred. (Alternative behaviors would be to
// reparent up to the first failure point or reparent all those
// which are acceptable to the target node, neither of which is
// as robust. PR-DOM-0818 isn't entirely clear on which it
// recommends?????
// No need to check kids for right-document; if they weren't,
// they wouldn't be kids of that DocFrag.
for(DOMNode *kid=newChild->getFirstChild(); // Prescan
kid!=0;
kid=kid->getNextSibling())
{
if (!DOMDocumentImpl::isKidOK(castToNode(this), kid))
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMParentNodeMemoryManager);
}
while(newChild->hasChildNodes()) // Move
castToNode(this)->insertBefore(newChild->getFirstChild(),refChild);
}
else if (!DOMDocumentImpl::isKidOK(castToNode(this), newChild))
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMParentNodeMemoryManager);
else
{
DOMNode *oldparent=newChild->getParentNode();
if(oldparent!=0)
oldparent->removeChild(newChild);
// Attach up
castToNodeImpl(newChild)->fOwnerNode = castToNode(this);
castToNodeImpl(newChild)->isOwned(true);
// Attach before and after
// Note: fFirstChild.previousSibling == lastChild!!
if (fFirstChild == 0) {
// this our first and only child
fFirstChild = newChild;
castToNodeImpl(newChild)->isFirstChild(true);
// castToChildImpl(newChild)->previousSibling = newChild;
DOMChildNode *newChild_ci = castToChildImpl(newChild);
newChild_ci->previousSibling = newChild;
} else {
if (refChild == 0) {
// this is an append
DOMNode *lastChild = castToChildImpl(fFirstChild)->previousSibling;
castToChildImpl(lastChild)->nextSibling = newChild;
castToChildImpl(newChild)->previousSibling = lastChild;
castToChildImpl(fFirstChild)->previousSibling = newChild;
} else {
// this is an insert
if (refChild == fFirstChild) {
// at the head of the list
castToNodeImpl(fFirstChild)->isFirstChild(false);
castToChildImpl(newChild)->nextSibling = fFirstChild;
castToChildImpl(newChild)->previousSibling = castToChildImpl(fFirstChild)->previousSibling;
castToChildImpl(fFirstChild)->previousSibling = newChild;
fFirstChild = newChild;
castToNodeImpl(newChild)->isFirstChild(true);
} else {
// somewhere in the middle
DOMNode *prev = castToChildImpl(refChild)->previousSibling;
castToChildImpl(newChild)->nextSibling = refChild;
castToChildImpl(prev)->nextSibling = newChild;
castToChildImpl(refChild)->previousSibling = newChild;
castToChildImpl(newChild)->previousSibling = prev;
}
}
}
}
changed();
if (fOwnerDocument != 0) {
Ranges* ranges = ((DOMDocumentImpl*)fOwnerDocument)->getRanges();
if ( ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateRangeForInsertedNode(newChild);
}
}
}
}
return newChild;
}
DOMNode *DOMParentNode::removeChild(DOMNode *oldChild)
{
if (castToNodeImpl(this)->isReadOnly())
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMParentNodeMemoryManager);
if (oldChild == 0 || oldChild->getParentNode() != castToNode(this))
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMParentNodeMemoryManager);
if (fOwnerDocument != 0) {
//notify iterators
NodeIterators* nodeIterators = ((DOMDocumentImpl*)fOwnerDocument)->getNodeIterators();
if (nodeIterators != 0) {
XMLSize_t sz = nodeIterators->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
if (nodeIterators->elementAt(i) != 0)
nodeIterators->elementAt(i)->removeNode(oldChild);
}
}
}
//fix other ranges for change before deleting the node
Ranges* ranges = ((DOMDocumentImpl*)fOwnerDocument)->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
if (ranges->elementAt(i) != 0)
ranges->elementAt(i)->updateRangeForDeletedNode(oldChild);
}
}
}
}
// Patch linked list around oldChild
// Note: lastChild == fFirstChild->previousSibling
if (oldChild == fFirstChild) {
// removing first child
castToNodeImpl(oldChild)->isFirstChild(false);
fFirstChild = castToChildImpl(oldChild)->nextSibling;
if (fFirstChild != 0) {
castToNodeImpl(fFirstChild)->isFirstChild(true);
castToChildImpl(fFirstChild)->previousSibling = castToChildImpl(oldChild)->previousSibling;
}
} else {
DOMNode *prev = castToChildImpl(oldChild)->previousSibling;
DOMNode *next = castToChildImpl(oldChild)->nextSibling;
castToChildImpl(prev)->nextSibling = next;
if (next == 0) {
// removing last child
castToChildImpl(fFirstChild)->previousSibling = prev;
} else {
// removing some other child in the middle
castToChildImpl(next)->previousSibling = prev;
}
}
// Remove oldChild's references to tree
castToNodeImpl(oldChild)->fOwnerNode = fOwnerDocument;
castToNodeImpl(oldChild)->isOwned(false);
castToChildImpl(oldChild)->nextSibling = 0;
castToChildImpl(oldChild)->previousSibling = 0;
changed();
return oldChild;
}
DOMNode *DOMParentNode::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{
insertBefore(newChild, oldChild);
// changed() already done.
return removeChild(oldChild);
}
DOMNode * DOMParentNode::appendChildFast(DOMNode *newChild)
{
// This function makes the following assumptions:
//
// - newChild != 0
// - newChild is not read-only
// - newChild is not a document fragment
// - owner documents of this node and newChild are the same
// - appending newChild to this node cannot result in a cycle
// - DOMDocumentImpl::isKidOK (this, newChild) return true (that is,
// appending newChild to this node results in a valid structure)
// - newChild->getParentNode() is 0
// - there are no ranges set for this document
//
// Attach up
castToNodeImpl(newChild)->fOwnerNode = castToNode(this);
castToNodeImpl(newChild)->isOwned(true);
// Attach before and after
// Note: fFirstChild.previousSibling == lastChild!!
if (fFirstChild != 0)
{
DOMNode *lastChild = castToChildImpl(fFirstChild)->previousSibling;
castToChildImpl(lastChild)->nextSibling = newChild;
castToChildImpl(newChild)->previousSibling = lastChild;
castToChildImpl(fFirstChild)->previousSibling = newChild;
}
else
{
// this our first and only child
fFirstChild = newChild;
castToNodeImpl(newChild)->isFirstChild(true);
// castToChildImpl(newChild)->previousSibling = newChild;
DOMChildNode *newChild_ci = castToChildImpl(newChild);
newChild_ci->previousSibling = newChild;
}
return newChild;
}
//Introduced in DOM Level 2
void DOMParentNode::normalize()
{
DOMNode *kid, *next;
for (kid = fFirstChild; kid != 0; kid = next)
{
next = castToChildImpl(kid)->nextSibling;
// If kid and next are both Text nodes (but _not_ CDATASection,
// which is a subclass of Text), they can be merged.
if (next != 0 &&
kid->getNodeType() == DOMNode::TEXT_NODE &&
next->getNodeType() == DOMNode::TEXT_NODE )
{
((DOMTextImpl *) kid)->appendData(((DOMTextImpl *) next)->getData());
// revisit:
// should I release the removed node?
// not released in case user still referencing it externally
removeChild(next);
next = kid; // Don't advance; there might be another.
}
// Otherwise it might be an Element, which is handled recursively
else
if (kid->getNodeType() == DOMNode::ELEMENT_NODE)
kid->normalize();
}
// changed() will have occurred when the removeChild() was done,
// so does not have to be reissued.
}
//Introduced in DOM Level 3
bool DOMParentNode::isEqualNode(const DOMNode* arg) const
{
if (arg && castToNodeImpl(this)->isSameNode(arg))
return true;
if (arg && castToNodeImpl(this)->isEqualNode(arg))
{
DOMNode *kid, *argKid;
for (kid = fFirstChild, argKid = arg->getFirstChild();
kid != 0 && argKid != 0;
kid = kid->getNextSibling(), argKid = argKid->getNextSibling())
{
if (!kid->isEqualNode(argKid))
return false;
}
return (kid || argKid) ? false : true;
}
return false;
}
//Non-standard extension
void DOMParentNode::release()
{
DOMNode *kid, *next;
for (kid = fFirstChild; kid != 0; kid = next)
{
next = castToChildImpl(kid)->nextSibling;
// set is Owned false before releasing its child
castToNodeImpl(kid)->isToBeReleased(true);
kid->release();
}
}
XERCES_CPP_NAMESPACE_END
+114
View File
@@ -0,0 +1,114 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMParentNode.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMPARENTNODE_HPP)
#define XERCESC_INCLUDE_GUARD_DOMPARENTNODE_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
/**
* ParentNode provides the capability of having child
* nodes. Not every node in the DOM can have children, so only nodes that can
* should include this class and pay the price for it.
* <P>
* While we have a direct reference to the first child, the last child is
* stored as the previous sibling of the first child. First child nodes are
* marked as being so, and getNextSibling hides this fact.
*
**/
#include <xercesc/util/XercesDefs.hpp>
#include "DOMNodeListImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DOMChildNode;
class DOMDocument;
class DOMNode;
class DOMNodeList;
class CDOM_EXPORT DOMParentNode {
public:
DOMDocument *fOwnerDocument; // Document this node belongs to
DOMNode *fFirstChild;
DOMNodeListImpl fChildNodeList; // for GetChildNodes()
public:
DOMParentNode(DOMDocument *ownerDocument);
DOMParentNode(const DOMParentNode &other);
DOMDocument * getOwnerDocument() const;
void setOwnerDocument(DOMDocument* doc);
// Track changes to the node tree structure under this node. An optimization
// for NodeLists.
int changes() const;
void changed();
DOMNode* appendChild(DOMNode *newChild);
DOMNodeList* getChildNodes() const;
DOMNode* getFirstChild() const;
DOMNode* getLastChild() const;
bool hasChildNodes() const;
DOMNode* insertBefore(DOMNode *newChild, DOMNode *refChild);
DOMNode* item(unsigned int index) const;
DOMNode* removeChild(DOMNode *oldChild);
DOMNode* replaceChild(DOMNode *newChild, DOMNode *oldChild);
// Append certain types of nodes fast. Used to speed up XML to DOM
// parsing. See the function implementation for detail.
virtual DOMNode* appendChildFast(DOMNode *newChild);
//Introduced in DOM Level 2
void normalize();
//Introduced in DOM Level 3
bool isEqualNode(const DOMNode* arg) const;
// NON-DOM
// unlike getOwnerDocument this never returns null, even for Document nodes
DOMDocument * getDocument() const;
void release();
public:
void cloneChildren(const DOMNode *other);
DOMNode * lastChild() const;
void lastChild(DOMNode *);
private:
// unimplemented
DOMParentNode& operator= (const DOMParentNode& other);
};
#define GetDOMParentNodeMemoryManager GET_DIRECT_MM(fOwnerDocument)
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,215 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMProcessingInstructionImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include "DOMProcessingInstructionImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMRangeImpl.hpp"
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc,
const XMLCh *targt,
const XMLCh *dat)
: fNode(ownerDoc), fCharacterData(ownerDoc, dat), fBaseURI(0)
{
fNode.setIsLeafNode(true);
this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt);
}
DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(
const DOMProcessingInstructionImpl &other,
bool /*deep*/)
: DOMProcessingInstruction(other),
fNode(other.fNode),
fChild(other.fChild),
fCharacterData(other.fCharacterData),
fTarget(other.fTarget),
fBaseURI(other.fBaseURI)
{
fNode.setIsLeafNode(true);
}
DOMProcessingInstructionImpl::~DOMProcessingInstructionImpl()
{
}
DOMNode *DOMProcessingInstructionImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMProcessingInstructionImpl::getNodeName() const
{
return fTarget;
}
DOMNode::NodeType DOMProcessingInstructionImpl::getNodeType() const {
return DOMNode::PROCESSING_INSTRUCTION_NODE;
}
/** A PI's "target" states what processor channel the PI's data
should be directed to. It is defined differently in HTML and XML.
In XML, a PI's "target" is the first (whitespace-delimited) token
following the "<?" token that begins the PI.
In HTML, target is always 0.
Note that getNodeName is aliased to getTarget.
*/
const XMLCh * DOMProcessingInstructionImpl::getTarget() const
{
return fTarget;
}
void DOMProcessingInstructionImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fCharacterData.releaseBuffer();
doc->release(this, DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
void DOMProcessingInstructionImpl::setBaseURI(const XMLCh* baseURI) {
this->fBaseURI = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(baseURI);
}
const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
{
return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI();
}
// Non standard extension for the range to work
DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
DOMProcessingInstruction *newText =
doc->createProcessingInstruction(
fTarget, this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
}
//
// Delegation stubs for inherited functions
//
DOMNode* DOMProcessingInstructionImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
DOMNamedNodeMap* DOMProcessingInstructionImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMProcessingInstructionImpl::getChildNodes() const {return fNode.getChildNodes (); }
DOMNode* DOMProcessingInstructionImpl::getFirstChild() const {return fNode.getFirstChild (); }
DOMNode* DOMProcessingInstructionImpl::getLastChild() const {return fNode.getLastChild (); }
const XMLCh* DOMProcessingInstructionImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMProcessingInstructionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMProcessingInstructionImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMProcessingInstructionImpl::getNodeValue() const {return fCharacterData.getNodeValue (); }
DOMDocument* DOMProcessingInstructionImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }
const XMLCh* DOMProcessingInstructionImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMProcessingInstructionImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMProcessingInstructionImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMProcessingInstructionImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
DOMNode* DOMProcessingInstructionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fNode.insertBefore (newChild, refChild); }
void DOMProcessingInstructionImpl::normalize() {fNode.normalize (); }
DOMNode* DOMProcessingInstructionImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
DOMNode* DOMProcessingInstructionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fNode.replaceChild (newChild, oldChild); }
bool DOMProcessingInstructionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMProcessingInstructionImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMProcessingInstructionImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMProcessingInstructionImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMProcessingInstructionImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
void* DOMProcessingInstructionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMProcessingInstructionImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
short DOMProcessingInstructionImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMProcessingInstructionImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMProcessingInstructionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMProcessingInstructionImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMProcessingInstructionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMProcessingInstructionImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
//
// Delegation of CharacerData functions.
//
const XMLCh* DOMProcessingInstructionImpl::getData() const {return fCharacterData.getData();}
void DOMProcessingInstructionImpl::deleteData(XMLSize_t offset, XMLSize_t count)
{fCharacterData.deleteData(this, offset, count);}
const XMLCh* DOMProcessingInstructionImpl::substringData(XMLSize_t offset, XMLSize_t count) const
{return fCharacterData.substringData(this, offset, count);}
void DOMProcessingInstructionImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);}
void DOMProcessingInstructionImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); }
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMProcessingInstructionImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMPROCESSINGINSTRUCTIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMPROCESSINGINSTRUCTIONIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMProcessingInstruction.hpp>
#include "DOMCharacterDataImpl.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMChildNode.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class DocumentImpl;
class CDOM_EXPORT DOMProcessingInstructionImpl: public DOMProcessingInstruction {
protected:
DOMNodeImpl fNode;
DOMChildNode fChild;
// use fCharacterData to store its data so that those character utitlites can be used
DOMCharacterDataImpl fCharacterData;
XMLCh *fTarget;
const XMLCh *fBaseURI;
public:
DOMProcessingInstructionImpl(DOMDocument *ownerDoc,
const XMLCh * target,
const XMLCh *data);
DOMProcessingInstructionImpl(const DOMProcessingInstructionImpl &other,
bool deep=false);
virtual ~DOMProcessingInstructionImpl();
public:
// Declare all of the functions from DOMNode.
DOMNODE_FUNCTIONS;
public:
virtual const XMLCh *getData() const;
virtual const XMLCh *getTarget() const;
virtual void setData(const XMLCh *arg);
// NON-DOM: set base uri
virtual void setBaseURI(const XMLCh* baseURI);
// Non standard extension for the range to work
void deleteData(XMLSize_t offset, XMLSize_t count);
const XMLCh* substringData(XMLSize_t offset, XMLSize_t count) const;
DOMProcessingInstruction* splitText(XMLSize_t offset);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMProcessingInstructionImpl & operator = (const DOMProcessingInstructionImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
File diff suppressed because it is too large Load Diff
+176
View File
@@ -0,0 +1,176 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMRangeImpl.hpp 641193 2008-03-26 08:06:57Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMRANGEIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMRANGEIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMRange.hpp>
#include <xercesc/util/PlatformUtils.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class DOMDocumentFragment;
class DOMDocument;
class DOMText;
class MemoryManager;
class CDOM_EXPORT DOMRangeImpl: public DOMRange {
protected:
enum TraversalType {
EXTRACT_CONTENTS = 1,
CLONE_CONTENTS = 2,
DELETE_CONTENTS = 3
};
enum TraversePoint {
BEFORE = -1,
START = 0,
AFTER = 1
};
//private data
DOMNode* fStartContainer;
XMLSize_t fStartOffset;
DOMNode* fEndContainer;
XMLSize_t fEndOffset;
bool fCollapsed;
DOMDocument* fDocument;
bool fDetached;
DOMNode* fRemoveChild;
MemoryManager* fMemoryManager;
public:
//c'tor
DOMRangeImpl(DOMDocument* doc, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
DOMRangeImpl(const DOMRangeImpl& other);
//d'tor
~DOMRangeImpl();
//getter functions
virtual DOMNode* getStartContainer() const;
virtual XMLSize_t getStartOffset() const;
virtual DOMNode* getEndContainer() const;
virtual XMLSize_t getEndOffset() const;
virtual bool getCollapsed() const;
virtual const DOMNode* getCommonAncestorContainer() const;
//setter functions
virtual void setStart(const DOMNode *parent, XMLSize_t offset);
virtual void setEnd(const DOMNode *parent, XMLSize_t offset);
virtual void setStartBefore(const DOMNode *refNode);
virtual void setStartAfter(const DOMNode *refNode);
virtual void setEndBefore(const DOMNode *refNode);
virtual void setEndAfter(const DOMNode *refNode);
//misc functions
virtual void collapse(bool toStart);
virtual void selectNode(const DOMNode *node);
virtual void selectNodeContents(const DOMNode *node);
//Functions related to comparing range Boundrary-Points
virtual short compareBoundaryPoints(CompareHow how, const DOMRange* range) const;
virtual void deleteContents();
virtual DOMDocumentFragment* extractContents();
virtual DOMDocumentFragment* cloneContents() const;
virtual void insertNode(DOMNode* node);
//Misc functions
virtual void surroundContents(DOMNode *node);
virtual DOMRange* cloneRange() const;
virtual const XMLCh* toString() const;
virtual void detach();
virtual void release();
//getter functions
DOMDocument* getDocument();
// functions to inform all existing valid ranges about a change
void updateSplitInfo(DOMNode* oldNode, DOMNode* startNode, XMLSize_t offset);
void updateRangeForInsertedNode(DOMNode* node);
void receiveReplacedText(DOMNode* node);
void updateRangeForDeletedText(DOMNode* node, XMLSize_t offset, XMLSize_t count);
void updateRangeForInsertedText(DOMNode* node, XMLSize_t offset, XMLSize_t count);
void updateRangeForDeletedNode(DOMNode* node);
protected:
//setter functions
void setStartContainer(const DOMNode* node);
void setStartOffset(XMLSize_t offset) ;
void setEndContainer(const DOMNode* node);
void setEndOffset(XMLSize_t offset) ;
//misc functions
void validateNode(const DOMNode* node) const;
bool isValidAncestorType(const DOMNode* node) const;
bool hasLegalRootContainer(const DOMNode* node) const;
bool isLegalContainedNode(const DOMNode* node ) const;
void checkIndex(const DOMNode* node, XMLSize_t offset) const;
static bool isAncestorOf(const DOMNode* a, const DOMNode* b);
XMLSize_t indexOf(const DOMNode* child, const DOMNode* parent) const;
const DOMNode* commonAncestorOf(const DOMNode* pointA, const DOMNode* pointB) const;
DOMNode* nextNode(const DOMNode* node, bool visitChildren) const;
DOMDocumentFragment* traverseContents(TraversalType type);
void checkReadOnly(DOMNode* start, DOMNode* end,
XMLSize_t starOffset, XMLSize_t endOffset);
void recurseTreeAndCheck(DOMNode* start, DOMNode* end);
DOMNode* removeChild(DOMNode* parent, DOMNode* child);
DOMDocumentFragment* traverseSameContainer( int how );
DOMDocumentFragment* traverseCommonStartContainer( DOMNode *endAncestor, int how );
DOMDocumentFragment* traverseCommonEndContainer( DOMNode *startAncestor, int how );
DOMDocumentFragment* traverseCommonAncestors( DOMNode *startAncestor, DOMNode *endAncestor, int how );
DOMNode* traverseRightBoundary( DOMNode *root, int how );
DOMNode* traverseLeftBoundary( DOMNode *root, int how );
DOMNode* traverseNode( DOMNode *n, bool isFullySelected, bool isLeft, int how );
DOMNode* traverseFullySelected( DOMNode *n, int how );
DOMNode* traversePartiallySelected( DOMNode *n, int how );
DOMNode* traverseTextNode( DOMNode *n, bool isLeft, int how );
DOMNode* getSelectedNode( DOMNode *container, int offset );
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMRangeImpl & operator = (const DOMRangeImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMStringListImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMStringListImpl.hpp"
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMStringListImpl::DOMStringListImpl(int nInitialSize, MemoryManager* manager)
{
fList=new (manager) RefVectorOf<XMLCh>(nInitialSize, false, manager);
}
DOMStringListImpl::~DOMStringListImpl()
{
delete fList;
}
void DOMStringListImpl::add(const XMLCh* str) {
fList->addElement((XMLCh*)str);
}
XMLSize_t DOMStringListImpl::getLength() const{
return fList->size();
}
const XMLCh* DOMStringListImpl::item(XMLSize_t index) const{
if(index<fList->size())
return fList->elementAt(index);
return 0;
}
bool DOMStringListImpl::contains(const XMLCh* str) const{
for(XMLSize_t i=0;i<fList->size();i++)
if(XMLString::equals(fList->elementAt(i), str))
return true;
return false;
}
void DOMStringListImpl::release() {
delete this;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMStringListImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMSTRINGLISTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMSTRINGLISTIMPL_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/dom/DOMStringList.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMStringListImpl: public XMemory,
public DOMStringList
{
protected:
RefVectorOf<XMLCh> *fList;
private:
// Unused, and unimplemented constructors, operators, etc.
DOMStringListImpl(const DOMStringListImpl & other);
DOMStringListImpl & operator = (const DOMStringListImpl & other);
public:
DOMStringListImpl(int nInitialSize, MemoryManager* manager);
void add(const XMLCh* impl);
virtual ~DOMStringListImpl();
virtual const XMLCh* item(XMLSize_t index) const;
virtual XMLSize_t getLength() const;
virtual bool contains(const XMLCh* str) const;
virtual void release();
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMStringPool.cpp 678766 2008-07-22 14:00:16Z borisk $
*/
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include "DOMStringPool.hpp"
#include "DOMDocumentImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
DOMBuffer::
DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity) :
fBuffer(0)
, fIndex(0)
, fCapacity(capacity)
, fDoc(doc)
{
// Buffer is one larger than capacity, to allow for zero term
fBuffer = (XMLCh*) doc->allocate((fCapacity+1)*sizeof(XMLCh));
// Keep it null terminated
fBuffer[0] = XMLCh(0);
}
// ---------------------------------------------------------------------------
// DOMBuffer: Private helper methods
// ---------------------------------------------------------------------------
void DOMBuffer::expandCapacity(const XMLSize_t extraNeeded)
{
//not enough room. Calc new capacity and allocate new buffer
const XMLSize_t newCap = (XMLSize_t)((fIndex + extraNeeded) * 1.25);
XMLCh* newBuf = (XMLCh*) fDoc->allocate((newCap+1)*sizeof(XMLCh));
// Copy over the old stuff
memcpy(newBuf, fBuffer, fCapacity * sizeof(XMLCh));
// revisit: Leave the old buffer in document heap, yes, this is a leak, but live with it!
// store new stuff
fBuffer = newBuf;
fCapacity = newCap;
}
XERCES_CPP_NAMESPACE_END
+211
View File
@@ -0,0 +1,211 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMStringPool.hpp 678766 2008-07-22 14:00:16Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMSTRINGPOOL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMSTRINGPOOL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMDocumentImpl;
//
// DStringPoolEntry - one of these structs is allocated for each
// XMLCh String in the pool. Each slot in the
// hash table array itself is a pointer to the head
// of a singly-linked list of these structs.
//
// Although this struct is delcared with a string length of one,
// the factory method allocates enough storage to hold the full
// string length.
//
struct DOMStringPoolEntry
{
DOMStringPoolEntry *fNext;
XMLCh fString[1];
};
//
// DOMBuffer is a lightweight text buffer
// The buffer is not nul terminated until some asks to see the raw buffer
// contents. This also avoids overhead during append operations.
class DOMBuffer
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity = 31);
~DOMBuffer()
{
}
// -----------------------------------------------------------------------
// Buffer Management
// -----------------------------------------------------------------------
void append (const XMLCh* const chars);
void append (const XMLCh* const chars, const XMLSize_t count);
void set (const XMLCh* const chars);
void set (const XMLCh* const chars, const XMLSize_t count);
const XMLCh* getRawBuffer() const
{
fBuffer[fIndex] = 0;
return fBuffer;
}
void reset()
{
fIndex = 0;
fBuffer[0] = 0;
}
void chop
(
const XMLSize_t count
)
{
fBuffer[count] = 0;
fIndex = count;
}
// -----------------------------------------------------------------------
// Getters
// -----------------------------------------------------------------------
XMLSize_t getLen() const
{
return fIndex;
}
XMLSize_t getCapacity() const
{
return fCapacity;
}
// -----------------------------------------------------------------------
// Private helpers
// -----------------------------------------------------------------------
void expandCapacity(const XMLSize_t extraNeeded);
private :
// -----------------------------------------------------------------------
// Private data members
//
// fBuffer
// The pointer to the buffer data. Its grown as needed. Its always
// one larger than fCapacity, to leave room for the null terminator.
//
// fIndex
// The current index into the buffer, as characters are appended
// to it. If its zero, then the buffer is empty.
//
// fCapacity
// The current capacity of the buffer. Its actually always one
// larger, to leave room for the null terminator.
//
// fDoc
// For allocating memory
// -----------------------------------------------------------------------
XMLCh* fBuffer;
XMLSize_t fIndex;
XMLSize_t fCapacity;
DOMDocumentImpl* fDoc;
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMBuffer(const DOMBuffer &);
DOMBuffer & operator = (const DOMBuffer &);
};
inline void DOMBuffer::
append (const XMLCh* const chars)
{
XMLSize_t count = XMLString::stringLen(chars);
if (fIndex + count >= fCapacity)
expandCapacity(count);
memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
fIndex += count;
// Keep it null terminated
fBuffer[fIndex] = 0;
}
inline void DOMBuffer::
append (const XMLCh* const chars, const XMLSize_t count)
{
if (fIndex + count >= fCapacity)
expandCapacity(count);
memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
fIndex += count;
// Keep it null terminated
fBuffer[fIndex] = 0;
}
inline void DOMBuffer::
set (const XMLCh* const chars)
{
XMLSize_t count = XMLString::stringLen(chars);
fIndex = 0;
if (count >= fCapacity)
expandCapacity(count);
memcpy(fBuffer, chars, count * sizeof(XMLCh));
fIndex = count;
// Keep it null terminated
fBuffer[fIndex] = 0;
}
inline void DOMBuffer::
set (const XMLCh* const chars, const XMLSize_t count)
{
fIndex = 0;
if (count >= fCapacity)
expandCapacity(count);
memcpy(fBuffer, chars, count * sizeof(XMLCh));
fIndex = count;
// Keep it null terminated
fBuffer[fIndex] = 0;
}
XERCES_CPP_NAMESPACE_END
#endif
+331
View File
@@ -0,0 +1,331 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMTextImpl.cpp 1027995 2010-10-27 15:09:39Z amassari $
*/
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMCDATASection.hpp>
#include <xercesc/dom/DOMNodeFilter.hpp>
#include <xercesc/dom/DOMTreeWalker.hpp>
#include "DOMDocumentImpl.hpp"
#include "DOMStringPool.hpp"
#include "DOMTextImpl.hpp"
#include "DOMCharacterDataImpl.hpp"
#include "DOMChildNode.hpp"
#include "DOMRangeImpl.hpp"
#include "DOMCasts.hpp"
#include <assert.h>
XERCES_CPP_NAMESPACE_BEGIN
class DOMDocument;
DOMTextImpl::DOMTextImpl(DOMDocument *ownerDoc, const XMLCh *dat)
: fNode(ownerDoc), fCharacterData(ownerDoc, dat)
{
fNode.setIsLeafNode(true);
}
DOMTextImpl::
DOMTextImpl(DOMDocument *ownerDoc, const XMLCh* dat, XMLSize_t n)
: fNode(ownerDoc), fCharacterData(ownerDoc, dat, n)
{
fNode.setIsLeafNode(true);
}
DOMTextImpl::DOMTextImpl(const DOMTextImpl &other, bool)
: DOMText(other)
, fNode(other.fNode)
, fCharacterData(other.fCharacterData)
{
fNode.setIsLeafNode(true);
}
DOMTextImpl::~DOMTextImpl()
{
}
DOMNode *DOMTextImpl::cloneNode(bool deep) const
{
DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::TEXT_OBJECT) DOMTextImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
const XMLCh * DOMTextImpl::getNodeName() const {
static const XMLCh gtext[] = {chPound, chLatin_t, chLatin_e, chLatin_x, chLatin_t, chNull};
return gtext;
}
DOMNode::NodeType DOMTextImpl::getNodeType() const {
return DOMNode::TEXT_NODE;
}
DOMText *DOMTextImpl::splitText(XMLSize_t offset)
{
if (fNode.isReadOnly())
{
throw DOMException(
DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
XMLSize_t len = fCharacterData.fDataBuf->getLen();
if (offset > len)
throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
DOMText *newText = doc->createTextNode(
this->substringData(offset, len - offset));
DOMNode *parent = getParentNode();
if (parent != 0)
parent->insertBefore(newText, getNextSibling());
fCharacterData.fDataBuf->chop(offset);
if (doc != 0) {
Ranges* ranges = doc->getRanges();
if (ranges != 0) {
XMLSize_t sz = ranges->size();
if (sz != 0) {
for (XMLSize_t i =0; i<sz; i++) {
ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
}
}
}
}
return newText;
}
bool DOMTextImpl::isIgnorableWhitespace() const
{
return fNode.ignorableWhitespace();
}
void DOMTextImpl::setIgnorableWhitespace(bool ignorable)
{
fNode.ignorableWhitespace(ignorable);
}
bool DOMTextImpl::getIsElementContentWhitespace() const
{
return isIgnorableWhitespace();
}
const XMLCh* DOMTextImpl::getWholeText() const
{
DOMDocument *doc = getOwnerDocument();
if (!doc) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
return 0;
}
DOMNode* root=doc->getDocumentElement();
DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
}
XMLBuffer buff(1023, GetDOMNodeMemoryManager);
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==TEXT_NODE || nextNode->getNodeType()==CDATA_SECTION_NODE)
buff.append(nextNode->getNodeValue());
}
pWalker->release();
XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
XMLString::copyString(wholeString, buff.getRawBuffer());
return wholeString;
}
DOMText* DOMTextImpl::replaceWholeText(const XMLCh* newText)
{
DOMDocument *doc = getOwnerDocument();
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* pFirstTextNode=this;
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
pFirstTextNode=prevNode;
}
// before doing any change we need to check if we are going to remove an entity reference that doesn't contain just text
DOMNode* pCurrentNode=pWalker->getCurrentNode();
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==ENTITY_REFERENCE_NODE)
{
DOMTreeWalker* pInnerWalker=doc->createTreeWalker(nextNode, DOMNodeFilter::SHOW_ALL, NULL, true);
while(pInnerWalker->nextNode())
{
short nodeType=pInnerWalker->getCurrentNode()->getNodeType();
if(nodeType!=ENTITY_REFERENCE_NODE && nodeType!=TEXT_NODE && nodeType!=CDATA_SECTION_NODE)
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
}
pInnerWalker->release();
}
}
DOMText* retVal=NULL;
// if the first node in the chain is a text node, replace its content, otherwise create a new node
if(newText && *newText)
{
if(!castToNodeImpl(pFirstTextNode)->isReadOnly() && (pFirstTextNode->getNodeType()==TEXT_NODE || pFirstTextNode->getNodeType()==CDATA_SECTION_NODE))
{
pFirstTextNode->setNodeValue(newText);
retVal=(DOMText*)pFirstTextNode;
}
else
{
if(getNodeType()==TEXT_NODE)
retVal=doc->createTextNode(newText);
else
retVal=doc->createCDATASection(newText);
pFirstTextNode->getParentNode()->insertBefore(retVal, pFirstTextNode);
}
}
// now delete all the following text nodes
pWalker->setCurrentNode(pCurrentNode);
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode!=retVal)
{
// keep the tree walker valid
pWalker->previousNode();
nextNode->getParentNode()->removeChild(nextNode);
nextNode->release();
}
}
pWalker->release();
return retVal;
}
void DOMTextImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fCharacterData.releaseBuffer();
doc->release(this, DOMMemoryManager::TEXT_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
//
// Delegation functions
//
DOMNode* DOMTextImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
DOMNamedNodeMap* DOMTextImpl::getAttributes() const {return fNode.getAttributes (); }
DOMNodeList* DOMTextImpl::getChildNodes() const {return fNode.getChildNodes (); }
DOMNode* DOMTextImpl::getFirstChild() const {return fNode.getFirstChild (); }
DOMNode* DOMTextImpl::getLastChild() const {return fNode.getLastChild (); }
const XMLCh* DOMTextImpl::getLocalName() const {return fNode.getLocalName (); }
const XMLCh* DOMTextImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
DOMNode* DOMTextImpl::getNextSibling() const {return fChild.getNextSibling (); }
const XMLCh* DOMTextImpl::getNodeValue() const {return fCharacterData.getNodeValue (); }
DOMDocument* DOMTextImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }
const XMLCh* DOMTextImpl::getPrefix() const {return fNode.getPrefix (); }
DOMNode* DOMTextImpl::getParentNode() const {return fChild.getParentNode (this); }
DOMNode* DOMTextImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
bool DOMTextImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
DOMNode* DOMTextImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
{return fNode.insertBefore (newChild, refChild); }
void DOMTextImpl::normalize() {fNode.normalize (); }
DOMNode* DOMTextImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
DOMNode* DOMTextImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{return fNode.replaceChild (newChild, oldChild); }
bool DOMTextImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{return fNode.isSupported (feature, version); }
void DOMTextImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
bool DOMTextImpl::hasAttributes() const {return fNode.hasAttributes(); }
bool DOMTextImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
bool DOMTextImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
void* DOMTextImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{return fNode.setUserData(key, data, handler); }
void* DOMTextImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
const XMLCh* DOMTextImpl::getBaseURI() const {return fNode.getBaseURI(); }
short DOMTextImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
const XMLCh* DOMTextImpl::getTextContent() const {return fNode.getTextContent(); }
void DOMTextImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
const XMLCh* DOMTextImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
bool DOMTextImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
const XMLCh* DOMTextImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
void* DOMTextImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
//
// Delegation of CharacerData functions.
//
const XMLCh* DOMTextImpl::getData() const {return fCharacterData.getData();}
XMLSize_t DOMTextImpl::getLength() const {return fCharacterData.getLength();}
const XMLCh* DOMTextImpl::substringData(XMLSize_t offset, XMLSize_t count) const
{return fCharacterData.substringData(this, offset, count);}
void DOMTextImpl::appendData(const XMLCh *arg) {fCharacterData.appendData(this, arg);}
void DOMTextImpl::insertData(XMLSize_t offset, const XMLCh *arg)
{fCharacterData.insertData(this, offset, arg);}
void DOMTextImpl::deleteData(XMLSize_t offset, XMLSize_t count)
{fCharacterData.deleteData(this, offset, count);}
void DOMTextImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
{fCharacterData.replaceData(this, offset, count, arg);}
void DOMTextImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);}
void DOMTextImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); }
void DOMTextImpl::appendData(const XMLCh *arg, XMLSize_t n) {fCharacterData.appendData(this, arg, n);}
XERCES_CPP_NAMESPACE_END
+103
View File
@@ -0,0 +1,103 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMTextImpl.hpp 678709 2008-07-22 10:56:56Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMTEXTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMTEXTIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/dom/DOMText.hpp>
#include "DOMChildNode.hpp"
#include "DOMNodeImpl.hpp"
#include "DOMCharacterDataImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMTextImpl: public DOMText {
public:
DOMNodeImpl fNode;
DOMChildNode fChild;
DOMCharacterDataImpl fCharacterData;
public:
DOMTextImpl(DOMDocument* ownerDoc, const XMLCh* data);
DOMTextImpl(DOMDocument *ownerDoc, const XMLCh* data, XMLSize_t n);
DOMTextImpl(const DOMTextImpl& other, bool deep=false);
virtual ~DOMTextImpl();
virtual DOMText* splitText(XMLSize_t offset);
// DOM Level 3
virtual bool getIsElementContentWhitespace() const;
virtual const XMLCh* getWholeText() const;
virtual DOMText* replaceWholeText(const XMLCh* content);
// non-standard extension
virtual bool isIgnorableWhitespace() const;
public:
// Declare the functions coming from DOMNode.
DOMNODE_FUNCTIONS;
public:
// All of the functions coming from DOMCharacterData
virtual const XMLCh* getData() const;
virtual XMLSize_t getLength() const;
virtual const XMLCh* substringData(XMLSize_t offset,
XMLSize_t count) const;
virtual void appendData(const XMLCh *arg);
virtual void insertData(XMLSize_t offset, const XMLCh *arg);
virtual void deleteData(XMLSize_t offset,
XMLSize_t count);
virtual void replaceData(XMLSize_t offset,
XMLSize_t count,
const XMLCh *arg);
virtual void setData(const XMLCh *data);
// Non-standard extension.
//
virtual void appendData(const XMLCh *arg, XMLSize_t n);
protected:
virtual void setIgnorableWhitespace(bool ignorable);
friend class AbstractDOMParser;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMTextImpl & operator = (const DOMTextImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,484 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMTreeWalkerImpl.cpp 671894 2008-06-26 13:29:21Z borisk $
*/
#include "DOMTreeWalkerImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/** constructor */
DOMTreeWalkerImpl::DOMTreeWalkerImpl (
DOMNode* root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* nodeFilter,
bool expandEntityRef)
: fWhatToShow(whatToShow),
fNodeFilter(nodeFilter),
fCurrentNode(root),
fRoot(root),
fExpandEntityReferences(expandEntityRef)
{
}
DOMTreeWalkerImpl::DOMTreeWalkerImpl (const DOMTreeWalkerImpl& twi)
: DOMTreeWalker(twi),
fWhatToShow(twi.fWhatToShow),
fNodeFilter(twi.fNodeFilter),
fCurrentNode(twi.fCurrentNode),
fRoot(twi.fRoot),
fExpandEntityReferences(twi.fExpandEntityReferences)
{
}
DOMTreeWalkerImpl& DOMTreeWalkerImpl::operator= (const DOMTreeWalkerImpl& twi) {
if (this != &twi)
{
fCurrentNode = twi.fCurrentNode;
fRoot = twi.fRoot;
fWhatToShow = twi.fWhatToShow;
fNodeFilter = twi.fNodeFilter;
fExpandEntityReferences = twi.fExpandEntityReferences;
}
return *this;
}
/** Return the root node */
DOMNode* DOMTreeWalkerImpl::getRoot () {
return fRoot;
}
/** Return the whatToShow value */
DOMNodeFilter::ShowType DOMTreeWalkerImpl::getWhatToShow () {
return fWhatToShow;
}
/** Return the NodeFilter */
DOMNodeFilter* DOMTreeWalkerImpl::getFilter () {
return fNodeFilter;
}
/** Get the expandEntity reference flag. */
bool DOMTreeWalkerImpl::getExpandEntityReferences() {
return fExpandEntityReferences;
}
/** Return the current Node. */
DOMNode* DOMTreeWalkerImpl::getCurrentNode () {
return fCurrentNode;
}
/** Return the current Node. */
void DOMTreeWalkerImpl::setCurrentNode (DOMNode* node) {
if (!node)
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMTreeWalkerMemoryManager);
fCurrentNode = node;
}
/** Return the parent Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::parentNode () {
if (!fCurrentNode) return 0;
DOMNode* node = getParentNode(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
}
return node;
}
/** Return the first child Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::firstChild () {
if (!fCurrentNode) return 0;
if(!fExpandEntityReferences && fCurrentNode->getNodeType()==DOMNode::ENTITY_REFERENCE_NODE)
return 0;
DOMNode* node = getFirstChild(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
}
return node;
}
/** Return the last child Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::lastChild () {
if (!fCurrentNode) return 0;
if(!fExpandEntityReferences && fCurrentNode->getNodeType()==DOMNode::ENTITY_REFERENCE_NODE)
return 0;
DOMNode* node = getLastChild(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
}
return node;
}
/** Return the previous sibling Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::previousSibling () {
if (!fCurrentNode) return 0;
DOMNode* node = getPreviousSibling(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
}
return node;
}
/** Return the next sibling Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::nextSibling () {
if (!fCurrentNode) return 0;
DOMNode* node = getNextSibling(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
}
return node;
}
/** Return the previous Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::previousNode () {
if (!fCurrentNode) return 0;
// get sibling
DOMNode* node = getPreviousSibling(fCurrentNode);
if (node == 0) {
node = getParentNode(fCurrentNode);
if ( node != 0) {
fCurrentNode = node;
}
return node;
}
else {
// get the lastChild of result.
DOMNode* lastChild = getLastChild(node);
// if there is a lastChild which passes filters return it.
if (lastChild != 0) {
fCurrentNode = lastChild;
}
else {
fCurrentNode = node;
}
return fCurrentNode;
}
}
/** Return the next Node from the current node,
* after applying filter, whatToshow.
* If result is not null, set the current Node.
*/
DOMNode* DOMTreeWalkerImpl::nextNode () {
if (!fCurrentNode) return 0;
DOMNode* node = getFirstChild(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
return node;
}
else {
node = getNextSibling(fCurrentNode);
if (node != 0) {
fCurrentNode = node;
return node;
}
else {
// return parent's 1st sibling.
DOMNode* parent = getParentNode(fCurrentNode);
while ( parent != 0) {
node = getNextSibling(parent);
if (node != 0) {
fCurrentNode = node;
return node;
} else {
parent = getParentNode(parent);
}
}
return node;
}
}
}
/** Internal function.
* Return the parent Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
DOMNode* DOMTreeWalkerImpl::getParentNode (DOMNode* node) {
if (!node || node == fRoot) return 0;
DOMNode* newNode = node->getParentNode();
if (!newNode) return 0;
short accept = acceptNode(newNode);
if (accept == DOMNodeFilter::FILTER_ACCEPT)
return newNode;
return getParentNode(newNode);
}
/** Internal function.
* Return the nextSibling Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
DOMNode* DOMTreeWalkerImpl::getNextSibling (DOMNode* node) {
if (!node || node == fRoot) return 0;
DOMNode* newNode = node->getNextSibling();
if (!newNode) {
newNode = node->getParentNode();
if (!newNode || node == fRoot) return 0;
short parentAccept = acceptNode(newNode);
if (parentAccept == DOMNodeFilter::FILTER_SKIP) {
return getNextSibling(newNode);
}
return 0;
}
short accept = acceptNode(newNode);
if (accept == DOMNodeFilter::FILTER_ACCEPT)
return newNode;
else
if (accept == DOMNodeFilter::FILTER_SKIP) {
DOMNode* fChild = getFirstChild(newNode);
if (!fChild && !newNode->hasChildNodes()) {
return getNextSibling(newNode);
}
return fChild;
}
return getNextSibling(newNode);
}
/** Internal function.
* Return the previous sibling Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
DOMNode* DOMTreeWalkerImpl::getPreviousSibling (DOMNode* node) {
if (!node || node == fRoot) return 0;
DOMNode* newNode = node->getPreviousSibling();
if (!newNode) {
newNode = node->getParentNode();
if (!newNode || node == fRoot) return 0;
short parentAccept = acceptNode(newNode);
if (parentAccept == DOMNodeFilter::FILTER_SKIP) {
return getPreviousSibling(newNode);
}
return 0;
}
short accept = acceptNode(newNode);
if (accept == DOMNodeFilter::FILTER_ACCEPT)
return newNode;
else
if (accept == DOMNodeFilter::FILTER_SKIP) {
DOMNode* fChild = getLastChild(newNode);
if (!fChild && !newNode->hasChildNodes()) {
return getPreviousSibling(newNode);
}
return fChild;
}
return getPreviousSibling(newNode);
}
/** Internal function.
* Return the first child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
DOMNode* DOMTreeWalkerImpl::getFirstChild (DOMNode* node) {
if (!node) return 0;
if(!fExpandEntityReferences && node->getNodeType()==DOMNode::ENTITY_REFERENCE_NODE)
return 0;
DOMNode* newNode = node->getFirstChild();
if (!newNode) return 0;
short accept = acceptNode(newNode);
if (accept == DOMNodeFilter::FILTER_ACCEPT)
return newNode;
else
if (accept == DOMNodeFilter::FILTER_SKIP
&& newNode->hasChildNodes())
{
return getFirstChild(newNode);
}
return getNextSibling(newNode);
}
/** Internal function.
* Return the last child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
DOMNode* DOMTreeWalkerImpl::getLastChild (DOMNode* node) {
if (!node) return 0;
if(!fExpandEntityReferences && node->getNodeType()==DOMNode::ENTITY_REFERENCE_NODE)
return 0;
DOMNode* newNode = node->getLastChild();
if (!newNode) return 0;
short accept = acceptNode(newNode);
if (accept == DOMNodeFilter::FILTER_ACCEPT)
return newNode;
else
if (accept == DOMNodeFilter::FILTER_SKIP
&& newNode->hasChildNodes())
{
return getLastChild(newNode);
}
return getPreviousSibling(newNode);
}
/** The node is accepted if it passes the whatToShow and the filter. */
short DOMTreeWalkerImpl::acceptNode (DOMNode* node) {
if (fNodeFilter == 0) {
if ( ( fWhatToShow & (1 << (node->getNodeType() - 1))) != 0)
{
return DOMNodeFilter::FILTER_ACCEPT;
}
else
{
return DOMNodeFilter::FILTER_SKIP;
}
} else {
// REVISIT: This logic is unclear from the spec!
if ((fWhatToShow & (1 << (node->getNodeType() - 1))) != 0 ) {
return fNodeFilter->acceptNode(node);
} else {
// what to show has failed!
if (fNodeFilter->acceptNode(node) == DOMNodeFilter::FILTER_REJECT) {
return DOMNodeFilter::FILTER_REJECT;
} else {
return DOMNodeFilter::FILTER_SKIP;
}
}
}
}
void DOMTreeWalkerImpl::release()
{
// for performance reason, do not recycle pointer
// chance that this is allocated again and again is not usual
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,168 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMTreeWalkerImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMTREEWALKERIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMTREEWALKERIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include <xercesc/dom/DOMTreeWalker.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMTreeWalkerImpl : public DOMTreeWalker {
protected:
// The whatToShow mask.
DOMNodeFilter::ShowType fWhatToShow;
// The NodeFilter reference.
DOMNodeFilter* fNodeFilter;
// The current Node.
DOMNode* fCurrentNode;
// The root Node.
DOMNode* fRoot;
// The expandEntity reference flag.
bool fExpandEntityReferences;
public:
// Implementation Note: No state is kept except the data above
// (fWhatToShow, fNodeFilter, fCurrentNode, fRoot) such that
// setters could be created for these data values and the
// implementation will still work.
/** Public constructor */
DOMTreeWalkerImpl (
DOMNode* root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* nodeFilter,
bool expandEntityRef);
DOMTreeWalkerImpl (const DOMTreeWalkerImpl& twi);
DOMTreeWalkerImpl& operator= (const DOMTreeWalkerImpl& twi);
// Return the root node.
virtual DOMNode* getRoot ();
// Return the whatToShow value.
virtual DOMNodeFilter::ShowType getWhatToShow ();
// Return the NodeFilter.
virtual DOMNodeFilter* getFilter ();
// Return the current DOMNode.
virtual DOMNode* getCurrentNode ();
// Return the current Node.
virtual void setCurrentNode (DOMNode* node);
// Return the parent Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* parentNode ();
// Return the first child Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* firstChild ();
// Return the last child Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* lastChild ();
// Return the previous sibling Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* previousSibling ();
// Return the next sibling Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* nextSibling ();
// Return the previous Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* previousNode ();
// Return the next Node from the current node,
// after applying filter, whatToshow.
// If result is not null, set the current Node.
virtual DOMNode* nextNode ();
// Get the expandEntity reference flag.
virtual bool getExpandEntityReferences();
// release the resource
virtual void release();
protected:
// Internal function.
// Return the parent Node, from the input node
// after applying filter, whatToshow.
// The current node is not consulted or set.
DOMNode* getParentNode (DOMNode* node);
// Internal function.
// Return the nextSibling Node, from the input node
// after applying filter, whatToshow.
// The current node is not consulted or set.
DOMNode* getNextSibling (DOMNode* node);
// Internal function.
// Return the previous sibling Node, from the input node
// after applying filter, whatToshow.
// The current node is not consulted or set.
DOMNode* getPreviousSibling (DOMNode* node);
// Internal function.
// Return the first child Node, from the input node
// after applying filter, whatToshow.
// The current node is not consulted or set.
DOMNode* getFirstChild (DOMNode* node);
// Internal function.
// Return the last child Node, from the input node
// after applying filter, whatToshow.
// The current node is not consulted or set.
DOMNode* getLastChild (DOMNode* node);
// The node is accepted if it passes the whatToShow and the filter.
short acceptNode (DOMNode* node);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,186 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DOMTypeInfoImpl.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/framework/psvi/PSVIItem.hpp>
#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedElement;
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdNotValidatedAttribute;
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedCDATAAttribute(XMLUni::fgInfosetURIName, XMLUni::fgCDATAString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefsString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITYAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntityString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITIESAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntitiesString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokenString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokensString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNOTATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNotationString);
/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENUMERATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEnumerationString);
DOMTypeInfoImpl::DOMTypeInfoImpl(const XMLCh* namespaceUri/*=0*/, const XMLCh* name/*=0*/)
: fBitFields(0),
fTypeName(name),
fTypeNamespace(namespaceUri),
fMemberTypeName(0),
fMemberTypeNamespace(0),
fDefaultValue(0),
fNormalizedValue(0)
{
// by setting the fBitField to 0 we are also setting:
// - [validity]=VALIDITY_NOTKNOWN
// - [validitation attempted]=VALIDATION_NONE
// - [schema specified]=false
}
DOMTypeInfoImpl::DOMTypeInfoImpl(DOMDocumentImpl* ownerDoc, const DOMPSVITypeInfo* sourcePSVI)
: fBitFields(0),
fTypeName(0),
fTypeNamespace(0),
fMemberTypeName(0),
fMemberTypeNamespace(0),
fDefaultValue(0),
fNormalizedValue(0)
{
setNumericProperty(DOMPSVITypeInfo::PSVI_Validity,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validity));
setNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted));
setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type));
setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous));
setNumericProperty(DOMPSVITypeInfo::PSVI_Nil,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Nil));
setNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous));
setNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified,
sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified));
setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name)));
setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace)));
setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name)));
setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace)));
setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default)));
setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value,
ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value)));
}
const XMLCh* DOMTypeInfoImpl::getTypeName() const {
// if it's a DTD, return the data that was stored
if(!getNumericProperty(PSVI_Schema_Specified))
return fTypeName;
// if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
if(!getNumericProperty(PSVI_Validity))
return fTypeName;
if(fMemberTypeName)
return fMemberTypeName;
return fTypeName;
}
const XMLCh* DOMTypeInfoImpl::getTypeNamespace() const {
// if it's a DTD, return the data that was stored
if(!getNumericProperty(PSVI_Schema_Specified))
return fTypeNamespace;
// if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
if(!getNumericProperty(PSVI_Validity))
return fTypeNamespace;
if(fMemberTypeName) // we check on the name, as the URI can be NULL
return fMemberTypeNamespace;
return fTypeNamespace;
}
bool DOMTypeInfoImpl::isDerivedFrom(const XMLCh* typeNamespaceArg, const XMLCh* typeNameArg, DerivationMethods) const
{
// if it's a DTD, return false
if(!getNumericProperty(PSVI_Schema_Specified))
return false;
if(XMLString::equals(typeNamespaceArg, getTypeNamespace()) && XMLString::equals(typeNameArg, getTypeName()))
return true;
// TODO: need a pointer to the Grammar object
return false;
}
const XMLCh* DOMTypeInfoImpl::getStringProperty(PSVIProperty prop) const {
switch(prop)
{
case PSVI_Type_Definition_Name: return fTypeName;
case PSVI_Type_Definition_Namespace: return fTypeNamespace;
case PSVI_Member_Type_Definition_Name: return fMemberTypeName;
case PSVI_Member_Type_Definition_Namespace: return fMemberTypeNamespace;
case PSVI_Schema_Default: return fDefaultValue;
case PSVI_Schema_Normalized_Value: return fNormalizedValue;
default: assert(false); /* it's not a string property */
}
return 0;
}
int DOMTypeInfoImpl::getNumericProperty(PSVIProperty prop) const {
switch(prop)
{
case PSVI_Validity: return (PSVIItem::VALIDITY_STATE)(fBitFields & 0x0003);
case PSVI_Validation_Attempted: return (PSVIItem::ASSESSMENT_TYPE)((fBitFields >> 2) & 0x0003);
case PSVI_Type_Definition_Type: return (fBitFields & (1 << 5))?XSTypeDefinition::COMPLEX_TYPE:XSTypeDefinition::SIMPLE_TYPE;
case PSVI_Type_Definition_Anonymous: return (fBitFields & (1 << 6))?true:false;
case PSVI_Nil: return (fBitFields & (1 << 7))?true:false;
case PSVI_Member_Type_Definition_Anonymous: return (fBitFields & (1 << 8))?true:false;
case PSVI_Schema_Specified: return (fBitFields & (1 << 9))?true:false;
default: assert(false); /* it's not a numeric property */
}
return 0;
}
void DOMTypeInfoImpl::setStringProperty(PSVIProperty prop, const XMLCh* value) {
switch(prop)
{
case PSVI_Type_Definition_Name: fTypeName=value; break;
case PSVI_Type_Definition_Namespace: fTypeNamespace=value; break;
case PSVI_Member_Type_Definition_Name: fMemberTypeName=value; break;
case PSVI_Member_Type_Definition_Namespace: fMemberTypeNamespace=value; break;
case PSVI_Schema_Default: fDefaultValue=value; break;
case PSVI_Schema_Normalized_Value: fNormalizedValue=value; break;
default: assert(false); /* it's not a string property */
}
}
void DOMTypeInfoImpl::setNumericProperty(PSVIProperty prop, int value) {
switch(prop)
{
case PSVI_Validity: fBitFields |= (value & 0x0003); break;
case PSVI_Validation_Attempted: fBitFields |= ((value & 0x0003) << 2); break;
case PSVI_Type_Definition_Type: fBitFields |= (value==XSTypeDefinition::COMPLEX_TYPE)?(1 << 5):0; break;
case PSVI_Type_Definition_Anonymous: fBitFields |= (value!=0)?(1 << 6):0; break;
case PSVI_Nil: fBitFields |= (value!=0)?(1 << 7):0; break;
case PSVI_Member_Type_Definition_Anonymous: fBitFields |= (value!=0)?(1 << 8):0; break;
case PSVI_Schema_Specified: fBitFields |= (value!=0)?(1 << 9):0; break;
default: assert(false); /* it's not a numeric property */
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file DOMTypeInfo.cpp
*/
@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// This file is part of the internal implementation of the C++ XML DOM.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#if !defined(XERCESC_INCLUDE_GUARD_DOMTYPEINFOIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMTYPEINFOIMPL_HPP
//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#include <xercesc/dom/DOMTypeInfo.hpp>
#include <xercesc/dom/DOMPSVITypeInfo.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMDocumentImpl;
class CDOM_EXPORT DOMTypeInfoImpl : public DOMTypeInfo, public DOMPSVITypeInfo
{
public:
//-----------------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------------
DOMTypeInfoImpl(const XMLCh* namespaceUri=0, const XMLCh* name=0);
DOMTypeInfoImpl(DOMDocumentImpl* ownerDoc, const DOMPSVITypeInfo* sourcePSVI);
static DOMTypeInfoImpl g_DtdValidatedElement;
static DOMTypeInfoImpl g_DtdNotValidatedAttribute;
static DOMTypeInfoImpl g_DtdValidatedCDATAAttribute;
static DOMTypeInfoImpl g_DtdValidatedIDAttribute;
static DOMTypeInfoImpl g_DtdValidatedIDREFAttribute;
static DOMTypeInfoImpl g_DtdValidatedIDREFSAttribute;
static DOMTypeInfoImpl g_DtdValidatedENTITYAttribute;
static DOMTypeInfoImpl g_DtdValidatedENTITIESAttribute;
static DOMTypeInfoImpl g_DtdValidatedNMTOKENAttribute;
static DOMTypeInfoImpl g_DtdValidatedNMTOKENSAttribute;
static DOMTypeInfoImpl g_DtdValidatedNOTATIONAttribute;
static DOMTypeInfoImpl g_DtdValidatedENUMERATIONAttribute;
// -----------------------------------------------------------------------
// DOMTypeInfo interface
// -----------------------------------------------------------------------
virtual const XMLCh* getTypeName() const;
virtual const XMLCh* getTypeNamespace() const;
virtual bool isDerivedFrom(const XMLCh* typeNamespaceArg, const XMLCh* typeNameArg, DerivationMethods derivationMethod) const;
// -----------------------------------------------------------------------
// DOMPSVITypeInfo interface
// -----------------------------------------------------------------------
virtual const XMLCh* getStringProperty(PSVIProperty prop) const;
virtual int getNumericProperty(PSVIProperty prop) const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
virtual void setStringProperty(PSVIProperty prop, const XMLCh* value);
virtual void setNumericProperty(PSVIProperty prop, int value);
protected:
int fBitFields;
const XMLCh* fTypeName;
const XMLCh* fTypeNamespace;
const XMLCh* fMemberTypeName;
const XMLCh* fMemberTypeNamespace;
const XMLCh* fDefaultValue;
const XMLCh* fNormalizedValue;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMTypeInfoImpl (const DOMTypeInfoImpl&);
DOMTypeInfoImpl & operator = (const DOMTypeInfoImpl &);
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file DOMTypeInfo.hpp
*/
@@ -0,0 +1,216 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DOMXPathExpressionImpl.hpp"
#include "DOMXPathResultImpl.hpp"
#include <xercesc/validators/schema/identity/XercesXPath.hpp>
#include <xercesc/validators/schema/identity/XPathMatcher.hpp>
#include <xercesc/validators/schema/identity/XPathException.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/util/StringPool.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/dom/DOMXPathException.hpp>
#include <xercesc/dom/DOM.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class WrapperForXPathNSResolver : public XercesNamespaceResolver
{
public:
WrapperForXPathNSResolver(XMLStringPool* pool, const DOMXPathNSResolver *resolver, MemoryManager* const manager) :
fStringPool(pool),
fResolver(resolver),
fMemoryManager(manager)
{
}
virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefix) const
{
if(fResolver==NULL)
throw DOMException(DOMException::NAMESPACE_ERR, 0, fMemoryManager);
const XMLCh* nsUri=fResolver->lookupNamespaceURI(prefix);
if(nsUri==NULL)
throw DOMException(DOMException::NAMESPACE_ERR, 0, fMemoryManager);
return fStringPool->addOrFind(nsUri);
}
protected:
XMLStringPool* fStringPool;
const DOMXPathNSResolver * fResolver;
MemoryManager* const fMemoryManager;
};
typedef JanitorMemFunCall<DOMXPathExpressionImpl> CleanupType;
DOMXPathExpressionImpl::DOMXPathExpressionImpl(const XMLCh *expression, const DOMXPathNSResolver *resolver, MemoryManager* const manager) :
fStringPool(NULL),
fParsedExpression(NULL),
fExpression(NULL),
fMoveToRoot(false),
fMemoryManager(manager)
{
if(expression==NULL || *expression==0)
throw DOMXPathException(DOMXPathException::INVALID_EXPRESSION_ERR, 0, fMemoryManager);
CleanupType cleanup(this, &DOMXPathExpressionImpl::cleanUp);
fStringPool = new (fMemoryManager) XMLStringPool(109, fMemoryManager);
// XercesPath will complain if the expression starts with '/', add a "." in front of it and start from the document root
if(*expression==chForwardSlash)
{
fExpression=(XMLCh*)fMemoryManager->allocate((XMLString::stringLen(expression)+2)*sizeof(XMLCh));
*fExpression = chPeriod;
*(fExpression+1) = chNull;
XMLString::catString(fExpression, expression);
fMoveToRoot=true;
}
else
fExpression=XMLString::replicate(expression);
try
{
WrapperForXPathNSResolver wrappedResolver(fStringPool, resolver, fMemoryManager);
fParsedExpression = new (fMemoryManager) XercesXPath(fExpression, fStringPool, &wrappedResolver, 0, true, fMemoryManager);
}
catch(const XPathException& )
{
throw DOMXPathException(DOMXPathException::INVALID_EXPRESSION_ERR, 0, fMemoryManager);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
DOMXPathExpressionImpl::~DOMXPathExpressionImpl()
{
cleanUp();
}
void DOMXPathExpressionImpl::cleanUp()
{
XMLString::release(&fExpression, fMemoryManager);
delete fParsedExpression;
delete fStringPool;
}
DOMXPathResult* DOMXPathExpressionImpl::evaluate(const DOMNode *contextNode,
DOMXPathResult::ResultType type,
DOMXPathResult* result) const
{
if(type!=DOMXPathResult::FIRST_ORDERED_NODE_TYPE && type!=DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE &&
type!=DOMXPathResult::ANY_UNORDERED_NODE_TYPE && type!=DOMXPathResult::UNORDERED_NODE_SNAPSHOT_TYPE)
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
if(contextNode==NULL || contextNode->getNodeType()!=DOMNode::ELEMENT_NODE)
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
JanitorMemFunCall<DOMXPathResultImpl> r_cleanup (
0, &DOMXPathResultImpl::release);
DOMXPathResultImpl* r=(DOMXPathResultImpl*)result;
if(r==NULL)
{
r=new (fMemoryManager) DOMXPathResultImpl(type, fMemoryManager);
r_cleanup.reset (r);
}
else
r->reset(type);
XPathMatcher matcher(fParsedExpression, fMemoryManager);
matcher.startDocumentFragment();
if(fMoveToRoot)
{
contextNode=contextNode->getOwnerDocument();
if(contextNode==NULL)
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
QName qName(contextNode->getNodeName(), 0, fMemoryManager);
SchemaElementDecl elemDecl(&qName);
RefVectorOf<XMLAttr> attrList(0, true, fMemoryManager);
matcher.startElement(elemDecl, 0, XMLUni::fgZeroLenString, attrList, 0);
DOMNode* child=contextNode->getFirstChild();
while(child)
{
if(child->getNodeType()==DOMNode::ELEMENT_NODE)
testNode(&matcher, r, (DOMElement*)child);
child=child->getNextSibling();
}
matcher.endElement(elemDecl, XMLUni::fgZeroLenString);
}
else
testNode(&matcher, r, (DOMElement*)contextNode);
r_cleanup.release ();
return r;
}
bool DOMXPathExpressionImpl::testNode(XPathMatcher* matcher, DOMXPathResultImpl* result, DOMElement *node) const
{
int uriId=fStringPool->addOrFind(node->getNamespaceURI());
QName qName(node->getNodeName(), uriId, fMemoryManager);
SchemaElementDecl elemDecl(&qName);
DOMNamedNodeMap* attrMap=node->getAttributes();
XMLSize_t attrCount = attrMap->getLength();
RefVectorOf<XMLAttr> attrList(attrCount, true, fMemoryManager);
for(XMLSize_t i=0;i<attrCount;i++)
{
DOMAttr* attr=(DOMAttr*)attrMap->item(i);
attrList.addElement(new (fMemoryManager) XMLAttr(fStringPool->addOrFind(attr->getNamespaceURI()),
attr->getNodeName(),
attr->getNodeValue(),
XMLAttDef::CData,
attr->getSpecified(),
fMemoryManager,
NULL,
true));
}
matcher->startElement(elemDecl, uriId, node->getPrefix(), attrList, attrCount);
unsigned char nMatch=matcher->isMatched();
if(nMatch!=0 && nMatch!=XPathMatcher::XP_MATCHED_DP)
{
result->addResult(node);
if(result->getResultType()==DOMXPathResult::ANY_UNORDERED_NODE_TYPE || result->getResultType()==DOMXPathResult::FIRST_ORDERED_NODE_TYPE)
return true; // abort navigation, we found one result
}
if(nMatch==0 || nMatch==XPathMatcher::XP_MATCHED_D || nMatch==XPathMatcher::XP_MATCHED_DP)
{
DOMNode* child=node->getFirstChild();
while(child)
{
if(child->getNodeType()==DOMNode::ELEMENT_NODE)
if(testNode(matcher, result, (DOMElement*)child))
return true;
child=child->getNextSibling();
}
}
matcher->endElement(elemDecl, XMLUni::fgZeroLenString);
return false;
}
void DOMXPathExpressionImpl::release()
{
DOMXPathExpressionImpl* me = this;
delete me;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMXPathExpressionImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMXPATHEXPRESSIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMXPATHEXPRESSIONIMPL_HPP
#include <xercesc/util/XMemory.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOMXPathExpression.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMElement;
class XercesXPath;
class XPathMatcher;
class DOMXPathResultImpl;
class DOMXPathNSResolver;
class XMLStringPool;
class CDOM_EXPORT DOMXPathExpressionImpl : public XMemory,
public DOMXPathExpression
{
public:
DOMXPathExpressionImpl(const XMLCh *expression,
const DOMXPathNSResolver *resolver,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual ~DOMXPathExpressionImpl();
virtual DOMXPathResult* evaluate(const DOMNode *contextNode,
DOMXPathResult::ResultType type,
DOMXPathResult* result) const;
virtual void release();
protected:
bool testNode(XPathMatcher* matcher,
DOMXPathResultImpl* result,
DOMElement *node) const;
void cleanUp();
XMLStringPool* fStringPool;
XercesXPath* fParsedExpression;
XMLCh* fExpression;
bool fMoveToRoot;
MemoryManager* const fMemoryManager;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DOMXPathNSResolverImpl.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMXPathNSResolverImpl::DOMXPathNSResolverImpl(const DOMNode *nodeResolver, MemoryManager* const manager) :
fNamespaceBindings(0),
fResolverNode(nodeResolver),
fManager(manager)
{
fNamespaceBindings = new (fManager) RefHashTableOf<KVStringPair>(7, true, fManager);
}
DOMXPathNSResolverImpl::~DOMXPathNSResolverImpl()
{
delete fNamespaceBindings;
}
const XMLCh* DOMXPathNSResolverImpl::lookupNamespaceURI(const XMLCh* prefix) const
{
if(prefix == 0) prefix = XMLUni::fgZeroLenString;
if(XMLString::equals(prefix, XMLUni::fgXMLString))
return XMLUni::fgXMLURIName;
const KVStringPair *pair = fNamespaceBindings->get((void*)prefix);
if(pair) {
// An empty namespace URI indicated that this binding was removed
// by the user.
//
if(*pair->getValue() == 0) return NULL;
return pair->getValue();
}
if(fResolverNode)
return fResolverNode->lookupNamespaceURI(
*prefix == 0 ? 0 : prefix); // Expects 0 for default namespace.
return NULL;
}
const XMLCh* DOMXPathNSResolverImpl::lookupPrefix(const XMLCh* uri) const
{
if (uri == 0 || *uri == 0)
return 0;
if(XMLString::equals(uri, XMLUni::fgXMLURIName))
return XMLUni::fgXMLString;
RefHashTableOfEnumerator<KVStringPair> enumerator((RefHashTableOf<KVStringPair>*)fNamespaceBindings);
while(enumerator.hasMoreElements()) {
KVStringPair &pair = enumerator.nextElement();
if(XMLString::equals(pair.getValue(), uri)) {
return pair.getKey();
}
}
if(fResolverNode)
{
const XMLCh* r = fResolverNode->lookupPrefix(uri);
if (r == 0 && fResolverNode->isDefaultNamespace(uri))
r = XMLUni::fgZeroLenString;
return r;
}
return 0;
}
void DOMXPathNSResolverImpl::addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri)
{
if(prefix == 0) prefix = XMLUni::fgZeroLenString;
if(uri == 0) uri = XMLUni::fgZeroLenString;
KVStringPair* pair = new (fManager) KVStringPair(prefix, uri, fManager);
fNamespaceBindings->put((void*)pair->getKey(), pair);
}
void DOMXPathNSResolverImpl::release()
{
DOMXPathNSResolverImpl* me=(DOMXPathNSResolverImpl*)this;
delete me;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMXPathNSResolverImpl.hpp 657774 2008-05-19 09:59:33Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMXPATHNSRESOLVERIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMXPATHNSRESOLVERIMPL_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMemory.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOMXPathNSResolver.hpp>
#include <xercesc/util/KVStringPair.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class CDOM_EXPORT DOMXPathNSResolverImpl : public XMemory,
public DOMXPathNSResolver
{
public:
DOMXPathNSResolverImpl(const DOMNode* nodeResolver = 0, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMXPathNSResolverImpl();
virtual const XMLCh* lookupNamespaceURI(const XMLCh* prefix) const;
virtual const XMLCh* lookupPrefix(const XMLCh* URI) const;
virtual void addNamespaceBinding(const XMLCh* prefix, const XMLCh* uri);
virtual void release();
protected:
RefHashTableOf<KVStringPair>* fNamespaceBindings;
const DOMNode* fResolverNode;
MemoryManager* fManager;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,138 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DOMXPathResultImpl.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMXPathException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
DOMXPathResultImpl::DOMXPathResultImpl(ResultType type,
MemoryManager* const manager)
: fType(type),
fMemoryManager(manager),
fIndex (0)
{
fSnapshot = new (fMemoryManager) RefVectorOf<DOMNode>(13, false, fMemoryManager);
}
DOMXPathResultImpl::~DOMXPathResultImpl()
{
delete fSnapshot;
}
//
//
DOMXPathResult::ResultType DOMXPathResultImpl::getResultType() const
{
return fType;
}
const DOMTypeInfo* DOMXPathResultImpl::getTypeInfo() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
bool DOMXPathResultImpl::isNode() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
bool DOMXPathResultImpl::getBooleanValue() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
int DOMXPathResultImpl::getIntegerValue() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
double DOMXPathResultImpl::getNumberValue() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
const XMLCh* DOMXPathResultImpl::getStringValue() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
DOMNode* DOMXPathResultImpl::getNodeValue() const
{
if(fType == ANY_UNORDERED_NODE_TYPE || fType == FIRST_ORDERED_NODE_TYPE)
{
return fSnapshot->size() > 0 ? fSnapshot->elementAt(0) : 0;
}
else if (fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
{
return fIndex < fSnapshot->size() ? fSnapshot->elementAt(fIndex) : 0;
}
else
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
bool DOMXPathResultImpl::iterateNext()
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
bool DOMXPathResultImpl::getInvalidIteratorState() const
{
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
bool DOMXPathResultImpl::snapshotItem(XMLSize_t index)
{
if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
{
fIndex = index;
return fIndex < fSnapshot->size();
}
else
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
XMLSize_t DOMXPathResultImpl::getSnapshotLength() const
{
if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
return fSnapshot->size();
else
throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
void DOMXPathResultImpl::release()
{
DOMXPathResultImpl* me = this;
delete me;
}
//
//
void DOMXPathResultImpl::reset(ResultType type)
{
fType = type;
fSnapshot->removeAllElements();
fIndex = 0;
}
void DOMXPathResultImpl::addResult(DOMNode* node)
{
fSnapshot->addElement(node);
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMXPathResultImpl.hpp 671894 2008-06-26 13:29:21Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMXPATHRESULTIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMXPATHRESULTIMPL_HPP
#include <xercesc/util/XMemory.hpp>
#include <xercesc/dom/DOMXPathResult.hpp>
#include <xercesc/util/RefVectorOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMXPathResultImpl : public XMemory,
public DOMXPathResult
{
public:
DOMXPathResultImpl(ResultType type, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~DOMXPathResultImpl();
virtual ResultType getResultType() const;
virtual const DOMTypeInfo *getTypeInfo() const;
virtual bool isNode() const;
virtual bool getBooleanValue() const;
virtual int getIntegerValue() const;
virtual double getNumberValue() const;
virtual const XMLCh* getStringValue() const;
virtual DOMNode* getNodeValue() const;
virtual bool iterateNext();
virtual bool getInvalidIteratorState() const;
virtual bool snapshotItem(XMLSize_t);
virtual XMLSize_t getSnapshotLength() const;
virtual void release();
public:
void reset(ResultType type);
void addResult(DOMNode* node);
protected:
ResultType fType;
MemoryManager* const fMemoryManager;
RefVectorOf<DOMNode>* fSnapshot;
XMLSize_t fIndex;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDElementNSImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
*/
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOMException.hpp>
#include "DOMDocumentImpl.hpp"
#include "XSDElementNSImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
XSDElementNSImpl::XSDElementNSImpl(DOMDocument *ownerDoc, const XMLCh *nam) :
DOMElementNSImpl(ownerDoc, nam)
, fLineNo(0)
, fColumnNo(0)
{
}
//Introduced in DOM Level 2
XSDElementNSImpl::XSDElementNSImpl(DOMDocument *ownerDoc,
const XMLCh *namespaceURI,
const XMLCh *qualifiedName,
const XMLFileLoc lineNo,
const XMLFileLoc columnNo) :
DOMElementNSImpl(ownerDoc, namespaceURI, qualifiedName)
, fLineNo(lineNo)
, fColumnNo(columnNo)
{
}
XSDElementNSImpl::XSDElementNSImpl(const XSDElementNSImpl &other, bool deep) :
DOMElementNSImpl(other, deep)
{
this->fLineNo = other.fLineNo;
this->fColumnNo =other.fColumnNo;
}
DOMNode * XSDElementNSImpl::cloneNode(bool deep) const {
DOMNode* newNode = new (fParent.fOwnerDocument) XSDElementNSImpl(*this, deep);
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
return newNode;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDElementNSImpl.hpp 672232 2008-06-27 10:16:38Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XSDELEMENTNSIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_XSDELEMENTNSIMPL_HPP
//
// This file is part of the internal implementation of the C++ XML DOM.
// It is used by TraverseSchema to store line/column information.
// It should NOT be included or used directly by application programs.
//
// Applications should include the file <xercesc/dom/DOM.hpp> for the entire
// DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
// name is substituded for the *.
//
#include "DOMElementNSImpl.hpp"
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT XSDElementNSImpl: public DOMElementNSImpl {
protected:
XMLFileLoc fLineNo; //Line number
XMLFileLoc fColumnNo; //Column number
public:
XSDElementNSImpl(DOMDocument *ownerDoc, const XMLCh *name);
XSDElementNSImpl(DOMDocument *ownerDoc, //DOM Level 2
const XMLCh *namespaceURI,
const XMLCh *qualifiedName,
const XMLFileLoc lineNo,
const XMLFileLoc columnNo);
XSDElementNSImpl(const XSDElementNSImpl &other, bool deep=false);
virtual DOMNode * cloneNode(bool deep) const;
XMLFileLoc getLineNo() const { return fLineNo; }
XMLFileLoc getColumnNo() const { return fColumnNo; }
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XSDElementNSImpl& operator=(const XSDElementNSImpl&);
};
XERCES_CPP_NAMESPACE_END
#endif