initial import

This commit is contained in:
Guenter Obiltschnig
2006-07-11 16:33:40 +00:00
commit f476bd6b32
1463 changed files with 242402 additions and 0 deletions

View File

@@ -0,0 +1,324 @@
//
// AbstractContainerNode.cpp
//
// $Id: //poco/1.1.0/XML/src/AbstractContainerNode.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/AbstractContainerNode.h"
#include "DOM/Document.h"
#include "DOM/DOMException.h"
XML_BEGIN
AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument):
AbstractNode(pOwnerDocument),
_pFirstChild(0)
{
}
AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument, const AbstractContainerNode& node):
AbstractNode(pOwnerDocument, node),
_pFirstChild(0)
{
}
AbstractContainerNode::~AbstractContainerNode()
{
AbstractNode* pChild = static_cast<AbstractNode*>(_pFirstChild);
while (pChild)
{
AbstractNode* pDelNode = pChild;
pChild = pChild->_pNext;
pDelNode->_pNext = 0;
pDelNode->_pParent = 0;
pDelNode->release();
}
}
Node* AbstractContainerNode::firstChild() const
{
return _pFirstChild;
}
Node* AbstractContainerNode::lastChild() const
{
AbstractNode* pChild = _pFirstChild;
if (pChild)
{
while (pChild->_pNext) pChild = pChild->_pNext;
return pChild;
}
return 0;
}
Node* AbstractContainerNode::insertBefore(Node* newChild, Node* refChild)
{
poco_check_ptr (newChild);
if (static_cast<AbstractNode*>(newChild)->_pOwner != _pOwner && static_cast<AbstractNode*>(newChild)->_pOwner != this)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
if (refChild && static_cast<AbstractNode*>(refChild)->_pParent != this)
throw DOMException(DOMException::NOT_FOUND_ERR);
if (newChild == refChild)
return newChild;
if (this == newChild)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
AbstractNode* pFirst = 0;
AbstractNode* pLast = 0;
if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)
{
AbstractContainerNode* pFrag = static_cast<AbstractContainerNode*>(newChild);
pFirst = pFrag->_pFirstChild;
pLast = pFirst;
if (pFirst)
{
while (pLast->_pNext)
{
pLast->_pParent = this;
pLast = pLast->_pNext;
}
pLast->_pParent = this;
}
pFrag->_pFirstChild = 0;
}
else
{
newChild->duplicate();
AbstractContainerNode* pParent = static_cast<AbstractNode*>(newChild)->_pParent;
if (pParent) pParent->removeChild(newChild);
pFirst = static_cast<AbstractNode*>(newChild);
pLast = pFirst;
pFirst->_pParent = this;
}
if (_pFirstChild && pFirst)
{
AbstractNode* pCur = _pFirstChild;
if (pCur == refChild)
{
pLast->_pNext = _pFirstChild;
_pFirstChild = pFirst;
}
else
{
while (pCur && pCur->_pNext != refChild) pCur = pCur->_pNext;
if (pCur)
{
pLast->_pNext = pCur->_pNext;
pCur->_pNext = pFirst;
}
else throw DOMException(DOMException::NOT_FOUND_ERR);
}
}
else _pFirstChild = pFirst;
if (events())
{
while (pFirst && pFirst != pLast->_pNext)
{
pFirst->dispatchNodeInserted();
pFirst->dispatchNodeInsertedIntoDocument();
pFirst = pFirst->_pNext;
}
dispatchSubtreeModified();
}
return newChild;
}
Node* AbstractContainerNode::replaceChild(Node* newChild, Node* oldChild)
{
poco_check_ptr (newChild);
poco_check_ptr (oldChild);
if (static_cast<AbstractNode*>(newChild)->_pOwner != _pOwner && static_cast<AbstractNode*>(newChild)->_pOwner != this)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
if (static_cast<AbstractNode*>(oldChild)->_pParent != this)
throw DOMException(DOMException::NOT_FOUND_ERR);
if (newChild == oldChild)
return newChild;
if (this == newChild)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
bool doEvents = events();
if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)
{
insertBefore(newChild, oldChild);
removeChild(oldChild);
}
else
{
AbstractContainerNode* pParent = static_cast<AbstractNode*>(newChild)->_pParent;
if (pParent) pParent->removeChild(newChild);
if (oldChild == _pFirstChild)
{
if (doEvents)
{
_pFirstChild->dispatchNodeRemoved();
_pFirstChild->dispatchNodeRemovedFromDocument();
}
static_cast<AbstractNode*>(newChild)->_pNext = static_cast<AbstractNode*>(oldChild)->_pNext;
static_cast<AbstractNode*>(newChild)->_pParent = this;
_pFirstChild->_pNext = 0;
_pFirstChild->_pParent = 0;
_pFirstChild = static_cast<AbstractNode*>(newChild);
if (doEvents)
{
static_cast<AbstractNode*>(newChild)->dispatchNodeInserted();
static_cast<AbstractNode*>(newChild)->dispatchNodeInsertedIntoDocument();
}
}
else
{
AbstractNode* pCur = _pFirstChild;
while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext;
if (pCur)
{
poco_assert_dbg (pCur->_pNext == oldChild);
if (doEvents)
{
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemoved();
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemovedFromDocument();
}
static_cast<AbstractNode*>(newChild)->_pNext = static_cast<AbstractNode*>(oldChild)->_pNext;
static_cast<AbstractNode*>(newChild)->_pParent = this;
static_cast<AbstractNode*>(oldChild)->_pNext = 0;
static_cast<AbstractNode*>(oldChild)->_pParent = 0;
pCur->_pNext = static_cast<AbstractNode*>(newChild);
if (doEvents)
{
static_cast<AbstractNode*>(newChild)->dispatchNodeInserted();
static_cast<AbstractNode*>(newChild)->dispatchNodeInsertedIntoDocument();
}
}
else throw DOMException(DOMException::NOT_FOUND_ERR);
}
newChild->duplicate();
oldChild->autoRelease();
}
if (doEvents) dispatchSubtreeModified();
return oldChild;
}
Node* AbstractContainerNode::removeChild(Node* oldChild)
{
poco_check_ptr (oldChild);
bool doEvents = events();
if (oldChild == _pFirstChild)
{
if (doEvents)
{
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemoved();
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemovedFromDocument();
}
_pFirstChild = _pFirstChild->_pNext;
static_cast<AbstractNode*>(oldChild)->_pNext = 0;
static_cast<AbstractNode*>(oldChild)->_pParent = 0;
}
else
{
AbstractNode* pCur = _pFirstChild;
while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext;
if (pCur)
{
if (doEvents)
{
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemoved();
static_cast<AbstractNode*>(oldChild)->dispatchNodeRemovedFromDocument();
}
pCur->_pNext = pCur->_pNext->_pNext;
static_cast<AbstractNode*>(oldChild)->_pNext = 0;
static_cast<AbstractNode*>(oldChild)->_pParent = 0;
}
else throw DOMException(DOMException::NOT_FOUND_ERR);
}
oldChild->autoRelease();
if (doEvents) dispatchSubtreeModified();
return oldChild;
}
Node* AbstractContainerNode::appendChild(Node* newChild)
{
return insertBefore(newChild, 0);
}
void AbstractContainerNode::dispatchNodeRemovedFromDocument()
{
AbstractNode::dispatchNodeRemovedFromDocument();
Node* pChild = firstChild();
while (pChild)
{
static_cast<AbstractNode*>(pChild)->dispatchNodeRemovedFromDocument();
pChild = pChild->nextSibling();
}
}
void AbstractContainerNode::dispatchNodeInsertedIntoDocument()
{
AbstractNode::dispatchNodeInsertedIntoDocument();
Node* pChild = firstChild();
while (pChild)
{
static_cast<AbstractNode*>(pChild)->dispatchNodeInsertedIntoDocument();
pChild = pChild->nextSibling();
}
}
bool AbstractContainerNode::hasChildNodes() const
{
return _pFirstChild != 0;
}
bool AbstractContainerNode::hasAttributes() const
{
return false;
}
XML_END

383
XML/src/AbstractNode.cpp Normal file
View File

@@ -0,0 +1,383 @@
//
// AbstractNode.cpp
//
// $Id: //poco/1.1.0/XML/src/AbstractNode.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/AbstractNode.h"
#include "DOM/Document.h"
#include "DOM/ChildNodesList.h"
#include "DOM/EventDispatcher.h"
#include "DOM/DOMException.h"
#include "DOM/EventException.h"
#include "DOM/DOMImplementation.h"
#include "DOM/Attr.h"
#include "XML/Name.h"
#include "DOM/AutoPtr.h"
XML_BEGIN
const XMLString AbstractNode::NODE_NAME = toXMLString("#node");
const XMLString AbstractNode::EMPTY_STRING;
AbstractNode::AbstractNode(Document* pOwnerDocument):
_pParent(0),
_pNext(0),
_pOwner(pOwnerDocument),
_pEventDispatcher(0)
{
}
AbstractNode::AbstractNode(Document* pOwnerDocument, const AbstractNode& node):
_pParent(0),
_pNext(0),
_pOwner(pOwnerDocument),
_pEventDispatcher(0)
{
}
AbstractNode::~AbstractNode()
{
delete _pEventDispatcher;
if (_pNext) _pNext->release();
}
void AbstractNode::autoRelease()
{
_pOwner->autoReleasePool().add(this);
}
const XMLString& AbstractNode::nodeName() const
{
return NODE_NAME;
}
const XMLString& AbstractNode::getNodeValue() const
{
return EMPTY_STRING;
}
void AbstractNode::setNodeValue(const XMLString& value)
{
throw DOMException(DOMException::NO_DATA_ALLOWED_ERR);
}
Node* AbstractNode::parentNode() const
{
return _pParent;
}
NodeList* AbstractNode::childNodes() const
{
return new ChildNodesList(this);
}
Node* AbstractNode::firstChild() const
{
return 0;
}
Node* AbstractNode::lastChild() const
{
return 0;
}
Node* AbstractNode::previousSibling() const
{
if (_pParent)
{
AbstractNode* pSibling = _pParent->_pFirstChild;
while (pSibling)
{
if (pSibling->_pNext == this) return pSibling;
pSibling = pSibling->_pNext;
}
}
return 0;
}
Node* AbstractNode::nextSibling() const
{
return _pNext;
}
NamedNodeMap* AbstractNode::attributes() const
{
return 0;
}
Document* AbstractNode::ownerDocument() const
{
return _pOwner;
}
Node* AbstractNode::insertBefore(Node* newChild, Node* refChild)
{
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
}
Node* AbstractNode::replaceChild(Node* newChild, Node* oldChild)
{
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
}
Node* AbstractNode::removeChild(Node* oldChild)
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
}
Node* AbstractNode::appendChild(Node* newChild)
{
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
}
bool AbstractNode::hasChildNodes() const
{
return false;
}
Node* AbstractNode::cloneNode(bool deep) const
{
return copyNode(deep, _pOwner);
}
void AbstractNode::normalize()
{
}
bool AbstractNode::isSupported(const XMLString& feature, const XMLString& version) const
{
return DOMImplementation::instance().hasFeature(feature, version);
}
const XMLString& AbstractNode::namespaceURI() const
{
return EMPTY_STRING;
}
XMLString AbstractNode::prefix() const
{
return EMPTY_STRING;
}
const XMLString& AbstractNode::localName() const
{
return EMPTY_STRING;
}
bool AbstractNode::hasAttributes() const
{
return false;
}
XMLString AbstractNode::innerText() const
{
XMLString result = nodeValue();
Node* pChild = firstChild();
while (pChild)
{
result.append(pChild->innerText());
pChild = pChild->nextSibling();
}
return result;
}
void AbstractNode::addEventListener(const XMLString& type, EventListener* listener, bool useCapture)
{
if (_pEventDispatcher)
_pEventDispatcher->removeEventListener(type, listener, useCapture);
else
_pEventDispatcher = new EventDispatcher;
_pEventDispatcher->addEventListener(type, listener, useCapture);
}
void AbstractNode::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture)
{
if (_pEventDispatcher)
_pEventDispatcher->removeEventListener(type, listener, useCapture);
}
bool AbstractNode::dispatchEvent(Event* evt)
{
if (eventsSuspended()) return true;
if (evt->type().empty()) throw EventException(EventException::UNSPECIFIED_EVENT_TYPE_ERR);
evt->setTarget(this);
evt->setCurrentPhase(Event::CAPTURING_PHASE);
if (_pParent) _pParent->captureEvent(evt);
if (_pEventDispatcher && !evt->isStopped())
{
evt->setCurrentPhase(Event::AT_TARGET);
evt->setCurrentTarget(this);
_pEventDispatcher->dispatchEvent(evt);
}
if (!evt->isStopped() && evt->bubbles() && _pParent)
{
evt->setCurrentPhase(Event::BUBBLING_PHASE);
_pParent->bubbleEvent(evt);
}
return evt->isCanceled();
}
void AbstractNode::captureEvent(Event* evt)
{
if (_pParent)
_pParent->captureEvent(evt);
if (_pEventDispatcher && !evt->isStopped())
{
evt->setCurrentTarget(this);
_pEventDispatcher->captureEvent(evt);
}
}
void AbstractNode::bubbleEvent(Event* evt)
{
evt->setCurrentTarget(this);
if (_pEventDispatcher)
{
_pEventDispatcher->bubbleEvent(evt);
}
if (_pParent && !evt->isStopped())
_pParent->bubbleEvent(evt);
}
void AbstractNode::dispatchSubtreeModified()
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMSubtreeModified, this, true, false, 0);
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchNodeInserted()
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInserted, this, true, false, parentNode());
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchNodeRemoved()
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemoved, this, true, false, parentNode());
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchNodeRemovedFromDocument()
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemovedFromDocument, this, false, false, 0);
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchNodeInsertedIntoDocument()
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInsertedIntoDocument, this, false, false, 0);
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue)
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMAttrModified, this, true, false, pAttr, prevValue, newValue, pAttr->name(), changeType);
dispatchEvent(pEvent.get());
}
void AbstractNode::dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue)
{
AutoPtr<MutationEvent> pEvent = new MutationEvent(_pOwner, MutationEvent::DOMCharacterDataModified, this, true, false, 0, prevValue, newValue, EMPTY_STRING, MutationEvent::MODIFICATION);
dispatchEvent(pEvent.get());
}
bool AbstractNode::events() const
{
return _pOwner->events();
}
bool AbstractNode::eventsSuspended() const
{
return _pOwner->eventsSuspended();
}
void AbstractNode::setOwnerDocument(Document* pOwnerDocument)
{
_pOwner = pOwnerDocument;
}
XML_END

148
XML/src/Attr.cpp Normal file
View File

@@ -0,0 +1,148 @@
//
// Attr.cpp
//
// $Id: //poco/1.1.0/XML/src/Attr.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Attr.h"
#include "DOM/Document.h"
#include "XML/NamePool.h"
XML_BEGIN
Attr::Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified):
AbstractNode(pOwnerDocument),
_name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)),
_value(value),
_specified(specified)
{
}
Attr::Attr(Document* pOwnerDocument, const Attr& attr):
AbstractNode(pOwnerDocument, attr),
_name(pOwnerDocument->namePool().insert(attr._name)),
_value(attr._value),
_specified(attr._specified)
{
}
Attr::~Attr()
{
}
void Attr::setValue(const XMLString& value)
{
XMLString oldValue = _value;
_value = value;
_specified = true;
if (_pParent && !_pOwner->eventsSuspended())
_pParent->dispatchAttrModified(this, MutationEvent::MODIFICATION, oldValue, value);
}
Node* Attr::parentNode() const
{
return 0;
}
Node* Attr::previousSibling() const
{
if (_pParent)
{
Attr* pSibling = static_cast<Element*>(_pParent)->_pFirstAttr;
while (pSibling)
{
if (pSibling->_pNext == const_cast<Attr*>(this)) return pSibling;
pSibling = static_cast<Attr*>(pSibling->_pNext);
}
return pSibling;
}
return 0;
}
const XMLString& Attr::nodeName() const
{
return _name.qname();
}
const XMLString& Attr::getNodeValue() const
{
return _value;
}
void Attr::setNodeValue(const XMLString& value)
{
setValue(value);
}
unsigned short Attr::nodeType() const
{
return ATTRIBUTE_NODE;
}
const XMLString& Attr::namespaceURI() const
{
return _name.namespaceURI();
}
XMLString Attr::prefix() const
{
return _name.prefix();
}
const XMLString& Attr::localName() const
{
return _name.localName();
}
Node* Attr::copyNode(bool deep, Document* pOwnerDocument) const
{
return new Attr(pOwnerDocument, *this);
}
XML_END

144
XML/src/AttrMap.cpp Normal file
View File

@@ -0,0 +1,144 @@
//
// AttrMap.cpp
//
// $Id: //poco/1.1.0/XML/src/AttrMap.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/AttrMap.h"
#include "DOM/Attr.h"
#include "DOM/Element.h"
#include "DOM/Document.h"
#include "DOM/DOMException.h"
XML_BEGIN
AttrMap::AttrMap(Element* pElement):
_pElement(pElement)
{
poco_check_ptr (pElement);
_pElement->duplicate();
}
AttrMap::~AttrMap()
{
_pElement->release();
}
Node* AttrMap::getNamedItem(const XMLString& name) const
{
return _pElement->getAttributeNode(name);
}
Node* AttrMap::setNamedItem(Node* arg)
{
poco_check_ptr (arg);
if (arg->nodeType() != Node::ATTRIBUTE_NODE)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
return _pElement->setAttributeNode(static_cast<Attr*>(arg));
}
Node* AttrMap::removeNamedItem(const XMLString& name)
{
Attr* pAttr = _pElement->getAttributeNode(name);
if (pAttr)
return _pElement->removeAttributeNode(pAttr);
else
return 0;
}
Node* AttrMap::item(unsigned long index) const
{
AbstractNode* pAttr = _pElement->_pFirstAttr;
while (index-- > 0 && pAttr) pAttr = static_cast<AbstractNode*>(pAttr->nextSibling());
return pAttr;
}
unsigned long AttrMap::length() const
{
unsigned long result = 0;
AbstractNode* pAttr = _pElement->_pFirstAttr;
while (pAttr)
{
pAttr = static_cast<AbstractNode*>(pAttr->nextSibling());
++result;
}
return result;
}
Node* AttrMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const
{
return _pElement->getAttributeNodeNS(namespaceURI, localName);
}
Node* AttrMap::setNamedItemNS(Node* arg)
{
poco_check_ptr (arg);
if (arg->nodeType() != Node::ATTRIBUTE_NODE)
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
return _pElement->setAttributeNodeNS(static_cast<Attr*>(arg));
}
Node* AttrMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName)
{
Attr* pAttr = _pElement->getAttributeNodeNS(namespaceURI, localName);
if (pAttr)
return _pElement->removeAttributeNode(pAttr);
else
return 0;
}
void AttrMap::autoRelease()
{
_pElement->ownerDocument()->autoReleasePool().add(this);
}
XML_END

48
XML/src/Attributes.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// Attributes.cpp
//
// $Id: //poco/1.1.0/XML/src/Attributes.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/Attributes.h"
XML_BEGIN
Attributes::~Attributes()
{
}
XML_END

392
XML/src/AttributesImpl.cpp Normal file
View File

@@ -0,0 +1,392 @@
//
// AttributesImpl.cpp
//
// $Id: //poco/1.1.0/XML/src/AttributesImpl.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/AttributesImpl.h"
XML_BEGIN
AttributesImpl::AttributesImpl()
{
}
AttributesImpl::AttributesImpl(const Attributes& attributes)
{
setAttributes(attributes);
}
AttributesImpl::~AttributesImpl()
{
}
AttributesImpl& AttributesImpl::operator = (const AttributesImpl& attributes)
{
if (&attributes != this)
{
_attributes = attributes._attributes;
}
return *this;
}
int AttributesImpl::getIndex(const XMLString& qname) const
{
int i = 0;
AttributeVec::const_iterator it;
for (it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->qname == qname) return i;
++i;
}
return -1;
}
int AttributesImpl::getIndex(const XMLString& namespaceURI, const XMLString& localName) const
{
int i = 0;
AttributeVec::const_iterator it;
for (it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->namespaceURI == namespaceURI && it->localName == localName) return i;
++i;
}
return -1;
}
int AttributesImpl::getLength() const
{
return (int) _attributes.size();
}
XMLString AttributesImpl::getLocalName(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].localName;
}
XMLString AttributesImpl::getQName(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].qname;
}
XMLString AttributesImpl::getType(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].type;
}
XMLString AttributesImpl::getType(const XMLString& qname) const
{
Attribute* pAttr = find(qname);
if (pAttr)
return pAttr->type;
else
return XMLString();
}
XMLString AttributesImpl::getType(const XMLString& namespaceURI, const XMLString& localName) const
{
Attribute* pAttr = find(namespaceURI, localName);
if (pAttr)
return pAttr->type;
else
return XMLString();
}
XMLString AttributesImpl::getValue(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].value;
}
XMLString AttributesImpl::getValue(const XMLString& qname) const
{
Attribute* pAttr = find(qname);
if (pAttr)
return pAttr->value;
else
return XMLString();
}
XMLString AttributesImpl::getValue(const XMLString& namespaceURI, const XMLString& localName) const
{
Attribute* pAttr = find(namespaceURI, localName);
if (pAttr)
return pAttr->value;
else
return XMLString();
}
XMLString AttributesImpl::getURI(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].namespaceURI;
}
bool AttributesImpl::isSpecified(int i) const
{
poco_assert (i < _attributes.size());
return _attributes[i].specified;
}
bool AttributesImpl::isSpecified(const XMLString& qname) const
{
Attribute* pAttr = find(qname);
if (pAttr)
return pAttr->specified;
else
return false;
}
bool AttributesImpl::isSpecified(const XMLString& namespaceURI, const XMLString& localName) const
{
Attribute* pAttr = find(namespaceURI, localName);
if (pAttr)
return pAttr->specified;
else
return false;
}
void AttributesImpl::setValue(int i, const XMLString& value)
{
poco_assert (i < _attributes.size());
_attributes[i].value = value;
_attributes[i].specified = true;
}
void AttributesImpl::setValue(const XMLString& qname, const XMLString& value)
{
Attribute* pAttr = find(qname);
if (pAttr)
{
pAttr->value = value;
pAttr->specified = true;
}
}
void AttributesImpl::setValue(const XMLString& namespaceURI, const XMLString& localName, const XMLString& value)
{
Attribute* pAttr = find(namespaceURI, localName);
if (pAttr)
{
pAttr->value = value;
pAttr->specified = true;
}
}
void AttributesImpl::setAttributes(const Attributes& attributes)
{
if (&attributes != this)
{
int count = attributes.getLength();
_attributes.clear();
_attributes.reserve(count);
for (int i = 0; i < count; i++)
{
addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), attributes.getValue(i));
}
}
}
void AttributesImpl::setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value)
{
poco_assert (i < _attributes.size());
_attributes[i].namespaceURI = namespaceURI;
_attributes[i].localName = localName;
_attributes[i].qname = qname;
_attributes[i].type = type;
_attributes[i].value = value;
_attributes[i].specified = true;
}
void AttributesImpl::addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value)
{
AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute());
it->namespaceURI = namespaceURI;
it->localName = localName;
it->qname = qname;
it->value = value;
it->type = type;
it->specified = true;
}
void AttributesImpl::addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value, bool specified)
{
AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute());
it->namespaceURI = namespaceURI;
it->localName = localName;
it->qname = qname;
it->value = value;
it->type = type;
it->specified = specified;
}
void AttributesImpl::addAttribute(const XMLChar* namespaceURI, const XMLChar* localName, const XMLChar* qname, const XMLChar* type, const XMLChar* value, bool specified)
{
AttributeVec::iterator it = _attributes.insert(_attributes.end(), Attribute());
it->namespaceURI = namespaceURI;
it->localName = localName;
it->qname = qname;
it->value = value;
it->type = type;
it->specified = specified;
}
void AttributesImpl::removeAttribute(int i)
{
int cur = 0;
for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it, ++cur)
{
if (cur == i)
{
_attributes.erase(it);
break;
}
}
}
void AttributesImpl::removeAttribute(const XMLString& qname)
{
for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->qname == qname)
{
_attributes.erase(it);
break;
}
}
}
void AttributesImpl::removeAttribute(const XMLString& namespaceURI, const XMLString& localName)
{
for (AttributeVec::iterator it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->namespaceURI == namespaceURI && it->localName == localName)
{
_attributes.erase(it);
break;
}
}
}
void AttributesImpl::clear()
{
_attributes.clear();
}
void AttributesImpl::setLocalName(int i, const XMLString& localName)
{
poco_assert (i < _attributes.size());
_attributes[i].localName = localName;
}
void AttributesImpl::setQName(int i, const XMLString& qname)
{
poco_assert (i < _attributes.size());
_attributes[i].qname = qname;
}
void AttributesImpl::setType(int i, const XMLString& type)
{
poco_assert (i < _attributes.size());
_attributes[i].type = type;
}
void AttributesImpl::setURI(int i, const XMLString& namespaceURI)
{
poco_assert (i < _attributes.size());
_attributes[i].namespaceURI = namespaceURI;
}
AttributesImpl::Attribute* AttributesImpl::find(const XMLString& qname) const
{
for (AttributeVec::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->qname == qname)
return const_cast<Attribute*>(&(*it));
}
return 0;
}
AttributesImpl::Attribute* AttributesImpl::find(const XMLString& namespaceURI, const XMLString& localName) const
{
for (AttributeVec::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it)
{
if (it->namespaceURI == namespaceURI && it->localName == localName)
return const_cast<Attribute*>(&(*it));
}
return 0;
}
XML_END

95
XML/src/CDATASection.cpp Normal file
View File

@@ -0,0 +1,95 @@
//
// CDATASection.cpp
//
// $Id: //poco/1.1.0/XML/src/CDATASection.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/CDATASection.h"
#include "DOM/Document.h"
#include "DOM/DOMException.h"
XML_BEGIN
const XMLString CDATASection::NODE_NAME = toXMLString("#cdata-section");
CDATASection::CDATASection(Document* pOwnerDocument, const XMLString& data):
Text(pOwnerDocument, data)
{
}
CDATASection::CDATASection(Document* pOwnerDocument, const CDATASection& sec):
Text(pOwnerDocument, sec)
{
}
CDATASection::~CDATASection()
{
}
Text* CDATASection::splitText(unsigned long offset)
{
Node* pParent = parentNode();
if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
int n = length() - offset;
Text* pNew = ownerDocument()->createCDATASection(substringData(offset, n));
deleteData(offset, n);
pParent->insertBefore(pNew, nextSibling())->release();
return pNew;
}
const XMLString& CDATASection::nodeName() const
{
return NODE_NAME;
}
unsigned short CDATASection::nodeType() const
{
return Node::CDATA_SECTION_NODE;
}
Node* CDATASection::copyNode(bool deep, Document* pOwnerDocument) const
{
return new CDATASection(pOwnerDocument, *this);
}
XML_END

140
XML/src/CharacterData.cpp Normal file
View File

@@ -0,0 +1,140 @@
//
// CharacterData.cpp
//
// $Id: //poco/1.1.0/XML/src/CharacterData.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/CharacterData.h"
#include "DOM/DOMException.h"
#include "Foundation/String.h"
XML_BEGIN
CharacterData::CharacterData(Document* pOwnerDocument, const XMLString& data):
AbstractNode(pOwnerDocument),
_data(data)
{
}
CharacterData::CharacterData(Document* pOwnerDocument, const CharacterData& data):
AbstractNode(pOwnerDocument, data),
_data(data._data)
{
}
CharacterData::~CharacterData()
{
}
void CharacterData::setData(const XMLString& data)
{
XMLString oldData = getData();
_data = data;
if (events()) dispatchCharacterDataModified(oldData, _data);
}
XMLString CharacterData::substringData(unsigned long offset, unsigned long count) const
{
if (offset >= _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR);
return _data.substr(offset, count);
}
void CharacterData::appendData(const XMLString& arg)
{
XMLString oldData = _data;
_data.append(arg);
if (events()) dispatchCharacterDataModified(oldData, _data);
}
void CharacterData::insertData(unsigned long offset, const XMLString& arg)
{
if (offset > _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data;
_data.insert(offset, arg);
if (events()) dispatchCharacterDataModified(oldData, _data);
}
void CharacterData::deleteData(unsigned long offset, unsigned long count)
{
if (offset >= _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data;
_data.replace(offset, count, EMPTY_STRING);
if (events()) dispatchCharacterDataModified(oldData, _data);
}
void CharacterData::replaceData(unsigned long offset, unsigned long count, const XMLString& arg)
{
if (offset >= _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data;
_data.replace(offset, count, arg);
if (events()) dispatchCharacterDataModified(oldData, _data);
}
const XMLString& CharacterData::getNodeValue() const
{
return _data;
}
void CharacterData::setNodeValue(const XMLString& value)
{
setData(value);
}
XMLString CharacterData::trimmedData() const
{
return Foundation::trim(_data);
}
XML_END

View File

@@ -0,0 +1,91 @@
//
// ChildNodesList.cpp
//
// $Id: //poco/1.1.0/XML/src/ChildNodesList.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/ChildNodesList.h"
#include "DOM/Node.h"
#include "DOM/Document.h"
XML_BEGIN
ChildNodesList::ChildNodesList(const Node* pParent):
_pParent(pParent)
{
poco_check_ptr (pParent);
_pParent->duplicate();
}
ChildNodesList::~ChildNodesList()
{
_pParent->release();
}
Node* ChildNodesList::item(unsigned long index) const
{
unsigned long n = 0;
Node* pCur = _pParent->firstChild();
while (pCur && n++ < index)
{
pCur = pCur->nextSibling();
}
return pCur;
}
unsigned long ChildNodesList::length() const
{
unsigned long n = 0;
Node* pCur = _pParent->firstChild();
while (pCur)
{
++n;
pCur = pCur->nextSibling();
}
return n;
}
void ChildNodesList::autoRelease()
{
_pParent->ownerDocument()->autoReleasePool().add(this);
}
XML_END

81
XML/src/Comment.cpp Normal file
View File

@@ -0,0 +1,81 @@
//
// Comment.cpp
//
// $Id: //poco/1.1.0/XML/src/Comment.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Comment.h"
XML_BEGIN
const XMLString Comment::NODE_NAME = toXMLString("#comment");
Comment::Comment(Document* pOwnerDocument, const XMLString& data):
CharacterData(pOwnerDocument, data)
{
}
Comment::Comment(Document* pOwnerDocument, const Comment& comment):
CharacterData(pOwnerDocument, comment)
{
}
Comment::~Comment()
{
}
const XMLString& Comment::nodeName() const
{
return NODE_NAME;
}
unsigned short Comment::nodeType() const
{
return Node::COMMENT_NODE;
}
Node* Comment::copyNode(bool deep, Document* pOwnerDocument) const
{
return new Comment(pOwnerDocument, *this);
}
XML_END

View File

@@ -0,0 +1,48 @@
//
// ContentHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/ContentHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/ContentHandler.h"
XML_BEGIN
ContentHandler::~ContentHandler()
{
}
XML_END

313
XML/src/DOMBuilder.cpp Normal file
View File

@@ -0,0 +1,313 @@
//
// DOMBuilder.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMBuilder.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMBuilder
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMBuilder.h"
#include "DOM/Document.h"
#include "DOM/DocumentType.h"
#include "DOM/CharacterData.h"
#include "DOM/Text.h"
#include "DOM/Comment.h"
#include "DOM/CDATASection.h"
#include "DOM/Element.h"
#include "DOM/Attr.h"
#include "DOM/Entity.h"
#include "DOM/EntityReference.h"
#include "DOM/Notation.h"
#include "DOM/ProcessingInstruction.h"
#include "DOM/AutoPtr.h"
#include "SAX/XMLReader.h"
#include "SAX/AttributesImpl.h"
XML_BEGIN
const XMLString DOMBuilder::EMPTY_STRING;
DOMBuilder::DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool):
_xmlReader(xmlReader),
_pNamePool(pNamePool),
_pDocument(0),
_pParent(0),
_pPrevious(0),
_inCDATA(false),
_namespaces(true)
{
_xmlReader.setContentHandler(this);
_xmlReader.setDTDHandler(this);
_xmlReader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(this));
if (_pNamePool) _pNamePool->duplicate();
}
DOMBuilder::~DOMBuilder()
{
if (_pNamePool) _pNamePool->release();
}
Document* DOMBuilder::parse(const XMLString& uri)
{
setupParse();
_pDocument->suspendEvents();
try
{
_xmlReader.parse(uri);
}
catch (...)
{
_pDocument->release();
_pDocument = 0;
_pParent = 0;
_pPrevious = 0;
throw;
}
_pDocument->resumeEvents();
_pDocument->collectGarbage();
return _pDocument;
}
Document* DOMBuilder::parse(InputSource* pInputSource)
{
setupParse();
_pDocument->suspendEvents();
try
{
_xmlReader.parse(pInputSource);
}
catch (...)
{
_pDocument->release();
_pDocument = 0;
_pParent = 0;
_pPrevious = 0;
throw;
}
_pDocument->resumeEvents();
_pDocument->collectGarbage();
return _pDocument;
}
void DOMBuilder::setupParse()
{
_pDocument = new Document(_pNamePool);
_pParent = _pDocument;
_pPrevious = 0;
_inCDATA = false;
_namespaces = _xmlReader.getFeature(XMLReader::FEATURE_NAMESPACES);
}
inline void DOMBuilder::appendNode(AbstractNode* pNode)
{
if (_pPrevious && _pPrevious != _pParent)
{
_pPrevious->_pNext = pNode;
pNode->_pParent = _pParent;
pNode->duplicate();
}
else _pParent->appendChild(pNode);
_pPrevious = pNode;
}
void DOMBuilder::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId)
{
DocumentType* pDoctype = _pDocument->getDoctype();
if (pDoctype)
{
AutoPtr<Notation> pNotation = _pDocument->createNotation(name, (publicId ? *publicId : EMPTY_STRING), (systemId ? *systemId : EMPTY_STRING));
pDoctype->appendChild(pNotation);
}
}
void DOMBuilder::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName)
{
DocumentType* pDoctype = _pDocument->getDoctype();
if (pDoctype)
{
AutoPtr<Entity> pEntity = _pDocument->createEntity(name, publicId ? *publicId : EMPTY_STRING, systemId, notationName);
pDoctype->appendChild(pEntity);
}
}
void DOMBuilder::setDocumentLocator(const Locator* loc)
{
}
void DOMBuilder::startDocument()
{
}
void DOMBuilder::endDocument()
{
}
void DOMBuilder::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
AutoPtr<Element> pElem = _namespaces ? _pDocument->createElementNS(uri, qname.empty() ? localName : qname) : _pDocument->createElement(qname);
const AttributesImpl& attrs = dynamic_cast<const AttributesImpl&>(attributes);
for (AttributesImpl::iterator it = attrs.begin(); it != attrs.end(); ++it)
{
AutoPtr<Attr> pAttr = new Attr(_pDocument, 0, it->namespaceURI, it->localName, it->qname, it->value, it->specified);
if (_namespaces)
pElem->setAttributeNodeNS(pAttr);
else
pElem->setAttributeNode(pAttr);
}
appendNode(pElem);
_pParent = pElem;
}
void DOMBuilder::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname)
{
_pPrevious = _pParent;
_pParent = static_cast<AbstractContainerNode*>(_pParent->parentNode());
}
void DOMBuilder::characters(const XMLChar ch[], int start, int length)
{
if (_inCDATA)
{
if (_pPrevious && _pPrevious->nodeType() == Node::CDATA_SECTION_NODE)
{
static_cast<CDATASection*>(_pPrevious)->appendData(XMLString(ch + start, length));
}
else
{
AutoPtr<CDATASection> pCDATA = _pDocument->createCDATASection(XMLString(ch + start, length));
appendNode(pCDATA);
}
}
else
{
if (_pPrevious && _pPrevious->nodeType() == Node::TEXT_NODE)
{
static_cast<Text*>(_pPrevious)->appendData(XMLString(ch + start, length));
}
else
{
AutoPtr<Text> pText = _pDocument->createTextNode(XMLString(ch + start, length));
appendNode(pText);
}
}
}
void DOMBuilder::ignorableWhitespace(const XMLChar ch[], int start, int length)
{
characters(ch, start, length);
}
void DOMBuilder::processingInstruction(const XMLString& target, const XMLString& data)
{
AutoPtr<ProcessingInstruction> pPI = _pDocument->createProcessingInstruction(target, data);
appendNode(pPI);
}
void DOMBuilder::startPrefixMapping(const XMLString& prefix, const XMLString& uri)
{
}
void DOMBuilder::endPrefixMapping(const XMLString& prefix)
{
}
void DOMBuilder::skippedEntity(const XMLString& name)
{
AutoPtr<EntityReference> pER = _pDocument->createEntityReference(name);
appendNode(pER);
}
void DOMBuilder::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId)
{
AutoPtr<DocumentType> pDoctype = new DocumentType(_pDocument, name, publicId, systemId);
_pDocument->setDoctype(pDoctype);
}
void DOMBuilder::endDTD()
{
}
void DOMBuilder::startEntity(const XMLString& name)
{
}
void DOMBuilder::endEntity(const XMLString& name)
{
}
void DOMBuilder::startCDATA()
{
_inCDATA = true;
}
void DOMBuilder::endCDATA()
{
_inCDATA = false;
}
void DOMBuilder::comment(const XMLChar ch[], int start, int length)
{
AutoPtr<Comment> pComment = _pDocument->createComment(XMLString(ch + start, length));
appendNode(pComment);
}
XML_END

122
XML/src/DOMException.cpp Normal file
View File

@@ -0,0 +1,122 @@
//
// DOMException.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMException.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMException.h"
#include <typeinfo>
XML_BEGIN
const std::string DOMException::MESSAGES[_NUMBER_OF_MESSAGES] =
{
"Invalid DOM exception code",
"Index or size is negative or greater than allowed value",
"The specified range of text does not fit into a DOMString",
"A node is inserted somewhere it doesn't belong",
"A node is used in a different document than the one that created it",
"An invalid character is specified",
"Data is specified for a node which does not support data",
"An attempt is made to modify an object where modifications are not allowed",
"An attempt was made to reference a node in a context where it does not exist",
"The implementation does not support the type of object requested",
"An attempt is made to add an attribute that is already in use elsewhere",
"A parameter or an operation is not supported by the underlying object",
"An invalid or illegal string is specified",
"An attempt is made to modify the type of the underlying object",
"An attempt is made to create or change an object in a way which is incorrect with regard to namespaces",
"An attempt is made to use an object that is not, or is no longer, usable"
};
DOMException::DOMException(unsigned short code):
XMLException(message(code)),
_code(code)
{
}
DOMException::DOMException(const DOMException& exc):
XMLException(exc),
_code(exc._code)
{
}
DOMException::~DOMException() throw()
{
}
DOMException& DOMException::operator = (const DOMException& exc)
{
if (&exc != this)
{
XMLException::operator = (exc);
_code = exc._code;
}
return *this;
}
const char* DOMException::name() const throw()
{
return "DOMException";
}
const char* DOMException::className() const throw()
{
return typeid(*this).name();
}
Foundation::Exception* DOMException::clone() const
{
return new DOMException(*this);
}
const std::string& DOMException::message(unsigned short code)
{
if (code >= 1 && code < _NUMBER_OF_MESSAGES)
return MESSAGES[code];
else
return MESSAGES[0];
}
XML_END

View File

@@ -0,0 +1,100 @@
//
// DOMImplementation.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMImplementation.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMImplementation.h"
#include "DOM/DocumentType.h"
#include "DOM/Document.h"
#include "DOM/Element.h"
#include "Foundation/String.h"
#include "Foundation/SingletonHolder.h"
XML_BEGIN
const XMLString DOMImplementation::FEATURE_XML = toXMLString("xml");
const XMLString DOMImplementation::FEATURE_CORE = toXMLString("core");
const XMLString DOMImplementation::FEATURE_EVENTS = toXMLString("events");
const XMLString DOMImplementation::FEATURE_MUTATIONEVENTS = toXMLString("mutationevents");
const XMLString DOMImplementation::FEATURE_TRAVERSAL = toXMLString("traversal");
DOMImplementation::DOMImplementation()
{
}
DOMImplementation::~DOMImplementation()
{
}
bool DOMImplementation::hasFeature(const XMLString& feature, const XMLString& version) const
{
XMLString lcFeature = Foundation::toLower(feature);
return lcFeature == FEATURE_XML && version == "1.0" ||
lcFeature == FEATURE_CORE && version == "2.0" ||
lcFeature == FEATURE_EVENTS && version == "2.0" ||
lcFeature == FEATURE_MUTATIONEVENTS && version == "2.0" ||
lcFeature == FEATURE_TRAVERSAL && version == "2.0";
}
DocumentType* DOMImplementation::createDocumentType(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const
{
return new DocumentType(0, name, publicId, systemId);
}
Document* DOMImplementation::createDocument(const XMLString& namespaceURI, const XMLString& qualifiedName, DocumentType* doctype) const
{
Document* pDoc = new Document(doctype);
if (namespaceURI.empty())
pDoc->appendChild(pDoc->createElement(qualifiedName))->release();
else
pDoc->appendChild(pDoc->createElementNS(namespaceURI, qualifiedName))->release();
return pDoc;
}
const DOMImplementation& DOMImplementation::instance()
{
static Foundation::SingletonHolder<DOMImplementation> sh;
return *sh.get();
}
XML_END

53
XML/src/DOMObject.cpp Normal file
View File

@@ -0,0 +1,53 @@
//
// DOMObject.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMObject.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMObject.h"
XML_BEGIN
DOMObject::DOMObject(): _rc(1)
{
}
DOMObject::~DOMObject()
{
}
XML_END

153
XML/src/DOMParser.cpp Normal file
View File

@@ -0,0 +1,153 @@
//
// DOMParser.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMParser.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMParser
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMParser.h"
#include "DOM/DOMBuilder.h"
#include "SAX/WhitespaceFilter.h"
#include "SAX/InputSource.h"
#include "XML/NamePool.h"
#include <sstream>
XML_BEGIN
const XMLString DOMParser::FEATURE_WHITESPACE = toXMLString("http://www.appinf.com/features/no-whitespace-in-element-content");
DOMParser::DOMParser(NamePool* pNamePool):
_pNamePool(pNamePool),
_whitespace(true)
{
if (_pNamePool) _pNamePool->duplicate();
}
DOMParser::~DOMParser()
{
if (_pNamePool) _pNamePool->release();
}
void DOMParser::setEncoding(const XMLString& encoding)
{
_saxParser.setEncoding(encoding);
}
const XMLString& DOMParser::getEncoding() const
{
return _saxParser.getEncoding();
}
void DOMParser::addEncoding(const XMLString& name, Foundation::TextEncoding* pEncoding)
{
_saxParser.addEncoding(name, pEncoding);
}
void DOMParser::setFeature(const XMLString& name, bool state)
{
if (name == FEATURE_WHITESPACE)
_whitespace = state;
else
_saxParser.setFeature(name, state);
}
bool DOMParser::getFeature(const XMLString& name) const
{
if (name == FEATURE_WHITESPACE)
return _whitespace;
else
return _saxParser.getFeature(name);
}
Document* DOMParser::parse(const XMLString& uri)
{
if (_whitespace)
{
DOMBuilder builder(_saxParser, _pNamePool);
return builder.parse(uri);
}
else
{
WhitespaceFilter filter(&_saxParser);
DOMBuilder builder(filter, _pNamePool);
return builder.parse(uri);
}
}
Document* DOMParser::parse(InputSource* pInputSource)
{
if (_whitespace)
{
DOMBuilder builder(_saxParser, _pNamePool);
return builder.parse(pInputSource);
}
else
{
WhitespaceFilter filter(&_saxParser);
DOMBuilder builder(filter, _pNamePool);
return builder.parse(pInputSource);
}
}
Document* DOMParser::parseString(const std::string& xml)
{
std::istringstream istr(xml);
InputSource src(istr);
return parse(&src);
}
EntityResolver* DOMParser::getEntityResolver() const
{
return _saxParser.getEntityResolver();
}
void DOMParser::setEntityResolver(EntityResolver* pEntityResolver)
{
_saxParser.setEntityResolver(pEntityResolver);
}
XML_END

338
XML/src/DOMSerializer.cpp Normal file
View File

@@ -0,0 +1,338 @@
//
// DOMSerializer.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMSerializer.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMSerializer
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMSerializer.h"
#include "DOM/Document.h"
#include "DOM/DocumentType.h"
#include "DOM/DocumentFragment.h"
#include "DOM/Element.h"
#include "DOM/Attr.h"
#include "DOM/Text.h"
#include "DOM/CDATASection.h"
#include "DOM/Comment.h"
#include "DOM/ProcessingInstruction.h"
#include "DOM/Entity.h"
#include "DOM/Notation.h"
#include "DOM/NamedNodeMap.h"
#include "DOM/AutoPtr.h"
#include "SAX/EntityResolver.h"
#include "SAX/DTDHandler.h"
#include "SAX/ContentHandler.h"
#include "SAX/LexicalHandler.h"
#include "SAX/AttributesImpl.h"
#include "SAX/ErrorHandler.h"
#include "SAX/SAXException.h"
XML_BEGIN
const XMLString DOMSerializer::CDATA = toXMLString("CDATA");
DOMSerializer::DOMSerializer():
_pEntityResolver(0),
_pDTDHandler(0),
_pContentHandler(0),
_pErrorHandler(0),
_pDeclHandler(0),
_pLexicalHandler(0)
{
}
DOMSerializer::~DOMSerializer()
{
}
void DOMSerializer::setEntityResolver(EntityResolver* pEntityResolver)
{
_pEntityResolver = pEntityResolver;
}
EntityResolver* DOMSerializer::getEntityResolver() const
{
return _pEntityResolver;
}
void DOMSerializer::setDTDHandler(DTDHandler* pDTDHandler)
{
_pDTDHandler = pDTDHandler;
}
DTDHandler* DOMSerializer::getDTDHandler() const
{
return _pDTDHandler;
}
void DOMSerializer::setContentHandler(ContentHandler* pContentHandler)
{
_pContentHandler = pContentHandler;
}
ContentHandler* DOMSerializer::getContentHandler() const
{
return _pContentHandler;
}
void DOMSerializer::setErrorHandler(ErrorHandler* pErrorHandler)
{
_pErrorHandler = pErrorHandler;
}
ErrorHandler* DOMSerializer::getErrorHandler() const
{
return _pErrorHandler;
}
void DOMSerializer::setFeature(const XMLString& featureId, bool state)
{
if (featureId == XMLReader::FEATURE_NAMESPACES)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES));
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES));
else
throw SAXNotRecognizedException(fromXMLString(featureId));
}
bool DOMSerializer::getFeature(const XMLString& featureId) const
{
if (featureId == XMLReader::FEATURE_NAMESPACES)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES));
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES));
else
throw SAXNotRecognizedException(fromXMLString(featureId));
}
void DOMSerializer::setProperty(const XMLString& propertyId, const XMLString& value)
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId));
else
throw SAXNotRecognizedException(fromXMLString(propertyId));
}
void DOMSerializer::setProperty(const XMLString& propertyId, void* value)
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
_pDeclHandler = reinterpret_cast<DeclHandler*>(value);
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
_pLexicalHandler = reinterpret_cast<LexicalHandler*>(value);
else throw SAXNotRecognizedException(fromXMLString(propertyId));
}
void* DOMSerializer::getProperty(const XMLString& propertyId) const
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
return _pDeclHandler;
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
return _pLexicalHandler;
else throw SAXNotSupportedException(fromXMLString(propertyId));
}
void DOMSerializer::serialize(const Node* pNode)
{
poco_check_ptr (pNode);
handleNode(pNode);
}
void DOMSerializer::parse(InputSource* pSource)
{
throw XMLException("The DOMSerializer cannot parse an InputSource");
}
void DOMSerializer::parse(const XMLString& systemId)
{
throw XMLException("The DOMSerializer cannot parse from a system identifier");
}
void DOMSerializer::iterate(const Node* pNode) const
{
while (pNode)
{
handleNode(pNode);
pNode = pNode->nextSibling();
}
}
void DOMSerializer::handleNode(const Node* pNode) const
{
switch (pNode->nodeType())
{
case Node::ELEMENT_NODE:
handleElement(static_cast<const Element*>(pNode));
break;
case Node::TEXT_NODE:
handleCharacterData(static_cast<const Text*>(pNode));
break;
case Node::CDATA_SECTION_NODE:
handleCDATASection(static_cast<const CDATASection*>(pNode));
break;
case Node::ENTITY_NODE:
handleEntity(static_cast<const Entity*>(pNode));
break;
case Node::PROCESSING_INSTRUCTION_NODE:
handlePI(static_cast<const ProcessingInstruction*>(pNode));
break;
case Node::COMMENT_NODE:
handleComment(static_cast<const Comment*>(pNode));
break;
case Node::DOCUMENT_NODE:
handleDocument(static_cast<const Document*>(pNode));
break;
case Node::DOCUMENT_TYPE_NODE:
handleDocumentType(static_cast<const DocumentType*>(pNode));
break;
case Node::DOCUMENT_FRAGMENT_NODE:
handleFragment(static_cast<const DocumentFragment*>(pNode));
break;
case Node::NOTATION_NODE:
handleNotation(static_cast<const Notation*>(pNode));
break;
}
}
void DOMSerializer::handleElement(const Element* pElement) const
{
if (_pContentHandler)
{
AutoPtr<NamedNodeMap> pAttrs = pElement->attributes();
AttributesImpl saxAttrs;
for (unsigned long i = 0; i < pAttrs->length(); ++i)
{
Attr* pAttr = static_cast<Attr*>(pAttrs->item(i));
saxAttrs.addAttribute(pAttr->namespaceURI(), pAttr->localName(), pAttr->nodeName(), CDATA, pAttr->value(), pAttr->specified());
}
_pContentHandler->startElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName(), saxAttrs);
}
iterate(pElement->firstChild());
if (_pContentHandler)
_pContentHandler->endElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName());
}
void DOMSerializer::handleCharacterData(const Text* pText) const
{
if (_pContentHandler)
{
const XMLString& data = pText->data();
_pContentHandler->characters(data.c_str(), 0, (int) data.length());
}
}
void DOMSerializer::handleComment(const Comment* pComment) const
{
if (_pLexicalHandler)
{
const XMLString& data = pComment->data();
_pLexicalHandler->comment(data.c_str(), 0, (int) data.length());
}
}
void DOMSerializer::handlePI(const ProcessingInstruction* pPI) const
{
if (_pContentHandler) _pContentHandler->processingInstruction(pPI->target(), pPI->data());
}
void DOMSerializer::handleCDATASection(const CDATASection* pCDATA) const
{
if (_pLexicalHandler) _pLexicalHandler->startCDATA();
handleCharacterData(pCDATA);
if (_pLexicalHandler) _pLexicalHandler->endCDATA();
}
void DOMSerializer::handleDocument(const Document* pDocument) const
{
if (_pContentHandler) _pContentHandler->startDocument();
const DocumentType* pDoctype = pDocument->doctype();
if (pDoctype) handleDocumentType(pDoctype);
iterate(pDocument->firstChild());
if (_pContentHandler) _pContentHandler->endDocument();
}
void DOMSerializer::handleDocumentType(const DocumentType* pDocumentType) const
{
if (_pLexicalHandler) _pLexicalHandler->startDTD(pDocumentType->name(), pDocumentType->publicId(), pDocumentType->systemId());
iterate(pDocumentType->firstChild());
if (_pLexicalHandler) _pLexicalHandler->endDTD();
}
void DOMSerializer::handleFragment(const DocumentFragment* pFragment) const
{
iterate(pFragment->firstChild());
}
void DOMSerializer::handleNotation(const Notation* pNotation) const
{
if (_pDTDHandler) _pDTDHandler->notationDecl(pNotation->nodeName(), &pNotation->publicId(), &pNotation->systemId());
}
void DOMSerializer::handleEntity(const Entity* pEntity) const
{
if (_pDTDHandler) _pDTDHandler->unparsedEntityDecl(pEntity->nodeName(), &pEntity->publicId(), pEntity->systemId(), pEntity->notationName());
}
XML_END

114
XML/src/DOMWriter.cpp Normal file
View File

@@ -0,0 +1,114 @@
//
// DOMWriter.cpp
//
// $Id: //poco/1.1.0/XML/src/DOMWriter.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMWriter
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DOMWriter.h"
#include "XML/XMLWriter.h"
#include "DOM/Document.h"
#include "DOM/DocumentFragment.h"
#include "DOM/DocumentType.h"
#include "DOM/DOMException.h"
#include "DOM/DOMSerializer.h"
#include "SAX/LexicalHandler.h"
#include "XML/XMLException.h"
#include <fstream>
XML_BEGIN
DOMWriter::DOMWriter():
_pTextEncoding(0),
_options(0)
{
}
DOMWriter::~DOMWriter()
{
}
void DOMWriter::setEncoding(const XMLString& encodingName, Foundation::TextEncoding& textEncoding)
{
_encodingName = encodingName;
_pTextEncoding = &textEncoding;
}
void DOMWriter::setOptions(int options)
{
_options = options;
}
void DOMWriter::setNewLine(const XMLString& newLine)
{
_newLine = newLine;
}
void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode)
{
poco_check_ptr (pNode);
bool isFragment = pNode->nodeType() != Node::DOCUMENT_NODE;
XMLWriter writer(ostr, _options, _encodingName, _pTextEncoding);
writer.setNewLine(_newLine);
DOMSerializer serializer;
serializer.setContentHandler(&writer);
serializer.setDTDHandler(&writer);
serializer.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(&writer));
if (isFragment) writer.startFragment();
serializer.serialize(pNode);
if (isFragment) writer.endFragment();
}
void DOMWriter::writeNode(const XMLString& systemId, const Node* pNode)
{
std::ofstream ostr(systemId.c_str());
if (ostr.good())
writeNode(ostr, pNode);
else
throw Foundation::CreateFileException(systemId);
}
XML_END

48
XML/src/DTDHandler.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// DTDHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/DTDHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/DTDHandler.h"
XML_BEGIN
DTDHandler::~DTDHandler()
{
}
XML_END

138
XML/src/DTDMap.cpp Normal file
View File

@@ -0,0 +1,138 @@
//
// DTDMap.cpp
//
// $Id: //poco/1.1.0/XML/src/DTDMap.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DTDMap.h"
#include "DOM/DocumentType.h"
#include "DOM/Document.h"
#include "DOM/DOMException.h"
XML_BEGIN
DTDMap::DTDMap(const DocumentType* pDocumentType, unsigned short type):
_pDocumentType(pDocumentType),
_type(type)
{
poco_check_ptr (pDocumentType->ownerDocument());
}
DTDMap::~DTDMap()
{
}
Node* DTDMap::getNamedItem(const XMLString& name) const
{
Node* pCur = _pDocumentType->firstChild();
while (pCur)
{
if (pCur->nodeType() == _type && pCur->nodeName() == name)
return pCur;
pCur = pCur->nextSibling();
}
return pCur;
}
Node* DTDMap::setNamedItem(Node* arg)
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
}
Node* DTDMap::removeNamedItem(const XMLString& name)
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
}
Node* DTDMap::item(unsigned long index) const
{
unsigned long n = 0;
Node* pCur = _pDocumentType->firstChild();
while (pCur)
{
if (pCur->nodeType() == _type)
{
if (n == index) return pCur;
++n;
}
pCur = pCur->nextSibling();
}
return pCur;
}
unsigned long DTDMap::length() const
{
unsigned long n = 0;
Node* pCur = _pDocumentType->firstChild();
while (pCur)
{
if (pCur->nodeType() == _type) ++n;
pCur = pCur->nextSibling();
}
return n;
}
Node* DTDMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const
{
return 0;
}
Node* DTDMap::setNamedItemNS(Node* arg)
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
}
Node* DTDMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName)
{
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
}
void DTDMap::autoRelease()
{
_pDocumentType->ownerDocument()->autoReleasePool().add(this);
}
XML_END

48
XML/src/DeclHandler.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// DeclHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/DeclHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/DeclHandler.h"
XML_BEGIN
DeclHandler::~DeclHandler()
{
}
XML_END

144
XML/src/DefaultHandler.cpp Normal file
View File

@@ -0,0 +1,144 @@
//
// DefaultHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/DefaultHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/DefaultHandler.h"
XML_BEGIN
DefaultHandler::DefaultHandler()
{
}
DefaultHandler::~DefaultHandler()
{
}
InputSource* DefaultHandler::resolveEntity(const XMLString* publicId, const XMLString& systemId)
{
return 0;
}
void DefaultHandler::releaseInputSource(InputSource* pSource)
{
}
void DefaultHandler::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId)
{
}
void DefaultHandler::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName)
{
}
void DefaultHandler::setDocumentLocator(const Locator* loc)
{
}
void DefaultHandler::startDocument()
{
}
void DefaultHandler::endDocument()
{
}
void DefaultHandler::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
}
void DefaultHandler::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname)
{
}
void DefaultHandler::characters(const XMLChar ch[], int start, int length)
{
}
void DefaultHandler::ignorableWhitespace(const XMLChar ch[], int start, int length)
{
}
void DefaultHandler::processingInstruction(const XMLString& target, const XMLString& data)
{
}
void DefaultHandler::startPrefixMapping(const XMLString& prefix, const XMLString& uri)
{
}
void DefaultHandler::endPrefixMapping(const XMLString& prefix)
{
}
void DefaultHandler::skippedEntity(const XMLString& name)
{
}
void DefaultHandler::warning(const SAXException& exc)
{
}
void DefaultHandler::error(const SAXException& exc)
{
}
void DefaultHandler::fatalError(const SAXException& exc)
{
}
XML_END

308
XML/src/Document.cpp Normal file
View File

@@ -0,0 +1,308 @@
//
// Document.cpp
//
// $Id: //poco/1.1.0/XML/src/Document.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Document.h"
#include "DOM/DocumentType.h"
#include "DOM/DOMImplementation.h"
#include "DOM/Element.h"
#include "DOM/Attr.h"
#include "DOM/DocumentFragment.h"
#include "DOM/Text.h"
#include "DOM/Comment.h"
#include "DOM/CDATASection.h"
#include "DOM/ProcessingInstruction.h"
#include "DOM/EntityReference.h"
#include "DOM/DOMException.h"
#include "DOM/ElementsByTagNameList.h"
#include "DOM/Entity.h"
#include "DOM/Notation.h"
#include "XML/Name.h"
#include "XML/NamePool.h"
XML_BEGIN
const XMLString Document::NODE_NAME = toXMLString("#document");
Document::Document(NamePool* pNamePool):
AbstractContainerNode(0),
_pDocumentType(0),
_eventSuspendLevel(0)
{
if (pNamePool)
{
_pNamePool = pNamePool;
_pNamePool->duplicate();
}
else
{
_pNamePool = new NamePool;
}
}
Document::Document(DocumentType* pDocumentType, NamePool* pNamePool):
AbstractContainerNode(0),
_pDocumentType(pDocumentType),
_eventSuspendLevel(0)
{
if (pNamePool)
{
_pNamePool = pNamePool;
_pNamePool->duplicate();
}
else
{
_pNamePool = new NamePool;
}
if (_pDocumentType)
{
_pDocumentType->duplicate();
_pDocumentType->setOwnerDocument(this);
}
}
Document::~Document()
{
if (_pDocumentType) _pDocumentType->release();
_pNamePool->release();
}
bool Document::dispatchEvent(Event* evt)
{
return _eventSuspendLevel > 0 || AbstractContainerNode::dispatchEvent(evt);
}
void Document::collectGarbage()
{
_autoReleasePool.release();
}
void Document::suspendEvents()
{
++_eventSuspendLevel;
}
void Document::resumeEvents()
{
poco_assert_dbg (_eventSuspendLevel > 0);
--_eventSuspendLevel;
}
const DOMImplementation& Document::implementation() const
{
return DOMImplementation::instance();
}
Element* Document::documentElement() const
{
// Skip non-element nodes before the document element
Node* pCur = firstChild();
while (pCur)
{
if (dynamic_cast<Element*>(pCur))
return static_cast<Element*>(pCur);
pCur = pCur->nextSibling();
}
return 0;
}
Element* Document::createElement(const XMLString& tagName) const
{
return new Element(const_cast<Document*>(this), EMPTY_STRING, EMPTY_STRING, tagName);
}
DocumentFragment* Document::createDocumentFragment() const
{
return new DocumentFragment(const_cast<Document*>(this));
}
Text* Document::createTextNode(const XMLString& data) const
{
return new Text(const_cast<Document*>(this), data);
}
Comment* Document::createComment(const XMLString& data) const
{
return new Comment(const_cast<Document*>(this), data);
}
CDATASection* Document::createCDATASection(const XMLString& data) const
{
return new CDATASection(const_cast<Document*>(this), data);
}
ProcessingInstruction* Document::createProcessingInstruction(const XMLString& target, const XMLString& data) const
{
return new ProcessingInstruction(const_cast<Document*>(this), target, data);
}
Attr* Document::createAttribute(const XMLString& name) const
{
return new Attr(const_cast<Document*>(this), 0, EMPTY_STRING, EMPTY_STRING, name, EMPTY_STRING);
}
EntityReference* Document::createEntityReference(const XMLString& name) const
{
return new EntityReference(const_cast<Document*>(this), name);
}
NodeList* Document::getElementsByTagName(const XMLString& name) const
{
return new ElementsByTagNameList(const_cast<Document*>(this), name);
}
const XMLString& Document::nodeName() const
{
return NODE_NAME;
}
unsigned short Document::nodeType() const
{
return Node::DOCUMENT_NODE;
}
Node* Document::importNode(Node* importedNode, bool deep)
{
return static_cast<AbstractNode*>(importedNode)->copyNode(deep, this);
}
Element* Document::createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const
{
return new Element(const_cast<Document*>(this), namespaceURI, Name::localName(qualifiedName), qualifiedName);
}
Attr* Document::createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const
{
return new Attr(const_cast<Document*>(this), 0, namespaceURI, Name::localName(qualifiedName), qualifiedName, EMPTY_STRING);
}
NodeList* Document::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const
{
return new ElementsByTagNameListNS(const_cast<Document*>(this), namespaceURI, localName);
}
Element* Document::getElementById(const XMLString& elementId) const
{
return 0;
}
Event* Document::createEvent(const XMLString& eventType) const
{
if (eventType == MutationEvent::DOMSubtreeModified ||
eventType == MutationEvent::DOMNodeInserted ||
eventType == MutationEvent::DOMNodeRemoved ||
eventType == MutationEvent::DOMNodeRemovedFromDocument ||
eventType == MutationEvent::DOMNodeInsertedIntoDocument ||
eventType == MutationEvent::DOMAttrModified ||
eventType == MutationEvent::DOMCharacterDataModified)
{
return new MutationEvent(const_cast<Document*>(this), eventType);
}
throw DOMException(DOMException::NOT_SUPPORTED_ERR);
}
Node* Document::copyNode(bool deep, Document* pOwnerDocument) const
{
throw DOMException(DOMException::NOT_SUPPORTED_ERR);
}
void Document::setDoctype(DocumentType* pDoctype)
{
if (_pDocumentType) _pDocumentType->release();
_pDocumentType = pDoctype;
if (_pDocumentType)
{
_pDocumentType->duplicate();
_pDocumentType->setOwnerDocument(this);
}
}
bool Document::eventsSuspended() const
{
return _eventSuspendLevel > 0;
}
bool Document::events() const
{
return _eventSuspendLevel == 0;
}
Entity* Document::createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const
{
return new Entity(const_cast<Document*>(this), name, publicId, systemId, notationName);
}
Notation* Document::createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const
{
return new Notation(const_cast<Document*>(this), name, publicId, systemId);
}
XML_END

48
XML/src/DocumentEvent.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// DocumentEvent.cpp
//
// $Id: //poco/1.1.0/XML/src/DocumentEvent.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DocumentEvent.h"
XML_BEGIN
DocumentEvent::~DocumentEvent()
{
}
XML_END

View File

@@ -0,0 +1,91 @@
//
// DocumentFragment.cpp
//
// $Id: //poco/1.1.0/XML/src/DocumentFragment.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DocumentFragment.h"
XML_BEGIN
const XMLString DocumentFragment::NODE_NAME = toXMLString("#document-fragment");
DocumentFragment::DocumentFragment(Document* pOwnerDocument):
AbstractContainerNode(pOwnerDocument)
{
}
DocumentFragment::DocumentFragment( Document* pOwnerDocument, const DocumentFragment& fragment):
AbstractContainerNode(pOwnerDocument, fragment)
{
}
DocumentFragment::~DocumentFragment()
{
}
const XMLString& DocumentFragment::nodeName() const
{
return NODE_NAME;
}
unsigned short DocumentFragment::nodeType() const
{
return Node::DOCUMENT_FRAGMENT_NODE;
}
Node* DocumentFragment::copyNode(bool deep, Document* pOwnerDocument) const
{
DocumentFragment* pClone = new DocumentFragment(pOwnerDocument, *this);
if (deep)
{
Node* pCur = firstChild();
while (pCur)
{
pClone->appendChild(static_cast<AbstractNode*>(pCur)->copyNode(deep, pOwnerDocument))->release();
pCur = pCur->nextSibling();
}
}
return pClone;
}
XML_END

105
XML/src/DocumentType.cpp Normal file
View File

@@ -0,0 +1,105 @@
//
// DocumentType.cpp
//
// $Id: //poco/1.1.0/XML/src/DocumentType.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/DocumentType.h"
#include "DOM/Document.h"
#include "DOM/DTDMap.h"
#include "DOM/DOMException.h"
XML_BEGIN
DocumentType::DocumentType(Document* pOwner, const XMLString& name, const XMLString& publicId, const XMLString& systemId):
AbstractContainerNode(pOwner),
_name(name),
_publicId(publicId),
_systemId(systemId)
{
}
DocumentType::DocumentType(Document* pOwner, const DocumentType& doctype):
AbstractContainerNode(pOwner, doctype),
_name(doctype._name),
_publicId(doctype._publicId),
_systemId(doctype._systemId)
{
}
DocumentType::~DocumentType()
{
}
NamedNodeMap* DocumentType::entities() const
{
return new DTDMap(this, Node::ENTITY_NODE);
}
NamedNodeMap* DocumentType::notations() const
{
return new DTDMap(this, Node::NOTATION_NODE);
}
const XMLString& DocumentType::nodeName() const
{
return _name;
}
unsigned short DocumentType::nodeType() const
{
return Node::DOCUMENT_TYPE_NODE;
}
const XMLString& DocumentType::internalSubset() const
{
return EMPTY_STRING;
}
Node* DocumentType::copyNode(bool deep, Document* pOwnerDocument) const
{
return new DocumentType(pOwnerDocument, *this);
}
XML_END

394
XML/src/Element.cpp Normal file
View File

@@ -0,0 +1,394 @@
//
// Element.cpp
//
// $Id: //poco/1.1.0/XML/src/Element.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Element.h"
#include "DOM/Document.h"
#include "DOM/Attr.h"
#include "DOM/DOMException.h"
#include "DOM/ElementsByTagNameList.h"
#include "DOM/Text.h"
#include "DOM/AttrMap.h"
XML_BEGIN
Element::Element(Document* pOwnerDocument, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname):
AbstractContainerNode(pOwnerDocument),
_name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)),
_pFirstAttr(0)
{
}
Element::Element(Document* pOwnerDocument, const Element& element):
AbstractContainerNode(pOwnerDocument, element),
_name(pOwnerDocument->namePool().insert(element._name)),
_pFirstAttr(0)
{
Attr* pAttr = element._pFirstAttr;
while (pAttr)
{
Attr* pClonedAttr = static_cast<Attr*>(pAttr->copyNode(false, pOwnerDocument));
setAttributeNode(pClonedAttr);
pClonedAttr->release();
pAttr = static_cast<Attr*>(pAttr->_pNext);
}
}
Element::~Element()
{
if (_pFirstAttr) _pFirstAttr->release();
}
const XMLString& Element::getAttribute(const XMLString& name) const
{
Attr* pAttr = getAttributeNode(name);
if (pAttr)
return pAttr->getValue();
else
return EMPTY_STRING;
}
void Element::setAttribute(const XMLString& name, const XMLString& value)
{
Attr* pAttr = getAttributeNode(name);
if (pAttr)
{
pAttr->setValue(value);
}
else
{
pAttr = ownerDocument()->createAttribute(name);
pAttr->setValue(value);
setAttributeNode(pAttr);
pAttr->release();
}
}
void Element::removeAttribute(const XMLString& name)
{
Attr* pAttr = getAttributeNode(name);
if (pAttr) removeAttributeNode(pAttr);
}
Attr* Element::getAttributeNode(const XMLString& name) const
{
Attr* pAttr = _pFirstAttr;
while (pAttr && pAttr->_name.qname() != name) pAttr = static_cast<Attr*>(pAttr->_pNext);
return pAttr;
}
Attr* Element::setAttributeNode(Attr* newAttr)
{
poco_check_ptr (newAttr);
if (newAttr->ownerDocument() != ownerDocument())
throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
if (newAttr->ownerElement())
throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR);
Attr* oldAttr = getAttributeNode(newAttr->name());
if (oldAttr) removeAttributeNode(oldAttr);
Attr* pCur = _pFirstAttr;
if (pCur)
{
while (pCur->_pNext) pCur = static_cast<Attr*>(pCur->_pNext);
pCur->_pNext = newAttr;
}
else _pFirstAttr = newAttr;
newAttr->duplicate();
newAttr->_pParent = this;
if (_pOwner->events())
dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue());
return oldAttr;
}
Attr* Element::removeAttributeNode(Attr* oldAttr)
{
poco_check_ptr (oldAttr);
if (_pOwner->events())
dispatchAttrModified(oldAttr, MutationEvent::REMOVAL, oldAttr->getValue(), EMPTY_STRING);
if (oldAttr != _pFirstAttr)
{
Attr* pCur = _pFirstAttr;
while (pCur->_pNext != oldAttr) pCur = static_cast<Attr*>(pCur->_pNext);
if (pCur)
{
pCur->_pNext = static_cast<Attr*>(pCur->_pNext->_pNext);
}
else throw DOMException(DOMException::NOT_FOUND_ERR);
}
else _pFirstAttr = static_cast<Attr*>(_pFirstAttr->_pNext);
oldAttr->_pNext = 0;
oldAttr->_pParent = 0;
oldAttr->autoRelease();
return oldAttr;
}
NodeList* Element::getElementsByTagName(const XMLString& name) const
{
return new ElementsByTagNameList(this, name);
}
NodeList* Element::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const
{
return new ElementsByTagNameListNS(this, namespaceURI, localName);
}
void Element::normalize()
{
Node* pCur = firstChild();
while (pCur)
{
if (pCur->nodeType() == Node::ELEMENT_NODE)
{
pCur->normalize();
}
else if (pCur->nodeType() == Node::TEXT_NODE)
{
Node* pNext = pCur->nextSibling();
while (pNext && pNext->nodeType() == Node::TEXT_NODE)
{
static_cast<Text*>(pCur)->appendData(pNext->nodeValue());
removeChild(pNext);
pNext = pCur->nextSibling();
}
}
pCur = pCur->nextSibling();
}
}
const XMLString& Element::nodeName() const
{
return tagName();
}
NamedNodeMap* Element::attributes() const
{
return new AttrMap(const_cast<Element*>(this));
}
unsigned short Element::nodeType() const
{
return Node::ELEMENT_NODE;
}
const XMLString& Element::getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const
{
Attr* pAttr = getAttributeNodeNS(namespaceURI, localName);
if (pAttr)
return pAttr->getValue();
else
return EMPTY_STRING;
}
void Element::setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value)
{
Attr* pAttr = getAttributeNodeNS(namespaceURI, qualifiedName);
if (pAttr)
{
pAttr->setValue(value);
}
else
{
pAttr = _pOwner->createAttributeNS(namespaceURI, qualifiedName);
pAttr->setValue(value);
setAttributeNodeNS(pAttr);
pAttr->release();
}
}
void Element::removeAttributeNS(const XMLString& namespaceURI, const XMLString& localName)
{
Attr* pAttr = getAttributeNodeNS(namespaceURI, localName);
if (pAttr) removeAttributeNode(pAttr);
}
Attr* Element::getAttributeNodeNS(const XMLString& namespaceURI, const XMLString& localName) const
{
Attr* pAttr = _pFirstAttr;
while (pAttr && (pAttr->_name.namespaceURI() != namespaceURI || pAttr->_name.localName() != localName)) pAttr = static_cast<Attr*>(pAttr->_pNext);
return pAttr;
}
Attr* Element::setAttributeNodeNS(Attr* newAttr)
{
poco_check_ptr (newAttr);
if (newAttr->ownerDocument() != ownerDocument())
throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
if (newAttr->ownerElement())
throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR);
Attr* oldAttr = getAttributeNodeNS(newAttr->namespaceURI(), newAttr->localName());
if (oldAttr) removeAttributeNode(oldAttr);
Attr* pCur = _pFirstAttr;
if (pCur)
{
while (pCur->_pNext) pCur = static_cast<Attr*>(pCur->_pNext);
pCur->_pNext = newAttr;
}
else _pFirstAttr = newAttr;
newAttr->_pParent = this;
newAttr->duplicate();
if (_pOwner->events())
dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue());
return oldAttr;
}
bool Element::hasAttribute(const XMLString& name) const
{
return getAttributeNode(name) != 0;
}
bool Element::hasAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const
{
return getAttributeNodeNS(namespaceURI, localName) != 0;
}
const XMLString& Element::namespaceURI() const
{
return _name.namespaceURI();
}
XMLString Element::prefix() const
{
return _name.prefix();
}
const XMLString& Element::localName() const
{
return _name.localName();
}
bool Element::hasAttributes() const
{
return _pFirstAttr != 0;
}
Element* Element::getChildElement(const XMLString& name) const
{
Node* pNode = firstChild();
while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->nodeName() == name))
pNode = pNode->nextSibling();
return static_cast<Element*>(pNode);
}
Element* Element::getChildElementNS(const XMLString& namespaceURI, const XMLString& localName) const
{
Node* pNode = firstChild();
while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->namespaceURI() == namespaceURI && pNode->localName() == localName))
pNode = pNode->nextSibling();
return static_cast<Element*>(pNode);
}
void Element::dispatchNodeRemovedFromDocument()
{
AbstractContainerNode::dispatchNodeRemovedFromDocument();
Attr* pAttr = _pFirstAttr;
while (pAttr)
{
pAttr->dispatchNodeRemovedFromDocument();
pAttr = static_cast<Attr*>(pAttr->_pNext);
}
}
void Element::dispatchNodeInsertedIntoDocument()
{
AbstractContainerNode::dispatchNodeInsertedIntoDocument();
Attr* pAttr = _pFirstAttr;
while (pAttr)
{
pAttr->dispatchNodeInsertedIntoDocument();
pAttr = static_cast<Attr*>(pAttr->_pNext);
}
}
Node* Element::copyNode(bool deep, Document* pOwnerDocument) const
{
Element* pClone = new Element(pOwnerDocument, *this);
if (deep)
{
Node* pNode = firstChild();
while (pNode)
{
pClone->appendChild(static_cast<AbstractNode*>(pNode)->copyNode(true, pOwnerDocument))->release();
pNode = pNode->nextSibling();
}
}
return pClone;
}
XML_END

View File

@@ -0,0 +1,169 @@
//
// ElementsByTagNameList.cpp
//
// $Id: //poco/1.1.0/XML/src/ElementsByTagNameList.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/ElementsByTagNameList.h"
#include "DOM/Node.h"
#include "DOM/Document.h"
XML_BEGIN
ElementsByTagNameList::ElementsByTagNameList(const Node* pParent, const XMLString& name):
_pParent(pParent),
_name(name),
_count(0)
{
poco_check_ptr (pParent);
_pParent->duplicate();
}
ElementsByTagNameList::~ElementsByTagNameList()
{
_pParent->release();
}
Node* ElementsByTagNameList::item(unsigned long index) const
{
_count = 0;
return find(_pParent, index);
}
unsigned long ElementsByTagNameList::length() const
{
_count = 0;
find(_pParent, ULONG_MAX);
return _count;
}
Node* ElementsByTagNameList::find(const Node* pParent, unsigned long index) const
{
static const XMLString asterisk = toXMLString("*");
if (!pParent) return 0;
// preorder search
Node* pCur = pParent->firstChild();
while (pCur)
{
if (pCur->nodeType() == Node::ELEMENT_NODE && (_name == asterisk || pCur->nodeName() == _name))
{
if (_count == index) return pCur;
_count++;
}
Node* pNode = find(pCur, index);
if (pNode) return pNode;
pCur = pCur->nextSibling();
}
return pCur;
}
void ElementsByTagNameList::autoRelease()
{
_pParent->ownerDocument()->autoReleasePool().add(this);
}
ElementsByTagNameListNS::ElementsByTagNameListNS(const Node* pParent, const XMLString& namespaceURI, const XMLString& localName):
_pParent(pParent),
_localName(localName),
_namespaceURI(namespaceURI),
_count(0)
{
poco_check_ptr (pParent);
_pParent->duplicate();
}
ElementsByTagNameListNS::~ElementsByTagNameListNS()
{
_pParent->release();
}
Node* ElementsByTagNameListNS::item(unsigned long index) const
{
_count = 0;
return find(_pParent, index);
}
unsigned long ElementsByTagNameListNS::length() const
{
_count = 0;
find(_pParent, ULONG_MAX);
return _count;
}
Node* ElementsByTagNameListNS::find(const Node* pParent, unsigned long index) const
{
static const XMLString asterisk = toXMLString("*");
if (!pParent) return 0;
// preorder search
Node* pCur = pParent->firstChild();
while (pCur)
{
if (pCur->nodeType() == Node::ELEMENT_NODE && (_localName == asterisk || pCur->localName() == _localName) && (_namespaceURI == asterisk || pCur->namespaceURI() == _namespaceURI))
{
if (_count == index) return pCur;
_count++;
}
Node* pNode = find(pCur, index);
if (pNode) return pNode;
pCur = pCur->nextSibling();
}
return pCur;
}
void ElementsByTagNameListNS::autoRelease()
{
_pParent->ownerDocument()->autoReleasePool().add(this);
}
XML_END

89
XML/src/Entity.cpp Normal file
View File

@@ -0,0 +1,89 @@
//
// Entity.cpp
//
// $Id: //poco/1.1.0/XML/src/Entity.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Entity.h"
XML_BEGIN
const XMLString Entity::NODE_NAME = toXMLString("#entity");
Entity::Entity(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName):
AbstractContainerNode(pOwnerDocument),
_name(name),
_publicId(publicId),
_systemId(systemId),
_notationName(notationName)
{
}
Entity::Entity(Document* pOwnerDocument, const Entity& entity):
AbstractContainerNode(pOwnerDocument, entity),
_name(entity._name),
_publicId(entity._publicId),
_systemId(entity._systemId),
_notationName(entity._notationName)
{
}
Entity::~Entity()
{
}
const XMLString& Entity::nodeName() const
{
return _name;
}
unsigned short Entity::nodeType() const
{
return Node::ENTITY_NODE;
}
Node* Entity::copyNode(bool deep, Document* pOwnerDocument) const
{
return new Entity(pOwnerDocument, *this);
}
XML_END

View File

@@ -0,0 +1,80 @@
//
// EntityReference.cpp
//
// $Id: //poco/1.1.0/XML/src/EntityReference.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/EntityReference.h"
XML_BEGIN
EntityReference::EntityReference(Document* pOwnerDocument, const XMLString& name):
AbstractNode(pOwnerDocument),
_name(name)
{
}
EntityReference::EntityReference(Document* pOwnerDocument, const EntityReference& ref):
AbstractNode(pOwnerDocument, ref),
_name(ref._name)
{
}
EntityReference::~EntityReference()
{
}
const XMLString& EntityReference::nodeName() const
{
return _name;
}
unsigned short EntityReference::nodeType() const
{
return Node::ENTITY_REFERENCE_NODE;
}
Node* EntityReference::copyNode(bool deep, Document* pOwnerDocument) const
{
return new EntityReference(pOwnerDocument, *this);
}
XML_END

View File

@@ -0,0 +1,48 @@
//
// EntityResolver.cpp
//
// $Id: //poco/1.1.0/XML/src/EntityResolver.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/EntityResolver.h"
XML_BEGIN
EntityResolver::~EntityResolver()
{
}
XML_END

View File

@@ -0,0 +1,100 @@
//
// EntityResolverImpl.cpp
//
// $Id: //poco/1.1.0/XML/src/EntityResolverImpl.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/EntityResolverImpl.h"
#include "SAX/InputSource.h"
#include "XML/XMLString.h"
#include "Foundation/URI.h"
#include "Foundation/Path.h"
#include "Foundation/Exception.h"
#include <fstream>
using Foundation::URIStreamOpener;
using Foundation::URI;
using Foundation::Path;
using Foundation::Exception;
using Foundation::IOException;
using Foundation::OpenFileException;
XML_BEGIN
EntityResolverImpl::EntityResolverImpl():
_opener(URIStreamOpener::defaultOpener())
{
}
EntityResolverImpl::EntityResolverImpl(const URIStreamOpener& opener):
_opener(opener)
{
}
EntityResolverImpl::~EntityResolverImpl()
{
}
InputSource* EntityResolverImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId)
{
std::istream* pIstr = resolveSystemId(systemId);
InputSource* pInputSource = new InputSource(systemId);
if (publicId) pInputSource->setPublicId(*publicId);
pInputSource->setByteStream(*pIstr);
return pInputSource;
}
void EntityResolverImpl::releaseInputSource(InputSource* pSource)
{
poco_check_ptr (pSource);
delete pSource->getByteStream();
delete pSource;
}
std::istream* EntityResolverImpl::resolveSystemId(const XMLString& systemId)
{
std::string sid = fromXMLString(systemId);
return _opener.open(sid);
}
XML_END

48
XML/src/ErrorHandler.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// ErrorHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/ErrorHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/ErrorHandler.h"
XML_BEGIN
ErrorHandler::~ErrorHandler()
{
}
XML_END

123
XML/src/Event.cpp Normal file
View File

@@ -0,0 +1,123 @@
//
// Event.cpp
//
// $Id: //poco/1.1.0/XML/src/Event.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Event.h"
#include "DOM/Document.h"
XML_BEGIN
Event::Event(Document* pOwnerDocument, const XMLString& type):
_pOwner(pOwnerDocument),
_type(type),
_pTarget(0),
_pCurrentTarget(0),
_currentPhase(CAPTURING_PHASE),
_bubbles(true),
_cancelable(true),
_canceled(false),
_stopped(false)
{
}
Event::Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable):
_pOwner(pOwnerDocument),
_type(type),
_pTarget(pTarget),
_pCurrentTarget(0),
_currentPhase(CAPTURING_PHASE),
_bubbles(canBubble),
_cancelable(isCancelable),
_canceled(false),
_stopped(false)
{
}
Event::~Event()
{
}
void Event::stopPropagation()
{
_stopped = true;
}
void Event::preventDefault()
{
_canceled = true;
}
void Event::initEvent(const XMLString& eventType, bool canBubble, bool isCancelable)
{
_type = eventType;
_bubbles = canBubble;
_cancelable = isCancelable;
_canceled = false;
_stopped = false;
}
void Event::setTarget(EventTarget* pTarget)
{
_pTarget = pTarget;
}
void Event::setCurrentPhase(PhaseType phase)
{
_currentPhase = phase;
}
void Event::setCurrentTarget(EventTarget* pTarget)
{
_pCurrentTarget = pTarget;
}
void Event::autoRelease()
{
_pOwner->autoReleasePool().add(this);
}
XML_END

167
XML/src/EventDispatcher.cpp Normal file
View File

@@ -0,0 +1,167 @@
//
// EventDispatcher.cpp
//
// $Id: //poco/1.1.0/XML/src/EventDispatcher.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/EventDispatcher.h"
#include "DOM/Event.h"
#include "DOM/EventListener.h"
namespace
{
class DispatchGuard
{
public:
DispatchGuard(int& count):
_count(count)
{
++_count;
}
~DispatchGuard()
{
--_count;
}
private:
int& _count;
};
}
XML_BEGIN
EventDispatcher::EventDispatcher():
_inDispatch(0)
{
}
EventDispatcher::~EventDispatcher()
{
}
void EventDispatcher::addEventListener(const XMLString& type, EventListener* listener, bool useCapture)
{
EventListenerItem item;
item.type = type;
item.pListener = listener;
item.useCapture = useCapture;
_listeners.push_front(item);
}
void EventDispatcher::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture)
{
EventListenerList::iterator it = _listeners.begin();
while (it != _listeners.end())
{
if (it->type == type && it->pListener == listener && it->useCapture == useCapture)
{
it->pListener = 0;
}
if (!_inDispatch && !it->pListener)
{
EventListenerList::iterator del = it++;
_listeners.erase(del);
}
else ++it;
}
}
void EventDispatcher::dispatchEvent(Event* evt)
{
DispatchGuard guard(_inDispatch);
EventListenerList::iterator it = _listeners.begin();
while (it != _listeners.end())
{
if (it->pListener && it->type == evt->type())
{
it->pListener->handleEvent(evt);
}
if (!it->pListener)
{
EventListenerList::iterator del = it++;
_listeners.erase(del);
}
else ++it;
}
}
void EventDispatcher::captureEvent(Event* evt)
{
DispatchGuard guard(_inDispatch);
EventListenerList::iterator it = _listeners.begin();
while (it != _listeners.end())
{
if (it->pListener && it->useCapture && it->type == evt->type())
{
it->pListener->handleEvent(evt);
}
if (!it->pListener)
{
EventListenerList::iterator del = it++;
_listeners.erase(del);
}
else ++it;
}
}
void EventDispatcher::bubbleEvent(Event* evt)
{
DispatchGuard guard(_inDispatch);
EventListenerList::iterator it = _listeners.begin();
while (it != _listeners.end())
{
if (it->pListener && !it->useCapture && it->type == evt->type())
{
it->pListener->handleEvent(evt);
}
if (!it->pListener)
{
EventListenerList::iterator del = it++;
_listeners.erase(del);
}
else ++it;
}
}
XML_END

View File

@@ -0,0 +1,86 @@
//
// EventException.cpp
//
// $Id: //poco/1.1.0/XML/src/EventException.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/EventException.h"
#include <typeinfo>
XML_BEGIN
EventException::EventException(int code):
XMLException("Unspecified event type")
{
}
EventException::EventException(const EventException& exc):
XMLException(exc)
{
}
EventException::~EventException() throw()
{
}
EventException& EventException::operator = (const EventException& exc)
{
XMLException::operator = (exc);
return *this;
}
const char* EventException::name() const throw()
{
return "EventException";
}
const char* EventException::className() const throw()
{
return typeid(*this).name();
}
Foundation::Exception* EventException::clone() const
{
return new EventException(*this);
}
XML_END

48
XML/src/EventListener.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// EventListener.cpp
//
// $Id: //poco/1.1.0/XML/src/EventListener.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/EventListener.h"
XML_BEGIN
EventListener::~EventListener()
{
}
XML_END

48
XML/src/EventTarget.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// EventTarget.cpp
//
// $Id: //poco/1.1.0/XML/src/EventTarget.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/EventTarget.h"
XML_BEGIN
EventTarget::~EventTarget()
{
}
XML_END

101
XML/src/InputSource.cpp Normal file
View File

@@ -0,0 +1,101 @@
//
// InputSource.cpp
//
// $Id: //poco/1.1.0/XML/src/InputSource.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/InputSource.h"
XML_BEGIN
InputSource::InputSource():
_bistr(0),
_cistr(0)
{
}
InputSource::InputSource(const XMLString& systemId):
_systemId(systemId),
_bistr(0),
_cistr(0)
{
}
InputSource::InputSource(XMLByteInputStream& bistr):
_bistr(&bistr),
_cistr(0)
{
}
InputSource::~InputSource()
{
}
void InputSource::setPublicId(const XMLString& publicId)
{
_publicId = publicId;
}
void InputSource::setSystemId(const XMLString& systemId)
{
_systemId = systemId;
}
void InputSource::setEncoding(const XMLString& encoding)
{
_encoding = encoding;
}
void InputSource::setByteStream(XMLByteInputStream& bistr)
{
_bistr = &bistr;
}
void InputSource::setCharacterStream(XMLCharInputStream& cistr)
{
_cistr = &cistr;
}
XML_END

View File

@@ -0,0 +1,48 @@
//
// LexicalHandler.cpp
//
// $Id: //poco/1.1.0/XML/src/LexicalHandler.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/LexicalHandler.h"
XML_BEGIN
LexicalHandler::~LexicalHandler()
{
}
XML_END

48
XML/src/Locator.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// Locator.cpp
//
// $Id: //poco/1.1.0/XML/src/Locator.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/Locator.h"
XML_BEGIN
Locator::~Locator()
{
}
XML_END

125
XML/src/LocatorImpl.cpp Normal file
View File

@@ -0,0 +1,125 @@
//
// LocatorImpl.cpp
//
// $Id: //poco/1.1.0/XML/src/LocatorImpl.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/LocatorImpl.h"
XML_BEGIN
LocatorImpl::LocatorImpl()
{
_lineNumber = 0;
_columnNumber = 0;
}
LocatorImpl::LocatorImpl(const Locator& loc)
{
_publicId = loc.getPublicId();
_systemId = loc.getSystemId();
_lineNumber = loc.getLineNumber();
_columnNumber = loc.getColumnNumber();
}
LocatorImpl::~LocatorImpl()
{
}
LocatorImpl& LocatorImpl::operator = (const Locator& loc)
{
if (&loc != this)
{
_publicId = loc.getPublicId();
_systemId = loc.getSystemId();
_lineNumber = loc.getLineNumber();
_columnNumber = loc.getColumnNumber();
}
return *this;
}
XMLString LocatorImpl::getPublicId() const
{
return _publicId;
}
XMLString LocatorImpl::getSystemId() const
{
return _systemId;
}
int LocatorImpl::getLineNumber() const
{
return _lineNumber;
}
int LocatorImpl::getColumnNumber() const
{
return _columnNumber;
}
void LocatorImpl::setPublicId(const XMLString& publicId)
{
_publicId = publicId;
}
void LocatorImpl::setSystemId(const XMLString& systemId)
{
_systemId = systemId;
}
void LocatorImpl::setLineNumber(int lineNumber)
{
_lineNumber = lineNumber;
}
void LocatorImpl::setColumnNumber(int columnNumber)
{
_columnNumber = columnNumber;
}
XML_END

97
XML/src/MutationEvent.cpp Normal file
View File

@@ -0,0 +1,97 @@
//
// MutationEvent.cpp
//
// $Id: //poco/1.1.0/XML/src/MutationEvent.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOMEvents
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/MutationEvent.h"
XML_BEGIN
const XMLString MutationEvent::DOMSubtreeModified = toXMLString("DOMSubtreeModified");
const XMLString MutationEvent::DOMNodeInserted = toXMLString("DOMNodeInserted");
const XMLString MutationEvent::DOMNodeRemoved = toXMLString("DOMNodeRemoved");
const XMLString MutationEvent::DOMNodeRemovedFromDocument = toXMLString("DOMNodeRemovedFromDocument");
const XMLString MutationEvent::DOMNodeInsertedIntoDocument = toXMLString("DOMNodeInsertedIntoDocument");
const XMLString MutationEvent::DOMAttrModified = toXMLString("DOMAttrModified");
const XMLString MutationEvent::DOMCharacterDataModified = toXMLString("DOMCharacterDataModified");
MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type):
Event(pOwnerDocument, type, 0, true, false),
_change(MODIFICATION),
_pRelatedNode(0)
{
}
MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode):
Event(pOwnerDocument, type, pTarget, canBubble, cancelable),
_change(MODIFICATION),
_pRelatedNode(relatedNode)
{
}
MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode,
const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change):
Event(pOwnerDocument, type, pTarget, canBubble, cancelable),
_prevValue(prevValue),
_newValue(newValue),
_attrName(attrName),
_change(change),
_pRelatedNode(relatedNode)
{
}
MutationEvent::~MutationEvent()
{
}
void MutationEvent::initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode,
const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change)
{
initEvent(type, canBubble, cancelable);
_pRelatedNode = relatedNode;
_prevValue = prevValue;
_newValue = newValue;
_attrName = attrName;
_change = change;
}
XML_END

191
XML/src/Name.cpp Normal file
View File

@@ -0,0 +1,191 @@
//
// Name.cpp
//
// $Id: //poco/1.1.0/XML/src/Name.cpp#2 $
//
// Library: XML
// Package: XML
// Module: Name
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/Name.h"
#include <algorithm>
XML_BEGIN
const XMLString Name::EMPTY_NAME;
Name::Name()
{
}
Name::Name(const XMLString& qname):
_qname(qname)
{
}
Name::Name(const XMLString& qname, const XMLString& namespaceURI):
_qname(qname),
_namespaceURI(namespaceURI),
_localName(localName(qname))
{
}
Name::Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName):
_qname(qname),
_namespaceURI(namespaceURI),
_localName(localName)
{
}
Name::Name(const Name& name):
_qname(name._qname),
_namespaceURI(name._namespaceURI),
_localName(name._localName)
{
}
Name::~Name()
{
}
Name& Name::operator = (const Name& name)
{
if (this != &name)
{
_qname = name._qname;
_namespaceURI = name._namespaceURI;
_localName = name._localName;
}
return *this;
}
void Name::swap(Name& name)
{
std::swap(_qname, name._qname);
std::swap(_namespaceURI, name._namespaceURI);
std::swap(_localName, name._localName);
}
void Name::assign(const XMLString& qname)
{
_qname = qname;
_namespaceURI.clear();
_localName.clear();
}
void Name::assign(const XMLString& qname, const XMLString& namespaceURI)
{
_qname = qname;
_namespaceURI = namespaceURI;
_localName = localName(qname);
}
void Name::assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
_qname = qname;
_namespaceURI = namespaceURI;
_localName = localName;
}
bool Name::equals(const Name& name) const
{
return name._namespaceURI == _namespaceURI && name._localName == _localName && name._qname == _qname;
}
bool Name::equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const
{
return _namespaceURI == namespaceURI && _localName == localName && _qname == qname;
}
bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const
{
return _qname == qname && !qname.empty() || _namespaceURI == namespaceURI && _localName == localName && !_localName.empty();
}
XMLString Name::prefix() const
{
return prefix(_qname);
}
void Name::split(const XMLString& qname, XMLString& prefix, XMLString& localName)
{
XMLString::size_type pos = qname.find(':');
if (pos != XMLString::npos)
{
prefix.assign(qname, 0, pos);
localName.assign(qname, pos + 1, qname.size() - pos - 1);
}
else
{
prefix.clear();
localName.assign(qname);
}
}
XMLString Name::localName(const XMLString& qname)
{
XMLString::size_type pos = qname.find(':');
if (pos != XMLString::npos)
return XMLString(qname, pos + 1, qname.size() - pos - 1);
else
return qname;
}
XMLString Name::prefix(const XMLString& qname)
{
XMLString::size_type pos = qname.find(':');
if (pos != XMLString::npos)
return XMLString(qname, 0, pos);
else
return EMPTY_NAME;
}
XML_END

147
XML/src/NamePool.cpp Normal file
View File

@@ -0,0 +1,147 @@
//
// NamePool.cpp
//
// $Id: //poco/1.1.0/XML/src/NamePool.cpp#2 $
//
// Library: XML
// Package: XML
// Module: NamePool
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/NamePool.h"
#include "Foundation/Exception.h"
XML_BEGIN
class NamePoolItem
{
public:
NamePoolItem(): _used(false)
{
}
~NamePoolItem()
{
}
bool set(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
if (!_used)
{
_name.assign(qname, namespaceURI, localName);
_used = true;
return true;
}
else return _name.equals(qname, namespaceURI, localName);
}
const Name& get() const
{
return _name;
}
bool used() const
{
return _used;
}
private:
Name _name;
bool _used;
};
NamePool::NamePool(unsigned long size):
_size(size),
_rc(1)
{
poco_assert (size > 1);
_pItems = new NamePoolItem[size];
}
NamePool::~NamePool()
{
delete [] _pItems;
}
void NamePool::duplicate()
{
++_rc;
}
void NamePool::release()
{
if (--_rc == 0)
delete this;
}
const Name& NamePool::insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
unsigned long i = 0;
unsigned long n = hash(qname, namespaceURI, localName) % _size;
while (!_pItems[n].set(qname, namespaceURI, localName) && i++ < _size)
n = (n + 1) % _size;
if (i > _size) throw Foundation::PoolOverflowException("XML name pool");
return _pItems[n].get();
}
const Name& NamePool::insert(const Name& name)
{
return insert(name.qname(), name.namespaceURI(), name.localName());
}
unsigned long NamePool::hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
unsigned long h = 0;
XMLString::const_iterator it = qname.begin();
XMLString::const_iterator end = qname.end();
while (it != end) h = (h << 5) + h + (unsigned long) *it++;
it = namespaceURI.begin();
end = namespaceURI.end();
while (it != end) h = (h << 5) + h + (unsigned long) *it++;
it = localName.begin();
end = localName.end();
while (it != end) h = (h << 5) + h + (unsigned long) *it++;
return h;
}
XML_END

48
XML/src/NamedNodeMap.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// NamedNodeMap.cpp
//
// $Id: //poco/1.1.0/XML/src/NamedNodeMap.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/NamedNodeMap.h"
XML_BEGIN
NamedNodeMap::~NamedNodeMap()
{
}
XML_END

View File

@@ -0,0 +1,210 @@
//
// NamespaceStrategy.cpp
//
// $Id: //poco/1.1.0/XML/src/NamespaceStrategy.cpp#2 $
//
// Library: XML
// Package: XML
// Module: NamespaceStrategy
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/NamespaceStrategy.h"
#include "SAX/AttributesImpl.h"
#include "SAX/ContentHandler.h"
#include "XML/XMLException.h"
#include "XML/Name.h"
XML_BEGIN
const XMLString NamespaceStrategy::NOTHING;
const XMLString NamespaceStrategy::CDATA = toXMLString("CDATA");
const XMLString NamespaceStrategy::COLON = toXMLString(":");
NamespaceStrategy::~NamespaceStrategy()
{
}
void NamespaceStrategy::splitName(const XMLChar* qname, XMLString& uri, XMLString& localName)
{
for (const XMLChar* p = qname; *p; ++p)
{
if (*p == '\t')
{
uri.assign(qname, p - qname);
localName.assign(p + 1);
return;
}
}
localName = qname;
}
void NamespaceStrategy::splitName(const XMLChar* qname, XMLString& uri, XMLString& localName, XMLString& prefix)
{
const XMLChar* p = qname;
while (*p && *p != '\t') ++p;
if (*p)
{
uri.assign(qname, p - qname);
++p;
const XMLChar* loc = p;
while (*p && *p != '\t') ++p;
localName.assign(loc, p - loc);
if (*p)
prefix.assign(++p);
}
else localName = qname;
}
NoNamespacesStrategy::NoNamespacesStrategy()
{
}
NoNamespacesStrategy::~NoNamespacesStrategy()
{
}
void NoNamespacesStrategy::startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && atts && pContentHandler);
AttributesImpl attributes;
for (int i = 0; *atts; ++i)
{
const XMLChar* attrName = *atts++;
const XMLChar* attrValue = *atts++;
attributes.addAttribute(NOTHING, NOTHING, attrName, CDATA, attrValue, i < specifiedCount);
}
pContentHandler->startElement(NOTHING, NOTHING, name, attributes);
}
void NoNamespacesStrategy::endElement(const XMLChar* name, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && pContentHandler);
pContentHandler->endElement(NOTHING, NOTHING, name);
}
NoNamespacePrefixesStrategy::NoNamespacePrefixesStrategy()
{
}
NoNamespacePrefixesStrategy::~NoNamespacePrefixesStrategy()
{
}
void NoNamespacePrefixesStrategy::startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && atts && pContentHandler);
AttributesImpl attributes;
for (int i = 0; *atts; ++i)
{
const XMLChar* attrName = *atts++;
const XMLChar* attrValue = *atts++;
XMLString attrURI;
XMLString attrLocal;
splitName(attrName, attrURI, attrLocal);
attributes.addAttribute(attrURI, attrLocal, NOTHING, CDATA, attrValue, i < specifiedCount);
}
XMLString uri;
XMLString local;
splitName(name, uri, local);
pContentHandler->startElement(uri, local, NOTHING, attributes);
}
void NoNamespacePrefixesStrategy::endElement(const XMLChar* name, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && pContentHandler);
XMLString uri;
XMLString local;
splitName(name, uri, local);
pContentHandler->endElement(uri, local, NOTHING);
}
NamespacePrefixesStrategy::NamespacePrefixesStrategy()
{
}
NamespacePrefixesStrategy::~NamespacePrefixesStrategy()
{
}
void NamespacePrefixesStrategy::startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && atts && pContentHandler);
AttributesImpl attributes;
for (int i = 0; *atts; ++i)
{
const XMLChar* attrName = *atts++;
const XMLChar* attrValue = *atts++;
XMLString attrURI;
XMLString attrLocal;
XMLString attrPrefix;
splitName(attrName, attrURI, attrLocal, attrPrefix);
attributes.addAttribute(attrURI, attrLocal, attrPrefix, CDATA, attrValue, i < specifiedCount);
}
XMLString uri;
XMLString local;
XMLString prefix;
splitName(name, uri, local, prefix);
pContentHandler->startElement(uri, local, prefix, attributes);
}
void NamespacePrefixesStrategy::endElement(const XMLChar* name, ContentHandler* pContentHandler)
{
poco_assert_dbg (name && pContentHandler);
XMLString uri;
XMLString local;
XMLString prefix;
splitName(name, uri, local, prefix);
pContentHandler->endElement(uri, local, prefix);
}
XML_END

View File

@@ -0,0 +1,208 @@
//
// NamespaceSupport.cpp
//
// $Id: //poco/1.1.0/XML/src/NamespaceSupport.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/NamespaceSupport.h"
#include "XML/Name.h"
XML_BEGIN
const XMLString NamespaceSupport::EMPTY_STRING;
const XMLString NamespaceSupport::XML_NAMESPACE = toXMLString("http://www.w3.org/XML/1998/namespace");
const XMLString NamespaceSupport::XML_NAMESPACE_PREFIX = toXMLString("xml");
const XMLString NamespaceSupport::XMLNS_NAMESPACE = toXMLString("http://www.w3.org/xmlns/2000/");
const XMLString NamespaceSupport::XMLNS_NAMESPACE_PREFIX = toXMLString("xmlns");
NamespaceSupport::NamespaceSupport()
{
reset();
}
NamespaceSupport::~NamespaceSupport()
{
}
bool NamespaceSupport::declarePrefix(const XMLString& prefix, const XMLString& namespaceURI)
{
poco_assert (_contexts.size() > 0);
Context& ctx = _contexts.back();
if (ctx.find(prefix) == ctx.end())
{
ctx.insert(Context::value_type(prefix, namespaceURI));
return true;
}
else return false;
}
bool NamespaceSupport::undeclarePrefix(const XMLString& prefix)
{
for (ContextVec::reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
Context::iterator it = rit->find(prefix);
if (it != rit->end())
{
rit->erase(it);
return true;
}
}
return false;
}
void NamespaceSupport::getDeclaredPrefixes(PrefixSet& prefixes) const
{
prefixes.clear();
const Context& ctx = _contexts.back();
for (Context::const_iterator it = ctx.begin(); it != ctx.end(); ++it)
prefixes.insert(it->first);
}
const XMLString& NamespaceSupport::getPrefix(const XMLString& namespaceURI) const
{
for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
{
if (it->second == namespaceURI)
return it->first;
}
}
return EMPTY_STRING;
}
bool NamespaceSupport::isMapped(const XMLString& namespaceURI) const
{
for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
{
if (it->second == namespaceURI)
return true;
}
}
return false;
}
void NamespaceSupport::getPrefixes(PrefixSet& prefixes) const
{
prefixes.clear();
for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
{
const XMLString& prefix = it->first;
if (!prefix.empty() && prefixes.find(prefix) == prefixes.end())
prefixes.insert(it->first);
}
}
}
void NamespaceSupport::getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const
{
prefixes.clear();
for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it)
{
const XMLString& prefix = it->first;
if (it->second == namespaceURI && !prefix.empty() && prefixes.find(prefix) == prefixes.end())
prefixes.insert(it->first);
}
}
}
const XMLString& NamespaceSupport::getURI(const XMLString& prefix) const
{
for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit)
{
Context::const_iterator it = rit->find(prefix);
if (it != rit->end())
return it->second;
}
return EMPTY_STRING;
}
void NamespaceSupport::pushContext()
{
_contexts.push_back(Context());
}
void NamespaceSupport::popContext()
{
_contexts.pop_back();
}
bool NamespaceSupport::processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const
{
XMLString prefix;
Name::split(qname, prefix, localName);
if (prefix.empty() && isAttribute)
{
namespaceURI.clear();
return true;
}
else
{
namespaceURI = getURI(prefix);
return !namespaceURI.empty() || prefix.empty();
}
}
void NamespaceSupport::reset()
{
_contexts.clear();
pushContext();
declarePrefix(XML_NAMESPACE_PREFIX, XML_NAMESPACE);
declarePrefix(XMLNS_NAMESPACE_PREFIX, XMLNS_NAMESPACE);
}
XML_END

48
XML/src/Node.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// Node.cpp
//
// $Id: //poco/1.1.0/XML/src/Node.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Node.h"
XML_BEGIN
Node::~Node()
{
}
XML_END

48
XML/src/NodeFilter.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// NodeFilter.cpp
//
// $Id: //poco/1.1.0/XML/src/NodeFilter.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: NodeFilter
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/NodeFilter.h"
XML_BEGIN
NodeFilter::~NodeFilter()
{
}
XML_END

197
XML/src/NodeIterator.cpp Normal file
View File

@@ -0,0 +1,197 @@
//
// NodeIterator.cpp
//
// $Id: //poco/1.1.0/XML/src/NodeIterator.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: NodeIterator
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/NodeIterator.h"
#include "DOM/AbstractNode.h"
#include "DOM/NodeFilter.h"
#include "DOM/DOMException.h"
XML_BEGIN
NodeIterator::NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter):
_pRoot(root),
_whatToShow(whatToShow),
_pFilter(pFilter),
_pCurrent(0)
{
}
NodeIterator::NodeIterator(const NodeIterator& iterator):
_pRoot(iterator._pRoot),
_whatToShow(iterator._whatToShow),
_pFilter(iterator._pFilter),
_pCurrent(iterator._pCurrent)
{
}
NodeIterator& NodeIterator::operator = (const NodeIterator& iterator)
{
if (&iterator != this)
{
_pRoot = iterator._pRoot;
_whatToShow = iterator._whatToShow;
_pFilter = iterator._pFilter;
_pCurrent = iterator._pCurrent;
}
return *this;
}
NodeIterator::~NodeIterator()
{
}
Node* NodeIterator::nextNode()
{
if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR);
if (_pCurrent)
_pCurrent = next();
else
_pCurrent = _pRoot;
while (_pCurrent && !accept(_pCurrent))
_pCurrent = next();
return _pCurrent;
}
Node* NodeIterator::previousNode()
{
if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR);
if (_pCurrent)
_pCurrent = previous();
else
_pCurrent = last();
while (_pCurrent && !accept(_pCurrent))
_pCurrent = previous();
return _pCurrent;
}
void NodeIterator::detach()
{
_pRoot = 0;
_pCurrent = 0;
}
bool NodeIterator::accept(Node* pNode) const
{
bool accept = false;
switch (pNode->nodeType())
{
case Node::ELEMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break;
case Node::ATTRIBUTE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break;
case Node::TEXT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break;
case Node::CDATA_SECTION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break;
case Node::ENTITY_REFERENCE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break;
case Node::ENTITY_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break;
case Node::PROCESSING_INSTRUCTION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break;
case Node::COMMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break;
case Node::DOCUMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break;
case Node::DOCUMENT_TYPE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break;
case Node::DOCUMENT_FRAGMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break;
case Node::NOTATION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break;
}
if (accept && _pFilter)
accept = _pFilter->acceptNode(pNode) == NodeFilter::FILTER_ACCEPT;
return accept;
}
Node* NodeIterator::next() const
{
Node* pNext = _pCurrent->firstChild();
if (pNext) return pNext;
pNext = _pCurrent;
while (pNext && pNext != _pRoot)
{
Node* pSibling = pNext->nextSibling();
if (pSibling) return pSibling;
pNext = pNext->parentNode();
}
return 0;
}
Node* NodeIterator::previous() const
{
if (_pCurrent == _pRoot) return 0;
Node* pPrev = _pCurrent->previousSibling();
while (pPrev)
{
Node* pLastChild = pPrev->lastChild();
if (pLastChild)
pPrev = pLastChild;
else
return pPrev;
}
return _pCurrent->parentNode();
}
Node* NodeIterator::last()
{
_pCurrent = _pRoot;
Node* pLast = 0;
while (_pCurrent)
{
pLast = _pCurrent;
_pCurrent = next();
}
return pLast;
}
XML_END

48
XML/src/NodeList.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// NodeList.cpp
//
// $Id: //poco/1.1.0/XML/src/NodeList.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/NodeList.h"
XML_BEGIN
NodeList::~NodeList()
{
}
XML_END

84
XML/src/Notation.cpp Normal file
View File

@@ -0,0 +1,84 @@
//
// Notation.cpp
//
// $Id: //poco/1.1.0/XML/src/Notation.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Notation.h"
XML_BEGIN
Notation::Notation(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId):
AbstractNode(pOwnerDocument),
_name(name),
_publicId(publicId),
_systemId(systemId)
{
}
Notation::Notation(Document* pOwnerDocument, const Notation& notation):
AbstractNode(pOwnerDocument, notation),
_name(notation._name),
_publicId(notation._publicId),
_systemId(notation._systemId)
{
}
Notation::~Notation()
{
}
const XMLString& Notation::nodeName() const
{
return _name;
}
unsigned short Notation::nodeType() const
{
return Node::NOTATION_NODE;
}
Node* Notation::copyNode(bool deep, Document* pOwnerDocument) const
{
return new Notation(pOwnerDocument, *this);
}
XML_END

831
XML/src/ParserEngine.cpp Normal file
View File

@@ -0,0 +1,831 @@
//
// ParserEngine.cpp
//
// $Id: //poco/1.1.0/XML/src/ParserEngine.cpp#2 $
//
// Library: XML
// Package: XML
// Module: ParserEngine
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/ParserEngine.h"
#include "XML/NamespaceStrategy.h"
#include "XML/XMLException.h"
#include "SAX/EntityResolver.h"
#include "SAX/EntityResolverImpl.h"
#include "SAX/DTDHandler.h"
#include "SAX/DeclHandler.h"
#include "SAX/ContentHandler.h"
#include "SAX/LexicalHandler.h"
#include "SAX/ErrorHandler.h"
#include "SAX/InputSource.h"
#include "SAX/Locator.h"
#include "SAX/LocatorImpl.h"
#include "SAX/SAXException.h"
#include "Foundation/URI.h"
#include <string.h>
using Foundation::URI;
using Foundation::TextEncoding;
XML_BEGIN
class ContextLocator: public Locator
{
public:
ContextLocator(XML_Parser parser, const XMLString& publicId, const XMLString& systemId):
_parser(parser),
_publicId(publicId),
_systemId(systemId)
{
}
~ContextLocator()
{
}
XMLString getPublicId() const
{
return _publicId;
}
XMLString getSystemId() const
{
return _systemId;
}
int getLineNumber() const
{
return XML_GetCurrentLineNumber(_parser);
}
int getColumnNumber() const
{
return XML_GetCurrentColumnNumber(_parser);
}
private:
XML_Parser _parser;
XMLString _publicId;
XMLString _systemId;
};
const int ParserEngine::PARSE_BUFFER_SIZE = 4096;
const XMLString ParserEngine::EMPTY_STRING;
ParserEngine::ParserEngine():
_parser(0),
_pBuffer(0),
_encodingSpecified(false),
_expandInternalEntities(true),
_externalGeneralEntities(false),
_externalParameterEntities(false),
_pNamespaceStrategy(new NoNamespacesStrategy()),
_pEntityResolver(0),
_pDTDHandler(0),
_pDeclHandler(0),
_pContentHandler(0),
_pLexicalHandler(0),
_pErrorHandler(0)
{
}
ParserEngine::ParserEngine(const XMLString& encoding):
_parser(0),
_pBuffer(0),
_encodingSpecified(true),
_encoding(encoding),
_expandInternalEntities(true),
_externalGeneralEntities(false),
_externalParameterEntities(false),
_pNamespaceStrategy(new NoNamespacesStrategy()),
_pEntityResolver(0),
_pDTDHandler(0),
_pDeclHandler(0),
_pContentHandler(0),
_pLexicalHandler(0),
_pErrorHandler(0)
{
}
ParserEngine::~ParserEngine()
{
resetContext();
if (_parser) XML_ParserFree(_parser);
delete [] _pBuffer;
delete _pNamespaceStrategy;
}
void ParserEngine::setEncoding(const XMLString& encoding)
{
_encoding = encoding;
_encodingSpecified = true;
}
void ParserEngine::addEncoding(const XMLString& name, TextEncoding* pEncoding)
{
poco_check_ptr (pEncoding);
if (_encodings.find(name) == _encodings.end())
_encodings[name] = pEncoding;
else
throw XMLException("Encoding already defined");
}
void ParserEngine::setNamespaceStrategy(NamespaceStrategy* pStrategy)
{
poco_check_ptr (pStrategy);
delete _pNamespaceStrategy;
_pNamespaceStrategy = pStrategy;
}
void ParserEngine::setExpandInternalEntities(bool flag)
{
_expandInternalEntities = flag;
}
void ParserEngine::setExternalGeneralEntities(bool flag)
{
_externalGeneralEntities = flag;
}
void ParserEngine::setExternalParameterEntities(bool flag)
{
_externalParameterEntities = flag;
}
void ParserEngine::setEntityResolver(EntityResolver* pResolver)
{
_pEntityResolver = pResolver;
}
void ParserEngine::setDTDHandler(DTDHandler* pDTDHandler)
{
_pDTDHandler = pDTDHandler;
}
void ParserEngine::setDeclHandler(DeclHandler* pDeclHandler)
{
_pDeclHandler = pDeclHandler;
}
void ParserEngine::setContentHandler(ContentHandler* pContentHandler)
{
_pContentHandler = pContentHandler;
}
void ParserEngine::setLexicalHandler(LexicalHandler* pLexicalHandler)
{
_pLexicalHandler = pLexicalHandler;
}
void ParserEngine::setErrorHandler(ErrorHandler* pErrorHandler)
{
_pErrorHandler = pErrorHandler;
}
void ParserEngine::parse(InputSource* pInputSource)
{
init();
resetContext();
pushContext(_parser, pInputSource);
if (_pContentHandler) _pContentHandler->setDocumentLocator(this);
if (_pContentHandler) _pContentHandler->startDocument();
if (pInputSource->getCharacterStream())
parseCharInputStream(*pInputSource->getCharacterStream());
else if (pInputSource->getByteStream())
parseByteInputStream(*pInputSource->getByteStream());
else throw XMLException("Input source has no stream");
if (_pContentHandler) _pContentHandler->endDocument();
popContext();
}
void ParserEngine::parseByteInputStream(XMLByteInputStream& istr)
{
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
int n = istr.gcount();
while (n > 0)
{
if (!XML_Parse(_parser, _pBuffer, n, 0))
handleError(XML_GetErrorCode(_parser));
if (istr.good())
{
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
n = istr.gcount();
}
else n = 0;
}
if (!XML_Parse(_parser, _pBuffer, 0, 1))
handleError(XML_GetErrorCode(_parser));
}
void ParserEngine::parseCharInputStream(XMLCharInputStream& istr)
{
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
int n = istr.gcount();
while (n > 0)
{
if (!XML_Parse(_parser, _pBuffer, n*sizeof(XMLChar), 0))
handleError(XML_GetErrorCode(_parser));
if (istr.good())
{
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
n = istr.gcount();
}
else n = 0;
}
if (!XML_Parse(_parser, _pBuffer, 0, 1))
handleError(XML_GetErrorCode(_parser));
}
void ParserEngine::parseExternal(XML_Parser extParser, InputSource* pInputSource)
{
pushContext(extParser, pInputSource);
if (pInputSource->getCharacterStream())
parseExternalCharInputStream(extParser, *pInputSource->getCharacterStream());
else if (pInputSource->getByteStream())
parseExternalByteInputStream(extParser, *pInputSource->getByteStream());
else throw XMLException("Input source has no stream");
popContext();
}
void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr)
{
char *pBuffer = new char[PARSE_BUFFER_SIZE];
try
{
istr.read(pBuffer, PARSE_BUFFER_SIZE);
int n = istr.gcount();
while (n > 0)
{
if (!XML_Parse(extParser, pBuffer, n, 0))
handleError(XML_GetErrorCode(extParser));
if (istr.good())
{
istr.read(pBuffer, PARSE_BUFFER_SIZE);
n = istr.gcount();
}
else n = 0;
}
if (!XML_Parse(extParser, pBuffer, 0, 1))
handleError(XML_GetErrorCode(extParser));
}
catch (...)
{
delete [] pBuffer;
throw;
}
delete [] pBuffer;
}
void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr)
{
XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)];
try
{
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
int n = istr.gcount();
while (n > 0)
{
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), n*sizeof(XMLChar), 0))
handleError(XML_GetErrorCode(extParser));
if (istr.good())
{
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
n = istr.gcount();
}
else n = 0;
}
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1))
handleError(XML_GetErrorCode(extParser));
}
catch (...)
{
delete [] pBuffer;
throw;
}
delete [] pBuffer;
}
XMLString ParserEngine::getPublicId() const
{
return locator().getPublicId();
}
XMLString ParserEngine::getSystemId() const
{
return locator().getSystemId();
}
int ParserEngine::getLineNumber() const
{
return locator().getLineNumber();
}
int ParserEngine::getColumnNumber() const
{
return locator().getColumnNumber();
}
const Locator& ParserEngine::locator() const
{
static LocatorImpl nullLocator;
if (_context.empty())
return nullLocator;
else
return *_context.back();
}
void ParserEngine::init()
{
if (_parser)
XML_ParserFree(_parser);
if (!_pBuffer)
_pBuffer = new char[PARSE_BUFFER_SIZE];
if (dynamic_cast<NoNamespacePrefixesStrategy*>(_pNamespaceStrategy))
{
_parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t');
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl);
}
else if (dynamic_cast<NamespacePrefixesStrategy*>(_pNamespaceStrategy))
{
_parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t');
XML_SetReturnNSTriplet(_parser, 1);
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl);
}
else
{
_parser = XML_ParserCreate(_encodingSpecified ? _encoding.c_str() : 0);
}
XML_SetUserData(_parser, this);
XML_SetElementHandler(_parser, handleStartElement, handleEndElement);
XML_SetCharacterDataHandler(_parser, handleCharacterData);
XML_SetProcessingInstructionHandler(_parser, handleProcessingInstruction);
if (_expandInternalEntities)
XML_SetDefaultHandlerExpand(_parser, handleDefault);
else
XML_SetDefaultHandler(_parser, handleDefault);
XML_SetUnparsedEntityDeclHandler(_parser, handleUnparsedEntityDecl);
XML_SetNotationDeclHandler(_parser, handleNotationDecl);
XML_SetExternalEntityRefHandler(_parser, handleExternalEntityRef);
XML_SetCommentHandler(_parser, handleComment);
XML_SetCdataSectionHandler(_parser, handleStartCdataSection, handleEndCdataSection);
XML_SetDoctypeDeclHandler(_parser, handleStartDoctypeDecl, handleEndDoctypeDecl);
XML_SetEntityDeclHandler(_parser, handleEntityDecl);
XML_SetSkippedEntityHandler(_parser, handleSkippedEntity);
XML_SetParamEntityParsing(_parser, _externalParameterEntities ? XML_PARAM_ENTITY_PARSING_ALWAYS : XML_PARAM_ENTITY_PARSING_NEVER);
XML_SetUnknownEncodingHandler(_parser, handleUnknownEncoding, this);
}
void ParserEngine::handleError(int errorNo)
{
try
{
switch (errorNo)
{
case XML_ERROR_NO_MEMORY:
throw XMLException("No memory");
case XML_ERROR_SYNTAX:
throw SAXParseException("Syntax error", locator());
case XML_ERROR_NO_ELEMENTS:
throw SAXParseException("No element found", locator());
case XML_ERROR_INVALID_TOKEN:
throw SAXParseException("Invalid token", locator());
case XML_ERROR_UNCLOSED_TOKEN:
throw SAXParseException("Unclosed token", locator());
case XML_ERROR_PARTIAL_CHAR:
throw SAXParseException("Partial character", locator());
case XML_ERROR_TAG_MISMATCH:
throw SAXParseException("Tag mismatch", locator());
case XML_ERROR_DUPLICATE_ATTRIBUTE:
throw SAXParseException("Duplicate attribute", locator());
case XML_ERROR_JUNK_AFTER_DOC_ELEMENT:
throw SAXParseException("Junk after document element", locator());
case XML_ERROR_PARAM_ENTITY_REF:
throw SAXParseException("Illegal parameter entity reference", locator());
case XML_ERROR_UNDEFINED_ENTITY:
throw SAXParseException("Undefined entity", locator());
case XML_ERROR_RECURSIVE_ENTITY_REF:
throw SAXParseException("Recursive entity reference", locator());
case XML_ERROR_ASYNC_ENTITY:
throw SAXParseException("Asynchronous entity", locator());
case XML_ERROR_BAD_CHAR_REF:
throw SAXParseException("Reference to invalid character number", locator());
case XML_ERROR_BINARY_ENTITY_REF:
throw SAXParseException("Reference to binary entity", locator());
case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF:
throw SAXParseException("Reference to external entity in attribute", locator());
case XML_ERROR_MISPLACED_XML_PI:
throw SAXParseException("XML processing instruction not at start of external entity", locator());
case XML_ERROR_UNKNOWN_ENCODING:
throw SAXParseException("Unknown encoding", locator());
case XML_ERROR_INCORRECT_ENCODING:
throw SAXParseException("Encoding specified in XML declaration is incorrect", locator());
case XML_ERROR_UNCLOSED_CDATA_SECTION:
throw SAXParseException("Unclosed CDATA section", locator());
case XML_ERROR_EXTERNAL_ENTITY_HANDLING:
throw SAXParseException("Error in processing external entity reference", locator());
case XML_ERROR_NOT_STANDALONE:
throw SAXParseException("Document is not standalone", locator());
case XML_ERROR_UNEXPECTED_STATE:
throw SAXParseException("Unexpected parser state - please send a bug report", locator());
case XML_ERROR_ENTITY_DECLARED_IN_PE:
throw SAXParseException("Entity declared in parameter entity", locator());
case XML_ERROR_FEATURE_REQUIRES_XML_DTD:
throw SAXParseException("Requested feature requires XML_DTD support in Expat", locator());
case XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING:
throw SAXParseException("Cannot change setting once parsing has begun", locator());
case XML_ERROR_UNBOUND_PREFIX:
throw SAXParseException("Unbound prefix", locator());
case XML_ERROR_UNDECLARING_PREFIX:
throw SAXParseException("Must not undeclare prefix", locator());
case XML_ERROR_INCOMPLETE_PE:
throw SAXParseException("Incomplete markup in parameter entity", locator());
case XML_ERROR_XML_DECL:
throw SAXParseException("XML declaration not well-formed", locator());
case XML_ERROR_TEXT_DECL:
throw SAXParseException("Text declaration not well-formed", locator());
case XML_ERROR_PUBLICID:
throw SAXParseException("Illegal character(s) in public identifier", locator());
case XML_ERROR_SUSPENDED:
throw SAXParseException("Parser suspended", locator());
case XML_ERROR_NOT_SUSPENDED:
throw SAXParseException("Parser not suspended", locator());
case XML_ERROR_ABORTED:
throw SAXParseException("Parsing aborted", locator());
case XML_ERROR_FINISHED:
throw SAXParseException("Parsing finished", locator());
case XML_ERROR_SUSPEND_PE:
throw SAXParseException("Cannot suspend in external parameter entity", locator());
}
throw XMLException("Unknown Expat error code");
}
catch (SAXException& exc)
{
if (_pErrorHandler) _pErrorHandler->error(exc);
throw;
}
catch (Foundation::Exception& exc)
{
if (_pErrorHandler) _pErrorHandler->fatalError(SAXParseException("Fatal error", locator(), exc));
throw;
}
}
void ParserEngine::pushContext(XML_Parser parser, InputSource* pInputSource)
{
ContextLocator* pLocator = new ContextLocator(parser, pInputSource->getPublicId(), pInputSource->getSystemId());
_context.push_back(pLocator);
}
void ParserEngine::popContext()
{
poco_assert (!_context.empty());
delete _context.back();
_context.pop_back();
}
void ParserEngine::resetContext()
{
for (ContextStack::iterator it = _context.begin(); it != _context.end(); ++it)
{
delete *it;
}
_context.clear();
}
void ParserEngine::handleStartElement(void* userData, const XML_Char* name, const XML_Char** atts)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
{
try
{
pThis->_pNamespaceStrategy->startElement(name, atts, XML_GetSpecifiedAttributeCount(pThis->_parser)/2, pThis->_pContentHandler);
}
catch (XMLException& exc)
{
throw SAXParseException(exc.message(), pThis->locator());
}
}
}
void ParserEngine::handleEndElement(void* userData, const XML_Char* name)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
{
try
{
pThis->_pNamespaceStrategy->endElement(name, pThis->_pContentHandler);
}
catch (XMLException& exc)
{
throw SAXParseException(exc.message(), pThis->locator());
}
}
}
void ParserEngine::handleCharacterData(void* userData, const XML_Char* s, int len)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
pThis->_pContentHandler->characters(s, 0, len);
}
void ParserEngine::handleProcessingInstruction(void* userData, const XML_Char* target, const XML_Char* data)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
pThis->_pContentHandler->processingInstruction(target, data);
}
void ParserEngine::handleDefault(void* userData, const XML_Char* s, int len)
{
}
void ParserEngine::handleUnparsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId, const XML_Char* notationName)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
XMLString pubId;
if (publicId) pubId.assign(publicId);
if (pThis->_pDTDHandler)
pThis->_pDTDHandler->unparsedEntityDecl(entityName, publicId ? &pubId : 0, systemId, notationName);
}
void ParserEngine::handleNotationDecl(void* userData, const XML_Char* notationName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
XMLString pubId;
if (publicId) pubId.assign(publicId);
XMLString sysId;
if (systemId) sysId.assign(systemId);
if (pThis->_pDTDHandler)
pThis->_pDTDHandler->notationDecl(notationName, publicId ? &pubId : 0, systemId ? &sysId : 0);
}
int ParserEngine::handleExternalEntityRef(XML_Parser parser, const XML_Char* context, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(XML_GetUserData(parser));
if (!context && !pThis->_externalParameterEntities) return XML_STATUS_ERROR;
if (context && !pThis->_externalGeneralEntities) return XML_STATUS_ERROR;
InputSource* pInputSource = 0;
EntityResolver* pEntityResolver = 0;
EntityResolverImpl defaultResolver;
XMLString sysId(systemId);
XMLString pubId;
if (publicId) pubId.assign(publicId);
URI uri(pThis->_context.back()->getSystemId());
uri.resolve(sysId);
if (pThis->_pEntityResolver)
{
pEntityResolver = pThis->_pEntityResolver;
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, uri.toString());
}
if (!pInputSource && pThis->_externalGeneralEntities)
{
pEntityResolver = &defaultResolver;
pInputSource = pEntityResolver->resolveEntity(publicId ? &pubId : 0, uri.toString());
}
if (pInputSource)
{
XML_Parser extParser = XML_ExternalEntityParserCreate(pThis->_parser, context, 0);
try
{
pThis->parseExternal(extParser, pInputSource);
}
catch (XMLException&)
{
pEntityResolver->releaseInputSource(pInputSource);
XML_ParserFree(extParser);
throw;
}
pEntityResolver->releaseInputSource(pInputSource);
XML_ParserFree(extParser);
return XML_STATUS_OK;
}
else return XML_STATUS_ERROR;
}
int ParserEngine::handleUnknownEncoding(void* encodingHandlerData, const XML_Char* name, XML_Encoding* info)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(encodingHandlerData);
XMLString encoding(name);
EncodingMap::const_iterator it = pThis->_encodings.find(encoding);
if (it != pThis->_encodings.end())
{
const TextEncoding::CharacterMap& map = it->second->characterMap();
for (int i = 0; i < 256; ++i)
info->map[i] = map[i];
info->data = it->second;
info->convert = &ParserEngine::convert;
info->release = 0;
return XML_STATUS_OK;
}
else return XML_STATUS_ERROR;
}
void ParserEngine::handleComment(void* userData, const XML_Char* data)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->comment(data, 0, (int) strlen(data));
}
void ParserEngine::handleStartCdataSection(void* userData)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->startCDATA();
}
void ParserEngine::handleEndCdataSection(void* userData)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->endCDATA();
}
void ParserEngine::handleStartNamespaceDecl(void* userData, const XML_Char* prefix, const XML_Char* uri)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
pThis->_pContentHandler->startPrefixMapping((prefix ? XMLString(prefix) : EMPTY_STRING), (uri ? XMLString(uri) : EMPTY_STRING));
}
void ParserEngine::handleEndNamespaceDecl(void* userData, const XML_Char* prefix)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
pThis->_pContentHandler->endPrefixMapping(prefix ? XMLString(prefix) : EMPTY_STRING);
}
void ParserEngine::handleStartDoctypeDecl(void* userData, const XML_Char* doctypeName, const XML_Char *systemId, const XML_Char* publicId, int hasInternalSubset)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pLexicalHandler)
{
XMLString sysId = systemId ? XMLString(systemId) : EMPTY_STRING;
XMLString pubId = publicId ? XMLString(publicId) : EMPTY_STRING;
pThis->_pLexicalHandler->startDTD(doctypeName, pubId, sysId);
}
}
void ParserEngine::handleEndDoctypeDecl(void* userData)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pLexicalHandler)
pThis->_pLexicalHandler->endDTD();
}
void ParserEngine::handleEntityDecl(void *userData, const XML_Char *entityName, int isParamEntity, const XML_Char *value, int valueLength,
const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName)
{
if (value)
handleInternalParsedEntityDecl(userData, entityName, value, valueLength);
else
handleExternalParsedEntityDecl(userData, entityName, base, systemId, publicId);
}
void ParserEngine::handleExternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
XMLString pubId;
if (publicId) pubId.assign(publicId);
if (pThis->_pDeclHandler)
pThis->_pDeclHandler->externalEntityDecl(entityName, publicId ? &pubId : 0, systemId);
}
void ParserEngine::handleInternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* replacementText, int replacementTextLength)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
XMLString replText(replacementText, replacementTextLength);
if (pThis->_pDeclHandler)
pThis->_pDeclHandler->internalEntityDecl(entityName, replText);
}
void ParserEngine::handleSkippedEntity(void* userData, const XML_Char* entityName, int isParameterEntity)
{
ParserEngine* pThis = reinterpret_cast<ParserEngine*>(userData);
if (pThis->_pContentHandler)
pThis->_pContentHandler->skippedEntity(entityName);
}
int ParserEngine::convert(void* data, const char* s)
{
TextEncoding* pEncoding = reinterpret_cast<TextEncoding*>(data);
return pEncoding->convert((const unsigned char*) s);
}
XML_END

View File

@@ -0,0 +1,100 @@
//
// ProcessingInstruction.cpp
//
// $Id: //poco/1.1.0/XML/src/ProcessingInstruction.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/ProcessingInstruction.h"
XML_BEGIN
ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const XMLString& target, const XMLString& data):
AbstractNode(pOwnerDocument),
_target(target),
_data(data)
{
}
ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const ProcessingInstruction& processingInstruction):
AbstractNode(pOwnerDocument, processingInstruction),
_target(processingInstruction._target),
_data(processingInstruction._data)
{
}
ProcessingInstruction::~ProcessingInstruction()
{
}
void ProcessingInstruction::setData(const XMLString& data)
{
_data = data;
}
const XMLString& ProcessingInstruction::nodeName() const
{
return _target;
}
const XMLString& ProcessingInstruction::getNodeValue() const
{
return _data;
}
void ProcessingInstruction::setNodeValue(const XMLString& data)
{
setData(data);
}
unsigned short ProcessingInstruction::nodeType() const
{
return Node::PROCESSING_INSTRUCTION_NODE;
}
Node* ProcessingInstruction::copyNode(bool deep, Document* pOwnerDocument) const
{
return new ProcessingInstruction(pOwnerDocument, *this);
}
XML_END

153
XML/src/SAXException.cpp Normal file
View File

@@ -0,0 +1,153 @@
//
// SAXException.cpp
//
// $Id: //poco/1.1.0/XML/src/SAXException.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/SAXException.h"
#include "SAX/Locator.h"
#include <typeinfo>
#include <sstream>
XML_BEGIN
POCO_IMPLEMENT_EXCEPTION(SAXException, XMLException, "SAX Exception")
POCO_IMPLEMENT_EXCEPTION(SAXNotRecognizedException, SAXException, "Unrecognized SAX feature or property identifier")
POCO_IMPLEMENT_EXCEPTION(SAXNotSupportedException, SAXException, "Unsupported SAX feature or property identifier")
SAXParseException::SAXParseException(const std::string& msg, const Locator& loc):
SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber())),
_publicId(loc.getPublicId()),
_systemId(loc.getSystemId()),
_lineNumber(loc.getLineNumber()),
_columnNumber(loc.getColumnNumber())
{
}
SAXParseException::SAXParseException(const std::string& msg, const Locator& loc, const Foundation::Exception& exc):
SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()), exc),
_publicId(loc.getPublicId()),
_systemId(loc.getSystemId()),
_lineNumber(loc.getLineNumber()),
_columnNumber(loc.getColumnNumber())
{
}
SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber):
SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber)),
_publicId(publicId),
_systemId(systemId),
_lineNumber(lineNumber),
_columnNumber(columnNumber)
{
}
SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Foundation::Exception& exc):
SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber), exc),
_publicId(publicId),
_systemId(systemId),
_lineNumber(lineNumber),
_columnNumber(columnNumber)
{
}
SAXParseException::SAXParseException(const SAXParseException& exc):
SAXException(exc),
_publicId(exc._publicId),
_systemId(exc._systemId),
_lineNumber(exc._lineNumber),
_columnNumber(exc._columnNumber)
{
}
SAXParseException::~SAXParseException() throw()
{
}
SAXParseException& SAXParseException::operator = (const SAXParseException& exc)
{
if (&exc != this)
{
SAXException::operator = (exc);
_publicId = exc._publicId;
_systemId = exc._systemId;
_lineNumber = exc._lineNumber;
_columnNumber = exc._columnNumber;
}
return *this;
}
const char* SAXParseException::name() const throw()
{
return "SAXParseException";
}
const char* SAXParseException::className() const throw()
{
return typeid(*this).name();
}
Foundation::Exception* SAXParseException::clone() const
{
return new SAXParseException(*this);
}
std::string SAXParseException::buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber)
{
std::ostringstream result;
if (!msg.empty()) result << msg << " ";
result << "in ";
if (!systemId.empty())
result << "'" << fromXMLString(systemId) << "', ";
else if (!publicId.empty())
result << "'" << fromXMLString(publicId) << "', ";
if (lineNumber > 0)
result << "line " << lineNumber << " column " << columnNumber;
return result.str();
}
XML_END

247
XML/src/SAXParser.cpp Normal file
View File

@@ -0,0 +1,247 @@
//
// SAXParser.cpp
//
// $Id: //poco/1.1.0/XML/src/SAXParser.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/SAXParser.h"
#include "SAX/SAXException.h"
#include "SAX/EntityResolverImpl.h"
#include "SAX/InputSource.h"
#include "XML/NamespaceStrategy.h"
#include <sstream>
XML_BEGIN
SAXParser::SAXParser():
_namespaces(true),
_namespacePrefixes(false)
{
}
SAXParser::SAXParser(const XMLString& encoding):
_engine(encoding),
_namespaces(true),
_namespacePrefixes(false)
{
}
SAXParser::~SAXParser()
{
}
void SAXParser::setEncoding(const XMLString& encoding)
{
_engine.setEncoding(encoding);
}
const XMLString& SAXParser::getEncoding() const
{
return _engine.getEncoding();
}
void SAXParser::addEncoding(const XMLString& name, Foundation::TextEncoding* pEncoding)
{
_engine.addEncoding(name, pEncoding);
}
void SAXParser::setEntityResolver(EntityResolver* pResolver)
{
_engine.setEntityResolver(pResolver);
}
EntityResolver* SAXParser::getEntityResolver() const
{
return _engine.getEntityResolver();
}
void SAXParser::setDTDHandler(DTDHandler* pDTDHandler)
{
_engine.setDTDHandler(pDTDHandler);
}
DTDHandler* SAXParser::getDTDHandler() const
{
return _engine.getDTDHandler();
}
void SAXParser::setContentHandler(ContentHandler* pContentHandler)
{
_engine.setContentHandler(pContentHandler);
}
ContentHandler* SAXParser::getContentHandler() const
{
return _engine.getContentHandler();
}
void SAXParser::setErrorHandler(ErrorHandler* pErrorHandler)
{
_engine.setErrorHandler(pErrorHandler);
}
ErrorHandler* SAXParser::getErrorHandler() const
{
return _engine.getErrorHandler();
}
void SAXParser::setFeature(const XMLString& featureId, bool state)
{
if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION));
else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES)
_engine.setExternalGeneralEntities(state);
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
_engine.setExternalParameterEntities(state);
else if (featureId == XMLReader::FEATURE_NAMESPACES)
_namespaces = state;
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
_namespacePrefixes = state;
else throw SAXNotRecognizedException(fromXMLString(featureId));
}
bool SAXParser::getFeature(const XMLString& featureId) const
{
if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING)
throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION));
else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES)
return _engine.getExternalGeneralEntities();
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
return _engine.getExternalParameterEntities();
else if (featureId == XMLReader::FEATURE_NAMESPACES)
return _namespaces;
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
return _namespacePrefixes;
else throw SAXNotRecognizedException(fromXMLString(featureId));
}
void SAXParser::setProperty(const XMLString& propertyId, const XMLString& value)
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId));
else
throw SAXNotRecognizedException(fromXMLString(propertyId));
}
void SAXParser::setProperty(const XMLString& propertyId, void* value)
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
_engine.setDeclHandler(reinterpret_cast<DeclHandler*>(value));
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
_engine.setLexicalHandler(reinterpret_cast<LexicalHandler*>(value));
else throw SAXNotRecognizedException(fromXMLString(propertyId));
}
void* SAXParser::getProperty(const XMLString& propertyId) const
{
if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER)
return _engine.getDeclHandler();
else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
return _engine.getLexicalHandler();
else throw SAXNotSupportedException(fromXMLString(propertyId));
}
void SAXParser::parse(InputSource* pInputSource)
{
if (pInputSource->getByteStream() || pInputSource->getCharacterStream())
{
setupParse();
_engine.parse(pInputSource);
}
else parse(pInputSource->getSystemId());
}
void SAXParser::parse(const XMLString& systemId)
{
setupParse();
EntityResolverImpl entityResolver;
InputSource* pInputSource = entityResolver.resolveEntity(0, systemId);
if (pInputSource)
{
try
{
_engine.parse(pInputSource);
}
catch (...)
{
entityResolver.releaseInputSource(pInputSource);
throw;
}
entityResolver.releaseInputSource(pInputSource);
}
else throw XMLException("Cannot resolve system identifier", systemId);
}
void SAXParser::parseString(const std::string& xml)
{
std::istringstream istr(xml);
InputSource src(istr);
parse(&src);
}
void SAXParser::setupParse()
{
if (_namespaces && !_namespacePrefixes)
_engine.setNamespaceStrategy(new NoNamespacePrefixesStrategy);
else if (_namespaces && _namespacePrefixes)
_engine.setNamespaceStrategy(new NamespacePrefixesStrategy);
else
_engine.setNamespaceStrategy(new NoNamespacesStrategy);
}
XML_END

95
XML/src/Text.cpp Normal file
View File

@@ -0,0 +1,95 @@
//
// Text.cpp
//
// $Id: //poco/1.1.0/XML/src/Text.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/Text.h"
#include "DOM/Document.h"
#include "DOM/DOMException.h"
XML_BEGIN
const XMLString Text::NODE_NAME = toXMLString("#text");
Text::Text(Document* pOwnerDocument, const XMLString& data):
CharacterData(pOwnerDocument, data)
{
}
Text::Text(Document* pOwnerDocument, const Text& text):
CharacterData(pOwnerDocument, text)
{
}
Text::~Text()
{
}
Text* Text::splitText(unsigned long offset)
{
Node* pParent = parentNode();
if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR);
int n = length() - offset;
Text* pNew = ownerDocument()->createTextNode(substringData(offset, n));
deleteData(offset, n);
pParent->insertBefore(pNew, nextSibling())->release();
return pNew;
}
const XMLString& Text::nodeName() const
{
return NODE_NAME;
}
unsigned short Text::nodeType() const
{
return Node::TEXT_NODE;
}
Node* Text::copyNode(bool deep, Document* pOwnerDocument) const
{
return new Text(pOwnerDocument, *this);
}
XML_END

248
XML/src/TreeWalker.cpp Normal file
View File

@@ -0,0 +1,248 @@
//
// TreeWalker.cpp
//
// $Id: //poco/1.1.0/XML/src/TreeWalker.cpp#2 $
//
// Library: XML
// Package: DOM
// Module: TreeWalker
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "DOM/TreeWalker.h"
#include "DOM/Node.h"
#include "DOM/NodeFilter.h"
XML_BEGIN
TreeWalker::TreeWalker(Node* root, unsigned long whatToShow, NodeFilter* pFilter):
_pRoot(root),
_whatToShow(whatToShow),
_pFilter(pFilter),
_pCurrent(root)
{
}
TreeWalker::TreeWalker(const TreeWalker& walker):
_pRoot(walker._pRoot),
_whatToShow(walker._whatToShow),
_pFilter(walker._pFilter),
_pCurrent(walker._pCurrent)
{
}
TreeWalker& TreeWalker::operator = (const TreeWalker& walker)
{
if (&walker != this)
{
_pRoot = walker._pRoot;
_whatToShow = walker._whatToShow;
_pFilter = walker._pFilter;
_pCurrent = walker._pCurrent;
}
return *this;
}
TreeWalker::~TreeWalker()
{
}
void TreeWalker::setCurrentNode(Node* pNode)
{
_pCurrent = pNode;
}
Node* TreeWalker::parentNode()
{
if (!_pCurrent || _pCurrent == _pRoot) return 0;
Node* pParent = _pCurrent->parentNode();
while (pParent && pParent != _pRoot && accept(pParent) != NodeFilter::FILTER_ACCEPT)
pParent = pParent->parentNode();
if (pParent && accept(pParent) == NodeFilter::FILTER_ACCEPT)
_pCurrent = pParent;
else
pParent = 0;
return pParent;
}
Node* TreeWalker::firstChild()
{
if (!_pCurrent) return 0;
Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->firstChild() : 0;
while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT)
pNode = pNode->nextSibling();
if (pNode)
_pCurrent = pNode;
return pNode;
}
Node* TreeWalker::lastChild()
{
if (!_pCurrent) return 0;
Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->lastChild() : 0;
while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT)
pNode = pNode->previousSibling();
if (pNode)
_pCurrent = pNode;
return pNode;
}
Node* TreeWalker::previousSibling()
{
if (!_pCurrent) return 0;
Node* pNode = _pCurrent->previousSibling();
while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT)
pNode = pNode->previousSibling();
if (pNode)
_pCurrent = pNode;
return pNode;
}
Node* TreeWalker::nextSibling()
{
if (!_pCurrent) return 0;
Node* pNode = _pCurrent->nextSibling();
while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT)
pNode = pNode->nextSibling();
if (pNode)
_pCurrent = pNode;
return pNode;
}
Node* TreeWalker::previousNode()
{
if (!_pCurrent) return 0;
Node* pPrev = previous(_pCurrent);
while (pPrev && accept(pPrev) != NodeFilter::FILTER_ACCEPT)
pPrev = previous(pPrev);
if (pPrev)
_pCurrent = pPrev;
return pPrev;
}
Node* TreeWalker::nextNode()
{
if (!_pCurrent) return 0;
Node* pNext = next(_pCurrent);
while (pNext && accept(pNext) != NodeFilter::FILTER_ACCEPT)
pNext = next(pNext);
if (pNext)
_pCurrent = pNext;
return pNext;
}
int TreeWalker::accept(Node* pNode) const
{
bool accept = false;
switch (pNode->nodeType())
{
case Node::ELEMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break;
case Node::ATTRIBUTE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break;
case Node::TEXT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break;
case Node::CDATA_SECTION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break;
case Node::ENTITY_REFERENCE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break;
case Node::ENTITY_NODE:
accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break;
case Node::PROCESSING_INSTRUCTION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break;
case Node::COMMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break;
case Node::DOCUMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break;
case Node::DOCUMENT_TYPE_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break;
case Node::DOCUMENT_FRAGMENT_NODE:
accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break;
case Node::NOTATION_NODE:
accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break;
}
if (accept && _pFilter)
return _pFilter->acceptNode(pNode);
else
return accept ? NodeFilter::FILTER_ACCEPT : NodeFilter::FILTER_REJECT;
}
Node* TreeWalker::next(Node* pNode) const
{
Node* pNext = accept(pNode) != NodeFilter::FILTER_REJECT ? pNode->firstChild() : 0;
if (pNext) return pNext;
pNext = pNode;
while (pNext && pNext != _pRoot)
{
Node* pSibling = pNext->nextSibling();
if (pSibling) return pSibling;
pNext = pNext->parentNode();
}
return 0;
}
Node* TreeWalker::previous(Node* pNode) const
{
if (pNode == _pRoot) return 0;
Node* pPrev = pNode->previousSibling();
while (pPrev)
{
Node* pLastChild = accept(pPrev) != NodeFilter::FILTER_REJECT ? pPrev->lastChild() : 0;
if (pLastChild)
pPrev = pLastChild;
else
return pPrev;
}
return pNode->parentNode();
}
XML_END

View File

@@ -0,0 +1,233 @@
//
// WhitespaceFilter.cpp
//
// $Id: //poco/1.1.0/XML/src/WhitespaceFilter.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: WhitespaceFilter
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/WhitespaceFilter.h"
#include "SAX/SAXException.h"
XML_BEGIN
WhitespaceFilter::WhitespaceFilter():
_pLexicalHandler(0),
_filter(true)
{
}
WhitespaceFilter::WhitespaceFilter(XMLReader* pReader):
XMLFilterImpl(pReader),
_pLexicalHandler(0),
_filter(true)
{
}
WhitespaceFilter::~WhitespaceFilter()
{
}
void WhitespaceFilter::setProperty(const XMLString& propertyId, const XMLString& value)
{
if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId));
else
XMLFilterImpl::setProperty(propertyId, value);
}
void WhitespaceFilter::setProperty(const XMLString& propertyId, void* value)
{
if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
_pLexicalHandler = reinterpret_cast<LexicalHandler*>(value);
else
XMLFilterImpl::setProperty(propertyId, value);
}
void* WhitespaceFilter::getProperty(const XMLString& propertyId) const
{
if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER)
return _pLexicalHandler;
else
return XMLFilterImpl::getProperty(propertyId);
}
void WhitespaceFilter::startDocument()
{
XMLFilterImpl::startDocument();
_filter = true;
_data.clear();
}
void WhitespaceFilter::endDocument()
{
XMLFilterImpl::endDocument();
_filter = true;
_data.clear();
}
void WhitespaceFilter::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList)
{
XMLFilterImpl::startElement(uri, localName, qname, attrList);
_filter = true;
_data.clear();
}
void WhitespaceFilter::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname)
{
XMLFilterImpl::endElement(uri, localName, qname);
_filter = true;
_data.clear();
}
void WhitespaceFilter::characters(const XMLChar ch[], int start, int length)
{
if (_filter)
{
bool ws = true;
const XMLChar* it = ch + start;
const XMLChar* end = ch + start + length;
_data.append(it, end);
while (it != end)
{
if (*it != '\r' && *it != '\n' && *it != '\t' && *it != ' ')
{
ws = false;
break;
}
++it;
}
if (!ws)
{
XMLFilterImpl::characters(_data.data(), 0, (int) _data.length());
_filter = false;
_data.clear();
}
}
else XMLFilterImpl::characters(ch, start, length);
}
void WhitespaceFilter::ignorableWhitespace(const XMLChar ch[], int start, int length)
{
// the handler name already says that this data can be ignored
}
void WhitespaceFilter::processingInstruction(const XMLString& target, const XMLString& data)
{
XMLFilterImpl::processingInstruction(target, data);
_filter = true;
_data.clear();
}
void WhitespaceFilter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId)
{
if (_pLexicalHandler)
_pLexicalHandler->startDTD(name, publicId, systemId);
}
void WhitespaceFilter::endDTD()
{
if (_pLexicalHandler)
_pLexicalHandler->endDTD();
}
void WhitespaceFilter::startEntity(const XMLString& name)
{
if (_pLexicalHandler)
_pLexicalHandler->startEntity(name);
_filter = true;
_data.clear();
}
void WhitespaceFilter::endEntity(const XMLString& name)
{
if (_pLexicalHandler)
_pLexicalHandler->endEntity(name);
_filter = true;
_data.clear();
}
void WhitespaceFilter::startCDATA()
{
if (_pLexicalHandler)
_pLexicalHandler->startCDATA();
_filter = false;
_data.clear();
}
void WhitespaceFilter::endCDATA()
{
if (_pLexicalHandler)
_pLexicalHandler->endCDATA();
_filter = true;
_data.clear();
}
void WhitespaceFilter::comment(const XMLChar ch[], int start, int length)
{
if (_pLexicalHandler)
_pLexicalHandler->comment(ch, start, length);
_filter = true;
_data.clear();
}
void WhitespaceFilter::setupParse()
{
XMLFilterImpl::setupParse();
parent()->setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(this));
}
XML_END

50
XML/src/XMLException.cpp Normal file
View File

@@ -0,0 +1,50 @@
//
// XMLException.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLException.cpp#2 $
//
// Library: XML
// Package: XML
// Module: XMLException
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/XMLException.h"
#include <typeinfo>
using Foundation::RuntimeException;
XML_BEGIN
POCO_IMPLEMENT_EXCEPTION(XMLException, RuntimeException, "XML Exception")
XML_END

48
XML/src/XMLFilter.cpp Normal file
View File

@@ -0,0 +1,48 @@
//
// XMLFilter.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLFilter.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAXFilters
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/XMLFilter.h"
XML_BEGIN
XMLFilter::~XMLFilter()
{
}
XML_END

327
XML/src/XMLFilterImpl.cpp Normal file
View File

@@ -0,0 +1,327 @@
//
// XMLFilterImpl.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLFilterImpl.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAXFilters
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/XMLFilterImpl.h"
#include "SAX/SAXException.h"
XML_BEGIN
XMLFilterImpl::XMLFilterImpl():
_pParent(0),
_pEntityResolver(0),
_pDTDHandler(0),
_pContentHandler(0),
_pErrorHandler(0)
{
}
XMLFilterImpl::XMLFilterImpl(XMLReader* pParent):
_pParent(pParent),
_pEntityResolver(0),
_pDTDHandler(0),
_pContentHandler(0),
_pErrorHandler(0)
{
}
XMLFilterImpl::~XMLFilterImpl()
{
}
XMLReader* XMLFilterImpl::getParent() const
{
return _pParent;
}
void XMLFilterImpl::setParent(XMLReader* pParent)
{
_pParent = pParent;
}
void XMLFilterImpl::setEntityResolver(EntityResolver* pResolver)
{
_pEntityResolver = pResolver;
}
EntityResolver* XMLFilterImpl::getEntityResolver() const
{
return _pEntityResolver;
}
void XMLFilterImpl::setDTDHandler(DTDHandler* pDTDHandler)
{
_pDTDHandler = pDTDHandler;
}
DTDHandler* XMLFilterImpl::getDTDHandler() const
{
return _pDTDHandler;
}
void XMLFilterImpl::setContentHandler(ContentHandler* pContentHandler)
{
_pContentHandler = pContentHandler;
}
ContentHandler* XMLFilterImpl::getContentHandler() const
{
return _pContentHandler;
}
void XMLFilterImpl::setErrorHandler(ErrorHandler* pErrorHandler)
{
_pErrorHandler = pErrorHandler;
}
ErrorHandler* XMLFilterImpl::getErrorHandler() const
{
return _pErrorHandler;
}
void XMLFilterImpl::setFeature(const XMLString& featureId, bool state)
{
if (_pParent)
_pParent->setFeature(featureId, state);
else
throw SAXNotRecognizedException(featureId);
}
bool XMLFilterImpl::getFeature(const XMLString& featureId) const
{
if (_pParent)
return _pParent->getFeature(featureId);
else
throw SAXNotRecognizedException(featureId);
}
void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& value)
{
if (_pParent)
_pParent->setProperty(propertyId, value);
else
throw SAXNotRecognizedException(propertyId);
}
void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value)
{
if (_pParent)
_pParent->setProperty(propertyId, value);
else
throw SAXNotRecognizedException(propertyId);
}
void* XMLFilterImpl::getProperty(const XMLString& propertyId) const
{
if (_pParent)
return _pParent->getProperty(propertyId);
else
throw SAXNotRecognizedException(propertyId);
}
void XMLFilterImpl::parse(InputSource* pSource)
{
setupParse();
_pParent->parse(pSource);
}
void XMLFilterImpl::parse(const XMLString& systemId)
{
setupParse();
_pParent->parse(systemId);
}
InputSource* XMLFilterImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId)
{
if (_pEntityResolver)
return _pEntityResolver->resolveEntity(publicId, systemId);
else
return 0;
}
void XMLFilterImpl::releaseInputSource(InputSource* pSource)
{
if (_pEntityResolver)
_pEntityResolver->releaseInputSource(pSource);
}
void XMLFilterImpl::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId)
{
if (_pDTDHandler)
_pDTDHandler->notationDecl(name, publicId, systemId);
}
void XMLFilterImpl::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName)
{
if (_pDTDHandler)
_pDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName);
}
void XMLFilterImpl::setDocumentLocator(const Locator* loc)
{
if (_pContentHandler)
_pContentHandler->setDocumentLocator(loc);
}
void XMLFilterImpl::startDocument()
{
if (_pContentHandler)
_pContentHandler->startDocument();
}
void XMLFilterImpl::endDocument()
{
if (_pContentHandler)
_pContentHandler->endDocument();
}
void XMLFilterImpl::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList)
{
if (_pContentHandler)
_pContentHandler->startElement(uri, localName, qname, attrList);
}
void XMLFilterImpl::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname)
{
if (_pContentHandler)
_pContentHandler->endElement(uri, localName, qname);
}
void XMLFilterImpl::characters(const XMLChar ch[], int start, int length)
{
if (_pContentHandler)
_pContentHandler->characters(ch, start, length);
}
void XMLFilterImpl::ignorableWhitespace(const XMLChar ch[], int start, int length)
{
if (_pContentHandler)
_pContentHandler->ignorableWhitespace(ch, start, length);
}
void XMLFilterImpl::processingInstruction(const XMLString& target, const XMLString& data)
{
if (_pContentHandler)
_pContentHandler->processingInstruction(target, data);
}
void XMLFilterImpl::startPrefixMapping(const XMLString& prefix, const XMLString& uri)
{
if (_pContentHandler)
_pContentHandler->startPrefixMapping(prefix, uri);
}
void XMLFilterImpl::endPrefixMapping(const XMLString& prefix)
{
if (_pContentHandler)
_pContentHandler->endPrefixMapping(prefix);
}
void XMLFilterImpl::skippedEntity(const XMLString& prefix)
{
if (_pContentHandler)
_pContentHandler->skippedEntity(prefix);
}
void XMLFilterImpl::warning(const SAXException& e)
{
if (_pErrorHandler)
_pErrorHandler->warning(e);
}
void XMLFilterImpl::error(const SAXException& e)
{
if (_pErrorHandler)
_pErrorHandler->error(e);
}
void XMLFilterImpl::fatalError(const SAXException& e)
{
if (_pErrorHandler)
_pErrorHandler->fatalError(e);
}
void XMLFilterImpl::setupParse()
{
poco_check_ptr (_pParent);
_pParent->setEntityResolver(this);
_pParent->setDTDHandler(this);
_pParent->setContentHandler(this);
_pParent->setErrorHandler(this);
}
XML_END

58
XML/src/XMLReader.cpp Normal file
View File

@@ -0,0 +1,58 @@
//
// XMLReader.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLReader.cpp#2 $
//
// Library: XML
// Package: SAX
// Module: SAX
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "SAX/XMLReader.h"
XML_BEGIN
const XMLString XMLReader::FEATURE_VALIDATION = toXMLString("http://xml.org/sax/features/validation");
const XMLString XMLReader::FEATURE_NAMESPACES = toXMLString("http://xml.org/sax/features/namespaces");
const XMLString XMLReader::FEATURE_NAMESPACE_PREFIXES = toXMLString("http://xml.org/sax/features/namespace-prefixes");
const XMLString XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES = toXMLString("http://xml.org/sax/features/external-general-entities");
const XMLString XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES = toXMLString("http://xml.org/sax/features/external-parameter-entities");
const XMLString XMLReader::FEATURE_STRING_INTERNING = toXMLString("http://xml.org/sax/features/string-interning");
const XMLString XMLReader::PROPERTY_DECLARATION_HANDLER = toXMLString("http://xml.org/sax/properties/declaration-handler");
const XMLString XMLReader::PROPERTY_LEXICAL_HANDLER = toXMLString("http://xml.org/sax/properties/lexical-handler");
XMLReader::~XMLReader()
{
}
XML_END

85
XML/src/XMLString.cpp Normal file
View File

@@ -0,0 +1,85 @@
//
// XMLString.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLString.cpp#2 $
//
// Library: XML
// Package: XML
// Module: XMLString
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/XMLString.h"
#if defined(XML_UNICODE_WCHAR_T)
#include <stdlib.h>
#endif
XML_BEGIN
#if defined(XML_UNICODE_WCHAR_T)
std::string fromXMLString(const XMLString& str)
{
std::string result;
result.reserve(str.size());
for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it)
{
char c;
wctomb(&c, *it);
result += c;
}
return result;
}
XMLString toXMLString(const std::string& str)
{
XMLString result;
result.reserve(str.size());
for (std::string::const_iterator it = str.begin(); it != str.end();)
{
wchar_t c;
int n = mbtowc(&c, &*it, MB_CUR_MAX);
result += c;
it += (n > 0 ? n : 1);
}
return result;
}
#endif // XML_UNICODE_WCHAR_T
XML_END

799
XML/src/XMLWriter.cpp Normal file
View File

@@ -0,0 +1,799 @@
//
// XMLWriter.cpp
//
// $Id: //poco/1.1.0/XML/src/XMLWriter.cpp#2 $
//
// Library: XML
// Package: XML
// Module: XMLWriter
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "XML/XMLWriter.h"
#include "XML/XMLString.h"
#include "XML/XMLException.h"
#include "SAX/AttributesImpl.h"
#include "Foundation/UTF8Encoding.h"
#include <sstream>
XML_BEGIN
const std::string XMLWriter::NEWLINE_DEFAULT;
const std::string XMLWriter::NEWLINE_CR = "\r";
const std::string XMLWriter::NEWLINE_CRLF = "\r\n";
const std::string XMLWriter::NEWLINE_LF = "\n";
const std::string XMLWriter::MARKUP_QUOTENC = "&quot;";
const std::string XMLWriter::MARKUP_APOSENC = "&apos;";
const std::string XMLWriter::MARKUP_AMPENC = "&amp;";
const std::string XMLWriter::MARKUP_LTENC = "&lt;";
const std::string XMLWriter::MARKUP_GTENC = "&gt;";
const std::string XMLWriter::MARKUP_LT = "<";
const std::string XMLWriter::MARKUP_GT = ">";
const std::string XMLWriter::MARKUP_SLASHGT = "/>";
const std::string XMLWriter::MARKUP_LTSLASH = "</";
const std::string XMLWriter::MARKUP_COLON = ":";
const std::string XMLWriter::MARKUP_EQQUOT = "=\"";
const std::string XMLWriter::MARKUP_QUOT = "\"";
const std::string XMLWriter::MARKUP_SPACE = " ";
const std::string XMLWriter::MARKUP_TAB = "\t";
const std::string XMLWriter::MARKUP_BEGIN_CDATA = "<![CDATA[";
const std::string XMLWriter::MARKUP_END_CDATA = "]]>";
#if defined(XML_UNICODE_WCHAR_T)
#define NATIVE_ENCODING Foundation::UTF16Encoding
#else
#define NATIVE_ENCODING Foundation::UTF8Encoding
#endif
XMLWriter::XMLWriter(XMLByteOutputStream& str, int options):
_pTextConverter(0),
_pInEncoding(new NATIVE_ENCODING),
_pOutEncoding(new Foundation::UTF8Encoding),
_options(options),
_encoding("UTF-8"),
_depth(-1),
_elementCount(0),
_inFragment(false),
_inCDATA(false),
_inDTD(false),
_inInternalDTD(false),
_contentWritten(false),
_unclosedStartTag(false),
_prefix(0)
{
_pTextConverter = new Foundation::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
setNewLine(NEWLINE_DEFAULT);
}
XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Foundation::TextEncoding& textEncoding):
_pTextConverter(0),
_pInEncoding(new NATIVE_ENCODING),
_pOutEncoding(0),
_options(options),
_encoding(encodingName),
_depth(-1),
_elementCount(0),
_inFragment(false),
_inCDATA(false),
_inDTD(false),
_inInternalDTD(false),
_contentWritten(false),
_unclosedStartTag(false),
_prefix(0)
{
_pTextConverter = new Foundation::OutputStreamConverter(str, *_pInEncoding, textEncoding);
setNewLine(NEWLINE_DEFAULT);
}
XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Foundation::TextEncoding* pTextEncoding):
_pTextConverter(0),
_pInEncoding(new NATIVE_ENCODING),
_pOutEncoding(0),
_options(options),
_encoding(encodingName),
_depth(-1),
_elementCount(0),
_inFragment(false),
_inCDATA(false),
_inDTD(false),
_inInternalDTD(false),
_contentWritten(false),
_unclosedStartTag(false),
_prefix(0)
{
if (pTextEncoding)
{
_pTextConverter = new Foundation::OutputStreamConverter(str, *_pInEncoding, *pTextEncoding);
}
else
{
_encoding = "UTF-8";
_pOutEncoding = new Foundation::UTF8Encoding;
_pTextConverter = new Foundation::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
}
setNewLine(NEWLINE_DEFAULT);
}
XMLWriter::~XMLWriter()
{
delete _pTextConverter;
delete _pInEncoding;
delete _pOutEncoding;
}
void XMLWriter::setDocumentLocator(const Locator* loc)
{
}
void XMLWriter::setNewLine(const std::string& newLineCharacters)
{
if (newLineCharacters.empty())
{
#if defined(_WIN32)
_newLine = NEWLINE_CRLF;
#else
_newLine = NEWLINE_LF;
#endif
}
else _newLine = newLineCharacters;
}
const std::string& XMLWriter::getNewLine() const
{
return _newLine;
}
void XMLWriter::startDocument()
{
if (_depth != -1)
throw XMLException("Cannot start a document in another document");
_inFragment = false;
_depth = 0;
_elementCount = 0;
_inDTD = false;
_inInternalDTD = false;
_prefix = 0;
if (_options & WRITE_XML_DECLARATION)
writeXMLDeclaration();
_contentWritten = true;
_namespaces.reset();
_namespaces.pushContext();
}
void XMLWriter::endDocument()
{
if (_depth > 0)
throw XMLException("Not well-formed (at least one tag has no matching end tag)");
if (_elementCount == 0)
throw XMLException("No document element");
_elementCount = 0;
_depth = -1;
}
void XMLWriter::startFragment()
{
if (_depth != -1)
throw XMLException("Cannot start a fragment in another fragment or document");
_inFragment = true;
_depth = 0;
_elementCount = 0;
_prefix = 0;
_contentWritten = true;
_namespaces.reset();
_namespaces.pushContext();
}
void XMLWriter::endFragment()
{
if (_depth > 1)
throw XMLException("Not well-formed (at least one tag has no matching end tag)");
_inFragment = false;
_elementCount = 0;
_depth = -1;
}
void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
AttributesImpl attributes;
startElement(namespaceURI, localName, qname, attributes);
}
void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
if (_depth == 0 && !_inFragment && _elementCount > 1)
throw XMLException("Not well-formed. Second root element found", nameToString(localName, qname));
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeStartElement(namespaceURI, localName, qname, attributes);
_elementStack.push_back(Name(qname, namespaceURI, localName));
_contentWritten = false;
++_depth;
}
void XMLWriter::endElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
if (_depth < 1)
throw XMLException("No unclosed tag");
if (!_elementStack.back().equalsWeakly(qname, namespaceURI, localName))
throw XMLException("End tag does not match start tag", nameToString(localName, qname));
_elementStack.pop_back();
--_depth;
if (!_unclosedStartTag) prettyPrint();
writeEndElement(namespaceURI, localName, qname);
_contentWritten = false;
if (_depth == 0)
writeNewLine();
}
void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
AttributesImpl attributes;
emptyElement(namespaceURI, localName, qname, attributes);
}
void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
if (_depth == 0 && _elementCount > 1)
throw XMLException("Not well-formed. Second root element found.");
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeStartElement(namespaceURI, localName, qname, attributes);
_contentWritten = false;
}
void XMLWriter::characters(const XMLChar ch[], int start, int length)
{
if (_unclosedStartTag) closeStartTag();
_contentWritten = length > 0;
if (_inCDATA)
{
while (length-- > 0) writeXML(ch[start++]);
}
else
{
while (length-- > 0)
{
XMLChar c = ch[start++];
switch (c)
{
case '"': writeMarkup(MARKUP_QUOTENC); break;
case '\'': writeMarkup(MARKUP_APOSENC); break;
case '&': writeMarkup(MARKUP_AMPENC); break;
case '<': writeMarkup(MARKUP_LTENC); break;
case '>': writeMarkup(MARKUP_GTENC); break;
default:
if (c >= 0 && c < 32)
{
if (c == '\t' || c == '\r' || c == '\n')
writeXML(c);
else
throw XMLException("Invalid character token.");
}
else writeXML(c);
}
}
}
}
void XMLWriter::characters(const XMLString& str)
{
characters(str.data(), 0, (int) str.length());
}
void XMLWriter::rawCharacters(const XMLString& str)
{
writeXML(str);
}
void XMLWriter::ignorableWhitespace(const XMLChar ch[], int start, int length)
{
characters(ch, start, length);
}
void XMLWriter::processingInstruction(const XMLString& target, const XMLString& data)
{
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeMarkup("<?");
writeXML(target);
if (!data.empty())
{
writeMarkup(MARKUP_SPACE);
writeXML(data);
}
writeMarkup("?>");
if (_depth == 0)
writeNewLine();
}
void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname,
const XMLString& data,
const XMLString& attr1, const XMLString& value1,
const XMLString& attr2, const XMLString& value2,
const XMLString& attr3, const XMLString& value3)
{
static const XMLString CDATA = toXMLString("CDATA");
AttributesImpl attributes;
if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1);
if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2);
if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3);
if (data.empty())
{
emptyElement(namespaceURI, localName, qname, attributes);
}
else
{
startElement(namespaceURI, localName, qname, attributes);
characters(data);
endElement(namespaceURI, localName, qname);
}
}
void XMLWriter::startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI)
{
if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX)
_namespaces.declarePrefix(prefix, namespaceURI);
}
void XMLWriter::endPrefixMapping(const XMLString& prefix)
{
if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX)
_namespaces.undeclarePrefix(prefix);
}
void XMLWriter::skippedEntity(const XMLString& name)
{
}
void XMLWriter::startCDATA()
{
if (_inCDATA) throw XMLException("Cannot nest CDATA sections");
if (_unclosedStartTag) closeStartTag();
_inCDATA = true;
writeMarkup(MARKUP_BEGIN_CDATA);
}
void XMLWriter::endCDATA()
{
poco_assert (_inCDATA);
_inCDATA = false;
writeMarkup(MARKUP_END_CDATA);
}
void XMLWriter::comment(const XMLChar ch[], int start, int length)
{
if (_unclosedStartTag) closeStartTag();
prettyPrint();
writeMarkup("<!--");
while (length-- > 0) writeXML(ch[start++]);
writeMarkup("-->");
_contentWritten = false;
}
void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId)
{
writeMarkup("<!DOCTYPE ");
writeXML(name);
if (!publicId.empty())
{
writeMarkup(" PUBLIC \"");
writeXML(publicId);
writeMarkup("\"");
}
if (!systemId.empty())
{
writeMarkup(" SYSTEM \"");
writeXML(systemId);
writeMarkup("\"");
}
_inDTD = true;
}
void XMLWriter::endDTD()
{
poco_assert (_inDTD);
if (_inInternalDTD)
{
writeNewLine();
writeMarkup("]");
_inInternalDTD = false;
}
writeMarkup(">");
writeNewLine();
_inDTD = false;
}
void XMLWriter::startEntity(const XMLString& name)
{
}
void XMLWriter::endEntity(const XMLString& name)
{
}
void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId)
{
if (!_inDTD) throw XMLException("Notation declaration not within DTD");
if (!_inInternalDTD)
{
writeMarkup(" [");
_inInternalDTD = true;
}
if (_options & PRETTY_PRINT)
{
writeNewLine();
writeMarkup(MARKUP_TAB);
}
writeMarkup("<!NOTATION ");
writeXML(name);
if (systemId && !systemId->empty())
{
writeMarkup(" SYSTEM \"");
writeXML(*systemId);
writeMarkup("\"");
}
if (publicId && !publicId->empty())
{
writeMarkup(" PUBLIC \"");
writeXML(*publicId);
writeMarkup("\"");
}
writeMarkup(">");
}
void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName)
{
if (!_inDTD) throw XMLException("Entity declaration not within DTD");
if (!_inInternalDTD)
{
writeMarkup(" [");
_inInternalDTD = true;
}
if (_options & PRETTY_PRINT)
{
writeNewLine();
writeMarkup(MARKUP_TAB);
}
writeMarkup("<!ENTITY ");
writeXML(name);
if (!systemId.empty())
{
writeMarkup(" SYSTEM \"");
writeXML(systemId);
writeMarkup("\"");
}
if (publicId && !publicId->empty())
{
writeMarkup(" PUBLIC \"");
writeXML(*publicId);
writeMarkup("\"");
}
if (!notationName.empty())
{
writeMarkup(" NDATA ");
writeXML(notationName);
}
writeMarkup(">");
}
void XMLWriter::prettyPrint() const
{
if ((_options & PRETTY_PRINT) && !_contentWritten)
{
writeNewLine();
writeIndent();
}
}
void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
++_elementCount;
writeMarkup(MARKUP_LT);
if (!localName.empty() && (qname.empty() || localName == qname))
{
XMLString prefix;
if (!namespaceURI.empty() && !_namespaces.isMapped(namespaceURI))
{
prefix = newPrefix();
_namespaces.declarePrefix(prefix, namespaceURI);
}
else prefix = _namespaces.getPrefix(namespaceURI);
writeName(prefix, localName);
}
else if (namespaceURI.empty() && localName.empty() && !qname.empty())
{
writeXML(qname);
}
else if (!localName.empty() && !qname.empty())
{
XMLString local;
XMLString prefix;
Name::split(qname, prefix, local);
if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI);
const XMLString& uri = _namespaces.getURI(prefix);
if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty())
{
_namespaces.declarePrefix(prefix, namespaceURI);
}
writeName(prefix, localName);
}
else throw XMLException("Tag mismatch", nameToString(localName, qname));
declareAttributeNamespaces(attributes);
AttributeMap attributeMap;
addNamespaceAttributes(attributeMap);
addAttributes(attributeMap, attributes, namespaceURI);
writeAttributes(attributeMap);
_unclosedStartTag = true;
_namespaces.pushContext();
}
void XMLWriter::writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
if (_unclosedStartTag)
{
writeMarkup(MARKUP_SLASHGT);
_unclosedStartTag = false;
}
else
{
writeMarkup(MARKUP_LTSLASH);
if (!localName.empty())
{
XMLString prefix = _namespaces.getPrefix(namespaceURI);
writeName(prefix, localName);
}
else
{
writeXML(qname);
}
writeMarkup(MARKUP_GT);
}
_namespaces.popContext();
}
void XMLWriter::closeStartTag()
{
_unclosedStartTag = false;
writeMarkup(MARKUP_GT);
}
void XMLWriter::declareAttributeNamespaces(const Attributes& attributes)
{
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i);
if (!localName.empty())
{
XMLString prefix;
XMLString splitLocalName;
Name::split(qname, prefix, splitLocalName);
if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI);
const XMLString& uri = _namespaces.getURI(prefix);
if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty())
{
_namespaces.declarePrefix(prefix, namespaceURI);
}
}
}
}
void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap)
{
NamespaceSupport::PrefixSet prefixes;
_namespaces.getDeclaredPrefixes(prefixes);
for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it)
{
XMLString prefix = *it;
XMLString uri = _namespaces.getURI(prefix);
XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
if (!prefix.empty())
{
qname.append(MARKUP_COLON);
qname.append(prefix);
}
attributeMap[qname] = uri;
}
}
void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI)
{
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i);
if (!localName.empty())
{
XMLString prefix;
if (namespaceURI != elementNamespaceURI)
prefix = _namespaces.getPrefix(namespaceURI);
if (!prefix.empty())
{
qname = prefix;
qname.append(MARKUP_COLON);
}
else qname.clear();
qname.append(localName);
}
attributeMap[qname] = attributes.getValue(i);
}
}
void XMLWriter::writeAttributes(const AttributeMap& attributeMap)
{
for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
{
writeMarkup(MARKUP_SPACE);
writeXML(it->first);
writeMarkup(MARKUP_EQQUOT);
characters(it->second);
writeMarkup(MARKUP_QUOT);
}
}
void XMLWriter::writeMarkup(const std::string& str) const
{
_pTextConverter->write(str.data(), (int) str.size());
}
void XMLWriter::writeXML(const XMLString& str) const
{
_pTextConverter->write((const char*) str.data(), (int) str.size()*sizeof(XMLChar));
}
void XMLWriter::writeXML(XMLChar ch) const
{
_pTextConverter->write((const char*) &ch, sizeof(ch));
}
void XMLWriter::writeName(const std::string& prefix, const std::string& localName)
{
if (prefix.empty())
{
writeXML(localName);
}
else
{
writeXML(prefix);
writeMarkup(MARKUP_COLON);
writeXML(localName);
}
}
void XMLWriter::writeNewLine() const
{
if (_options & PRETTY_PRINT)
writeMarkup(_newLine);
}
void XMLWriter::writeIndent() const
{
for (int i = 0; i < _depth; ++i)
writeMarkup(MARKUP_TAB);
}
void XMLWriter::writeXMLDeclaration()
{
writeMarkup("<?xml version=\"1.0\"");
if (!_encoding.empty())
{
writeMarkup(" encoding=\"");
writeMarkup(_encoding);
writeMarkup("\"");
}
writeMarkup("?>");
writeNewLine();
}
std::string XMLWriter::nameToString(const XMLString& localName, const XMLString& qname)
{
if (qname.empty())
return fromXMLString(localName);
else
return fromXMLString(qname);
}
XMLString XMLWriter::newPrefix()
{
std::ostringstream str;
str << "ns" << ++_prefix;
return toXMLString(str.str());
}
XML_END

85
XML/src/ascii.h Normal file
View File

@@ -0,0 +1,85 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
#define ASCII_A 0x41
#define ASCII_B 0x42
#define ASCII_C 0x43
#define ASCII_D 0x44
#define ASCII_E 0x45
#define ASCII_F 0x46
#define ASCII_G 0x47
#define ASCII_H 0x48
#define ASCII_I 0x49
#define ASCII_J 0x4A
#define ASCII_K 0x4B
#define ASCII_L 0x4C
#define ASCII_M 0x4D
#define ASCII_N 0x4E
#define ASCII_O 0x4F
#define ASCII_P 0x50
#define ASCII_Q 0x51
#define ASCII_R 0x52
#define ASCII_S 0x53
#define ASCII_T 0x54
#define ASCII_U 0x55
#define ASCII_V 0x56
#define ASCII_W 0x57
#define ASCII_X 0x58
#define ASCII_Y 0x59
#define ASCII_Z 0x5A
#define ASCII_a 0x61
#define ASCII_b 0x62
#define ASCII_c 0x63
#define ASCII_d 0x64
#define ASCII_e 0x65
#define ASCII_f 0x66
#define ASCII_g 0x67
#define ASCII_h 0x68
#define ASCII_i 0x69
#define ASCII_j 0x6A
#define ASCII_k 0x6B
#define ASCII_l 0x6C
#define ASCII_m 0x6D
#define ASCII_n 0x6E
#define ASCII_o 0x6F
#define ASCII_p 0x70
#define ASCII_q 0x71
#define ASCII_r 0x72
#define ASCII_s 0x73
#define ASCII_t 0x74
#define ASCII_u 0x75
#define ASCII_v 0x76
#define ASCII_w 0x77
#define ASCII_x 0x78
#define ASCII_y 0x79
#define ASCII_z 0x7A
#define ASCII_0 0x30
#define ASCII_1 0x31
#define ASCII_2 0x32
#define ASCII_3 0x33
#define ASCII_4 0x34
#define ASCII_5 0x35
#define ASCII_6 0x36
#define ASCII_7 0x37
#define ASCII_8 0x38
#define ASCII_9 0x39
#define ASCII_TAB 0x09
#define ASCII_SPACE 0x20
#define ASCII_EXCL 0x21
#define ASCII_QUOT 0x22
#define ASCII_AMP 0x26
#define ASCII_APOS 0x27
#define ASCII_MINUS 0x2D
#define ASCII_PERIOD 0x2E
#define ASCII_COLON 0x3A
#define ASCII_SEMI 0x3B
#define ASCII_LT 0x3C
#define ASCII_EQUALS 0x3D
#define ASCII_GT 0x3E
#define ASCII_LSQB 0x5B
#define ASCII_RSQB 0x5D
#define ASCII_UNDERSCORE 0x5F

36
XML/src/asciitab.h Normal file
View File

@@ -0,0 +1,36 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML,
/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML,
/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM,
/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS,
/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS,
/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL,
/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI,
/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST,
/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB,
/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT,
/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER,

61
XML/src/expat_config.h Normal file
View File

@@ -0,0 +1,61 @@
//
// expat_config.h
//
// $Id: //poco/1.1.0/XML/src/expat_config.h#2 $
//
// Poco XML specific configuration for expat.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef EXPAT_CONFIG_H
#define EXPAT_CONFIG_H
#ifndef Foundation_Platform_INCLUDED
#include "Foundation/Platform.h"
#endif
#include <memory.h>
#include <string.h>
#define XML_CONTEXT_BYTES 1024
#if defined POCO_ARCH_LITTLE_ENDIAN
#define BYTEORDER 1234
#else
#define BYTEORDER 4321
#endif
#define HAVE_MEMMOVE
#endif /* EXPAT_CONFIG_H */

37
XML/src/iasciitab.h Normal file
View File

@@ -0,0 +1,37 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */
/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML,
/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML,
/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM,
/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS,
/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS,
/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL,
/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT,
/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI,
/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST,
/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB,
/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT,
/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX,
/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT,
/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER,

73
XML/src/internal.h Normal file
View File

@@ -0,0 +1,73 @@
/* internal.h
Internal definitions used by Expat. This is not needed to compile
client code.
The following calling convention macros are defined for frequently
called functions:
FASTCALL - Used for those internal functions that have a simple
body and a low number of arguments and local variables.
PTRCALL - Used for functions called though function pointers.
PTRFASTCALL - Like PTRCALL, but for low number of arguments.
inline - Used for selected internal functions for which inlining
may improve performance on some platforms.
Note: Use of these macros is based on judgement, not hard rules,
and therefore subject to change.
*/
#if defined(__GNUC__) && defined(__i386__)
/* We'll use this version by default only where we know it helps.
regparm() generates warnings on Solaris boxes. See SF bug #692878.
Instability reported with egcs on a RedHat Linux 7.3.
Let's comment out:
#define FASTCALL __attribute__((stdcall, regparm(3)))
and let's try this:
*/
#define FASTCALL __attribute__((regparm(3)))
#define PTRFASTCALL __attribute__((regparm(3)))
#endif
/* Using __fastcall seems to have an unexpected negative effect under
MS VC++, especially for function pointers, so we won't use it for
now on that platform. It may be reconsidered for a future release
if it can be made more effective.
Likely reason: __fastcall on Windows is like stdcall, therefore
the compiler cannot perform stack optimizations for call clusters.
*/
/* Make sure all of these are defined if they aren't already. */
#ifndef FASTCALL
#define FASTCALL
#endif
#ifndef PTRCALL
#define PTRCALL
#endif
#ifndef PTRFASTCALL
#define PTRFASTCALL
#endif
#ifndef XML_MIN_SIZE
#if !defined(__cplusplus) && !defined(inline)
#ifdef __GNUC__
#define inline __inline
#endif /* __GNUC__ */
#endif
#endif /* XML_MIN_SIZE */
#ifdef __cplusplus
#define inline inline
#else
#ifndef inline
#define inline
#endif
#endif

36
XML/src/latin1tab.h Normal file
View File

@@ -0,0 +1,36 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER,
/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME,
/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER,
/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER,
/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,
/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT,

150
XML/src/nametab.h Normal file
View File

@@ -0,0 +1,150 @@
static const unsigned namingBitmap[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE,
0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF,
0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF,
0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF,
0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD,
0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF,
0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF,
0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE,
0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF,
0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000,
0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060,
0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003,
0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003,
0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000,
0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001,
0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003,
0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000,
0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003,
0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003,
0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000,
0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000,
0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF,
0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB,
0x40000000, 0xF580C900, 0x00000007, 0x02010800,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF,
0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF,
0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF,
0x00000000, 0x00004C40, 0x00000000, 0x00000000,
0x00000007, 0x00000000, 0x00000000, 0x00000000,
0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF,
0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF,
0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000,
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000,
0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE,
0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF,
0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF,
0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000,
0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003,
0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD,
0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF,
0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF,
0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE,
0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF,
0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF,
0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF,
0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF,
0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF,
0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0,
0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1,
0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3,
0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80,
0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3,
0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3,
0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000,
0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000,
0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF,
0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x1FFF0000, 0x00000002,
0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF,
0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF,
};
static const unsigned char nmstrtPages[] = {
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00,
0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13,
0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char namePages[] = {
0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00,
0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13,
0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

37
XML/src/utf8tab.h Normal file
View File

@@ -0,0 +1,37 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2,
/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3,
/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4,
/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM,

6264
XML/src/xmlparse.cpp Normal file

File diff suppressed because it is too large Load Diff

1330
XML/src/xmlrole.c Normal file

File diff suppressed because it is too large Load Diff

114
XML/src/xmlrole.h Normal file
View File

@@ -0,0 +1,114 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
#ifndef XmlRole_INCLUDED
#define XmlRole_INCLUDED 1
#ifdef __VMS
/* 0 1 2 3 0 1 2 3
1234567890123456789012345678901 1234567890123456789012345678901 */
#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt
#endif
#include "xmltok.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
XML_ROLE_ERROR = -1,
XML_ROLE_NONE = 0,
XML_ROLE_XML_DECL,
XML_ROLE_INSTANCE_START,
XML_ROLE_DOCTYPE_NONE,
XML_ROLE_DOCTYPE_NAME,
XML_ROLE_DOCTYPE_SYSTEM_ID,
XML_ROLE_DOCTYPE_PUBLIC_ID,
XML_ROLE_DOCTYPE_INTERNAL_SUBSET,
XML_ROLE_DOCTYPE_CLOSE,
XML_ROLE_GENERAL_ENTITY_NAME,
XML_ROLE_PARAM_ENTITY_NAME,
XML_ROLE_ENTITY_NONE,
XML_ROLE_ENTITY_VALUE,
XML_ROLE_ENTITY_SYSTEM_ID,
XML_ROLE_ENTITY_PUBLIC_ID,
XML_ROLE_ENTITY_COMPLETE,
XML_ROLE_ENTITY_NOTATION_NAME,
XML_ROLE_NOTATION_NONE,
XML_ROLE_NOTATION_NAME,
XML_ROLE_NOTATION_SYSTEM_ID,
XML_ROLE_NOTATION_NO_SYSTEM_ID,
XML_ROLE_NOTATION_PUBLIC_ID,
XML_ROLE_ATTRIBUTE_NAME,
XML_ROLE_ATTRIBUTE_TYPE_CDATA,
XML_ROLE_ATTRIBUTE_TYPE_ID,
XML_ROLE_ATTRIBUTE_TYPE_IDREF,
XML_ROLE_ATTRIBUTE_TYPE_IDREFS,
XML_ROLE_ATTRIBUTE_TYPE_ENTITY,
XML_ROLE_ATTRIBUTE_TYPE_ENTITIES,
XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN,
XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS,
XML_ROLE_ATTRIBUTE_ENUM_VALUE,
XML_ROLE_ATTRIBUTE_NOTATION_VALUE,
XML_ROLE_ATTLIST_NONE,
XML_ROLE_ATTLIST_ELEMENT_NAME,
XML_ROLE_IMPLIED_ATTRIBUTE_VALUE,
XML_ROLE_REQUIRED_ATTRIBUTE_VALUE,
XML_ROLE_DEFAULT_ATTRIBUTE_VALUE,
XML_ROLE_FIXED_ATTRIBUTE_VALUE,
XML_ROLE_ELEMENT_NONE,
XML_ROLE_ELEMENT_NAME,
XML_ROLE_CONTENT_ANY,
XML_ROLE_CONTENT_EMPTY,
XML_ROLE_CONTENT_PCDATA,
XML_ROLE_GROUP_OPEN,
XML_ROLE_GROUP_CLOSE,
XML_ROLE_GROUP_CLOSE_REP,
XML_ROLE_GROUP_CLOSE_OPT,
XML_ROLE_GROUP_CLOSE_PLUS,
XML_ROLE_GROUP_CHOICE,
XML_ROLE_GROUP_SEQUENCE,
XML_ROLE_CONTENT_ELEMENT,
XML_ROLE_CONTENT_ELEMENT_REP,
XML_ROLE_CONTENT_ELEMENT_OPT,
XML_ROLE_CONTENT_ELEMENT_PLUS,
XML_ROLE_PI,
XML_ROLE_COMMENT,
#ifdef XML_DTD
XML_ROLE_TEXT_DECL,
XML_ROLE_IGNORE_SECT,
XML_ROLE_INNER_PARAM_ENTITY_REF,
#endif /* XML_DTD */
XML_ROLE_PARAM_ENTITY_REF
};
typedef struct prolog_state {
int (PTRCALL *handler) (struct prolog_state *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc);
unsigned level;
int role_none;
#ifdef XML_DTD
unsigned includeLevel;
int documentEntity;
int inEntityValue;
#endif /* XML_DTD */
} PROLOG_STATE;
void XmlPrologStateInit(PROLOG_STATE *);
#ifdef XML_DTD
void XmlPrologStateInitExternalEntity(PROLOG_STATE *);
#endif /* XML_DTD */
#define XmlTokenRole(state, tok, ptr, end, enc) \
(((state)->handler)(state, tok, ptr, end, enc))
#ifdef __cplusplus
}
#endif
#endif /* not XmlRole_INCLUDED */

1639
XML/src/xmltok.c Normal file

File diff suppressed because it is too large Load Diff

316
XML/src/xmltok.h Normal file
View File

@@ -0,0 +1,316 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
#ifndef XmlTok_INCLUDED
#define XmlTok_INCLUDED 1
#ifdef __cplusplus
extern "C" {
#endif
/* The following token may be returned by XmlContentTok */
#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be
start of illegal ]]> sequence */
/* The following tokens may be returned by both XmlPrologTok and
XmlContentTok.
*/
#define XML_TOK_NONE -4 /* The string to be scanned is empty */
#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
might be part of CRLF sequence */
#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
#define XML_TOK_PARTIAL -1 /* only part of a token */
#define XML_TOK_INVALID 0
/* The following tokens are returned by XmlContentTok; some are also
returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok.
*/
#define XML_TOK_START_TAG_WITH_ATTS 1
#define XML_TOK_START_TAG_NO_ATTS 2
#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
#define XML_TOK_END_TAG 5
#define XML_TOK_DATA_CHARS 6
#define XML_TOK_DATA_NEWLINE 7
#define XML_TOK_CDATA_SECT_OPEN 8
#define XML_TOK_ENTITY_REF 9
#define XML_TOK_CHAR_REF 10 /* numeric character reference */
/* The following tokens may be returned by both XmlPrologTok and
XmlContentTok.
*/
#define XML_TOK_PI 11 /* processing instruction */
#define XML_TOK_XML_DECL 12 /* XML decl or text decl */
#define XML_TOK_COMMENT 13
#define XML_TOK_BOM 14 /* Byte order mark */
/* The following tokens are returned only by XmlPrologTok */
#define XML_TOK_PROLOG_S 15
#define XML_TOK_DECL_OPEN 16 /* <!foo */
#define XML_TOK_DECL_CLOSE 17 /* > */
#define XML_TOK_NAME 18
#define XML_TOK_NMTOKEN 19
#define XML_TOK_POUND_NAME 20 /* #name */
#define XML_TOK_OR 21 /* | */
#define XML_TOK_PERCENT 22
#define XML_TOK_OPEN_PAREN 23
#define XML_TOK_CLOSE_PAREN 24
#define XML_TOK_OPEN_BRACKET 25
#define XML_TOK_CLOSE_BRACKET 26
#define XML_TOK_LITERAL 27
#define XML_TOK_PARAM_ENTITY_REF 28
#define XML_TOK_INSTANCE_START 29
/* The following occur only in element type declarations */
#define XML_TOK_NAME_QUESTION 30 /* name? */
#define XML_TOK_NAME_ASTERISK 31 /* name* */
#define XML_TOK_NAME_PLUS 32 /* name+ */
#define XML_TOK_COND_SECT_OPEN 33 /* <![ */
#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
#define XML_TOK_COMMA 38
/* The following token is returned only by XmlAttributeValueTok */
#define XML_TOK_ATTRIBUTE_VALUE_S 39
/* The following token is returned only by XmlCdataSectionTok */
#define XML_TOK_CDATA_SECT_CLOSE 40
/* With namespace processing this is returned by XmlPrologTok for a
name with a colon.
*/
#define XML_TOK_PREFIXED_NAME 41
#ifdef XML_DTD
#define XML_TOK_IGNORE_SECT 42
#endif /* XML_DTD */
#ifdef XML_DTD
#define XML_N_STATES 4
#else /* not XML_DTD */
#define XML_N_STATES 3
#endif /* not XML_DTD */
#define XML_PROLOG_STATE 0
#define XML_CONTENT_STATE 1
#define XML_CDATA_SECTION_STATE 2
#ifdef XML_DTD
#define XML_IGNORE_SECTION_STATE 3
#endif /* XML_DTD */
#define XML_N_LITERAL_TYPES 2
#define XML_ATTRIBUTE_VALUE_LITERAL 0
#define XML_ENTITY_VALUE_LITERAL 1
/* The size of the buffer passed to XmlUtf8Encode must be at least this. */
#define XML_UTF8_ENCODE_MAX 4
/* The size of the buffer passed to XmlUtf16Encode must be at least this. */
#define XML_UTF16_ENCODE_MAX 2
typedef struct position {
/* first line and first column are 0 not 1 */
XML_Size lineNumber;
XML_Size columnNumber;
} POSITION;
typedef struct {
const char *name;
const char *valuePtr;
const char *valueEnd;
char normalized;
} ATTRIBUTE;
struct encoding;
typedef struct encoding ENCODING;
typedef int (PTRCALL *SCANNER)(const ENCODING *,
const char *,
const char *,
const char **);
struct encoding {
SCANNER scanners[XML_N_STATES];
SCANNER literalScanners[XML_N_LITERAL_TYPES];
int (PTRCALL *sameName)(const ENCODING *,
const char *,
const char *);
int (PTRCALL *nameMatchesAscii)(const ENCODING *,
const char *,
const char *,
const char *);
int (PTRFASTCALL *nameLength)(const ENCODING *, const char *);
const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *);
int (PTRCALL *getAtts)(const ENCODING *enc,
const char *ptr,
int attsMax,
ATTRIBUTE *atts);
int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr);
int (PTRCALL *predefinedEntityName)(const ENCODING *,
const char *,
const char *);
void (PTRCALL *updatePosition)(const ENCODING *,
const char *ptr,
const char *end,
POSITION *);
int (PTRCALL *isPublicId)(const ENCODING *enc,
const char *ptr,
const char *end,
const char **badPtr);
void (PTRCALL *utf8Convert)(const ENCODING *enc,
const char **fromP,
const char *fromLim,
char **toP,
const char *toLim);
void (PTRCALL *utf16Convert)(const ENCODING *enc,
const char **fromP,
const char *fromLim,
unsigned short **toP,
const unsigned short *toLim);
int minBytesPerChar;
char isUtf8;
char isUtf16;
};
/* Scan the string starting at ptr until the end of the next complete
token, but do not scan past eptr. Return an integer giving the
type of token.
Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
Return XML_TOK_PARTIAL when the string does not contain a complete
token; nextTokPtr will not be set.
Return XML_TOK_INVALID when the string does not start a valid
token; nextTokPtr will be set to point to the character which made
the token invalid.
Otherwise the string starts with a valid token; nextTokPtr will be
set to point to the character following the end of that token.
Each data character counts as a single token, but adjacent data
characters may be returned together. Similarly for characters in
the prolog outside literals, comments and processing instructions.
*/
#define XmlTok(enc, state, ptr, end, nextTokPtr) \
(((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
#define XmlPrologTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
#define XmlContentTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
#ifdef XML_DTD
#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
#endif /* XML_DTD */
/* This is used for performing a 2nd-level tokenization on the content
of a literal that has already been returned by XmlTok.
*/
#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
(((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
#define XmlNameLength(enc, ptr) \
(((enc)->nameLength)(enc, ptr))
#define XmlSkipS(enc, ptr) \
(((enc)->skipS)(enc, ptr))
#define XmlGetAttributes(enc, ptr, attsMax, atts) \
(((enc)->getAtts)(enc, ptr, attsMax, atts))
#define XmlCharRefNumber(enc, ptr) \
(((enc)->charRefNumber)(enc, ptr))
#define XmlPredefinedEntityName(enc, ptr, end) \
(((enc)->predefinedEntityName)(enc, ptr, end))
#define XmlUpdatePosition(enc, ptr, end, pos) \
(((enc)->updatePosition)(enc, ptr, end, pos))
#define XmlIsPublicId(enc, ptr, end, badPtr) \
(((enc)->isPublicId)(enc, ptr, end, badPtr))
#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
(((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
(((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
typedef struct {
ENCODING initEnc;
const ENCODING **encPtr;
} INIT_ENCODING;
int XmlParseXmlDecl(int isGeneralTextEntity,
const ENCODING *enc,
const char *ptr,
const char *end,
const char **badPtr,
const char **versionPtr,
const char **versionEndPtr,
const char **encodingNamePtr,
const ENCODING **namedEncodingPtr,
int *standalonePtr);
int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING *XmlGetUtf8InternalEncoding(void);
const ENCODING *XmlGetUtf16InternalEncoding(void);
int FASTCALL XmlUtf8Encode(int charNumber, char *buf);
int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf);
int XmlSizeOfUnknownEncoding(void);
typedef int (XMLCALL *CONVERTER) (void *userData, const char *p);
ENCODING *
XmlInitUnknownEncoding(void *mem,
int *table,
CONVERTER convert,
void *userData);
int XmlParseXmlDeclNS(int isGeneralTextEntity,
const ENCODING *enc,
const char *ptr,
const char *end,
const char **badPtr,
const char **versionPtr,
const char **versionEndPtr,
const char **encodingNamePtr,
const ENCODING **namedEncodingPtr,
int *standalonePtr);
int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING *XmlGetUtf8InternalEncodingNS(void);
const ENCODING *XmlGetUtf16InternalEncodingNS(void);
ENCODING *
XmlInitUnknownEncodingNS(void *mem,
int *table,
CONVERTER convert,
void *userData);
#ifdef __cplusplus
}
#endif
#endif /* not XmlTok_INCLUDED */

1779
XML/src/xmltok_impl.c Normal file

File diff suppressed because it is too large Load Diff

46
XML/src/xmltok_impl.h Normal file
View File

@@ -0,0 +1,46 @@
/*
Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
enum {
BT_NONXML,
BT_MALFORM,
BT_LT,
BT_AMP,
BT_RSQB,
BT_LEAD2,
BT_LEAD3,
BT_LEAD4,
BT_TRAIL,
BT_CR,
BT_LF,
BT_GT,
BT_QUOT,
BT_APOS,
BT_EQUALS,
BT_QUEST,
BT_EXCL,
BT_SOL,
BT_SEMI,
BT_NUM,
BT_LSQB,
BT_S,
BT_NMSTRT,
BT_COLON,
BT_HEX,
BT_DIGIT,
BT_NAME,
BT_MINUS,
BT_OTHER, /* known not to be a name or name start character */
BT_NONASCII, /* might be a name or name start character */
BT_PERCNT,
BT_LPAR,
BT_RPAR,
BT_AST,
BT_PLUS,
BT_COMMA,
BT_VERBAR
};
#include <stddef.h>

106
XML/src/xmltok_ns.c Normal file
View File

@@ -0,0 +1,106 @@
const ENCODING *
NS(XmlGetUtf8InternalEncoding)(void)
{
return &ns(internal_utf8_encoding).enc;
}
const ENCODING *
NS(XmlGetUtf16InternalEncoding)(void)
{
#if BYTEORDER == 1234
return &ns(internal_little2_encoding).enc;
#elif BYTEORDER == 4321
return &ns(internal_big2_encoding).enc;
#else
const short n = 1;
return (*(const char *)&n
? &ns(internal_little2_encoding).enc
: &ns(internal_big2_encoding).enc);
#endif
}
static const ENCODING * const NS(encodings)[] = {
&ns(latin1_encoding).enc,
&ns(ascii_encoding).enc,
&ns(utf8_encoding).enc,
&ns(big2_encoding).enc,
&ns(big2_encoding).enc,
&ns(little2_encoding).enc,
&ns(utf8_encoding).enc /* NO_ENC */
};
static int PTRCALL
NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
const char **nextTokPtr)
{
return initScan(NS(encodings), (const INIT_ENCODING *)enc,
XML_PROLOG_STATE, ptr, end, nextTokPtr);
}
static int PTRCALL
NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
const char **nextTokPtr)
{
return initScan(NS(encodings), (const INIT_ENCODING *)enc,
XML_CONTENT_STATE, ptr, end, nextTokPtr);
}
int
NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
const char *name)
{
int i = getEncodingIndex(name);
if (i == UNKNOWN_ENC)
return 0;
SET_INIT_ENC_INDEX(p, i);
p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
p->initEnc.updatePosition = initUpdatePosition;
p->encPtr = encPtr;
*encPtr = &(p->initEnc);
return 1;
}
static const ENCODING *
NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
{
#define ENCODING_MAX 128
char buf[ENCODING_MAX];
char *p = buf;
int i;
XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
if (ptr != end)
return 0;
*p = 0;
if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
return enc;
i = getEncodingIndex(buf);
if (i == UNKNOWN_ENC)
return 0;
return NS(encodings)[i];
}
int
NS(XmlParseXmlDecl)(int isGeneralTextEntity,
const ENCODING *enc,
const char *ptr,
const char *end,
const char **badPtr,
const char **versionPtr,
const char **versionEndPtr,
const char **encodingName,
const ENCODING **encoding,
int *standalone)
{
return doParseXmlDecl(NS(findEncoding),
isGeneralTextEntity,
enc,
ptr,
end,
badPtr,
versionPtr,
versionEndPtr,
encodingName,
encoding,
standalone);
}