summaryrefslogtreecommitdiff
path: root/unoxml/source/dom
diff options
context:
space:
mode:
Diffstat (limited to 'unoxml/source/dom')
-rw-r--r--unoxml/source/dom/attr.cxx153
-rw-r--r--unoxml/source/dom/attr.hxx210
-rw-r--r--unoxml/source/dom/attributesmap.cxx211
-rw-r--r--unoxml/source/dom/attributesmap.hxx97
-rw-r--r--unoxml/source/dom/cdatasection.cxx60
-rw-r--r--unoxml/source/dom/cdatasection.hxx230
-rw-r--r--unoxml/source/dom/characterdata.cxx233
-rw-r--r--unoxml/source/dom/characterdata.hxx239
-rw-r--r--unoxml/source/dom/childlist.cxx72
-rw-r--r--unoxml/source/dom/childlist.hxx64
-rw-r--r--unoxml/source/dom/comment.cxx58
-rw-r--r--unoxml/source/dom/comment.hxx222
-rw-r--r--unoxml/source/dom/document.cxx751
-rw-r--r--unoxml/source/dom/document.hxx366
-rw-r--r--unoxml/source/dom/documentbuilder.cxx429
-rw-r--r--unoxml/source/dom/documentbuilder.hxx157
-rw-r--r--unoxml/source/dom/documentfragment.cxx45
-rw-r--r--unoxml/source/dom/documentfragment.hxx179
-rw-r--r--unoxml/source/dom/documenttype.cxx127
-rw-r--r--unoxml/source/dom/documenttype.hxx217
-rw-r--r--unoxml/source/dom/domimplementation.cxx75
-rw-r--r--unoxml/source/dom/domimplementation.hxx73
-rw-r--r--unoxml/source/dom/element.cxx649
-rw-r--r--unoxml/source/dom/element.hxx296
-rw-r--r--unoxml/source/dom/elementlist.cxx133
-rw-r--r--unoxml/source/dom/elementlist.hxx86
-rw-r--r--unoxml/source/dom/entitiesmap.cxx100
-rw-r--r--unoxml/source/dom/entitiesmap.hxx97
-rw-r--r--unoxml/source/dom/entity.cxx90
-rw-r--r--unoxml/source/dom/entity.hxx200
-rw-r--r--unoxml/source/dom/entityreference.cxx52
-rw-r--r--unoxml/source/dom/entityreference.hxx176
-rw-r--r--unoxml/source/dom/makefile.mk74
-rw-r--r--unoxml/source/dom/node.cxx1027
-rw-r--r--unoxml/source/dom/node.hxx354
-rw-r--r--unoxml/source/dom/notation.cxx70
-rw-r--r--unoxml/source/dom/notation.hxx191
-rw-r--r--unoxml/source/dom/notationsmap.cxx101
-rw-r--r--unoxml/source/dom/notationsmap.hxx97
-rw-r--r--unoxml/source/dom/processinginstruction.cxx92
-rw-r--r--unoxml/source/dom/processinginstruction.hxx198
-rw-r--r--unoxml/source/dom/saxbuilder.cxx353
-rw-r--r--unoxml/source/dom/saxbuilder.hxx150
-rw-r--r--unoxml/source/dom/text.cxx72
-rw-r--r--unoxml/source/dom/text.hxx241
45 files changed, 9167 insertions, 0 deletions
diff --git a/unoxml/source/dom/attr.cxx b/unoxml/source/dom/attr.cxx
new file mode 100644
index 000000000000..a1773a7db99f
--- /dev/null
+++ b/unoxml/source/dom/attr.cxx
@@ -0,0 +1,153 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "attr.hxx"
+#include "element.hxx"
+#include <com/sun/star/xml/dom/DOMException.hdl>
+#include <string.h>
+
+namespace DOM
+{
+ CAttr::CAttr(const xmlAttrPtr pAttr)
+ {
+ m_aAttrPtr = pAttr;
+ m_aNodeType = NodeType_ATTRIBUTE_NODE;
+ init_node((xmlNodePtr)pAttr);
+ }
+
+ OUString SAL_CALL CAttr::getNodeName()
+ throw (RuntimeException)
+ {
+ return getName();
+ }
+ OUString SAL_CALL CAttr::getNodeValue()
+ throw (RuntimeException)
+ {
+ return getValue();
+ }
+ OUString SAL_CALL CAttr::getLocalName()
+ throw (RuntimeException)
+ {
+ return getName();
+ }
+
+
+ /**
+ Returns the name of this attribute.
+ */
+ OUString SAL_CALL CAttr::getName() throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aAttrPtr != NULL)
+ {
+ aName = OUString((char*)m_aAttrPtr->name, strlen((char*)m_aAttrPtr->name), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+
+ /**
+ The Element node this attribute is attached to or null if this
+ attribute is not in use.
+ */
+ Reference< XElement > SAL_CALL CAttr::getOwnerElement()
+ throw (RuntimeException)
+ {
+ Reference< XElement > aElement;
+ if (m_aAttrPtr != NULL && m_aAttrPtr->parent != NULL)
+ {
+ aElement = Reference< XElement >(static_cast< CElement* >(CNode::get(m_aAttrPtr->parent)));
+ }
+ return aElement;
+ }
+
+ /**
+ If this attribute was explicitly given a value in the original
+ document, this is true; otherwise, it is false.
+ */
+ sal_Bool SAL_CALL CAttr::getSpecified()
+ throw (RuntimeException)
+ {
+ // XXX what is this supposed do exactly?
+ return sal_False;
+ }
+
+ /**
+ On retrieval, the value of the attribute is returned as a string.
+ */
+ OUString SAL_CALL CAttr::getValue()
+ throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aAttrPtr != NULL && m_aAttrPtr->children != NULL)
+ {
+ aName = OUString((char*)m_aAttrPtr->children->content, strlen((char*)m_aAttrPtr->children->content),
+ RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+
+ /**
+ Sets the value of the attribute from a string.
+ */
+ void SAL_CALL CAttr::setValue(const OUString& value)
+ throw (RuntimeException, DOMException)
+ {
+ // remember old value (for mutation event)
+ OUString sOldValue = getValue();
+
+ OString o1 = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
+ xmlChar* xValue = (xmlChar*)o1.getStr();
+ // xmlChar* xName = OUStringToOString(m_aAttrPtr->name, RTL_TEXTENCODING_UTF8).getStr();
+ // this does not work if the attribute was created anew
+ // xmlNodePtr pNode = m_aAttrPtr->parent;
+ // xmlSetProp(pNode, m_aAttrPtr->name, xValue);
+ xmlChar *buffer = xmlEncodeEntitiesReentrant(m_aAttrPtr->doc, xValue);
+ m_aAttrPtr->children = xmlStringGetNodeList(m_aAttrPtr->doc, buffer);
+ xmlNodePtr tmp = m_aAttrPtr->children;
+ while (tmp != NULL) {
+ tmp->parent = (xmlNodePtr) m_aNodePtr;
+ tmp->doc = m_aAttrPtr->doc;
+ if (tmp->next == NULL)
+ m_aNodePtr->last = tmp;
+ tmp = tmp->next;
+ }
+
+ // dispatch DOM events to signal change in attribute value
+ // dispatch DomAttrModified + DOMSubtreeModified
+ OUString sEventName( RTL_CONSTASCII_USTRINGPARAM("DOMAttrModified") );
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(sEventName),UNO_QUERY);
+ event->initMutationEvent(
+ sEventName, sal_True, sal_False,
+ Reference<XNode>( static_cast<XAttr*>( this ) ),
+ sOldValue, value, getName(), AttrChangeType_MODIFICATION );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ dispatchSubtreeModified();
+ xmlFree(buffer);
+ }
+
+}
diff --git a/unoxml/source/dom/attr.hxx b/unoxml/source/dom/attr.hxx
new file mode 100644
index 000000000000..b79927b46037
--- /dev/null
+++ b/unoxml/source/dom/attr.hxx
@@ -0,0 +1,210 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ATTR_HXX
+#define _ATTR_HXX
+
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XAttr.hpp>
+#include "node.hxx"
+#include <libxml/tree.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CAttr : public cppu::ImplInheritanceHelper1< CNode, XAttr >
+ {
+ friend class CNode;
+ friend class CElement;
+ private:
+ xmlAttrPtr m_aAttrPtr;
+
+ protected:
+ CAttr(const xmlAttrPtr aAttrPtr);
+
+ public:
+ /**
+ Returns the name of this attribute.
+ */
+ virtual OUString SAL_CALL getName() throw (RuntimeException);
+
+ /**
+ The Element node this attribute is attached to or null if this
+ attribute is not in use.
+ */
+ virtual Reference< XElement > SAL_CALL getOwnerElement() throw (RuntimeException);
+
+ /**
+ If this attribute was explicitly given a value in the original
+ document, this is true; otherwise, it is false.
+ */
+ virtual sal_Bool SAL_CALL getSpecified()throw (RuntimeException);
+
+ /**
+ On retrieval, the value of the attribute is returned as a string.
+ */
+ virtual OUString SAL_CALL getValue() throw (RuntimeException);
+
+ /**
+ Sets the value of the attribute from a string.
+ */
+
+ virtual void SAL_CALL setValue(const OUString& value) throw (RuntimeException, DOMException);
+
+ // resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException);
+
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return setValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/attributesmap.cxx b/unoxml/source/dom/attributesmap.cxx
new file mode 100644
index 000000000000..c411365cf1b0
--- /dev/null
+++ b/unoxml/source/dom/attributesmap.cxx
@@ -0,0 +1,211 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "attributesmap.hxx"
+#include <string.h>
+
+namespace DOM
+{
+ CAttributesMap::CAttributesMap(const CElement* aElement)
+ : m_pElement(aElement)
+ {
+ }
+
+ /**
+ The number of nodes in this map.
+ */
+ sal_Int32 SAL_CALL CAttributesMap::getLength() throw (RuntimeException)
+ {
+ sal_Int32 count = 0;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ xmlAttrPtr cur = pNode->properties;
+ while (cur != NULL)
+ {
+ count++;
+ cur = cur->next;
+ }
+ }
+ return count;
+
+ }
+
+ /**
+ Retrieves a node specified by local name
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::getNamedItem(const OUString& name) throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar* xName = (xmlChar*)o1.getStr();
+ xmlAttrPtr cur = pNode->properties;
+ while (cur != NULL)
+ {
+ if( strcmp((char*)xName, (char*)cur->name) == 0)
+ {
+ aNode = Reference< XNode >(static_cast<CNode*>(CNode::get((xmlNodePtr)cur)));
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ return aNode;
+ }
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::getNamedItemNS(const OUString& namespaceURI,const OUString& localName) throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar* xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar* xNs = (xmlChar*)o1.getStr();
+ xmlNsPtr pNs = xmlSearchNs(pNode->doc, pNode, xNs);
+ xmlAttrPtr cur = pNode->properties;
+ while (cur != NULL && pNs != NULL)
+ {
+ if( strcmp((char*)xName, (char*)cur->name) == 0 &&
+ cur->ns == pNs)
+ {
+ aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ return aNode;
+ }
+
+ /**
+ Returns the indexth item in the map.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::item(sal_Int32 index) throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ xmlAttrPtr cur = pNode->properties;
+ sal_Int32 count = 0;
+ while (cur != NULL)
+ {
+ if (count == index)
+ {
+ aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
+ break;
+ }
+ count++;
+ cur = cur->next;
+ }
+ }
+ return aNode;
+
+ }
+
+ /**
+ Removes a node specified by name.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::removeNamedItem(const OUString& name) throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar* xName = (xmlChar*)o1.getStr();
+ xmlAttrPtr cur = pNode->properties;
+ while (cur != NULL)
+ {
+ if( strcmp((char*)xName, (char*)cur->name) == 0)
+ {
+ aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
+ xmlUnlinkNode((xmlNodePtr)cur);
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ return aNode;
+ }
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ xmlNodePtr pNode = m_pElement->m_aNodePtr;
+ if (pNode != NULL)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar* xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar* xNs = (xmlChar*)o1.getStr();
+ xmlNsPtr pNs = xmlSearchNs(pNode->doc, pNode, xNs);
+ xmlAttrPtr cur = pNode->properties;
+ while (cur != NULL && pNs != NULL)
+ {
+ if( strcmp((char*)xName, (char*)cur->name) == 0 &&
+ cur->ns == pNs)
+ {
+ aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
+ xmlUnlinkNode((xmlNodePtr)cur);
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ return aNode;
+ }
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::setNamedItem(const Reference< XNode >& arg) throw (RuntimeException)
+ {
+ return arg;
+ // return Reference< XNode >();
+ }
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ Reference< XNode > SAL_CALL CAttributesMap::setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException)
+ {
+ return arg;
+ // return Reference< XNode >();
+ }
+}
diff --git a/unoxml/source/dom/attributesmap.hxx b/unoxml/source/dom/attributesmap.hxx
new file mode 100644
index 000000000000..d19b517251a0
--- /dev/null
+++ b/unoxml/source/dom/attributesmap.hxx
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ATTRIBUTESMAP_HXX
+#define _ATTRIBUTESMAP_HXX
+
+#include <map>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+#include "node.hxx"
+#include "element.hxx"
+#include "attr.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CAttributesMap : public cppu::WeakImplHelper1< XNamedNodeMap >
+ {
+ private:
+ const CElement* m_pElement;
+ public:
+ CAttributesMap(const CElement* aDocType);
+
+ /**
+ The number of nodes in this map.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException);
+
+ /**
+ Returns the indexth item in the map.
+ */
+ virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
+
+ /**
+ Removes a node specified by name.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException);
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItem(const Reference< XNode >& arg) throw (RuntimeException);
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/cdatasection.cxx b/unoxml/source/dom/cdatasection.cxx
new file mode 100644
index 000000000000..7c775484770c
--- /dev/null
+++ b/unoxml/source/dom/cdatasection.cxx
@@ -0,0 +1,60 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "cdatasection.hxx"
+
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+
+namespace DOM
+{
+ CCDATASection::CCDATASection(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_CDATA_SECTION_NODE;
+ init_text(aNodePtr);
+ }
+
+ void SAL_CALL CCDATASection::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
+ if (xExtended.is()) {
+ xExtended->startCDATA();
+ i_xHandler->characters(getData());
+ xExtended->endCDATA();
+ }
+ }
+
+ OUString SAL_CALL CCDATASection::getNodeName()throw (RuntimeException)
+ {
+ return OUString::createFromAscii("#cdata-section");
+ }
+
+ OUString SAL_CALL CCDATASection::getNodeValue() throw (RuntimeException)
+ {
+ return CCharacterData::getData();
+ }
+}
diff --git a/unoxml/source/dom/cdatasection.hxx b/unoxml/source/dom/cdatasection.hxx
new file mode 100644
index 000000000000..400b2a6a02d3
--- /dev/null
+++ b/unoxml/source/dom/cdatasection.hxx
@@ -0,0 +1,230 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _CDATASECTION_HXX
+#define _CDATASECTION_HXX
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XCDATASection.hpp>
+
+#include "text.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CCDATASection : public cppu::ImplInheritanceHelper1< CText, XCDATASection >
+ {
+ friend class CNode;
+ protected:
+ CCDATASection(const xmlNodePtr aNodePtr);
+
+ public:
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ virtual Reference< XText > SAL_CALL splitText(sal_Int32 offset)
+ throw (RuntimeException)
+ {
+ return CText::splitText(offset);
+ }
+
+ // --- delegations for XCharacterData
+ virtual void SAL_CALL appendData(const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::appendData(arg);
+ }
+ virtual void SAL_CALL deleteData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::deleteData(offset, count);
+ }
+ virtual OUString SAL_CALL getData() throw (RuntimeException)
+ {
+ return CCharacterData::getData();
+ }
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException)
+ {
+ return CCharacterData::getLength();
+ }
+ virtual void SAL_CALL insertData(sal_Int32 offset, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::insertData(offset, arg);
+ }
+ virtual void SAL_CALL replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::replaceData(offset, count, arg);
+ }
+ virtual void SAL_CALL setData(const OUString& data)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::setData(data);
+ }
+ virtual OUString SAL_CALL subStringData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::subStringData(offset, count);
+ }
+
+
+ // --- overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+
+}
+
+#endif
diff --git a/unoxml/source/dom/characterdata.cxx b/unoxml/source/dom/characterdata.cxx
new file mode 100644
index 000000000000..8a8407678272
--- /dev/null
+++ b/unoxml/source/dom/characterdata.cxx
@@ -0,0 +1,233 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
+#include "characterdata.hxx"
+#include "../events/mutationevent.hxx"
+#include <string.h>
+
+namespace DOM
+{
+
+ CCharacterData::CCharacterData()
+ {}
+
+ void CCharacterData::_dispatchEvent(const OUString& prevValue, const OUString& newValue)
+ {
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMCharacterDataModified")), UNO_QUERY);
+ event->initMutationEvent(
+ OUString::createFromAscii("DOMCharacterDataModified"),
+ sal_True, sal_False, Reference< XNode >(),
+ prevValue, newValue, OUString(), (AttrChangeType)0 );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ dispatchSubtreeModified();
+ }
+
+ void CCharacterData::init_characterdata(const xmlNodePtr aNodePtr)
+ {
+ init_node(aNodePtr);
+ }
+
+ /**
+ Append the string to the end of the character data of the node.
+ */
+ void SAL_CALL CCharacterData::appendData(const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ if (m_aNodePtr != NULL)
+ {
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ xmlNodeAddContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+ }
+ }
+
+ /**
+ Remove a range of 16-bit units from the node.
+ */
+ void SAL_CALL CCharacterData::deleteData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ if (m_aNodePtr != NULL)
+ {
+ // get current data
+ OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
+ if (offset > tmp.getLength() || offset < 0 || count < 0) {
+ DOMException e;
+ e.Code = DOMExceptionType_INDEX_SIZE_ERR;
+ throw e;
+ }
+ if ((offset+count) > tmp.getLength())
+ count = tmp.getLength() - offset;
+
+ OUString tmp2 = tmp.copy(0, offset);
+ tmp2 += tmp.copy(offset+count, tmp.getLength() - (offset+count));
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
+ }
+ }
+
+
+ /**
+ Return the character data of the node that implements this interface.
+ */
+ OUString SAL_CALL CCharacterData::getData() throw (RuntimeException)
+ {
+ OUString aData;
+ if (m_aNodePtr != NULL)
+ {
+ OSL_ENSURE(m_aNodePtr->content, "character data node with NULL content, please inform lars.oppermann@sun.com!");
+ if (m_aNodePtr->content != NULL)
+ {
+ aData = OUString((const sal_Char*)m_aNodePtr->content, strlen((const sal_Char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ }
+ }
+ return aData;
+ }
+
+ /**
+ The number of 16-bit units that are available through data and the
+ substringData method below.
+ */
+ sal_Int32 CCharacterData::getLength() throw (RuntimeException)
+ {
+ sal_Int32 length = 0;
+ if (m_aNodePtr != NULL)
+ {
+ OUString aData((const sal_Char*)m_aNodePtr->content, strlen((const sal_Char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ length = aData.getLength();
+ }
+ return length;
+ }
+
+ /**
+ Insert a string at the specified 16-bit unit offset.
+ */
+ void SAL_CALL CCharacterData::insertData(sal_Int32 offset, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ if (m_aNodePtr != NULL)
+ {
+ // get current data
+ OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
+ if (offset > tmp.getLength() || offset < 0) {
+ DOMException e;
+ e.Code = DOMExceptionType_INDEX_SIZE_ERR;
+ throw e;
+ }
+
+ OUString tmp2 = tmp.copy(0, offset);
+ tmp2 += arg;
+ tmp2 += tmp.copy(offset, tmp.getLength() - offset);
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
+ }
+ }
+
+
+ /**
+ Replace the characters starting at the specified 16-bit unit offset
+ with the specified string.
+ */
+ void SAL_CALL CCharacterData::replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ if (m_aNodePtr != NULL)
+ {
+ // get current data
+ OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
+ if (offset > tmp.getLength() || offset < 0 || count < 0){
+ DOMException e;
+ e.Code = DOMExceptionType_INDEX_SIZE_ERR;
+ throw e;
+ }
+ if ((offset+count) > tmp.getLength())
+ count = tmp.getLength() - offset;
+
+ OUString tmp2 = tmp.copy(0, offset);
+ tmp2 += arg;
+ tmp2 += tmp.copy(offset+count, tmp.getLength() - (offset+count));
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(tmp2, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+ }
+ }
+
+ /**
+ Set the character data of the node that implements this interface.
+ */
+ void SAL_CALL CCharacterData::setData(const OUString& data)
+ throw (RuntimeException, DOMException)
+ {
+ if (m_aNodePtr != NULL)
+ {
+ OUString oldValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ xmlNodeSetContent(m_aNodePtr, (const xmlChar*)(OUStringToOString(data, RTL_TEXTENCODING_UTF8).getStr()));
+ OUString newValue((char*)m_aNodePtr->content, strlen((char*)m_aNodePtr->content), RTL_TEXTENCODING_UTF8);
+ _dispatchEvent(oldValue, newValue);
+
+ }
+ }
+
+ /**
+ Extracts a range of data from the node.
+ */
+ OUString SAL_CALL CCharacterData::subStringData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ OUString aStr;
+ if (m_aNodePtr != NULL)
+ {
+ // get current data
+ OString aData((const sal_Char*)xmlNodeGetContent(m_aNodePtr));
+ OUString tmp(aData, aData.getLength(), RTL_TEXTENCODING_UTF8);
+ if (offset > tmp.getLength() || offset < 0 || count < 0) {
+ DOMException e;
+ e.Code = DOMExceptionType_INDEX_SIZE_ERR;
+ throw e;
+ }
+ aStr = tmp.copy(offset, count);
+ }
+ return aStr;
+ }
+
+
+} // namspace DOM
+
diff --git a/unoxml/source/dom/characterdata.hxx b/unoxml/source/dom/characterdata.hxx
new file mode 100644
index 000000000000..4ff1da570f7c
--- /dev/null
+++ b/unoxml/source/dom/characterdata.hxx
@@ -0,0 +1,239 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _CHARACTERDATA_HXX
+#define _CHARACTERDATA_HXX
+
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XCharacterData.hpp>
+#include <com/sun/star/xml/dom/XElement.hpp>
+#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
+#include <libxml/tree.h>
+#include "node.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CCharacterData : public cppu::ImplInheritanceHelper1< CNode, XCharacterData >
+ {
+
+
+ protected:
+ CCharacterData();
+ void init_characterdata(const xmlNodePtr aNodePtr);
+ void _dispatchEvent(const OUString& prevValue, const OUString& newValue);
+
+ public:
+ /**
+ Append the string to the end of the character data of the node.
+ */
+ virtual void SAL_CALL appendData(const OUString& arg)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Remove a range of 16-bit units from the node.
+ */
+ virtual void SAL_CALL deleteData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Return the character data of the node that implements this interface.
+ */
+ virtual OUString SAL_CALL getData() throw (RuntimeException);
+
+ /**
+ The number of 16-bit units that are available through data and the
+ substringData method below.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+
+ /**
+ Insert a string at the specified 16-bit unit offset.
+ */
+ virtual void SAL_CALL insertData(sal_Int32 offset, const OUString& arg)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Replace the characters starting at the specified 16-bit unit offset
+ with the specified string.
+ */
+ virtual void SAL_CALL replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Set the character data of the node that implements this interface.
+ */
+ virtual void SAL_CALL setData(const OUString& data)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Extracts a range of data from the node.
+ */
+ virtual OUString SAL_CALL subStringData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException);
+
+ // --- delegation for XNode base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeName();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException)
+ {
+ return getData();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return setData(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/childlist.cxx b/unoxml/source/dom/childlist.cxx
new file mode 100644
index 000000000000..aaa6e157225d
--- /dev/null
+++ b/unoxml/source/dom/childlist.cxx
@@ -0,0 +1,72 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "childlist.hxx"
+namespace DOM
+{
+ CChildList::CChildList(const CNode* base)
+ : m_pNode(base->m_aNodePtr)
+ {
+ }
+
+ /**
+ The number of nodes in the list.
+ */
+ sal_Int32 SAL_CALL CChildList::getLength() throw (RuntimeException)
+ {
+ sal_Int32 length = 0;
+ if (m_pNode != NULL)
+ {
+ xmlNodePtr cur = m_pNode->children;
+ while (cur != NULL)
+ {
+ length++;
+ cur = cur->next;
+ }
+ }
+ return length;
+
+ }
+ /**
+ Returns the indexth item in the collection.
+ */
+ Reference< XNode > SAL_CALL CChildList::item(sal_Int32 index) throw (RuntimeException)
+ {
+ Reference< XNode >aNode;
+ if (m_pNode != NULL)
+ {
+ xmlNodePtr cur = m_pNode->children;
+ while (cur != NULL)
+ {
+ if (index-- == 0)
+ aNode = Reference< XNode >(CNode::get(cur));
+ cur = cur->next;
+ }
+ }
+ return aNode;
+ }
+}
diff --git a/unoxml/source/dom/childlist.hxx b/unoxml/source/dom/childlist.hxx
new file mode 100644
index 000000000000..89b73ff2e113
--- /dev/null
+++ b/unoxml/source/dom/childlist.hxx
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _CHILDLIST_HXX
+#define _CHILDLIST_HXX
+
+#include <map>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNodeList.hpp>
+#include "node.hxx"
+#include "libxml/tree.h"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CChildList : public cppu::WeakImplHelper1< XNodeList >
+ {
+ private:
+ const xmlNodePtr m_pNode;
+ public:
+ CChildList(const CNode* base);
+ /**
+ The number of nodes in the list.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+ /**
+ Returns the indexth item in the collection.
+ */
+ virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/comment.cxx b/unoxml/source/dom/comment.cxx
new file mode 100644
index 000000000000..f0f14a2d944a
--- /dev/null
+++ b/unoxml/source/dom/comment.cxx
@@ -0,0 +1,58 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "comment.hxx"
+
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+
+namespace DOM
+{
+ CComment::CComment(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_COMMENT_NODE;
+ init_node(aNodePtr);
+ }
+
+ void SAL_CALL CComment::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
+ if (xExtended.is()) {
+ xExtended->comment(getData());
+ }
+ }
+
+ OUString SAL_CALL CComment::getNodeName()throw (RuntimeException)
+ {
+ return OUString::createFromAscii("#comment");
+ }
+
+ OUString SAL_CALL CComment::getNodeValue() throw (RuntimeException)
+ {
+ return CCharacterData::getData();
+ }
+}
diff --git a/unoxml/source/dom/comment.hxx b/unoxml/source/dom/comment.hxx
new file mode 100644
index 000000000000..196c7460399e
--- /dev/null
+++ b/unoxml/source/dom/comment.hxx
@@ -0,0 +1,222 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _COMMENT_HXX
+#define _COMMENT_HXX
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XComment.hpp>
+#include "characterdata.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CComment : public cppu::ImplInheritanceHelper1< CCharacterData, XComment >
+ {
+ friend class CNode;
+ protected:
+ CComment(const xmlNodePtr aNodePtr);
+
+ public:
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ // --- delegations for XCharacterData
+ virtual void SAL_CALL appendData(const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::appendData(arg);
+ }
+ virtual void SAL_CALL deleteData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::deleteData(offset, count);
+ }
+ virtual OUString SAL_CALL getData() throw (RuntimeException)
+ {
+ return CCharacterData::getData();
+ }
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException)
+ {
+ return CCharacterData::getLength();
+ }
+ virtual void SAL_CALL insertData(sal_Int32 offset, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::insertData(offset, arg);
+ }
+ virtual void SAL_CALL replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::replaceData(offset, count, arg);
+ }
+ virtual void SAL_CALL setData(const OUString& data)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::setData(data);
+ }
+ virtual OUString SAL_CALL subStringData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::subStringData(offset, count);
+ }
+
+
+ // --- overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CCharacterData::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CCharacterData::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CCharacterData::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::setPrefix(prefix);
+ }
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/document.cxx b/unoxml/source/dom/document.cxx
new file mode 100644
index 000000000000..656aa1cbef6c
--- /dev/null
+++ b/unoxml/source/dom/document.cxx
@@ -0,0 +1,751 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <com/sun/star/uno/Sequence.h>
+
+#include "document.hxx"
+#include "attr.hxx"
+#include "element.hxx"
+#include "cdatasection.hxx"
+#include "documentfragment.hxx"
+#include "text.hxx"
+#include "cdatasection.hxx"
+#include "comment.hxx"
+#include "processinginstruction.hxx"
+#include "entityreference.hxx"
+#include "documenttype.hxx"
+#include "elementlist.hxx"
+#include "domimplementation.hxx"
+
+#include "../events/event.hxx"
+#include "../events/mutationevent.hxx"
+#include "../events/uievent.hxx"
+#include "../events/mouseevent.hxx"
+
+#include <string.h>
+
+#include <com/sun/star/xml/sax/FastToken.hpp>
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+
+namespace DOM
+{
+ void CDocument::addnode(xmlNodePtr aNode)
+ {
+ if (aNode != (xmlNodePtr)m_aDocPtr)
+ {
+ Reference< XNode >* nref = new Reference< XNode >(CNode::get(aNode));
+ m_aNodeRefList.push_back(nref);
+ }
+ }
+
+ CDocument::~CDocument()
+ {
+ Reference< XNode >* pRef;
+ nodereflist_t::const_iterator r = m_aNodeRefList.begin();
+ while (r!=m_aNodeRefList.end())
+ {
+ pRef = *r;
+ delete pRef;
+ r++;
+ }
+
+ // get rid of leftover instances, if anybody still holds a
+ // reference to one of these, it will be invalid!
+ /*
+ CNode* aNode = 0;
+ nodelist_t::const_iterator i = m_aNodeList.begin();
+ while (i!=m_aNodeList.end())
+ {
+ aNode = CNode::get(*i, sal_False);
+ if (aNode != 0)
+ {
+ // CNode::remove(*i);
+ // delete will remove
+ delete aNode;
+ }
+ i++;
+ }
+ */
+
+ xmlFreeDoc(m_aDocPtr);
+
+ }
+
+ CDocument::CDocument(xmlDocPtr aDocPtr):
+ m_aNodeRefList(),
+ m_aDocPtr(aDocPtr),
+ m_streamListeners()
+ {
+ // init node base
+ m_aNodeType = NodeType_DOCUMENT_NODE;
+ init_node((xmlNodePtr)m_aDocPtr);
+ }
+
+ void SAL_CALL CDocument::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ i_xHandler->startDocument();
+ for (xmlNodePtr pChild = m_aNodePtr->children;
+ pChild != 0; pChild = pChild->next) {
+ CNode * pNode = CNode::get(pChild);
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+ pNode->saxify(i_xHandler);
+ }
+ i_xHandler->endDocument();
+ }
+
+ void SAL_CALL CDocument::fastSaxify( Context& rContext ) {
+ rContext.mxDocHandler->startDocument();
+ for (xmlNodePtr pChild = m_aNodePtr->children;
+ pChild != 0; pChild = pChild->next) {
+ CNode * pNode = CNode::get(pChild);
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+ pNode->fastSaxify(rContext);
+ }
+ rContext.mxDocHandler->endDocument();
+ }
+
+ void SAL_CALL CDocument::addListener(const Reference< XStreamListener >& aListener )
+ throw (RuntimeException)
+ {
+ m_streamListeners.insert(aListener);
+ }
+
+ void SAL_CALL CDocument::removeListener(const Reference< XStreamListener >& aListener )
+ throw (RuntimeException)
+ {
+ m_streamListeners.erase(aListener);
+ }
+
+ // IO context functions for libxml2 interaction
+ typedef struct {
+ Reference< XOutputStream > stream;
+ bool allowClose;
+ } IOContext;
+
+ extern "C" {
+ // write callback
+ // int xmlOutputWriteCallback (void * context, const char * buffer, int len)
+ static int writeCallback(void *context, const char* buffer, int len){
+ // create a sequence and write it to the stream
+ IOContext *pContext = static_cast<IOContext*>(context);
+ Sequence<sal_Int8> bs(reinterpret_cast<const sal_Int8*>(buffer), len);
+ pContext->stream->writeBytes(bs);
+ return len;
+ }
+
+ // clsoe callback
+ //int xmlOutputCloseCallback (void * context)
+ static int closeCallback(void *context)
+ {
+ IOContext *pContext = static_cast<IOContext*>(context);
+ if (pContext->allowClose) {
+ pContext->stream->closeOutput();
+ }
+ return 0;
+ }
+ } // extern "C"
+
+ void SAL_CALL CDocument::start()
+ throw (RuntimeException)
+ {
+ if (! m_rOutputStream.is()) return;
+
+ // notify listners about start
+ listenerlist_t::const_iterator iter1 = m_streamListeners.begin();
+ while (iter1 != m_streamListeners.end()) {
+ Reference< XStreamListener > aListener = *iter1;
+ aListener->started();
+ iter1++;
+ }
+
+ // setup libxml IO and write data to output stream
+ IOContext ioctx = {m_rOutputStream, false};
+ xmlOutputBufferPtr pOut = xmlOutputBufferCreateIO(
+ writeCallback, closeCallback, &ioctx, NULL);
+ xmlSaveFileTo(pOut, m_aNodePtr->doc, NULL);
+
+ // call listeners
+ listenerlist_t::const_iterator iter2 = m_streamListeners.begin();
+ while (iter2 != m_streamListeners.end()) {
+ Reference< XStreamListener > aListener = *iter2;
+ aListener->closed();
+ iter2++;
+ }
+
+ }
+
+ void SAL_CALL CDocument::terminate()
+ throw (RuntimeException)
+ {
+ // not supported
+ }
+
+ void SAL_CALL CDocument::setOutputStream( const Reference< XOutputStream >& aStream )
+ throw (RuntimeException)
+ {
+ m_rOutputStream = aStream;
+ }
+
+ Reference< XOutputStream > SAL_CALL CDocument::getOutputStream() throw (RuntimeException)
+ {
+ return m_rOutputStream;
+ }
+
+ // Creates an Attr of the given name.
+ Reference< XAttr > SAL_CALL CDocument::createAttribute(const OUString& name)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ return Reference< XAttr >(static_cast< CAttr* >(
+ CNode::get((xmlNodePtr)xmlNewDocProp(m_aDocPtr, xName, NULL))));
+ };
+
+ // Creates an attribute of the given qualified name and namespace URI.
+ Reference< XAttr > SAL_CALL CDocument::createAttributeNS(
+ const OUString& ns, const OUString& qname)
+ throw (RuntimeException, DOMException)
+ {
+
+ // libxml does not allow a NS definition to be attached to an
+ // attribute node - which is a good thing, since namespaces are
+ // only defined as parts of element nodes
+ // thus, we create a temporary element node which carries the ns definition
+ // and is removed/merged as soon as the attribute gets append to it's
+ // actual parent
+ sal_Int32 i = qname.indexOf(':');
+ OString oPrefix, oName, oUri;
+ xmlChar *xPrefix, *xName, *xUri;
+ if (i != -1)
+ {
+ oPrefix = OUStringToOString(qname.copy(0, i), RTL_TEXTENCODING_UTF8);
+ xPrefix = (xmlChar*)oPrefix.getStr();
+ oName = OUStringToOString(qname.copy(i+1, qname.getLength()-i-1), RTL_TEXTENCODING_UTF8);
+ }
+ else
+ {
+ xPrefix = (xmlChar*)"";
+ oName = OUStringToOString(qname, RTL_TEXTENCODING_UTF8);
+ }
+ xName = (xmlChar*)oName.getStr();
+ oUri = OUStringToOString(ns, RTL_TEXTENCODING_UTF8);
+ xUri = (xmlChar*)oUri.getStr();
+
+ // create the carrier node
+ xmlNodePtr pNode = xmlNewDocNode(m_aDocPtr, NULL, (xmlChar*)"__private", NULL);
+ xmlNsPtr pNs = xmlNewNs(pNode, xUri, xPrefix);
+ xmlAttrPtr pAttr = xmlNewNsProp(pNode, pNs, xName, NULL);
+ return Reference< XAttr >(static_cast< CAttr* >(CNode::get((xmlNodePtr)pAttr)));
+ };
+
+ // Creates a CDATASection node whose value is the specified string.
+ Reference< XCDATASection > SAL_CALL CDocument::createCDATASection(const OUString& data)
+ throw (RuntimeException)
+ {
+ xmlChar *xData = (xmlChar*)OUStringToOString(data, RTL_TEXTENCODING_UTF8).getStr();
+ xmlNodePtr pText = xmlNewCDataBlock(m_aDocPtr, xData, strlen((char*)xData));
+ return Reference< XCDATASection >(static_cast< CCDATASection* >(CNode::get(pText)));
+ }
+
+ // Creates a Comment node given the specified string.
+ Reference< XComment > SAL_CALL CDocument::createComment(const OUString& data)
+ throw (RuntimeException)
+ {
+ OString o1 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
+ xmlChar *xData = (xmlChar*)o1.getStr();
+ xmlNodePtr pComment = xmlNewDocComment(m_aDocPtr, xData);
+ return Reference< XComment >(static_cast< CComment* >(CNode::get(pComment)));
+ }
+
+ //Creates an empty DocumentFragment object.
+ Reference< XDocumentFragment > SAL_CALL CDocument::createDocumentFragment()
+ throw (RuntimeException)
+ {
+ xmlNodePtr pFrag = xmlNewDocFragment(m_aDocPtr);
+ return Reference< XDocumentFragment >(static_cast< CDocumentFragment* >(CNode::get(pFrag)));
+ }
+
+ // Creates an element of the type specified.
+ Reference< XElement > SAL_CALL CDocument::createElement(const OUString& tagName)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(tagName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ xmlNodePtr aNodePtr = xmlNewDocNode(m_aDocPtr, NULL, xName, NULL);
+ return Reference< XElement >(static_cast< CElement* >(CNode::get(aNodePtr)));
+ }
+
+ // Creates an element of the given qualified name and namespace URI.
+ Reference< XElement > SAL_CALL CDocument::createElementNS(
+ const OUString& ns, const OUString& qname)
+ throw (RuntimeException, DOMException)
+ {
+ sal_Int32 i = qname.indexOf(':');
+ if (ns.getLength() == 0) throw RuntimeException();
+ xmlChar *xPrefix;
+ xmlChar *xName;
+ OString o1, o2, o3;
+ if ( i != -1) {
+ o1 = OUStringToOString(qname.copy(0, i), RTL_TEXTENCODING_UTF8);
+ xPrefix = (xmlChar*)o1.getStr();
+ o2 = OUStringToOString(qname.copy(i+1, qname.getLength()-i-1), RTL_TEXTENCODING_UTF8);
+ xName = (xmlChar*)o2.getStr();
+ } else {
+ // default prefix
+ xPrefix = (xmlChar*)"";
+ o2 = OUStringToOString(qname, RTL_TEXTENCODING_UTF8);
+ xName = (xmlChar*)o2.getStr();
+ }
+ o3 = OUStringToOString(ns, RTL_TEXTENCODING_UTF8);
+ xmlChar *xUri = (xmlChar*)o3.getStr();
+
+ // xmlNsPtr aNsPtr = xmlNewReconciledNs?
+ // xmlNsPtr aNsPtr = xmlNewGlobalNs?
+ xmlNodePtr aNodePtr = xmlNewDocNode(m_aDocPtr, NULL, xName, NULL);
+ xmlNsPtr pNs = xmlNewNs(aNodePtr, xUri, xPrefix);
+ xmlSetNs(aNodePtr, pNs);
+ return Reference< XElement >(static_cast< CElement* >(CNode::get(aNodePtr)));
+ }
+
+ //Creates an EntityReference object.
+ Reference< XEntityReference > SAL_CALL CDocument::createEntityReference(const OUString& name)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ xmlNodePtr aNodePtr = xmlNewReference(m_aDocPtr, xName);
+ return Reference< XEntityReference >(static_cast< CEntityReference* >(CNode::get(aNodePtr)));
+ }
+
+ // Creates a ProcessingInstruction node given the specified name and
+ // data strings.
+ Reference< XProcessingInstruction > SAL_CALL CDocument::createProcessingInstruction(
+ const OUString& target, const OUString& data)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(target, RTL_TEXTENCODING_UTF8);
+ xmlChar *xTarget = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
+ xmlChar *xData = (xmlChar*)o2.getStr();
+ xmlNodePtr aNodePtr = xmlNewPI(xTarget, xData);
+ aNodePtr->doc = m_aDocPtr;
+ return Reference< XProcessingInstruction >(static_cast< CProcessingInstruction* >(CNode::get(aNodePtr)));
+ }
+
+ // Creates a Text node given the specified string.
+ Reference< XText > SAL_CALL CDocument::createTextNode(const OUString& data)
+ throw (RuntimeException)
+ {
+ OString o1 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
+ xmlChar *xData = (xmlChar*)o1.getStr();
+ xmlNodePtr aNodePtr = xmlNewDocText(m_aDocPtr, xData);
+ return Reference< XText >(static_cast< CText* >(CNode::get(aNodePtr)));
+ }
+
+ // The Document Type Declaration (see DocumentType) associated with this
+ // document.
+ Reference< XDocumentType > SAL_CALL CDocument::getDoctype()
+ throw (RuntimeException)
+ {
+ // find the doc type
+ xmlNodePtr cur = m_aDocPtr->children;
+ while (cur != NULL)
+ {
+ if (cur->type == XML_DOCUMENT_TYPE_NODE || cur->type == XML_DTD_NODE)
+ break;
+ }
+ return Reference< XDocumentType >(static_cast< CDocumentType* >(CNode::get(cur)));
+ }
+
+ /// get the pointer to the root element node of the document
+ static xmlNodePtr SAL_CALL _getDocumentRootPtr(xmlDocPtr i_pDocument) {
+ // find the document element
+ xmlNodePtr cur = i_pDocument->children;
+ while (cur != NULL)
+ {
+ if (cur->type == XML_ELEMENT_NODE)
+ break;
+ cur = cur->next;
+ }
+ return cur;
+ }
+
+ // This is a convenience attribute that allows direct access to the child
+ // node that is the root element of the document.
+ Reference< XElement > SAL_CALL CDocument::getDocumentElement()
+ throw (RuntimeException)
+ {
+ xmlNodePtr cur = _getDocumentRootPtr(m_aDocPtr);
+ return Reference< XElement >(static_cast< CElement* >(CNode::get(cur)));
+ }
+
+ static xmlNodePtr _search_element_by_id(const xmlNodePtr cur, const xmlChar* id)
+ {
+
+ if (cur == NULL)
+ return NULL;
+ // look in current node
+ if (cur->type == XML_ELEMENT_NODE)
+ {
+ xmlAttrPtr a = cur->properties;
+ while (a != NULL)
+ {
+ if (a->atype == XML_ATTRIBUTE_ID) {
+ if (strcmp((char*)a->children->content, (char*)id) == 0)
+ return cur;
+ }
+ a = a->next;
+ }
+ }
+ // look in children
+ xmlNodePtr result = _search_element_by_id(cur->children, id);
+ if (result != NULL)
+ return result;
+ result = _search_element_by_id(cur->next, id);
+ return result;
+ }
+
+ // Returns the Element whose ID is given by elementId.
+ Reference< XElement > SAL_CALL CDocument::getElementById(const OUString& elementId)
+ throw (RuntimeException)
+ {
+ // search the tree for an element with the given ID
+ OString o1 = OUStringToOString(elementId, RTL_TEXTENCODING_UTF8);
+ xmlChar *xId = (xmlChar*)o1.getStr();
+ xmlNodePtr pStart = CNode::getNodePtr(getDocumentElement().get());
+ xmlNodePtr aNodePtr = _search_element_by_id(pStart, xId);
+ return Reference< XElement >(static_cast< CElement* >(CNode::get(aNodePtr)));
+ }
+
+
+ Reference< XNodeList > SAL_CALL CDocument::getElementsByTagName(const OUString& tagname)
+ throw (RuntimeException)
+ {
+ // build a list
+ return Reference< XNodeList >(
+ new CElementList(static_cast< CElement* >(
+ this->getDocumentElement().get()), tagname));
+ }
+
+ Reference< XNodeList > SAL_CALL CDocument::getElementsByTagNameNS(
+ const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException)
+ {
+ return Reference< XNodeList >(
+ new CElementList(static_cast< CElement* >(
+ this->getDocumentElement().get()), namespaceURI, localName));
+ }
+
+ Reference< XDOMImplementation > SAL_CALL CDocument::getImplementation()
+ throw (RuntimeException)
+ {
+ // XXX
+ return Reference< XDOMImplementation >(CDOMImplementation::get());
+ }
+
+ // helper function to recall import for siblings
+ static Reference< XNode > _import_siblings (
+ const Reference< XNode > aNode, const Reference< XNode> parent, CDocument* pTarget)
+ {
+ Reference< XNode > sibling = aNode;
+ Reference< XNode > tmp;
+ Reference< XNode > firstImported;
+ while (sibling.is())
+ {
+ tmp = pTarget->importNode(sibling, sal_True);
+ parent->appendChild(tmp);
+ if (!firstImported.is())
+ firstImported = tmp;
+ sibling = sibling->getNextSibling();
+ }
+ return firstImported;
+ }
+
+ Reference< XNode > SAL_CALL CDocument::importNode(
+ const Reference< XNode >& importedNode, sal_Bool deep)
+ throw (RuntimeException, DOMException)
+ {
+ // this node could be from another memory model
+ // only use uno interfaces to access is!!!
+
+ // allready in doc?
+ if ( importedNode->getOwnerDocument() ==
+ Reference< XDocument>(static_cast< CDocument* >(CNode::get((xmlNodePtr)m_aDocPtr))))
+ return importedNode;
+
+ Reference< XNode > aNode;
+ NodeType aNodeType = importedNode->getNodeType();
+ switch (aNodeType)
+ {
+ case NodeType_ATTRIBUTE_NODE:
+ {
+ Reference< XAttr > attr(importedNode, UNO_QUERY);
+ Reference< XAttr > newAttr = createAttribute(attr->getName());
+ newAttr->setValue(attr->getValue());
+ aNode.set(newAttr, UNO_QUERY);
+ break;
+ }
+ case NodeType_CDATA_SECTION_NODE:
+ {
+ Reference< XCDATASection > cdata(importedNode, UNO_QUERY);
+ Reference< XCDATASection > newCdata = createCDATASection(cdata->getData());
+ aNode.set(newCdata, UNO_QUERY);
+ break;
+ }
+ case NodeType_COMMENT_NODE:
+ {
+ Reference< XComment > comment(importedNode, UNO_QUERY);
+ Reference< XComment > newComment = createComment(comment->getData());
+ aNode.set(newComment, UNO_QUERY);
+ break;
+ }
+ case NodeType_DOCUMENT_FRAGMENT_NODE:
+ {
+ Reference< XDocumentFragment > frag(importedNode, UNO_QUERY);
+ Reference< XDocumentFragment > newFrag = createDocumentFragment();
+ aNode.set(newFrag, UNO_QUERY);
+ break;
+ }
+ case NodeType_ELEMENT_NODE:
+ {
+ Reference< XElement > element(importedNode, UNO_QUERY);
+ OUString aNsUri = importedNode->getNamespaceURI();
+ OUString aNsPrefix = importedNode->getPrefix();
+ OUString aQName = element->getTagName();
+ Reference< XElement > newElement;
+ if (aNsUri.getLength() > 0)
+ {
+
+ if (aNsPrefix.getLength() > 0)
+ aQName = aNsPrefix + OUString::createFromAscii(":") + aQName;
+ newElement = createElementNS(aNsUri, aQName);
+ }
+ else
+ newElement = createElement(aQName);
+
+ // get attributes
+ if (element->hasAttributes())
+ {
+ Reference< XNamedNodeMap > attribs = element->getAttributes();
+ Reference< XAttr > curAttr;
+ for (sal_Int32 i = 0; i < attribs->getLength(); i++)
+ {
+ curAttr = Reference< XAttr >(attribs->item(i), UNO_QUERY);
+ OUString aAttrUri = curAttr->getNamespaceURI();
+ OUString aAttrPrefix = curAttr->getPrefix();
+ OUString aAttrName = curAttr->getName();
+ if (aAttrUri.getLength() > 0)
+ {
+ if (aAttrPrefix.getLength() > 0)
+ aAttrName = aAttrPrefix + OUString::createFromAscii(":") + aAttrName;
+ newElement->setAttributeNS(aAttrUri, aAttrName, curAttr->getValue());
+ }
+ else
+ newElement->setAttribute(aAttrName, curAttr->getValue());
+ }
+ }
+ aNode.set(newElement, UNO_QUERY);
+ break;
+ }
+ case NodeType_ENTITY_REFERENCE_NODE:
+ {
+ Reference< XEntityReference > ref(importedNode, UNO_QUERY);
+ Reference< XEntityReference > newRef(createEntityReference(ref->getNodeName()));
+ aNode.set(newRef, UNO_QUERY);
+ break;
+ }
+ case NodeType_PROCESSING_INSTRUCTION_NODE:
+ {
+ Reference< XProcessingInstruction > pi(importedNode, UNO_QUERY);
+ Reference< XProcessingInstruction > newPi(
+ createProcessingInstruction(pi->getTarget(), pi->getData()));
+ aNode.set(newPi, UNO_QUERY);
+ break;
+ }
+ case NodeType_TEXT_NODE:
+ {
+ Reference< XText > text(importedNode, UNO_QUERY);
+ Reference< XText > newText(createTextNode(text->getData()));
+ aNode.set(newText, UNO_QUERY);
+ break;
+ }
+ case NodeType_ENTITY_NODE:
+ case NodeType_DOCUMENT_NODE:
+ case NodeType_DOCUMENT_TYPE_NODE:
+ case NodeType_NOTATION_NODE:
+ default:
+ // can't be imported
+ throw RuntimeException();
+
+ }
+ if (deep)
+ {
+ // get children and import them
+ Reference< XNode > child = importedNode->getFirstChild();
+ if (child.is())
+ {
+ _import_siblings(child, aNode, this);
+ }
+ }
+
+ /* DOMNodeInsertedIntoDocument
+ * Fired when a node is being inserted into a document,
+ * either through direct insertion of the Node or insertion of a
+ * subtree in which it is contained. This event is dispatched after
+ * the insertion has taken place. The target of this event is the node
+ * being inserted. If the Node is being directly inserted the DOMNodeInserted
+ * event will fire before the DOMNodeInsertedIntoDocument event.
+ * Bubbles: No
+ * Cancelable: No
+ * Context Info: None
+ */
+ if (aNode.is())
+ {
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMNodeInsertedIntoDocument")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMNodeInsertedIntoDocument")
+ , sal_True, sal_False, Reference< XNode >(),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ }
+
+ return aNode;
+ }
+ OUString SAL_CALL CDocument::getNodeName()throw (RuntimeException)
+ {
+ return OUString::createFromAscii("#document");
+ }
+ OUString SAL_CALL CDocument::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+
+ Reference< XEvent > SAL_CALL CDocument::createEvent(const OUString& aType) throw (RuntimeException)
+ {
+ events::CEvent *pEvent = 0;
+ if (
+ aType.compareToAscii("DOMSubtreeModified") == 0||
+ aType.compareToAscii("DOMNodeInserted") == 0||
+ aType.compareToAscii("DOMNodeRemoved") == 0||
+ aType.compareToAscii("DOMNodeRemovedFromDocument") == 0||
+ aType.compareToAscii("DOMNodeInsertedIntoDocument") == 0||
+ aType.compareToAscii("DOMAttrModified") == 0||
+ aType.compareToAscii("DOMCharacterDataModified") == 0)
+ {
+ pEvent = new events::CMutationEvent;
+
+ } else if (
+ aType.compareToAscii("DOMFocusIn") == 0||
+ aType.compareToAscii("DOMFocusOut") == 0||
+ aType.compareToAscii("DOMActivate") == 0)
+ {
+ pEvent = new events::CUIEvent;
+ } else if (
+ aType.compareToAscii("click") == 0||
+ aType.compareToAscii("mousedown") == 0||
+ aType.compareToAscii("mouseup") == 0||
+ aType.compareToAscii("mouseover") == 0||
+ aType.compareToAscii("mousemove") == 0||
+ aType.compareToAscii("mouseout") == 0 )
+ {
+ pEvent = new events::CMouseEvent;
+ }
+ else // generic event
+ {
+ pEvent = new events::CEvent;
+ }
+ return Reference< XEvent >(pEvent);
+ }
+
+ // ::com::sun::star::xml::sax::XSAXSerializable
+ void SAL_CALL CDocument::serialize(
+ const Reference< XDocumentHandler >& i_xHandler,
+ const Sequence< beans::StringPair >& i_rNamespaces)
+ throw (RuntimeException, SAXException)
+ {
+ // add new namespaces to root node
+ xmlNodePtr pRoot = _getDocumentRootPtr(m_aDocPtr);
+ if (0 != pRoot) {
+ const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
+ for (const beans::StringPair *pNsDef = pSeq;
+ pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
+ OString prefix = OUStringToOString(pNsDef->First,
+ RTL_TEXTENCODING_UTF8);
+ OString href = OUStringToOString(pNsDef->Second,
+ RTL_TEXTENCODING_UTF8);
+ // this will only add the ns if it does not exist already
+ xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
+ reinterpret_cast<const xmlChar*>(prefix.getStr()));
+ }
+ // eliminate duplicate namespace declarations
+ _nscleanup(pRoot->children, pRoot);
+ }
+ saxify(i_xHandler);
+ }
+
+ // ::com::sun::star::xml::sax::XFastSAXSerializable
+ void SAL_CALL CDocument::fastSerialize( const Reference< XFastDocumentHandler >& i_xHandler,
+ const Reference< XFastTokenHandler >& i_xTokenHandler,
+ const Sequence< beans::StringPair >& i_rNamespaces,
+ const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& i_rRegisterNamespaces )
+ throw (SAXException, RuntimeException)
+ {
+ // add new namespaces to root node
+ xmlNodePtr pRoot = _getDocumentRootPtr(m_aDocPtr);
+ if (0 != pRoot) {
+ const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
+ for (const beans::StringPair *pNsDef = pSeq;
+ pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
+ OString prefix = OUStringToOString(pNsDef->First,
+ RTL_TEXTENCODING_UTF8);
+ OString href = OUStringToOString(pNsDef->Second,
+ RTL_TEXTENCODING_UTF8);
+ // this will only add the ns if it does not exist already
+ xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
+ reinterpret_cast<const xmlChar*>(prefix.getStr()));
+ }
+ // eliminate duplicate namespace declarations
+ _nscleanup(pRoot->children, pRoot);
+ }
+
+ Context aContext(i_xHandler,
+ i_xTokenHandler);
+
+ // register namespace ids
+ const beans::Pair<OUString,sal_Int32>* pSeq = i_rRegisterNamespaces.getConstArray();
+ for (const beans::Pair<OUString,sal_Int32>* pNs = pSeq;
+ pNs < pSeq + i_rRegisterNamespaces.getLength(); ++pNs)
+ {
+ OSL_ENSURE(pNs->Second >= FastToken::NAMESPACE,
+ "CDocument::fastSerialize(): invalid NS token id");
+ aContext.maNamespaceMap[ pNs->First ] = pNs->Second;
+ }
+
+ fastSaxify(aContext);
+ }
+}
diff --git a/unoxml/source/dom/document.hxx b/unoxml/source/dom/document.hxx
new file mode 100644
index 000000000000..b653619031a1
--- /dev/null
+++ b/unoxml/source/dom/document.hxx
@@ -0,0 +1,366 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DOCUMENT_HXX
+#define _DOCUMENT_HXX
+
+#include <list>
+#include <set>
+#include <sal/types.h>
+#include <cppuhelper/implbase6.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/beans/StringPair.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XAttr.hpp>
+#include <com/sun/star/xml/dom/XElement.hpp>
+#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
+#include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
+#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/io/XActiveDataControl.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+
+#include "node.hxx"
+
+#include <libxml/tree.h>
+
+using namespace std;
+using ::rtl::OUString;
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::sax;
+using namespace com::sun::star::io;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+namespace DOM
+{
+
+ class CDocument : public cppu::ImplInheritanceHelper6<
+ CNode, XDocument, XDocumentEvent,
+ XActiveDataControl, XActiveDataSource, XSAXSerializable, XFastSAXSerializable>
+ {
+ friend class CNode;
+ typedef std::list< Reference< XNode >* > nodereflist_t;
+ typedef set< Reference< XStreamListener > > listenerlist_t;
+ private:
+
+ nodereflist_t m_aNodeRefList;
+
+ xmlDocPtr m_aDocPtr;
+
+ // datacontrol/source state
+ listenerlist_t m_streamListeners;
+ Reference< XOutputStream > m_rOutputStream;
+
+ protected:
+ CDocument(xmlDocPtr aDocPtr);
+
+ void addnode(xmlNodePtr aNode);
+
+ public:
+
+ virtual ~CDocument();
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ virtual void SAL_CALL fastSaxify( Context& rContext );
+
+ /**
+ Creates an Attr of the given name.
+ */
+ virtual Reference< XAttr > SAL_CALL createAttribute(const OUString& name)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates an attribute of the given qualified name and namespace URI.
+ */
+ virtual Reference< XAttr > SAL_CALL createAttributeNS(const OUString& namespaceURI, const OUString& qualifiedName)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates a CDATASection node whose value is the specified string.
+ */
+ virtual Reference< XCDATASection > SAL_CALL createCDATASection(const OUString& data)
+ throw (RuntimeException);
+
+ /**
+ Creates a Comment node given the specified string.
+ */
+ virtual Reference< XComment > SAL_CALL createComment(const OUString& data)
+ throw (RuntimeException);
+
+ /**
+ Creates an empty DocumentFragment object.
+ */
+ virtual Reference< XDocumentFragment > SAL_CALL createDocumentFragment()
+ throw (RuntimeException);
+
+ /**
+ Creates an element of the type specified.
+ */
+ virtual Reference< XElement > SAL_CALL createElement(const OUString& tagName)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates an element of the given qualified name and namespace URI.
+ */
+ virtual Reference< XElement > SAL_CALL createElementNS(const OUString& namespaceURI, const OUString& qualifiedName)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates an EntityReference object.
+ */
+ virtual Reference< XEntityReference > SAL_CALL createEntityReference(const OUString& name)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates a ProcessingInstruction node given the specified name and
+ data strings.
+ */
+ virtual Reference< XProcessingInstruction > SAL_CALL createProcessingInstruction(
+ const OUString& target, const OUString& data)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Creates a Text node given the specified string.
+ */
+ virtual Reference< XText > SAL_CALL createTextNode(const OUString& data)
+ throw (RuntimeException);
+
+ /**
+ The Document Type Declaration (see DocumentType) associated with this
+ document.
+ */
+ virtual Reference< XDocumentType > SAL_CALL getDoctype()
+ throw (RuntimeException);
+
+ /**
+ This is a convenience attribute that allows direct access to the child
+ node that is the root element of the document.
+ */
+ virtual Reference< XElement > SAL_CALL getDocumentElement()
+ throw (RuntimeException);
+
+ /**
+ Returns the Element whose ID is given by elementId.
+ */
+ virtual Reference< XElement > SAL_CALL getElementById(const OUString& elementId)
+ throw (RuntimeException);
+
+ /**
+ Returns a NodeList of all the Elements with a given tag name in the
+ order in which they are encountered in a preorder traversal of the
+ Document tree.
+ */
+ virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& tagname)
+ throw (RuntimeException);
+
+ /**
+ Returns a NodeList of all the Elements with a given local name and
+ namespace URI in the order in which they are encountered in a preorder
+ traversal of the Document tree.
+ */
+ virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException);
+
+ /**
+ The DOMImplementation object that handles this document.
+ */
+ virtual Reference< XDOMImplementation > SAL_CALL getImplementation()
+ throw (RuntimeException);
+
+ /**
+ Imports a node from another document to this document.
+ */
+ virtual Reference< XNode > SAL_CALL importNode(const Reference< XNode >& importedNode, sal_Bool deep)
+ throw (RuntimeException, DOMException);
+
+ // XDocumentEvent
+ virtual Reference< XEvent > SAL_CALL createEvent(const OUString& eventType) throw (RuntimeException);
+
+ // XActiveDataControl,
+ // see http://api.openoffice.org/docs/common/ref/com/sun/star/io/XActiveDataControl.html
+ virtual void SAL_CALL addListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
+ virtual void SAL_CALL removeListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
+ virtual void SAL_CALL start() throw (RuntimeException);
+ virtual void SAL_CALL terminate() throw (RuntimeException);
+
+ // XActiveDataSource
+ // see http://api.openoffice.org/docs/common/ref/com/sun/star/io/XActiveDataSource.html
+ virtual void SAL_CALL setOutputStream( const Reference< XOutputStream >& aStream ) throw (RuntimeException);
+ virtual Reference< XOutputStream > SAL_CALL getOutputStream() throw (RuntimeException);
+
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ // ::com::sun::star::xml::sax::XSAXSerializable
+ virtual void SAL_CALL serialize(
+ const Reference< XDocumentHandler >& i_xHandler,
+ const Sequence< beans::StringPair >& i_rNamespaces)
+ throw (RuntimeException, SAXException);
+
+ // ::com::sun::star::xml::sax::XFastSAXSerializable
+ virtual void SAL_CALL fastSerialize( const Reference< XFastDocumentHandler >& handler,
+ const Reference< XFastTokenHandler >& tokenHandler,
+ const Sequence< beans::StringPair >& i_rNamespaces,
+ const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& namespaces )
+ throw (SAXException, RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/documentbuilder.cxx b/unoxml/source/dom/documentbuilder.cxx
new file mode 100644
index 000000000000..484c04b7f23b
--- /dev/null
+++ b/unoxml/source/dom/documentbuilder.cxx
@@ -0,0 +1,429 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "documentbuilder.hxx"
+#include "node.hxx"
+#include "document.hxx"
+
+#include <rtl/alloc.h>
+#include <rtl/memory.h>
+#include <rtl/ustrbuf.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+
+#include <libxml/xmlerror.h>
+
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <ucbhelper/content.hxx>
+#include <ucbhelper/commandenvironment.hxx>
+
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+
+using ::rtl::OUStringBuffer;
+using ::rtl::OString;
+using ::com::sun::star::xml::sax::InputSource;
+using namespace ucbhelper;
+using namespace ::com::sun::star::ucb;
+using ::com::sun::star::task::XInteractionHandler;
+
+
+namespace DOM
+{
+ extern "C" {
+ //char *strdup(const char *s);
+ /*
+ static char* strdupfunc(const char* s)
+ {
+ sal_Int32 len = 0;
+ while (s[len] != '\0') len++;
+ char *newStr = (char*)rtl_allocateMemory(len+1);
+ if (newStr != NULL)
+ rtl_copyMemory(newStr, s, len+1);
+ return newStr;
+ }
+ */
+ }
+
+
+ class CDefaultEntityResolver : public cppu::WeakImplHelper1< XEntityResolver >
+ {
+ public:
+ virtual InputSource SAL_CALL resolveEntity( const OUString& sPublicId, const OUString& sSystemId )
+ throw (::com::sun::star::uno::RuntimeException)
+ {
+ InputSource is;
+ is.sPublicId = sPublicId;
+ is.sSystemId = sSystemId;
+ is.sEncoding = OUString();
+
+ try {
+ Reference< XCommandEnvironment > aEnvironment(
+ new CommandEnvironment(Reference< XInteractionHandler >(),
+ Reference< XProgressHandler >() ));
+ Content aContent(sSystemId, aEnvironment);
+
+ is.aInputStream = aContent.openStream();
+ } catch (com::sun::star::uno::Exception) {
+ OSL_ENSURE(sal_False, "exception in default entity resolver");
+ is.aInputStream = Reference< XInputStream >();
+ }
+ return is;
+ }
+
+ };
+
+ CDocumentBuilder::CDocumentBuilder(const Reference< XMultiServiceFactory >& xFactory)
+ : m_aFactory(xFactory)
+ , m_aEntityResolver(Reference< XEntityResolver > (new CDefaultEntityResolver()))
+ {
+ // init libxml. libxml will protect itself against multiple
+ // initializations so there is no problem here if this gets
+ // called multiple times.
+ xmlInitParser();
+ }
+
+ Reference< XInterface > CDocumentBuilder::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
+ {
+ // XXX
+ return static_cast< XDocumentBuilder* >(new CDocumentBuilder(rSMgr));
+ }
+
+ const char* CDocumentBuilder::aImplementationName = "com.sun.star.comp.xml.dom.DocumentBuilder";
+ const char* CDocumentBuilder::aSupportedServiceNames[] = {
+ "com.sun.star.xml.dom.DocumentBuilder",
+ NULL
+ };
+
+ OUString CDocumentBuilder::_getImplementationName()
+ {
+ return OUString::createFromAscii(aImplementationName);
+ }
+ Sequence<OUString> CDocumentBuilder::_getSupportedServiceNames()
+ {
+ Sequence<OUString> aSequence;
+ for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
+ aSequence.realloc(i+1);
+ aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
+ }
+ return aSequence;
+ }
+
+ Sequence< OUString > SAL_CALL CDocumentBuilder::getSupportedServiceNames()
+ throw (RuntimeException)
+ {
+ return CDocumentBuilder::_getSupportedServiceNames();
+ }
+
+ OUString SAL_CALL CDocumentBuilder::getImplementationName()
+ throw (RuntimeException)
+ {
+ return CDocumentBuilder::_getImplementationName();
+ }
+
+ sal_Bool SAL_CALL CDocumentBuilder::supportsService(const OUString& aServiceName)
+ throw (RuntimeException)
+ {
+ Sequence< OUString > supported = CDocumentBuilder::_getSupportedServiceNames();
+ for (sal_Int32 i=0; i<supported.getLength(); i++)
+ {
+ if (supported[i] == aServiceName) return sal_True;
+ }
+ return sal_False;
+ }
+
+ Reference< XDOMImplementation > SAL_CALL CDocumentBuilder::getDOMImplementation()
+ throw (RuntimeException)
+ {
+
+ return Reference< XDOMImplementation >();
+ }
+
+ sal_Bool SAL_CALL CDocumentBuilder::isNamespaceAware()
+ throw (RuntimeException)
+ {
+ return sal_True;
+ }
+
+ sal_Bool SAL_CALL CDocumentBuilder::isValidating()
+ throw (RuntimeException)
+ {
+ return sal_False;
+ }
+
+ Reference< XDocument > SAL_CALL CDocumentBuilder::newDocument()
+ throw (RuntimeException)
+ {
+ // create a new document
+ xmlDocPtr pDocument = xmlNewDoc((const xmlChar*)"1.0");
+ return Reference< XDocument >(static_cast< CDocument* >(CNode::get((xmlNodePtr)pDocument)));
+ }
+
+ static OUString make_error_message(xmlParserCtxtPtr ctxt)
+ {
+ OUStringBuffer buf;
+ buf.appendAscii(ctxt->lastError.message);
+ buf.appendAscii("Line: ");
+ buf.append(static_cast<sal_Int32>(ctxt->lastError.line));
+ buf.appendAscii("\nColumn: ");
+ buf.append(static_cast<sal_Int32>(ctxt->lastError.int2));
+ OUString msg = buf.makeStringAndClear();
+ return msg;
+ }
+
+ // -- callbacks and context struct for parsing from stream
+ // -- c-linkage, so the callbacks can be used by libxml
+ extern "C" {
+
+ // context struct passed to IO functions
+ typedef struct context {
+ CDocumentBuilder *pBuilder;
+ Reference< XInputStream > rInputStream;
+ bool close;
+ bool freeOnClose;
+ } context_t;
+
+ static int xmlIO_read_func( void *context, char *buffer, int len)
+ {
+ // get the context...
+ context_t *pctx = static_cast<context_t*>(context);
+ if (!pctx->rInputStream.is())
+ return -1;
+ try {
+ // try to read the requested number of bytes
+ Sequence< sal_Int8 > chunk(len);
+ int nread = pctx->rInputStream->readBytes(chunk, len);
+
+ // copy bytes to the provided buffer
+ rtl_copyMemory(buffer, chunk.getConstArray(), nread);
+ return nread;
+ } catch (com::sun::star::uno::Exception& ex) {
+ (void) ex;
+ OSL_ENSURE(sal_False, OUStringToOString(ex.Message, RTL_TEXTENCODING_UTF8).getStr());
+ return -1;
+ }
+ }
+
+ static int xmlIO_close_func(void* context)
+ {
+ // get the context...
+ context_t *pctx = static_cast<context_t*>(context);
+ if (!pctx->rInputStream.is())
+ return 0;
+ try
+ {
+ if (pctx->close)
+ pctx->rInputStream->closeInput();
+ if (pctx->freeOnClose)
+ delete pctx;
+ return 0;
+ } catch (com::sun::star::uno::Exception& ex) {
+ (void) ex;
+ OSL_ENSURE(sal_False, OUStringToOString(ex.Message, RTL_TEXTENCODING_UTF8).getStr());
+ return -1;
+ }
+ }
+
+ static xmlParserInputPtr resolve_func(void *ctx,
+ const xmlChar *publicId,
+ const xmlChar *systemId)
+ {
+ // get the CDocumentBuilder object
+ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
+ CDocumentBuilder *builder = static_cast< CDocumentBuilder* >(ctxt->_private);
+ Reference< XEntityResolver > resolver = builder->getEntityResolver();
+ OUString sysid;
+ if (systemId != 0)
+ sysid = OUString((sal_Char*)systemId, strlen((char*)systemId), RTL_TEXTENCODING_UTF8);
+ OUString pubid;
+ if (publicId != 0)
+ pubid = OUString((sal_Char*)publicId, strlen((char*)publicId), RTL_TEXTENCODING_UTF8);
+
+ // resolve the entity
+ InputSource src = resolver->resolveEntity(pubid, sysid);
+
+ // create IO context on heap because this call will no longer be on the stack
+ // when IO is actually performed through the callbacks. The close function must
+ // free the memory which is indicated by the freeOnClose field in the context struct
+ context_t *c = new context_t;
+ c->pBuilder = builder;
+ c->rInputStream = src.aInputStream;
+ c->close = true;
+ c->freeOnClose = true;
+
+ // set up the inputBuffer and inputPtr for libxml
+ xmlParserInputBufferPtr pBuffer =
+ xmlParserInputBufferCreateIO(xmlIO_read_func, xmlIO_close_func, c, XML_CHAR_ENCODING_NONE);
+ xmlParserInputPtr pInput =
+ xmlNewIOInputStream(ctxt, pBuffer, XML_CHAR_ENCODING_NONE);
+ return pInput;
+ }
+
+ static xmlParserInputPtr external_entity_loader(const char *URL, const char * /*ID*/, xmlParserCtxtPtr ctxt)
+ {
+ // just call our resolver function using the URL as systemId
+ return resolve_func(ctxt, 0, (const xmlChar*)URL);
+ }
+
+ // default warning handler triggers assertion
+ static void warning_func(void * ctx, const char * /*msg*/, ...)
+ {
+ OUStringBuffer buf(OUString::createFromAscii("libxml2 warning\n"));
+ buf.append(make_error_message(static_cast< xmlParserCtxtPtr >(ctx)));
+ OString msg = OUStringToOString(buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
+ OSL_ENSURE(sal_False, msg.getStr());
+ }
+
+ // default error handler triggers assertion
+ static void error_func(void * ctx, const char * /*msg*/, ...)
+ {
+ OUStringBuffer buf(OUString::createFromAscii("libxml2 error\n"));
+ buf.append(make_error_message(static_cast< xmlParserCtxtPtr >(ctx)));
+ OString msg = OUStringToOString(buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
+ OSL_ENSURE(sal_False, msg.getStr());
+ }
+
+ } // extern "C"
+
+ void throwEx(xmlParserCtxtPtr ctxt) {
+ OUString msg = make_error_message(ctxt);
+ xmlFreeParserCtxt(ctxt);
+ com::sun::star::xml::sax::SAXParseException saxex;
+ saxex.Message = msg;
+ saxex.LineNumber = static_cast<sal_Int32>(ctxt->lastError.line);
+ saxex.ColumnNumber = static_cast<sal_Int32>(ctxt->lastError.int2);
+ throw saxex;
+ }
+
+ Reference< XDocument > SAL_CALL CDocumentBuilder::parse(const Reference< XInputStream >& is)
+ throw (RuntimeException, SAXParseException, IOException)
+ {
+
+ // encoding...
+ /*
+ xmlChar *encstr = (xmlChar*) OUStringToOString(src.sEncoding, RTL_TEXTENCODING_UTF8).getStr();
+ xmlCharEncoding enc = xmlParseCharEncoding(encstr);
+ */
+
+ xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
+
+ // register error functions to prevent errors being printed
+ // on the console
+ ctxt->_private = this;
+ ctxt->sax->error = error_func;
+ ctxt->sax->warning = warning_func;
+ ctxt->sax->resolveEntity = resolve_func;
+
+ // IO context struct
+ context_t c;
+ c.pBuilder = this;
+ c.rInputStream = is;
+ // we did not open the stream, thus we do not close it.
+ c.close = false;
+ c.freeOnClose = false;
+ xmlDocPtr pDoc = xmlCtxtReadIO(ctxt, xmlIO_read_func, xmlIO_close_func, &c,
+ 0, 0, 0);
+
+ if (pDoc == 0) {
+ throwEx(ctxt);
+ }
+ xmlFreeParserCtxt(ctxt);
+ return Reference< XDocument >(static_cast< CDocument* >(CNode::get((xmlNodePtr)pDoc)));
+ }
+
+ Reference< XDocument > SAL_CALL CDocumentBuilder::parseSource(const InputSource& is)
+ throw (RuntimeException, SAXParseException, IOException)
+ {
+ // if there is an encoding specified in the input source, use it
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
+ if (is.sEncoding.getLength() > 0) {
+ OString oEncstr = OUStringToOString(is.sEncoding, RTL_TEXTENCODING_UTF8);
+ char *encstr = (char*) oEncstr.getStr();
+ enc = xmlParseCharEncoding(encstr);
+ }
+
+ // set up parser context
+ xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
+ // register error functions to prevent errors being printed
+ // on the console
+ ctxt->_private = this;
+ ctxt->sax->error = error_func;
+ ctxt->sax->warning = warning_func;
+
+ // setup entity resolver binding(s)
+ ctxt->sax->resolveEntity = resolve_func;
+ xmlSetExternalEntityLoader(external_entity_loader);
+
+ // if an input stream is provided, use it
+
+ // use the systemID
+
+ return Reference< XDocument >();
+ }
+
+ Reference< XDocument > SAL_CALL CDocumentBuilder::parseURI(const OUString& sUri)
+ throw (RuntimeException, SAXParseException, IOException)
+ {
+ xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
+ ctxt->_private = this;
+ ctxt->sax->error = error_func;
+ ctxt->sax->warning = warning_func;
+ ctxt->sax->resolveEntity = resolve_func;
+ // xmlSetExternalEntityLoader(external_entity_loader);
+ OString oUri = OUStringToOString(sUri, RTL_TEXTENCODING_UTF8);
+ char *uri = (char*) oUri.getStr();
+ xmlDocPtr pDoc = xmlCtxtReadFile(ctxt, uri, 0, 0);
+ if (pDoc == 0) {
+ throwEx(ctxt);
+ }
+ xmlFreeParserCtxt(ctxt);
+ return Reference< XDocument >(static_cast< CDocument* >(CNode::get((xmlNodePtr)pDoc)));
+ }
+
+ void SAL_CALL CDocumentBuilder::setEntityResolver(const Reference< XEntityResolver >& er)
+ throw (RuntimeException)
+ {
+ m_aEntityResolver = er;
+ }
+
+ Reference< XEntityResolver > SAL_CALL CDocumentBuilder::getEntityResolver()
+ throw (RuntimeException)
+ {
+ return m_aEntityResolver;
+ }
+
+
+ void SAL_CALL CDocumentBuilder::setErrorHandler(const Reference< XErrorHandler >& eh)
+ throw (RuntimeException)
+ {
+ m_aErrorHandler = eh;
+ }
+}
diff --git a/unoxml/source/dom/documentbuilder.hxx b/unoxml/source/dom/documentbuilder.hxx
new file mode 100644
index 000000000000..7f5a2079a051
--- /dev/null
+++ b/unoxml/source/dom/documentbuilder.hxx
@@ -0,0 +1,157 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DOCUMENTBUILDER_HXX
+#define _DOCUMENTBUILDER_HXX
+
+#include <sal/types.h>
+#include <cppuhelper/implbase2.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Sequence.h>
+
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
+#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
+#include <com/sun/star/xml/sax/XEntityResolver.hpp>
+#include <com/sun/star/xml/sax/XErrorHandler.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/IOException.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include "libxml/tree.h"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::sax;
+using namespace com::sun::star::io;
+
+namespace DOM
+{
+ class CDocumentBuilder
+ : public ::cppu::WeakImplHelper2< XDocumentBuilder, XServiceInfo >
+ {
+ private:
+ Reference< XMultiServiceFactory > m_aFactory;
+ Reference< XEntityResolver > m_aEntityResolver;
+ Reference< XErrorHandler > m_aErrorHandler;
+
+ public:
+
+ // ctor
+ CDocumentBuilder(const Reference< XMultiServiceFactory >& xFactory);
+
+ // call for factory
+ static Reference< XInterface > getInstance(const Reference < XMultiServiceFactory >& xFactory);
+
+ // static helpers for service info and component management
+ static const char* aImplementationName;
+ static const char* aSupportedServiceNames[];
+ static OUString _getImplementationName();
+ static Sequence< OUString > _getSupportedServiceNames();
+ static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr);
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName()
+ throw (RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
+ throw (RuntimeException);
+ virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ()
+ throw (RuntimeException);
+
+ /**
+ Obtain an instance of a DOMImplementation object.
+ */
+ virtual Reference< XDOMImplementation > SAL_CALL getDOMImplementation()
+ throw (RuntimeException);
+
+ /**
+ Indicates whether or not this parser is configured to understand
+ namespaces.
+ */
+ virtual sal_Bool SAL_CALL isNamespaceAware()
+ throw (RuntimeException);
+
+ /**
+ Indicates whether or not this parser is configured to validate XML
+ documents.
+ */
+ virtual sal_Bool SAL_CALL isValidating()
+ throw (RuntimeException);
+
+ /**
+ Obtain a new instance of a DOM Document object to build a DOM tree
+ with.
+ */
+ virtual Reference< XDocument > SAL_CALL newDocument()
+ throw (RuntimeException);
+
+ /**
+ Parse the content of the given InputStream as an XML document and
+ return a new DOM Document object.
+ */
+ virtual Reference< XDocument > SAL_CALL parse(const Reference< XInputStream >& is)
+ throw (RuntimeException, SAXParseException, IOException);
+
+ /**
+ Parse the content of the given URI as an XML document and return
+ a new DOM Document object.
+ */
+ virtual Reference< XDocument > SAL_CALL parseURI(const OUString& uri)
+ throw (RuntimeException, SAXParseException, IOException);
+
+ virtual Reference< XDocument > SAL_CALL parseSource(const InputSource& is)
+ throw (RuntimeException, SAXParseException, IOException);
+
+
+ /**
+ Specify the EntityResolver to be used to resolve entities present
+ in the XML document to be parsed.
+ */
+ virtual void SAL_CALL setEntityResolver(const Reference< XEntityResolver >& er)
+ throw (RuntimeException);
+
+ virtual Reference< XEntityResolver > SAL_CALL getEntityResolver()
+ throw (RuntimeException);
+
+
+ /**
+ Specify the ErrorHandler to be used to report errors present in
+ the XML document to be parsed.
+ */
+ virtual void SAL_CALL setErrorHandler(const Reference< XErrorHandler >& eh)
+ throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/documentfragment.cxx b/unoxml/source/dom/documentfragment.cxx
new file mode 100644
index 000000000000..a3f5ac40b5aa
--- /dev/null
+++ b/unoxml/source/dom/documentfragment.cxx
@@ -0,0 +1,45 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "documentfragment.hxx"
+
+namespace DOM
+{
+ CDocumentFragment::CDocumentFragment(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_DOCUMENT_FRAGMENT_NODE;
+ init_node(aNodePtr);
+ }
+ OUString SAL_CALL CDocumentFragment::getNodeName()throw (RuntimeException)
+ {
+ return OUString::createFromAscii("#document-fragment");
+ }
+ OUString SAL_CALL CDocumentFragment::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+}
diff --git a/unoxml/source/dom/documentfragment.hxx b/unoxml/source/dom/documentfragment.hxx
new file mode 100644
index 000000000000..7649f6368c9a
--- /dev/null
+++ b/unoxml/source/dom/documentfragment.hxx
@@ -0,0 +1,179 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DOCUMENTFRAGMENT_HXX
+#define _DOCUMENTFRAGMENT_HXX
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XDocumentFragment.hpp>
+
+#include "node.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CDocumentFragment : public cppu::ImplInheritanceHelper1< CNode, XDocumentFragment >
+ {
+ friend class CNode;
+ protected:
+ CDocumentFragment(const xmlNodePtr aNodePtr);
+
+ public:
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+
+ };
+}
+#endif
+
diff --git a/unoxml/source/dom/documenttype.cxx b/unoxml/source/dom/documenttype.cxx
new file mode 100644
index 000000000000..bc5004dfd23c
--- /dev/null
+++ b/unoxml/source/dom/documenttype.cxx
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "documenttype.hxx"
+#include "entitiesmap.hxx"
+#include "notationsmap.hxx"
+
+#include <string.h>
+
+namespace DOM
+{
+
+ CDocumentType::CDocumentType(const xmlDtdPtr aDtdPtr)
+ {
+ m_aNodeType = NodeType_DOCUMENT_TYPE_NODE;
+ m_aDtdPtr = aDtdPtr;
+ init_node((xmlNodePtr)aDtdPtr);
+ }
+
+ /**
+ A NamedNodeMap containing the general entities, both external and
+ internal, declared in the DTD.
+ */
+ Reference< XNamedNodeMap > SAL_CALL CDocumentType::getEntities() throw (RuntimeException)
+ {
+ Reference< XNamedNodeMap > aMap;
+ if (m_aDtdPtr != NULL)
+ {
+ aMap = Reference< XNamedNodeMap >(new CEntitiesMap(this));
+ }
+ return aMap;
+ }
+
+ /**
+ The internal subset as a string, or null if there is none.
+ */
+ OUString SAL_CALL CDocumentType::getInternalSubset() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+ /**
+ The name of DTD; i.e., the name immediately following the DOCTYPE
+ keyword.
+ */
+ OUString SAL_CALL CDocumentType::getName() throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aDtdPtr != NULL)
+ {
+ aName = OUString((sal_Char*)m_aDtdPtr->name, strlen((char*)m_aDtdPtr->name), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+
+ /**
+ A NamedNodeMap containing the notations declared in the DTD.
+ */
+ Reference< XNamedNodeMap > SAL_CALL CDocumentType::getNotations() throw (RuntimeException)
+ {
+ Reference< XNamedNodeMap > aMap;
+ if (m_aDtdPtr != NULL)
+ {
+ aMap.set(new CNotationsMap(this));
+ }
+ return aMap;
+ }
+
+ /**
+ The public identifier of the external subset.
+ */
+ OUString SAL_CALL CDocumentType::getPublicId() throw (RuntimeException)
+ {
+ OUString aId;
+ if (m_aDtdPtr != NULL)
+ {
+ aId = OUString((sal_Char*)m_aDtdPtr->name, strlen((char*)m_aDtdPtr->ExternalID), RTL_TEXTENCODING_UTF8);
+ }
+ return aId;
+ }
+
+ /**
+ The system identifier of the external subset.
+ */
+ OUString SAL_CALL CDocumentType::getSystemId() throw (RuntimeException)
+ {
+ OUString aId;
+ if (m_aDtdPtr != NULL)
+ {
+ aId = OUString((sal_Char*)m_aDtdPtr->name, strlen((char*)m_aDtdPtr->SystemID), RTL_TEXTENCODING_UTF8);
+ }
+ return aId;
+ }
+ OUString SAL_CALL CDocumentType::getNodeName()throw (RuntimeException)
+ {
+ return getName();
+ }
+ OUString SAL_CALL CDocumentType::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+}
diff --git a/unoxml/source/dom/documenttype.hxx b/unoxml/source/dom/documenttype.hxx
new file mode 100644
index 000000000000..4ea6d0c89219
--- /dev/null
+++ b/unoxml/source/dom/documenttype.hxx
@@ -0,0 +1,217 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DOCUMENTTYPE_HXX
+#define _DOCUMENTTYPE_HXX
+
+#include <sal/types.h>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XDocumentType.hpp>
+#include <com/sun/star/xml/dom/XNodeList.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+
+#include "node.hxx"
+
+#include <libxml/tree.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CDocumentType : public cppu::ImplInheritanceHelper1< CNode, XDocumentType >
+ {
+ friend class CNode;
+ private:
+ xmlDtdPtr m_aDtdPtr;
+
+ protected:
+ CDocumentType(const xmlDtdPtr aDtdPtr);
+
+ public:
+ /**
+ A NamedNodeMap containing the general entities, both external and
+ internal, declared in the DTD.
+ */
+ virtual Reference< XNamedNodeMap > SAL_CALL getEntities() throw (RuntimeException);
+
+ /**
+ The internal subset as a string, or null if there is none.
+ */
+ virtual OUString SAL_CALL getInternalSubset() throw (RuntimeException);
+
+ /**
+ The name of DTD; i.e., the name immediately following the DOCTYPE
+ keyword.
+ */
+ virtual OUString SAL_CALL getName() throw (RuntimeException);
+
+ /**
+ A NamedNodeMap containing the notations declared in the DTD.
+ */
+ virtual Reference< XNamedNodeMap > SAL_CALL getNotations() throw (RuntimeException);
+
+ /**
+ The public identifier of the external subset.
+ */
+ virtual OUString SAL_CALL getPublicId() throw (RuntimeException);
+
+ /**
+ The system identifier of the external subset.
+ */
+ virtual OUString SAL_CALL getSystemId() throw (RuntimeException);
+
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+}
+#endif
diff --git a/unoxml/source/dom/domimplementation.cxx b/unoxml/source/dom/domimplementation.cxx
new file mode 100644
index 000000000000..5d80147e7fb6
--- /dev/null
+++ b/unoxml/source/dom/domimplementation.cxx
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "domimplementation.hxx"
+
+namespace DOM
+{
+ CDOMImplementation* CDOMImplementation::aDOMImplementation = new CDOMImplementation();
+ CDOMImplementation* CDOMImplementation::get()
+ {
+ return CDOMImplementation::aDOMImplementation;
+ }
+
+ /**
+ Creates a DOM Document object of the specified type with its document element.
+ */
+ Reference <XDocument > SAL_CALL CDOMImplementation::createDocument(
+ const OUString& namespaceURI,
+ const OUString& qualifiedName,
+ const Reference< XDocumentType >& doctype)
+ throw (RuntimeException)
+ {
+ OUString aNamespaceURI = namespaceURI;
+ OUString aQName = qualifiedName;
+ Reference< XDocumentType > aType = doctype;
+ return Reference<XDocument>();
+ }
+
+ /**
+ Creates an empty DocumentType node.
+ */
+ Reference< XDocumentType > SAL_CALL CDOMImplementation::createDocumentType(
+ const OUString& qualifiedName, const OUString& publicId, const OUString& systemId)
+ throw (RuntimeException)
+ {
+ OUString qName = qualifiedName;
+ OUString aPublicId = publicId;
+ OUString aSystemId = systemId;
+ return Reference<XDocumentType>();
+ }
+ /**
+ Test if the DOM implementation implements a specific feature.
+ */
+ sal_Bool SAL_CALL CDOMImplementation::hasFeature(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ OUString aFeature = feature;
+ OUString aVersion = ver;
+ return sal_False;
+ }
+}
diff --git a/unoxml/source/dom/domimplementation.hxx b/unoxml/source/dom/domimplementation.hxx
new file mode 100644
index 000000000000..e0282fa8e3f4
--- /dev/null
+++ b/unoxml/source/dom/domimplementation.hxx
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DOMIMPLEMENTATION_HXX
+#define _DOMIMPLEMENTATION_HXX
+
+#include <map>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
+#include <com/sun/star/xml/dom/XDocumentType.hpp>
+#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
+#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CDOMImplementation : public cppu::WeakImplHelper1< XDOMImplementation >
+ {
+
+ public:
+ static CDOMImplementation* aDOMImplementation;
+ static CDOMImplementation* get();
+
+ /**
+ Creates a DOM Document object of the specified type with its document element.
+ */
+ virtual Reference <XDocument > SAL_CALL createDocument(const OUString& namespaceURI, const OUString& qualifiedName, const Reference< XDocumentType >& doctype)
+ throw (RuntimeException);
+
+ /**
+ Creates an empty DocumentType node.
+ */
+ virtual Reference< XDocumentType > SAL_CALL createDocumentType(const OUString& qualifiedName, const OUString& publicId, const OUString& systemId)
+ throw (RuntimeException);
+
+ /**
+ Test if the DOM implementation implements a specific feature.
+ */
+ virtual sal_Bool SAL_CALL hasFeature(const OUString& feature, const OUString& ver)
+ throw (RuntimeException);
+ };
+}
+#endif
diff --git a/unoxml/source/dom/element.cxx b/unoxml/source/dom/element.cxx
new file mode 100644
index 000000000000..7de79e39e3e4
--- /dev/null
+++ b/unoxml/source/dom/element.cxx
@@ -0,0 +1,649 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "node.hxx"
+#include "element.hxx"
+#include "attr.hxx"
+#include "elementlist.hxx"
+#include "attributesmap.hxx"
+#include "../events/mutationevent.hxx"
+
+#include "comphelper/attributelist.hxx"
+#include <com/sun/star/xml/sax/FastToken.hdl>
+
+#include <string.h>
+
+
+namespace DOM
+{
+
+ CElement::CElement(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_ELEMENT_NODE;
+ init_node(aNodePtr);
+ }
+
+ void SAL_CALL CElement::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ comphelper::AttributeList *pAttrs =
+ new comphelper::AttributeList();
+ OUString type = OUString::createFromAscii("");
+ // add namespace definitions to attributes
+ for (xmlNsPtr pNs = m_aNodePtr->nsDef; pNs != 0; pNs = pNs->next) {
+ const xmlChar *pPrefix = pNs->prefix;
+ OUString prefix(reinterpret_cast<const sal_Char*>(pPrefix),
+ strlen(reinterpret_cast<const char*>(pPrefix)),
+ RTL_TEXTENCODING_UTF8);
+ OUString name = (prefix.equalsAscii(""))
+ ? OUString::createFromAscii("xmlns")
+ : OUString::createFromAscii("xmlns:") + prefix;
+ const xmlChar *pHref = pNs->href;
+ OUString val(reinterpret_cast<const sal_Char*>(pHref),
+ strlen(reinterpret_cast<const char*>(pHref)),
+ RTL_TEXTENCODING_UTF8);
+ pAttrs->AddAttribute(name, type, val);
+ }
+ // add attributes
+ for (xmlAttrPtr pAttr = m_aNodePtr->properties;
+ pAttr != 0; pAttr = pAttr->next) {
+ CNode * pNode = CNode::get(reinterpret_cast<xmlNodePtr>(pAttr));
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+ OUString prefix = pNode->getPrefix();
+ OUString name = (prefix.getLength() == 0)
+ ? pNode->getLocalName()
+ : prefix + OUString(static_cast<sal_Unicode>(':')) + pNode->getLocalName();
+ OUString val = pNode->getNodeValue();
+ pAttrs->AddAttribute(name, type, val);
+ }
+ OUString prefix = getPrefix();
+ OUString name = (prefix.getLength() == 0)
+ ? getLocalName()
+ : prefix + OUString(static_cast<sal_Unicode>(':')) + getLocalName();
+ Reference< XAttributeList > xAttrList(pAttrs);
+ i_xHandler->startElement(name, xAttrList);
+ // recurse
+ for (xmlNodePtr pChild = m_aNodePtr->children;
+ pChild != 0; pChild = pChild->next) {
+ CNode * pNode = CNode::get(pChild);
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+ pNode->saxify(i_xHandler);
+ }
+ i_xHandler->endElement(name);
+ }
+
+ void SAL_CALL CElement::fastSaxify( Context& i_rContext ) {
+ if (!i_rContext.mxDocHandler.is()) throw RuntimeException();
+ pushContext(i_rContext);
+ addNamespaces(i_rContext,m_aNodePtr);
+
+ // add attributes
+ i_rContext.mxAttribList->clear();
+ for (xmlAttrPtr pAttr = m_aNodePtr->properties;
+ pAttr != 0; pAttr = pAttr->next) {
+ CNode * pNode = CNode::get(reinterpret_cast<xmlNodePtr>(pAttr));
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+
+ const xmlChar* xName = pAttr->name;
+ sal_Int32 nAttributeToken=FastToken::DONTKNOW;
+
+ if( pAttr->ns && strlen((char*)pAttr->ns->prefix) )
+ nAttributeToken = getTokenWithPrefix( i_rContext,
+ (sal_Char*)pAttr->ns->prefix,
+ (sal_Char*)xName );
+ else
+ nAttributeToken = getToken( i_rContext, (sal_Char*)xName );
+
+ if( nAttributeToken != FastToken::DONTKNOW )
+ i_rContext.mxAttribList->add( nAttributeToken,
+ OUStringToOString(pNode->getNodeValue(),
+ RTL_TEXTENCODING_UTF8));
+ }
+
+ const xmlChar* xPrefix = m_aNodePtr->ns ? m_aNodePtr->ns->prefix : (const xmlChar*)"";
+ const xmlChar* xName = m_aNodePtr->name;
+ sal_Int32 nElementToken=FastToken::DONTKNOW;
+ if( strlen((char*)xPrefix) )
+ nElementToken = getTokenWithPrefix( i_rContext, (sal_Char*)xPrefix, (sal_Char*)xName );
+ else
+ nElementToken = getToken( i_rContext, (sal_Char*)xName );
+
+ Reference<XFastContextHandler> xParentHandler(i_rContext.mxCurrentHandler);
+ try
+ {
+ Reference< XFastAttributeList > xAttr( i_rContext.mxAttribList.get() );
+ if( nElementToken == FastToken::DONTKNOW )
+ {
+ const OUString aNamespace;
+ const OUString aElementName( (sal_Char*)xPrefix,
+ strlen((char*)xPrefix),
+ RTL_TEXTENCODING_UTF8 );
+
+ if( xParentHandler.is() )
+ i_rContext.mxCurrentHandler = xParentHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
+ else
+ i_rContext.mxCurrentHandler = i_rContext.mxDocHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
+
+ if( i_rContext.mxCurrentHandler.is() )
+ i_rContext.mxCurrentHandler->startUnknownElement( aNamespace, aElementName, xAttr );
+ }
+ else
+ {
+ if( xParentHandler.is() )
+ i_rContext.mxCurrentHandler = xParentHandler->createFastChildContext( nElementToken, xAttr );
+ else
+ i_rContext.mxCurrentHandler = i_rContext.mxDocHandler->createFastChildContext( nElementToken, xAttr );
+
+ if( i_rContext.mxCurrentHandler.is() )
+ i_rContext.mxCurrentHandler->startFastElement( nElementToken, xAttr );
+ }
+ }
+ catch( Exception& )
+ {}
+
+ // recurse
+ for (xmlNodePtr pChild = m_aNodePtr->children;
+ pChild != 0; pChild = pChild->next) {
+ CNode * pNode = CNode::get(pChild);
+ OSL_ENSURE(pNode != 0, "CNode::get returned 0");
+ pNode->fastSaxify(i_rContext);
+ }
+
+ if( i_rContext.mxCurrentHandler.is() ) try
+ {
+ if( nElementToken != FastToken::DONTKNOW )
+ i_rContext.mxCurrentHandler->endFastElement( nElementToken );
+ else
+ {
+ const OUString aNamespace;
+ const OUString aElementName( (sal_Char*)xPrefix,
+ strlen((char*)xPrefix),
+ RTL_TEXTENCODING_UTF8 );
+
+ i_rContext.mxCurrentHandler->endUnknownElement( aNamespace, aElementName );
+ }
+ }
+ catch( Exception& )
+ {}
+
+ // restore after children have been processed
+ i_rContext.mxCurrentHandler = xParentHandler;
+ popContext(i_rContext);
+ }
+
+ /**
+ Retrieves an attribute value by name.
+ return empty string if attribute is not set
+ */
+ OUString CElement::getAttribute(const OUString& name)
+ throw (RuntimeException)
+ {
+ OUString aValue;
+ // search properties
+ if (m_aNodePtr != NULL)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xValue = xmlGetProp(m_aNodePtr, (xmlChar*)o1.getStr());
+ if (xValue != NULL) {
+ aValue = OUString((sal_Char*)xValue, strlen((char*)xValue), RTL_TEXTENCODING_UTF8);
+ }
+ }
+ return aValue;
+ }
+
+ /**
+ Retrieves an attribute node by name.
+ */
+ Reference< XAttr > CElement::getAttributeNode(const OUString& name)
+ throw (RuntimeException)
+ {
+ Reference< XAttr > aAttr;
+ if (m_aNodePtr != NULL)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ xmlAttrPtr pAttr = xmlHasProp(m_aNodePtr, xName);
+ aAttr = Reference< XAttr >(static_cast< CAttr* >(CNode::get((xmlNodePtr)pAttr)));
+ }
+ return aAttr;
+ }
+
+ /**
+ Retrieves an Attr node by local name and namespace URI.
+ */
+ Reference< XAttr > CElement::getAttributeNodeNS(
+ const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException)
+ {
+ Reference< XAttr > aAttr;
+ if (m_aNodePtr != NULL)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar *xNS = (xmlChar*)o2.getStr();
+ xmlAttrPtr pAttr = xmlHasNsProp(m_aNodePtr, xName, xNS);
+ aAttr = Reference< XAttr >(static_cast< CAttr* >(CNode::get((xmlNodePtr)pAttr)));
+ }
+ return aAttr;
+ }
+
+ /**
+ Retrieves an attribute value by local name and namespace URI.
+ return empty string if attribute is not set
+ */
+ OUString CElement::getAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException)
+ {
+ OUString aValue;
+ // search properties
+ if (m_aNodePtr != NULL)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar *xNS = (xmlChar*)o2.getStr();
+ xmlChar *xValue = (xmlChar*)xmlGetNsProp(m_aNodePtr, xName, xNS);
+ if (xValue != NULL) {
+ aValue = OUString((sal_Char*)xValue, strlen((char*)xValue), RTL_TEXTENCODING_UTF8);
+ xmlFree(xValue);
+ }
+ }
+ return aValue;
+ }
+
+ /**
+ Returns a NodeList of all descendant Elements with a given tag name,
+ in the order in which they are
+ encountered in a preorder traversal of this Element tree.
+ */
+ Reference< XNodeList > CElement::getElementsByTagName(const OUString& name)
+ throw (RuntimeException)
+ {
+ Reference< XNodeList > aList = Reference< XNodeList >(new CElementList(this, name));
+ return aList;
+ }
+
+ /**
+ Returns a NodeList of all the descendant Elements with a given local
+ name and namespace URI in the order in which they are encountered in
+ a preorder traversal of this Element tree.
+ */
+ Reference< XNodeList > CElement::getElementsByTagNameNS(const OUString& namespaceURI,
+ const OUString& localName)
+ throw (RuntimeException)
+ {
+ Reference< XNodeList > aList = Reference< XNodeList >(new CElementList(this, localName, namespaceURI));
+ return aList;
+ }
+
+ /**
+ The name of the element.
+ */
+ OUString CElement::getTagName()
+ throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ aName = OUString((sal_Char*)m_aNodePtr->name, strlen((char*)m_aNodePtr->name), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+
+
+ /**
+ Returns true when an attribute with a given name is specified on this
+ element or has a default value, false otherwise.
+ */
+ sal_Bool CElement::hasAttribute(const OUString& name)
+ throw (RuntimeException)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ return (m_aNodePtr != NULL && xmlHasProp(m_aNodePtr, xName) != NULL);
+ }
+
+ /**
+ Returns true when an attribute with a given local name and namespace
+ URI is specified on this element or has a default value, false otherwise.
+ */
+ sal_Bool CElement::hasAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar *xNs = (xmlChar*)o2.getStr();
+ return (m_aNodePtr != NULL && xmlHasNsProp(m_aNodePtr, xName, xNs) != NULL);
+ }
+
+ /**
+ Removes an attribute by name.
+ */
+ void CElement::removeAttribute(const OUString& name)
+ throw (RuntimeException, DOMException)
+ {
+ xmlChar *xName = (xmlChar*)OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr();
+ if (m_aNodePtr != NULL) {
+ xmlUnsetProp(m_aNodePtr, xName);
+ }
+ }
+
+ /**
+ Removes an attribute by local name and namespace URI.
+ */
+ void CElement::removeAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ xmlChar *xURI = (xmlChar*)o2.getStr();
+ if (m_aNodePtr != NULL) {
+ // XXX
+ xmlNsPtr pNs = xmlSearchNsByHref(m_aNodePtr->doc, m_aNodePtr, xURI);
+ xmlUnsetNsProp(m_aNodePtr, pNs, xName);
+ }
+ }
+
+ /**
+ Removes the specified attribute node.
+ */
+ Reference< XAttr > CElement::removeAttributeNode(const Reference< XAttr >& oldAttr)
+ throw (RuntimeException, DOMException)
+ {
+ Reference< XAttr > aAttr;
+ if(m_aNodePtr != NULL)
+ {
+ xmlAttrPtr pAttr = (xmlAttrPtr) CNode::getNodePtr(oldAttr.get());
+
+ if (pAttr->parent != m_aNodePtr)
+ {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+ if (pAttr->doc != m_aNodePtr->doc)
+ {
+ DOMException e;
+ e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
+ throw e;
+ }
+
+ if (oldAttr->getNamespaceURI().getLength() > 0)
+ aAttr = oldAttr->getOwnerDocument()->createAttributeNS(
+ oldAttr->getNamespaceURI(), oldAttr->getName());
+ else
+ aAttr = oldAttr->getOwnerDocument()->createAttribute(oldAttr->getName());
+ aAttr->setValue(oldAttr->getValue());
+ xmlRemoveProp(pAttr);
+
+ }
+ return aAttr;
+ }
+
+ /**
+ Adds a new attribute node.
+ */
+ Reference< XAttr > CElement::_setAttributeNode(const Reference< XAttr >& newAttr, sal_Bool bNS)
+ throw (RuntimeException)
+ {
+ Reference< XAttr > aAttr;
+ if (m_aNodePtr != NULL)
+ {
+ // check whether the attrib belongs to this document
+ Reference< XDocument > newDoc(newAttr->getOwnerDocument(), UNO_QUERY);
+ Reference< XDocument > oldDoc(CNode::getOwnerDocument(), UNO_QUERY);
+ if (newDoc != oldDoc) {
+ throw RuntimeException();
+ }
+
+ // get the implementation
+ xmlAttrPtr pAttr = (xmlAttrPtr) CNode::getNodePtr(newAttr.get());
+
+ // check whether the attribute is not in use by another element
+ xmlNsPtr pNs = NULL;
+ if (pAttr->parent != NULL)
+ if(strcmp((char*)pAttr->parent->name, "__private") == 0
+ && pNs && pAttr->ns != NULL)
+ {
+ pNs = xmlSearchNs(m_aNodePtr->doc, m_aNodePtr, pAttr->ns->prefix);
+ if (pNs == NULL || strcmp((char*)pNs->href, (char*)pAttr->ns->href) !=0 )
+ pNs = xmlNewNs(m_aNodePtr, pAttr->ns->href, pAttr->ns->href);
+ else
+ throw RuntimeException();
+ }
+
+ xmlAttrPtr res = NULL;
+
+ if (bNS)
+ res = xmlNewNsProp(m_aNodePtr, pNs, pAttr->name, pAttr->children->content);
+ else
+ res = xmlNewProp(m_aNodePtr, pAttr->name, pAttr->children->content);
+
+ // free carrier node ...
+ if(pAttr->parent != NULL && strcmp((char*)pAttr->parent->name, "__private")== 0)
+ xmlFreeNode(pAttr->parent);
+ // ... remove the old attr from the node cache
+ CNode::remove((xmlNodePtr)pAttr);
+
+ // get the new attr node
+ aAttr = Reference< XAttr >(static_cast< CAttr* >(CNode::get((xmlNodePtr)res)));
+ }
+
+ if (aAttr.is())
+ {
+ // attribute adition event
+ // dispatch DOMAttrModified event
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMAttrModified")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMAttrModified"),
+ sal_True, sal_False, Reference< XNode >(aAttr, UNO_QUERY),
+ OUString(), aAttr->getValue(), aAttr->getName(), AttrChangeType_ADDITION);
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ dispatchSubtreeModified();
+ }
+ return aAttr;
+ }
+
+ Reference< XAttr > CElement::setAttributeNode(const Reference< XAttr >& newAttr)
+ throw (RuntimeException, DOMException)
+ {
+ return _setAttributeNode(newAttr, sal_False);
+ }
+
+ /**
+ Adds a new attribute.
+ */
+ Reference< XAttr > CElement::setAttributeNodeNS(const Reference< XAttr >& newAttr)
+ throw (RuntimeException, DOMException)
+ {
+ return _setAttributeNode(newAttr, sal_True);
+ }
+
+ /**
+ Adds a new attribute.
+ */
+ void CElement::setAttribute(const OUString& name, const OUString& value)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)o1.getStr();
+ OString o2 = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
+ xmlChar *xValue = (xmlChar*)o2.getStr();
+ if (m_aNodePtr != NULL)
+ {
+ OUString oldValue;
+ AttrChangeType aChangeType = AttrChangeType_MODIFICATION;
+ xmlChar *xOld = xmlGetProp(m_aNodePtr, xName);
+ if (xOld == NULL)
+ {
+ aChangeType = AttrChangeType_ADDITION;
+ xmlNewProp(m_aNodePtr, xName, xValue);
+ }
+ else
+ {
+ oldValue = OUString((char*)xOld, strlen((char*)xOld), RTL_TEXTENCODING_UTF8);
+ xmlSetProp(m_aNodePtr, xName, xValue);
+ }
+
+ // dispatch DOMAttrModified event
+
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMAttrModified")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMAttrModified"),
+ sal_True, sal_False, Reference< XNode >(getAttributeNode(name), UNO_QUERY),
+ oldValue, value, name, aChangeType);
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ dispatchSubtreeModified();
+ }
+ }
+
+ /**
+ Adds a new attribute.
+ */
+ void CElement::setAttributeNS(
+ const OUString& namespaceURI, const OUString& qualifiedName, const OUString& value)
+ throw (RuntimeException, DOMException)
+ {
+ if (namespaceURI.getLength() == 0) throw RuntimeException();
+
+ OString o1, o2, o3, o4, o5;
+ xmlChar *xPrefix = NULL;
+ xmlChar *xLName = NULL;
+ o1 = OUStringToOString(qualifiedName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xQName = (xmlChar*)o1.getStr();
+ sal_Int32 idx = qualifiedName.indexOf(':');
+ if (idx != -1)
+ {
+ o2 = OUStringToOString(
+ qualifiedName.copy(0,idx),
+ RTL_TEXTENCODING_UTF8);
+ xPrefix = (xmlChar*)o2.getStr();
+ o3 = OUStringToOString(
+ qualifiedName.copy(idx+1),
+ RTL_TEXTENCODING_UTF8);
+ xLName = (xmlChar*)o3.getStr();
+ } else {
+ xPrefix = (xmlChar*)"";
+ xLName = xQName;
+ }
+ o4 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
+ o5 = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
+ xmlChar *xURI= (xmlChar*)o4.getStr();
+ xmlChar *xValue = (xmlChar*)o5.getStr();
+ if (m_aNodePtr != NULL)
+ {
+ //find the right namespace
+ xmlNsPtr pNs = xmlSearchNs(m_aNodePtr->doc, m_aNodePtr, xPrefix);
+ // if no namespace found, create a new one
+ if (pNs == NULL)
+ pNs = xmlNewNs(m_aNodePtr, xURI, xPrefix);
+
+ if (strcmp((char*)pNs->href, (char*)xURI) == 0)
+ {
+ // found namespace matches
+
+ OUString oldValue;
+ AttrChangeType aChangeType = AttrChangeType_MODIFICATION;
+ xmlChar *xOld = xmlGetNsProp(m_aNodePtr, xLName, pNs->href);
+ if (xOld == NULL)
+ {
+ aChangeType = AttrChangeType_ADDITION;
+ xmlNewNsProp(m_aNodePtr, pNs, xLName, xValue);
+ }
+ else
+ {
+ oldValue = OUString((char *)xOld, strlen((char *)xOld), RTL_TEXTENCODING_UTF8);
+ xmlSetNsProp(m_aNodePtr, pNs, xLName, xValue);
+ }
+ // dispatch DOMAttrModified event
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMAttrModified")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMAttrModified"), sal_True, sal_False,
+ Reference< XNode >(getAttributeNodeNS(namespaceURI, OUString((char*)xLName, strlen((char*)xLName), RTL_TEXTENCODING_UTF8)), UNO_QUERY),
+ oldValue, value, qualifiedName, aChangeType);
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ dispatchSubtreeModified();
+
+ } else {
+ // ambigious ns prefix
+ throw RuntimeException();
+ }
+
+ }
+ }
+
+ Reference< XNamedNodeMap > SAL_CALL CElement::getAttributes()throw (RuntimeException)
+ {
+ Reference< XNamedNodeMap > aMap;
+ if (hasAttributes()) {
+ aMap = Reference< XNamedNodeMap >(new CAttributesMap(this));
+ }
+ return aMap;
+ }
+ OUString SAL_CALL CElement::getNodeName()throw (RuntimeException)
+ {
+ return getLocalName();
+ }
+ OUString SAL_CALL CElement::getLocalName()throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ const xmlChar* xName = m_aNodePtr->name;
+ aName = OUString((const sal_Char*)xName, strlen((const char*)xName), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+ OUString SAL_CALL CElement::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+
+ void SAL_CALL CElement::setElementName(const OUString& aName) throw (RuntimeException, DOMException)
+ {
+ if (aName.getLength() > 0 && aName.indexOf(OUString::createFromAscii(":")) < 0)
+ {
+ OString oName = OUStringToOString(aName, RTL_TEXTENCODING_UTF8);
+ xmlChar *xName = (xmlChar*)oName.getStr();
+ // xmlFree((void*)m_aNodePtr->name);
+ m_aNodePtr->name = xmlStrdup(xName);
+ }
+ else
+ {
+ DOMException e;
+ e.Code = DOMExceptionType_INVALID_CHARACTER_ERR;
+ throw e;
+ }
+ }
+
+}
diff --git a/unoxml/source/dom/element.hxx b/unoxml/source/dom/element.hxx
new file mode 100644
index 000000000000..d0df7102f12f
--- /dev/null
+++ b/unoxml/source/dom/element.hxx
@@ -0,0 +1,296 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ELEMENT_HXX
+#define _ELEMENT_HXX
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNodeList.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+#include <com/sun/star/xml/dom/NodeType.hpp>
+#include <libxml/tree.h>
+#include "node.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CElement : public cppu::ImplInheritanceHelper1<CNode, XElement >
+ {
+ friend class CNode;
+ private:
+ Reference< XAttr > _setAttributeNode(const Reference< XAttr >& newAttr, sal_Bool bNS)
+ throw (RuntimeException);
+
+ protected:
+ CElement(const xmlNodePtr aNodePtr);
+
+ public:
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ virtual void SAL_CALL fastSaxify( Context& i_rContext );
+
+ /**
+ Retrieves an attribute value by name.
+ */
+ virtual OUString SAL_CALL getAttribute(const OUString& name)
+ throw (RuntimeException);
+
+ /**
+ Retrieves an attribute node by name.
+ */
+ virtual Reference< XAttr > SAL_CALL getAttributeNode(const OUString& name)
+ throw (RuntimeException);
+
+ /**
+ Retrieves an Attr node by local name and namespace URI.
+ */
+ virtual Reference< XAttr > SAL_CALL getAttributeNodeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException);
+
+ /**
+ Retrieves an attribute value by local name and namespace URI.
+ */
+ virtual OUString SAL_CALL getAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException);
+
+ /**
+ Returns a NodeList of all descendant Elements with a given tag name,
+ in the order in which they are
+ encountered in a preorder traversal of this Element tree.
+ */
+ virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& name)
+ throw (RuntimeException);
+
+ /**
+ Returns a NodeList of all the descendant Elements with a given local
+ name and namespace URI in the order in which they are encountered in
+ a preorder traversal of this Element tree.
+ */
+ virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI,
+ const OUString& localName)
+ throw (RuntimeException);
+
+ /**
+ The name of the element.
+ */
+ virtual OUString SAL_CALL getTagName()
+ throw (RuntimeException);
+
+ /**
+ Returns true when an attribute with a given name is specified on this
+ element or has a default value, false otherwise.
+ */
+ virtual sal_Bool SAL_CALL hasAttribute(const OUString& name)
+ throw (RuntimeException);
+
+ /**
+ Returns true when an attribute with a given local name and namespace
+ URI is specified on this element or has a default value, false otherwise.
+ */
+ virtual sal_Bool SAL_CALL hasAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException);
+
+ /**
+ Removes an attribute by name.
+ */
+ virtual void SAL_CALL removeAttribute(const OUString& name)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Removes the specified attribute node.
+ */
+ virtual Reference< XAttr > SAL_CALL removeAttributeNode(const Reference< XAttr >& oldAttr)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Removes an attribute by local name and namespace URI.
+ */
+ virtual void SAL_CALL removeAttributeNS(const OUString& namespaceURI, const OUString& localName)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Adds a new attribute.
+ */
+ virtual void SAL_CALL setAttribute(const OUString& name, const OUString& value)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Adds a new attribute node.
+ */
+ virtual Reference< XAttr > SAL_CALL setAttributeNode(const Reference< XAttr >& newAttr)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Adds a new attribute.
+ */
+ virtual Reference< XAttr > SAL_CALL setAttributeNodeNS(const Reference< XAttr >& newAttr)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Adds a new attribute.
+ */
+ virtual void SAL_CALL setAttributeNS(
+ const OUString& namespaceURI, const OUString& qualifiedName, const OUString& value)
+ throw (RuntimeException, DOMException);
+
+ /**
+ sets the element name
+ */
+ virtual void SAL_CALL setElementName(const OUString& elementName)
+ throw (RuntimeException, DOMException);
+
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException);
+
+ // resolve uno inheritance problems...
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+
+}
+
+#endif
diff --git a/unoxml/source/dom/elementlist.cxx b/unoxml/source/dom/elementlist.cxx
new file mode 100644
index 000000000000..8db7b2d3bcb4
--- /dev/null
+++ b/unoxml/source/dom/elementlist.cxx
@@ -0,0 +1,133 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "elementlist.hxx"
+
+#include <string.h>
+
+namespace DOM
+{
+
+ CElementList::CElementList(const CElement* aElement, const OUString& aName)
+ : m_pElement(aElement)
+ , m_aName(aName)
+ , xURI(0)
+ , m_bRebuild(sal_True)
+ {
+ OString o1 = OUStringToOString(aName, RTL_TEXTENCODING_UTF8);
+ xName = new xmlChar[o1.getLength()];
+ strcpy((char*)xName, o1.getStr());
+ registerListener(aElement);
+ }
+
+ CElementList::CElementList(const CElement* aElement, const OUString& aName, const OUString& aURI)
+ : m_pElement(aElement)
+ , m_aName(aName)
+ , m_aURI(aURI)
+ , m_bRebuild(sal_True)
+ {
+ OString o1 = OUStringToOString(aName, RTL_TEXTENCODING_UTF8);
+ xName = new xmlChar[o1.getLength()];
+ strcpy((char*)xName, o1.getStr());
+ OString o2 = OUStringToOString(aURI, RTL_TEXTENCODING_UTF8);
+ xURI = new xmlChar[o2.getLength()];
+ strcpy((char*)xURI, o2.getStr());
+ registerListener(aElement);
+ }
+
+ void CElementList::registerListener(const CElement* pElement)
+ {
+ try {
+ // get the XNode
+ Reference< XNode > xNode(CNode::get(static_cast<const CNode*>(pElement)->m_aNodePtr));
+ Reference< XEventTarget > xTarget(xNode, UNO_QUERY_THROW);
+ OUString aType = OUString::createFromAscii("DOMSubtreeModified");
+ sal_Bool capture = sal_False;
+ xTarget->addEventListener(aType, Reference< XEventListener >(this), capture);
+ } catch (Exception &e){
+ OString aMsg("Exception caught while registering NodeList as listener:\n");
+ aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
+ OSL_ENSURE(sal_False, aMsg.getStr());
+ }
+ }
+
+ void CElementList::buildlist(xmlNodePtr pNode, sal_Bool start)
+ {
+ // bail out if no rebuild is needed
+ if (start) {
+ if (!m_bRebuild)
+ {
+ return;
+ } else {
+ m_nodevector.erase(m_nodevector.begin(), m_nodevector.end());
+ m_bRebuild = sal_False; // don't rebuild until tree is mutated
+ }
+ }
+
+ while (pNode != NULL )
+ {
+ if (pNode->type == XML_ELEMENT_NODE && strcmp((char*)pNode->name, (char*)xName)==0)
+ {
+ if (xURI == NULL)
+ m_nodevector.push_back(pNode);
+ else
+ if (pNode->ns != NULL && strcmp((char*)pNode->ns->href, (char*)xURI) == 0)
+ m_nodevector.push_back(pNode);
+ }
+ if (pNode->children != NULL) buildlist(pNode->children, sal_False);
+
+ if (!start) pNode = pNode->next;
+ else break; // fold back
+ }
+ }
+
+ /**
+ The number of nodes in the list.
+ */
+ sal_Int32 SAL_CALL CElementList::getLength() throw (RuntimeException)
+ {
+ // this has to be 'live'
+ buildlist(static_cast<const CNode*>(m_pElement)->m_aNodePtr);
+ return m_nodevector.size();
+ }
+ /**
+ Returns the indexth item in the collection.
+ */
+ Reference< XNode > SAL_CALL CElementList::item(sal_Int32 index) throw (RuntimeException)
+ {
+ if (index < 0) throw RuntimeException();
+ buildlist(static_cast<const CNode*>(m_pElement)->m_aNodePtr);
+ return Reference< XNode >(CNode::get(m_nodevector[index]));
+ }
+
+ // tree mutations can change the list
+ void SAL_CALL CElementList::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException)
+ {
+ Reference< XEvent > aEvent = evt;
+ m_bRebuild = sal_True;
+ }
+}
diff --git a/unoxml/source/dom/elementlist.hxx b/unoxml/source/dom/elementlist.hxx
new file mode 100644
index 000000000000..0ebfd2722eea
--- /dev/null
+++ b/unoxml/source/dom/elementlist.hxx
@@ -0,0 +1,86 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ELEMENTLIST_HXX
+#define _ELEMENTLIST_HXX
+
+#include <vector>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNodeList.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include <com/sun/star/xml/dom/events/XEventListener.hpp>
+#include "element.hxx"
+#include "document.hxx"
+#include "libxml/tree.h"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+namespace DOM
+{
+ typedef std::vector< xmlNodePtr > nodevector;
+
+ class CElementList : public cppu::WeakImplHelper2< XNodeList, com::sun::star::xml::dom::events::XEventListener >
+ {
+ private:
+ const CElement* m_pElement;
+ const OUString m_aName;
+ const OUString m_aURI;
+ xmlChar *xName;
+ xmlChar *xURI;
+ sal_Bool m_bRebuild;
+ nodevector m_nodevector;
+
+
+ void buildlist(xmlNodePtr pNode, sal_Bool start=sal_True);
+ void registerListener(const CElement* pElement);
+
+ public:
+ CElementList(const CElement* aDoc, const OUString& aName);
+ CElementList(const CElement* aDoc, const OUString& aName, const OUString& aURI);
+ /**
+ The number of nodes in the list.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+ /**
+ Returns the indexth item in the collection.
+ */
+ virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
+
+ // XEventListener
+ virtual void SAL_CALL handleEvent(const Reference< XEvent >& evt) throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/entitiesmap.cxx b/unoxml/source/dom/entitiesmap.cxx
new file mode 100644
index 000000000000..98db3d2c7395
--- /dev/null
+++ b/unoxml/source/dom/entitiesmap.cxx
@@ -0,0 +1,100 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "entitiesmap.hxx"
+
+namespace DOM
+{
+ CEntitiesMap::CEntitiesMap(const CDocumentType* aDocType)
+ : m_pDocType(aDocType)
+ {
+ }
+
+ /**
+ The number of nodes in this map.
+ */
+ sal_Int32 SAL_CALL CEntitiesMap::getLength() throw (RuntimeException)
+ {
+ return 0;
+ }
+
+ /**
+ Retrieves a node specified by local name
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::getNamedItem(const OUString& /*name*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::getNamedItemNS(const OUString& /*namespaceURI*/,const OUString& /*localName*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Returns the indexth item in the map.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::item(sal_Int32 /*index*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Removes a node specified by name.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::removeNamedItem(const OUString& /*name*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::removeNamedItemNS(const OUString& /*namespaceURI*/, const OUString& /*localName*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::setNamedItem(const Reference< XNode >& /*arg*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ Reference< XNode > SAL_CALL CEntitiesMap::setNamedItemNS(const Reference< XNode >& /*arg*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+}
diff --git a/unoxml/source/dom/entitiesmap.hxx b/unoxml/source/dom/entitiesmap.hxx
new file mode 100644
index 000000000000..8480f1e0eecd
--- /dev/null
+++ b/unoxml/source/dom/entitiesmap.hxx
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ENTITIESMAP_HXX
+#define _ENTITIESMAP_HXX
+
+#include <map>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+#include "document.hxx"
+#include "documenttype.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CEntitiesMap : public cppu::WeakImplHelper1< XNamedNodeMap >
+ {
+ private:
+ const CDocumentType* m_pDocType;
+ public:
+ CEntitiesMap(const CDocumentType* aDocType);
+
+ /**
+ The number of nodes in this map.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException);
+
+ /**
+ Returns the indexth item in the map.
+ */
+ virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
+
+ /**
+ Removes a node specified by name.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException);
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItem(const Reference< XNode >& arg) throw (RuntimeException);
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/entity.cxx b/unoxml/source/dom/entity.cxx
new file mode 100644
index 000000000000..de711ae62d8d
--- /dev/null
+++ b/unoxml/source/dom/entity.cxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "entity.hxx"
+
+#include <string.h>
+
+namespace DOM
+{
+
+ CEntity::CEntity(const xmlEntityPtr aEntityPtr)
+ {
+ m_aNodeType = NodeType_ENTITY_NODE;
+ m_aEntityPtr = aEntityPtr;
+ init_node((xmlNodePtr)aEntityPtr);
+ }
+
+ /**
+ For unparsed entities, the name of the notation for the entity.
+ */
+ OUString SAL_CALL CEntity::getNotationName() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+ /**
+ The public identifier associated with the entity, if specified.
+ */
+ OUString SAL_CALL CEntity::getPublicId() throw (RuntimeException)
+ {
+ OUString aID;
+ if(m_aEntityPtr != NULL)
+ {
+ aID = OUString((sal_Char*)m_aEntityPtr->ExternalID, strlen((char*)m_aEntityPtr->ExternalID), RTL_TEXTENCODING_UTF8);
+ }
+ return aID;
+ }
+
+ /**
+ The system identifier associated with the entity, if specified.
+ */
+ OUString SAL_CALL CEntity::getSystemId() throw (RuntimeException)
+ {
+ OUString aID;
+ if(m_aEntityPtr != NULL)
+ {
+ aID = OUString((sal_Char*)m_aEntityPtr->SystemID, strlen((char*)m_aEntityPtr->SystemID), RTL_TEXTENCODING_UTF8);
+ }
+ return aID;
+ }
+ OUString SAL_CALL CEntity::getNodeName()throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ const xmlChar* xName = m_aNodePtr->name;
+ aName = OUString((sal_Char*)xName, strlen((char*)xName), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+ OUString SAL_CALL CEntity::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+}
diff --git a/unoxml/source/dom/entity.hxx b/unoxml/source/dom/entity.hxx
new file mode 100644
index 000000000000..0343a13dda16
--- /dev/null
+++ b/unoxml/source/dom/entity.hxx
@@ -0,0 +1,200 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ENTITY_HXX
+#define _ENTITY_HXX
+
+#include <sal/types.h>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XEntity.hpp>
+#include "node.hxx"
+#include <libxml/tree.h>
+#include <libxml/entities.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CEntity : public cppu::ImplInheritanceHelper1< CNode, XEntity >
+ {
+ friend class CNode;
+ private:
+ xmlEntityPtr m_aEntityPtr;
+
+ protected:
+ CEntity(const xmlEntityPtr aEntityPtr);
+
+ public:
+
+ /**
+ For unparsed entities, the name of the notation for the entity.
+ */
+ virtual OUString SAL_CALL getNotationName() throw (RuntimeException);
+
+ /**
+ The public identifier associated with the entity, if specified.
+ */
+ virtual OUString SAL_CALL getPublicId() throw (RuntimeException);
+
+ /**
+ The system identifier associated with the entity, if specified.
+ */
+ virtual OUString SAL_CALL getSystemId() throw (RuntimeException);
+
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/entityreference.cxx b/unoxml/source/dom/entityreference.cxx
new file mode 100644
index 000000000000..6cdce0c8ed3d
--- /dev/null
+++ b/unoxml/source/dom/entityreference.cxx
@@ -0,0 +1,52 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "entityreference.hxx"
+#include <string.h>
+
+namespace DOM
+{
+ CEntityReference::CEntityReference(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_ENTITY_REFERENCE_NODE;
+ init_node(aNodePtr);
+ }
+ OUString SAL_CALL CEntityReference::getNodeName()throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ const xmlChar* xName = m_aNodePtr->name;
+ aName = OUString((sal_Char*)xName, strlen((char*)xName), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+ OUString SAL_CALL CEntityReference::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+}
diff --git a/unoxml/source/dom/entityreference.hxx b/unoxml/source/dom/entityreference.hxx
new file mode 100644
index 000000000000..1ab8217bc628
--- /dev/null
+++ b/unoxml/source/dom/entityreference.hxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _ENTITYREFERENCE_HXX
+#define _ENTITYREFERENCE_HXX
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XEntityReference.hpp>
+#include "node.hxx"
+#include <libxml/tree.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CEntityReference : public cppu::ImplInheritanceHelper1< CNode, XEntityReference >
+ {
+ friend class CNode;
+ protected:
+ CEntityReference(const xmlNodePtr aNodePtr);
+
+ public:
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+}
+#endif
diff --git a/unoxml/source/dom/makefile.mk b/unoxml/source/dom/makefile.mk
new file mode 100644
index 000000000000..32a35ebfd54b
--- /dev/null
+++ b/unoxml/source/dom/makefile.mk
@@ -0,0 +1,74 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..
+
+PRJNAME=unoxml
+TARGET=domimpl
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+.IF "$(SYSTEM_LIBXML)" == "YES"
+CFLAGS+=-DSYSTEM_LIBXML $(LIBXML_CFLAGS)
+.ENDIF
+
+# --- Files --------------------------------------------------------
+
+SLOFILES = \
+ $(SLO)$/attr.obj \
+ $(SLO)$/cdatasection.obj \
+ $(SLO)$/characterdata.obj \
+ $(SLO)$/comment.obj \
+ $(SLO)$/document.obj \
+ $(SLO)$/documentbuilder.obj \
+ $(SLO)$/documentfragment.obj \
+ $(SLO)$/documenttype.obj \
+ $(SLO)$/element.obj \
+ $(SLO)$/entity.obj \
+ $(SLO)$/entityreference.obj \
+ $(SLO)$/node.obj \
+ $(SLO)$/notation.obj \
+ $(SLO)$/processinginstruction.obj \
+ $(SLO)$/text.obj \
+ $(SLO)$/domimplementation.obj \
+ $(SLO)$/elementlist.obj \
+ $(SLO)$/childlist.obj \
+ $(SLO)$/notationsmap.obj \
+ $(SLO)$/entitiesmap.obj \
+ $(SLO)$/attributesmap.obj \
+ $(SLO)$/saxbuilder.obj
+
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+
diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx
new file mode 100644
index 000000000000..fb4a6bf508b3
--- /dev/null
+++ b/unoxml/source/dom/node.cxx
@@ -0,0 +1,1027 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "node.hxx"
+#include "element.hxx"
+#include "text.hxx"
+#include "cdatasection.hxx"
+#include "entityreference.hxx"
+#include "entity.hxx"
+#include "processinginstruction.hxx"
+#include "comment.hxx"
+#include "document.hxx"
+#include "documenttype.hxx"
+#include "documentfragment.hxx"
+#include "notation.hxx"
+#include "childlist.hxx"
+#include "attr.hxx"
+
+#include <com/sun/star/xml/sax/FastToken.hpp>
+#include "rtl/instance.hxx"
+#include "osl/mutex.hxx"
+#include "../events/eventdispatcher.hxx"
+#include "../events/mutationevent.hxx"
+
+#include <boost/bind.hpp>
+#include <algorithm>
+
+namespace {
+//see CNode::remove
+ struct NodeMutex: public ::rtl::Static<osl::Mutex, NodeMutex> {};
+}
+
+namespace DOM
+{
+ void pushContext(Context& io_rContext)
+ {
+ io_rContext.maNamespaces.push_back(
+ io_rContext.maNamespaces.back());
+ }
+
+ void popContext(Context& io_rContext)
+ {
+ io_rContext.maNamespaces.pop_back();
+ }
+
+ void addNamespaces(Context& io_rContext, xmlNodePtr pNode)
+ {
+ // add node's namespaces to current context
+ for (xmlNsPtr pNs = pNode->nsDef; pNs != 0; pNs = pNs->next) {
+ const xmlChar *pPrefix = pNs->prefix;
+ OString prefix(reinterpret_cast<const sal_Char*>(pPrefix),
+ strlen(reinterpret_cast<const char*>(pPrefix)));
+ const xmlChar *pHref = pNs->href;
+ OUString val(reinterpret_cast<const sal_Char*>(pHref),
+ strlen(reinterpret_cast<const char*>(pHref)),
+ RTL_TEXTENCODING_UTF8);
+
+ OSL_TRACE("Trying to add namespace %s (prefix %s)",
+ (const char*)pHref, (const char*)pPrefix);
+
+ Context::NamespaceMapType::iterator aIter=
+ io_rContext.maNamespaceMap.find(val);
+ if( aIter != io_rContext.maNamespaceMap.end() )
+ {
+ Context::Namespace aNS;
+ aNS.maPrefix = prefix;
+ aNS.mnToken = aIter->second;
+ aNS.maNamespaceURL = val;
+
+ io_rContext.maNamespaces.back().push_back(aNS);
+
+ OSL_TRACE("Added with token 0x%x", aIter->second);
+ }
+ }
+ }
+
+ sal_Int32 getToken( const Context& rContext, const sal_Char* pToken )
+ {
+ const Sequence<sal_Int8> aSeq( (sal_Int8*)pToken, strlen( pToken ) );
+ return rContext.mxTokenHandler->getTokenFromUTF8( aSeq );
+ }
+
+ sal_Int32 getTokenWithPrefix( const Context& rContext, const sal_Char* pPrefix, const sal_Char* pName )
+ {
+ sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
+ OString prefix(pPrefix,
+ strlen(reinterpret_cast<const char*>(pPrefix)));
+
+ OSL_TRACE("getTokenWithPrefix(): prefix %s, name %s",
+ (const char*)pPrefix, (const char*)pName);
+
+ Context::NamespaceVectorType::value_type::const_iterator aIter;
+ if( (aIter=std::find_if(rContext.maNamespaces.back().begin(),
+ rContext.maNamespaces.back().end(),
+ boost::bind(std::equal_to<OString>(),
+ boost::bind(&Context::Namespace::getPrefix,
+ _1),
+ boost::cref(prefix)))) != rContext.maNamespaces.back().end() )
+ {
+ nNamespaceToken = aIter->mnToken;
+ sal_Int32 nNameToken = getToken( rContext, pName );
+ if( nNameToken != FastToken::DONTKNOW )
+ nNamespaceToken |= nNameToken;
+ }
+
+ return nNamespaceToken;
+ }
+
+
+ nodemap_t CNode::theNodeMap;
+
+ void CNode::remove(const xmlNodePtr aNode)
+ {
+ //Using the guard here protects against races when at the same time
+ //CNode::get() is called. This fix helps in many cases but is still
+ //incorrect. remove is called from ~CNode. That is, while the object
+ //is being destructed it can still be obtained by calling CNode::get().
+ //Another bug currently prevents the correct destruction of CNodes. So
+ //the destructor is rarely called.
+ //
+ //Doing this right would probably mean to store WeakReferences in the
+ //map and also guard oder functions. To keep the risk at a minimum
+ //we keep this imperfect fix for the upcoming release and fix it later
+ //properly (http://qa.openoffice.org/issues/show_bug.cgi?id=113682)
+ ::osl::MutexGuard guard(NodeMutex::get());
+ nodemap_t::iterator i = CNode::theNodeMap.find(aNode);
+ if (i != CNode::theNodeMap.end())
+ {
+ // CNode *pNode = i->second;
+ CNode::theNodeMap.erase(i);
+ }
+ }
+
+
+ CNode* CNode::get(const xmlNodePtr aNode, sal_Bool bCreate)
+ {
+ CNode* pNode = 0;
+ if (aNode == NULL)
+ return 0;
+ //see CNode::remove
+ ::osl::MutexGuard guard(NodeMutex::get());
+ //check whether there is already an instance for this node
+ nodemap_t::const_iterator i = CNode::theNodeMap.find(aNode);
+ if (i != CNode::theNodeMap.end())
+ {
+ pNode = i->second;
+ } else
+ {
+
+ // there is not yet an instance wrapping this node,
+ // create it and store it in the map
+ if (!bCreate) return NULL;
+
+ switch (aNode->type)
+ {
+ case XML_ELEMENT_NODE:
+ // m_aNodeType = NodeType::ELEMENT_NODE;
+ pNode = static_cast< CNode* >(new CElement(aNode));
+ break;
+ case XML_TEXT_NODE:
+ // m_aNodeType = NodeType::TEXT_NODE;
+ pNode = static_cast< CNode* >(new CText(aNode));
+ break;
+ case XML_CDATA_SECTION_NODE:
+ // m_aNodeType = NodeType::CDATA_SECTION_NODE;
+ pNode = static_cast< CNode* >(new CCDATASection(aNode));
+ break;
+ case XML_ENTITY_REF_NODE:
+ // m_aNodeType = NodeType::ENTITY_REFERENCE_NODE;
+ pNode = static_cast< CNode* >(new CEntityReference(aNode));
+ break;
+ case XML_ENTITY_NODE:
+ // m_aNodeType = NodeType::ENTITY_NODE;
+ pNode = static_cast< CNode* >(new CEntity((xmlEntityPtr)aNode));
+ break;
+ case XML_PI_NODE:
+ // m_aNodeType = NodeType::PROCESSING_INSTRUCTION_NODE;
+ pNode = static_cast< CNode* >(new CProcessingInstruction(aNode));
+ break;
+ case XML_COMMENT_NODE:
+ // m_aNodeType = NodeType::COMMENT_NODE;
+ pNode = static_cast< CNode* >(new CComment(aNode));
+ break;
+ case XML_DOCUMENT_NODE:
+ // m_aNodeType = NodeType::DOCUMENT_NODE;
+ pNode = static_cast< CNode* >(new CDocument((xmlDocPtr)aNode));
+ break;
+ case XML_DOCUMENT_TYPE_NODE:
+ case XML_DTD_NODE:
+ // m_aNodeType = NodeType::DOCUMENT_TYPE_NODE;
+ pNode = static_cast< CNode* >(new CDocumentType((xmlDtdPtr)aNode));
+ break;
+ case XML_DOCUMENT_FRAG_NODE:
+ // m_aNodeType = NodeType::DOCUMENT_FRAGMENT_NODE;
+ pNode = static_cast< CNode* >(new CDocumentFragment(aNode));
+ break;
+ case XML_NOTATION_NODE:
+ // m_aNodeType = NodeType::NOTATION_NODE;
+ pNode = static_cast< CNode* >(new CNotation((xmlNotationPtr)aNode));
+ break;
+ case XML_ATTRIBUTE_NODE:
+ // m_aNodeType = NodeType::NOTATION_NODE;
+ pNode = static_cast< CNode* >(new CAttr((xmlAttrPtr)aNode));
+ break;
+ // unsopported node types
+ case XML_HTML_DOCUMENT_NODE:
+ case XML_ELEMENT_DECL:
+ case XML_ATTRIBUTE_DECL:
+ case XML_ENTITY_DECL:
+ case XML_NAMESPACE_DECL:
+ default:
+ pNode = 0;
+ break;
+ }
+ }
+ if ( pNode != 0 )
+ {
+ if(CNode::theNodeMap.insert(nodemap_t::value_type(aNode, pNode)).second)
+ {
+ // insertion done, register node with document
+ xmlDocPtr doc = aNode->doc;
+ if( doc != NULL)
+ {
+ CDocument* pDoc = static_cast< CDocument* >(CNode::get((xmlNodePtr)doc));
+ pDoc->addnode(aNode);
+ } else
+ {
+ // if insertion failed, delete the new instance and return null
+ delete pNode;
+ pNode = 0;
+ }
+ }
+ }
+ OSL_ENSURE(pNode, "no node produced during CNode::get!");
+ return pNode;
+ }
+
+ xmlNodePtr CNode::getNodePtr(const Reference< XNode >& aNode)
+ {
+ try {
+ CNode* pNode=dynamic_cast<CNode*>(aNode.get());
+ if( pNode )
+ return pNode->m_aNodePtr;
+ }
+ catch(...) {}
+ return 0;
+ }
+
+ CNode::CNode()
+ : m_aNodePtr(0)
+ {
+ }
+
+ void CNode::init_node(const xmlNodePtr aNode)
+ {
+ m_aNodePtr = aNode;
+
+ // keep containing document alive
+ // (if we are not that document ourselves)
+ if (m_aNodePtr->type != XML_DOCUMENT_NODE)
+ m_rDocument = getOwnerDocument();
+ }
+
+ CNode::~CNode()
+ {
+ //remove from list if this wrapper goes away
+ if (m_aNodePtr != 0)
+ CNode::remove(m_aNodePtr);
+ }
+
+ static void _nsexchange(const xmlNodePtr aNode, xmlNsPtr oldNs, xmlNsPtr newNs)
+ {
+ // recursively exchange any references to oldNs with references to newNs
+ xmlNodePtr cur = aNode;
+ while (cur != 0)
+ {
+ if (cur->ns == oldNs)
+ cur->ns = newNs;
+ if (cur->type == XML_ELEMENT_NODE)
+ {
+ xmlAttrPtr curAttr = cur->properties;
+ while(curAttr != 0)
+ {
+ if (curAttr->ns == oldNs)
+ curAttr->ns = newNs;
+ curAttr = curAttr->next;
+ }
+ _nsexchange(cur->children, oldNs, newNs);
+ }
+ cur = cur->next;
+ }
+ }
+
+ /*static*/ void _nscleanup(const xmlNodePtr aNode, const xmlNodePtr aParent)
+ {
+ xmlNodePtr cur = aNode;
+
+ //handle attributes
+ if (cur != NULL && cur->type == XML_ELEMENT_NODE)
+ {
+ xmlAttrPtr curAttr = cur->properties;
+ while(curAttr != 0)
+ {
+ if (curAttr->ns != NULL)
+ {
+ xmlNsPtr ns = xmlSearchNs(cur->doc, aParent, curAttr->ns->prefix);
+ if (ns != NULL)
+ curAttr->ns = ns;
+ }
+ curAttr = curAttr->next;
+ }
+ }
+
+ while (cur != NULL)
+ {
+ _nscleanup(cur->children, cur);
+ if (cur->ns != NULL)
+ {
+ xmlNsPtr ns = xmlSearchNs(cur->doc, aParent, cur->ns->prefix);
+ if (ns != NULL && ns != cur->ns && strcmp((char*)ns->href, (char*)cur->ns->href)==0)
+ {
+ xmlNsPtr curDef = cur->nsDef;
+ xmlNsPtr *refp = &(cur->nsDef); // insert point
+ while (curDef != NULL)
+ {
+ ns = xmlSearchNs(cur->doc, aParent, curDef->prefix);
+ if (ns != NULL && ns != curDef && strcmp((char*)ns->href, (char*)curDef->href)==0)
+ {
+ // reconnect ns pointers in sub-tree to newly found ns before
+ // removing redundant nsdecl to prevent dangling pointers.
+ _nsexchange(cur, curDef, ns);
+ *refp = curDef->next;
+ xmlFreeNs(curDef);
+ curDef = *refp;
+ } else {
+ refp = &(curDef->next);
+ curDef = curDef->next;
+ }
+ }
+ }
+ }
+ cur = cur->next;
+ }
+ }
+
+ void SAL_CALL CNode::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ // default: do nothing
+ }
+
+ void SAL_CALL CNode::fastSaxify(Context& io_rContext) {
+ if (!io_rContext.mxDocHandler.is()) throw RuntimeException();
+ // default: do nothing
+ }
+
+ /**
+ Adds the node newChild to the end of the list of children of this node.
+ */
+ Reference< XNode > CNode::appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ Reference< XNode> aNode;
+ if (m_aNodePtr != NULL) {
+ xmlNodePtr cur = CNode::getNodePtr(newChild.get());
+
+ // error checks:
+ // from other document
+ if (cur->doc != m_aNodePtr->doc) {
+ DOMException e;
+ e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
+ throw e;
+ }
+ // same node
+ if (cur == m_aNodePtr) {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+ // already has parant and is not attribute
+ if (cur->parent != NULL && cur->type != XML_ATTRIBUTE_NODE) {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+ // check whether this is an attribute node so we remove it's
+ // carrier node if it has one
+ xmlNodePtr res = NULL;
+ if (cur->type == XML_ATTRIBUTE_NODE)
+ {
+ if (cur->parent != NULL)
+ {
+ if (m_aNodePtr->type != XML_ELEMENT_NODE ||
+ strcmp((char*)cur->parent->name, "__private") != 0)
+ {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+ xmlNsPtr pAttrNs = cur->ns;
+ xmlNsPtr pParentNs = xmlSearchNs(m_aNodePtr->doc, m_aNodePtr, pAttrNs->prefix);
+ if (pParentNs == NULL || strcmp((char*)pParentNs->href, (char*)pAttrNs->href) != 0)
+ pParentNs = xmlNewNs(m_aNodePtr, pAttrNs->href, pAttrNs->prefix);
+
+ if (cur->children != NULL)
+ res = (xmlNodePtr)xmlNewNsProp(m_aNodePtr, pParentNs, cur->name, cur->children->content);
+ else
+ res = (xmlNodePtr)xmlNewProp(m_aNodePtr, cur->name, (xmlChar*) "");
+
+ xmlFreeNode(cur->parent);
+ cur->parent = NULL;
+ }
+ else
+ {
+ if (cur->children != NULL)
+ res = (xmlNodePtr)xmlNewProp(m_aNodePtr, cur->name, cur->children->content);
+ else
+ res = (xmlNodePtr)xmlNewProp(m_aNodePtr, cur->name, (xmlChar*) "");
+ }
+ }
+ else
+ {
+ res = xmlAddChild(m_aNodePtr, cur);
+ }
+
+ // libxml can do optimizations, when appending nodes.
+ // if res != cur, something was optimized and the newchild-wrapper
+ // should be updated
+ if (cur != res)
+ CNode::remove(cur);
+
+ // use custom ns cleanup instaead of
+ // xmlReconciliateNs(m_aNodePtr->doc, m_aNodePtr);
+ // because that will not remove unneeded ns decls
+ _nscleanup(res, m_aNodePtr);
+
+ aNode = Reference< XNode>(CNode::get(res));
+ }
+ //XXX check for errors
+
+ // dispatch DOMNodeInserted event, target is the new node
+ // this node is the related node
+ // does bubble
+ if (aNode.is())
+ {
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMNodeInserted")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMNodeInserted")
+ , sal_True, sal_False, Reference< XNode >(CNode::get(m_aNodePtr)),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+
+ // dispatch subtree modified for this node
+ dispatchSubtreeModified();
+ }
+ return aNode;
+ }
+
+ /**
+ Returns a duplicate of this node, i.e., serves as a generic copy
+ constructor for nodes.
+ */
+ Reference< XNode > CNode::cloneNode(sal_Bool bDeep)
+ throw (RuntimeException)
+ {
+ Reference< XNode> aNode;
+ if (m_aNodePtr != NULL)
+ {
+ aNode = Reference< XNode>(CNode::get(
+ xmlCopyNode (m_aNodePtr, static_cast< int >(bDeep))
+ ));
+ }
+ //XXX check for errors
+ return aNode;
+ }
+
+ /**
+ A NamedNodeMap containing the attributes of this node (if it is an Element)
+ or null otherwise.
+ */
+ Reference< XNamedNodeMap > CNode::getAttributes()
+ throw (RuntimeException)
+ {
+ // return empty reference
+ // only element node may override this impl
+ return Reference< XNamedNodeMap>();
+
+ // get all children that are attributes
+ /* --> CElement
+ Reference< NamedNodeMap > aNodeMap(new AttributeNamedNodeMap(m_aNodePtr), UNO_QUERY);
+ return aNodeMap;
+ */
+ }
+
+ /**
+ A NodeList that contains all children of this node.
+ */
+ Reference< XNodeList > CNode::getChildNodes()
+ throw (RuntimeException)
+ {
+ Reference< XNodeList > aNodeList;
+ if (m_aNodePtr != NULL)
+ {
+ aNodeList = Reference< XNodeList >(new CChildList(CNode::get(m_aNodePtr)));
+ }
+ // XXX check for errors?
+ return aNodeList;
+ }
+
+ /**
+ The first child of this node.
+ */
+ Reference< XNode > CNode::getFirstChild()
+ throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ if (m_aNodePtr != NULL) {
+ aNode = Reference< XNode >(CNode::get(m_aNodePtr->children));
+ }
+ return aNode;
+ }
+
+ /**
+ The last child of this node.
+ */
+ Reference< XNode > SAL_CALL CNode::getLastChild()
+ throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ if (m_aNodePtr != NULL) {
+ aNode = Reference< XNode >(CNode::get(xmlGetLastChild(m_aNodePtr)));
+ }
+ return aNode;
+ }
+
+ /**
+ Returns the local part of the qualified name of this node.
+ */
+ OUString SAL_CALL CNode::getLocalName()
+ throw (RuntimeException)
+ {
+ OUString aName;
+ /*
+ --> Element / Attribute
+ if(m_aNodePtr != NULL && (m_aNodeType == NodeType::ATTRIBUTE_NODE
+ || m_aNodeType == NodeType::ELEMENT_NODE))
+ {
+ aName = OUString(m_aNodePtr->name, RTL_TEXTENCODING_UTF8);
+ }
+ //XXX error checking
+ */
+ return aName;
+ }
+
+
+ /**
+ The namespace URI of this node, or null if it is unspecified.
+ */
+ OUString SAL_CALL CNode::getNamespaceURI()
+ throw (RuntimeException)
+ {
+ OUString aURI;
+ if (m_aNodePtr != NULL &&
+ (m_aNodePtr->type == XML_ELEMENT_NODE || m_aNodePtr->type == XML_ATTRIBUTE_NODE) &&
+ m_aNodePtr->ns != NULL)
+ {
+ const xmlChar* xHref = m_aNodePtr->ns->href;
+ aURI = OUString((sal_Char*)xHref, strlen((char*)xHref), RTL_TEXTENCODING_UTF8);
+ }
+ return aURI;
+ }
+
+ /**
+ The node immediately following this node.
+ */
+ Reference< XNode > SAL_CALL CNode::getNextSibling()
+ throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ if(m_aNodePtr != NULL)
+ {
+ aNode = Reference< XNode >(CNode::get(m_aNodePtr->next));
+ }
+ return aNode;
+ }
+
+ /**
+ The name of this node, depending on its type; see the table above.
+ */
+ OUString SAL_CALL CNode::getNodeName()
+ throw (RuntimeException)
+ {
+ /*
+ Interface nodeName nodeValue attributes
+ --------------------------------------------------------------------------------------
+ Attr name of attribute value of attribute null
+ CDATASection "#cdata-section" content of the CDATA Section null
+ Comment "#comment" content of the comment null
+ Document "#document" null null
+ DocumentFragment "#document-fragment" null null
+ DocumentType document type name null null
+ Element tag name null NamedNodeMap
+ Entity entity name null null
+ EntityReference name of entity null null
+ referenced
+ Notation notation name null null
+ Processing\ target entire content excluding null
+ Instruction the target
+ Text "#text" content of the text node null
+ */
+ OUString aName;
+ return aName;
+ }
+
+ /**
+ A code representing the type of the underlying object, as defined above.
+ */
+ NodeType SAL_CALL CNode::getNodeType()
+ throw (RuntimeException)
+ {
+ return m_aNodeType;
+ }
+
+ /**
+ The value of this node, depending on its type; see the table above.
+ */
+ OUString SAL_CALL CNode::getNodeValue()
+ throw (RuntimeException)
+ {
+ OUString aValue;
+ return aValue;
+ }
+
+ /**
+ The Document object associated with this node.
+ */
+ Reference< XDocument > SAL_CALL CNode::getOwnerDocument()
+ throw (RuntimeException)
+ {
+ Reference<XDocument> aDoc;
+ if (m_aNodePtr != NULL)
+ {
+ aDoc = Reference< XDocument >(static_cast< CDocument* >(
+ CNode::get((xmlNodePtr)m_aNodePtr->doc)));
+ }
+ return aDoc;
+
+ }
+
+ /**
+ The parent of this node.
+ */
+ Reference< XNode > SAL_CALL CNode::getParentNode()
+ throw (RuntimeException)
+ {
+ Reference<XNode> aNode;
+ if (m_aNodePtr != NULL)
+ {
+ aNode = Reference< XNode >(CNode::get(m_aNodePtr->parent));
+ }
+ return aNode;
+ }
+
+ /**
+ The namespace prefix of this node, or null if it is unspecified.
+ */
+ OUString SAL_CALL CNode::getPrefix()
+ throw (RuntimeException)
+ {
+ OUString aPrefix;
+ if (m_aNodePtr != NULL &&
+ (m_aNodePtr->type == XML_ELEMENT_NODE || m_aNodePtr->type == XML_ATTRIBUTE_NODE) &&
+ m_aNodePtr->ns != NULL)
+ {
+ const xmlChar* xPrefix = m_aNodePtr->ns->prefix;
+ if( xPrefix != NULL )
+ aPrefix = OUString((sal_Char*)xPrefix, strlen((char*)xPrefix), RTL_TEXTENCODING_UTF8);
+ }
+ return aPrefix;
+
+ }
+
+ /**
+ The node immediately preceding this node.
+ */
+ Reference< XNode > SAL_CALL CNode::getPreviousSibling()
+ throw (RuntimeException)
+ {
+ Reference< XNode > aNode;
+ if (m_aNodePtr != NULL)
+ {
+ aNode = Reference< XNode >(CNode::get(m_aNodePtr->prev));
+ }
+ return aNode;
+ }
+
+ /**
+ Returns whether this node (if it is an element) has any attributes.
+ */
+ sal_Bool SAL_CALL CNode::hasAttributes()
+ throw (RuntimeException)
+ {
+ return (m_aNodePtr != NULL && m_aNodePtr->properties != NULL);
+ }
+
+ /**
+ Returns whether this node has any children.
+ */
+ sal_Bool SAL_CALL CNode::hasChildNodes()
+ throw (RuntimeException)
+ {
+ return (m_aNodePtr != NULL && m_aNodePtr->children != NULL);
+ }
+
+ /**
+ Inserts the node newChild before the existing child node refChild.
+ */
+ Reference< XNode > SAL_CALL CNode::insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+
+ if (newChild->getOwnerDocument() != getOwnerDocument()) {
+ DOMException e;
+ e.Code = DOMExceptionType_WRONG_DOCUMENT_ERR;
+ throw e;
+ }
+ if (refChild->getParentNode() != Reference< XNode >(this)) {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+ xmlNodePtr pRefChild = CNode::getNodePtr(refChild.get());
+ xmlNodePtr pNewChild = CNode::getNodePtr(newChild.get());
+ xmlNodePtr cur = m_aNodePtr->children;
+
+ //search cild before which to insert
+ while (cur != NULL)
+ {
+ if (cur == pRefChild) {
+ // insert before
+ pNewChild->next = cur;
+ pNewChild->prev = cur->prev;
+ cur->prev = pNewChild;
+ if( pNewChild->prev != NULL)
+ pNewChild->prev->next = pNewChild;
+ }
+ cur = cur->next;
+ }
+ return refChild;
+ }
+
+ /**
+ Tests whether the DOM implementation implements a specific feature and
+ that feature is supported by this node.
+ */
+ sal_Bool SAL_CALL CNode::isSupported(const OUString& /*feature*/, const OUString& /*ver*/)
+ throw (RuntimeException)
+ {
+ // XXX
+ return sal_False;
+ }
+
+ /**
+ Puts all Text nodes in the full depth of the sub-tree underneath this
+ Node, including attribute nodes, into a "normal" form where only structure
+ (e.g., elements, comments, processing instructions, CDATA sections, and
+ entity references) separates Text nodes, i.e., there are neither adjacent
+ Text nodes nor empty Text nodes.
+ */
+ void SAL_CALL CNode::normalize()
+ throw (RuntimeException)
+ {
+ //XXX combine adjacent text nodes and remove empty ones
+ }
+
+ /**
+ Removes the child node indicated by oldChild from the list of children,
+ and returns it.
+ */
+ Reference< XNode > SAL_CALL CNode::removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+
+ if (oldChild->getParentNode() != Reference< XNode >(this)) {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+ Reference<XNode> xReturn( oldChild );
+
+ xmlNodePtr old = CNode::getNodePtr(oldChild);
+
+ if( old->type == XML_ATTRIBUTE_NODE )
+ {
+ xmlAttrPtr pAttr = (xmlAttrPtr) old;
+ xmlRemoveProp( pAttr );
+ xReturn.clear();
+ }
+ else
+ {
+
+ // update .last
+ if (m_aNodePtr->last == old)
+ m_aNodePtr->last = old->prev;
+
+ xmlNodePtr cur = m_aNodePtr->children;
+ //find old node in child list
+ while (cur != NULL)
+ {
+ if(cur == old)
+ {
+ // unlink node from list
+ if (cur->prev != NULL)
+ cur->prev->next = cur->next;
+ if (cur->next != NULL)
+ cur->next->prev = cur->prev;
+ if (cur->parent != NULL && cur->parent->children == cur)
+ cur->parent->children = cur->next;
+ cur->prev = NULL;
+ cur->next = NULL;
+ cur->parent = NULL;
+ }
+ cur = cur->next;
+ }
+ }
+
+ /*DOMNodeRemoved
+ * Fired when a node is being removed from its parent node.
+ * This event is dispatched before the node is removed from the tree.
+ * The target of this event is the node being removed.
+ * Bubbles: Yes
+ * Cancelable: No
+ * Context Info: relatedNode holds the parent node
+ */
+ if (oldChild.is())
+ {
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMNodeRemoved")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMNodeRemoved"), sal_True,
+ sal_False, Reference< XNode >(CNode::get(m_aNodePtr)),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+
+ // subtree modofied for this node
+ dispatchSubtreeModified();
+ }
+ return xReturn;
+ }
+
+ /**
+ Replaces the child node oldChild with newChild in the list of children,
+ and returns the oldChild node.
+ */
+ Reference< XNode > SAL_CALL CNode::replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ // XXX check node types
+
+ if (oldChild->getParentNode() != Reference< XNode >(this)) {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+/*
+ Reference< XNode > aNode = removeChild(oldChild);
+ appendChild(newChild);
+*/
+ xmlNodePtr pOld = CNode::getNodePtr(oldChild);
+ xmlNodePtr pNew = CNode::getNodePtr(newChild);
+
+ if( pOld->type == XML_ATTRIBUTE_NODE )
+ {
+ // can only replace attribute with attribute
+ if ( pOld->type != pNew->type )
+ {
+ DOMException e;
+ e.Code = DOMExceptionType_HIERARCHY_REQUEST_ERR;
+ throw e;
+ }
+
+ xmlAttrPtr pAttr = (xmlAttrPtr)pOld;
+ xmlRemoveProp( pAttr );
+ appendChild( newChild );
+ }
+ else
+ {
+
+ xmlNodePtr cur = m_aNodePtr->children;
+ //find old node in child list
+ while (cur != NULL)
+ {
+ if(cur == pOld)
+ {
+ // exchange nodes
+ pNew->prev = pOld->prev;
+ if (pNew->prev != NULL)
+ pNew->prev->next = pNew;
+ pNew->next = pOld->next;
+ if (pNew->next != NULL)
+ pNew->next->prev = pNew;
+ pNew->parent = pOld->parent;
+ if(pNew->parent->children == pOld)
+ pNew->parent->children = pNew;
+ if(pNew->parent->last == pOld)
+ pNew->parent->last = pNew;
+ pOld->next = NULL;
+ pOld->prev = NULL;
+ pOld->parent = NULL;
+ }
+ cur = cur->next;
+ }
+ }
+
+ dispatchSubtreeModified();
+
+ return oldChild;
+ }
+
+ void CNode::dispatchSubtreeModified()
+ {
+ // dispatch DOMSubtreeModified
+ // target is _this_ node
+ Reference< XDocumentEvent > docevent(getOwnerDocument(), UNO_QUERY);
+ Reference< XMutationEvent > event(docevent->createEvent(
+ OUString::createFromAscii("DOMSubtreeModified")), UNO_QUERY);
+ event->initMutationEvent(OUString::createFromAscii("DOMSubtreeModified"), sal_True,
+ sal_False, Reference< XNode >(),
+ OUString(), OUString(), OUString(), (AttrChangeType)0 );
+ dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
+ }
+
+ /**
+ The value of this node, depending on its type; see the table above.
+ */
+ void SAL_CALL CNode::setNodeValue(const OUString& /*nodeValue*/)
+ throw (RuntimeException, DOMException)
+ {
+ // use specific node implememntation
+ // if we end up down here, something went wrong
+ DOMException e;
+ e.Code = DOMExceptionType_NO_MODIFICATION_ALLOWED_ERR;
+ throw e;
+ }
+
+ /**
+ The namespace prefix of this node, or null if it is unspecified.
+ */
+ void SAL_CALL CNode::setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ OString o1 = OUStringToOString(prefix, RTL_TEXTENCODING_UTF8);
+ xmlChar *pBuf = (xmlChar*)o1.getStr();
+ // XXX copy buf?
+ // XXX free old string? (leak?)
+ if (m_aNodePtr != NULL && m_aNodePtr->ns != NULL)
+ {
+ m_aNodePtr->ns->prefix = pBuf;
+ }
+
+ }
+
+ // --- XEventTarget
+ void SAL_CALL CNode::addEventListener(const OUString& eventType,
+ const Reference< com::sun::star::xml::dom::events::XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException)
+ {
+ events::CEventDispatcher::addListener(m_aNodePtr, eventType, listener, useCapture);
+ }
+
+ void SAL_CALL CNode::removeEventListener(const OUString& eventType,
+ const Reference< com::sun::star::xml::dom::events::XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException)
+ {
+ events::CEventDispatcher::removeListener(m_aNodePtr, eventType, listener, useCapture);
+ }
+
+ sal_Bool SAL_CALL CNode::dispatchEvent(const Reference< XEvent >& evt)
+ throw(RuntimeException, EventException)
+ {
+ events::CEventDispatcher::dispatchEvent(m_aNodePtr, evt);
+ return sal_True;
+ }
+
+ ::sal_Int64 SAL_CALL CNode::getSomething(const Sequence< ::sal_Int8 >& /*aIdentifier*/)
+ throw (RuntimeException)
+ {
+ return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(m_aNodePtr));
+ }
+}
+
diff --git a/unoxml/source/dom/node.hxx b/unoxml/source/dom/node.hxx
new file mode 100644
index 000000000000..a4397e7053fd
--- /dev/null
+++ b/unoxml/source/dom/node.hxx
@@ -0,0 +1,354 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _NODE_HXX
+#define _NODE_HXX
+
+#include <rtl/ref.hxx>
+#include <rtl/string.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <sax/fastattribs.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNodeList.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+#include <com/sun/star/xml/dom/NodeType.hpp>
+#include <com/sun/star/uno/Sequence.h>
+#include <com/sun/star/xml/dom/events/XEventTarget.hpp>
+#include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
+#include <com/sun/star/xml/dom/events/XEvent.hpp>
+#include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
+#include <com/sun/star/xml/dom/events/XUIEvent.hpp>
+#include <com/sun/star/xml/dom/events/XMouseEvent.hpp>
+#include <com/sun/star/xml/dom/DOMException.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
+#include <libxml/tree.h>
+
+#include <map>
+#include <hash_map>
+
+using ::rtl::OUString;
+using ::rtl::OString;
+using namespace sax_fastparser;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::sax;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::dom::events;
+
+using com::sun::star::lang::XUnoTunnel;
+
+namespace DOM
+{
+ struct Context
+ {
+ Context( const Reference< XFastDocumentHandler >& i_xHandler,
+ const Reference< XFastTokenHandler >& i_xTokenHandler ) :
+ maNamespaces( 1, std::vector<Namespace>() ),
+ maNamespaceMap(101),
+ mxAttribList(new FastAttributeList(i_xTokenHandler)),
+ mxCurrentHandler(i_xHandler, UNO_QUERY_THROW),
+ mxDocHandler(i_xHandler),
+ mxTokenHandler(i_xTokenHandler)
+ {}
+
+ struct Namespace
+ {
+ OString maPrefix;
+ sal_Int32 mnToken;
+ OUString maNamespaceURL;
+
+ const OString& getPrefix() const { return maPrefix; }
+ };
+
+ typedef std::vector< std::vector<Namespace> > NamespaceVectorType;
+ typedef std::hash_map< OUString,
+ sal_Int32,
+ rtl::OUStringHash > NamespaceMapType;
+
+ /// outer vector: xml context; inner vector: current NS
+ NamespaceVectorType maNamespaces;
+ NamespaceMapType maNamespaceMap;
+ ::rtl::Reference<FastAttributeList> mxAttribList;
+ Reference<XFastContextHandler> mxCurrentHandler;
+ Reference<XFastDocumentHandler> mxDocHandler;
+ Reference<XFastTokenHandler> mxTokenHandler;
+ };
+
+ void pushContext(Context& io_rContext);
+ void popContext(Context& io_rContext);
+
+ sal_Int32 getTokenWithPrefix( const Context& rContext, const sal_Char* xPrefix, const sal_Char* xName );
+ sal_Int32 getToken( const Context& rContext, const sal_Char* xName );
+
+ /// add namespaces on this node to context
+ void addNamespaces(Context& io_rContext, xmlNodePtr pNode);
+
+ class CNode;
+ typedef std::map< const xmlNodePtr, CNode* > nodemap_t;
+
+
+ class CNode : public cppu::WeakImplHelper3< XNode, XUnoTunnel, XEventTarget >
+ {
+ friend class CDocument;
+ friend class CElement;
+ friend class CAttributesMap;
+ friend class CChildList;
+ friend class CElementList;
+ friend class CEntitiesMap;
+ friend class CNotationsMap;
+ private:
+ static nodemap_t theNodeMap;
+
+ protected:
+ NodeType m_aNodeType;
+ xmlNodePtr m_aNodePtr;
+
+ Reference< XDocument > m_rDocument;
+
+ // for initialization by classes derived through ImplInheritanceHelper
+ CNode();
+ void init_node(const xmlNodePtr aNode);
+
+ void dispatchSubtreeModified();
+
+ public:
+
+ virtual ~CNode();
+
+ // get a representaion for a libxml node
+ static CNode* get(const xmlNodePtr aNode, sal_Bool bCreate = sal_True);
+ // remove a wrapper instance
+ static void remove(const xmlNodePtr aNode);
+
+ // get the libxml node implementation
+ static xmlNodePtr getNodePtr(const Reference< XNode >& aNode);
+
+ //static Sequence< sal_Int8 >
+
+ // recursively create SAX events
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ // recursively create SAX events
+ virtual void SAL_CALL fastSaxify( Context& io_rContext );
+
+ // ---- DOM interfaces
+
+ /**
+ Adds the node newChild to the end of the list of children of this node.
+ */
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Returns a duplicate of this node, i.e., serves as a generic copy
+ constructor for nodes.
+ */
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException);
+
+ /**
+ A NamedNodeMap containing the attributes of this node (if it is an Element)
+ or null otherwise.
+ */
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException);
+
+ /**
+ A NodeList that contains all children of this node.
+ */
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException);
+
+ /**
+ The first child of this node.
+ */
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException);
+
+ /**
+ The last child of this node.
+ */
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException);
+
+ /**
+ Returns the local part of the qualified name of this node.
+ */
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException);
+
+ /**
+ The namespace URI of this node, or null if it is unspecified.
+ */
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException);
+
+ /**
+ The node immediately following this node.
+ */
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException);
+
+ /**
+ The name of this node, depending on its type; see the table above.
+ -- virtual implemented by actual node types
+ */
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+
+ /**
+ A code representing the type of the underlying object, as defined above.
+ */
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException);
+
+ /**
+ The value of this node, depending on its type; see the table above.
+ -- virtual implemented by actual node types
+ */
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+
+ /**
+ The Document object associated with this node.
+ */
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException);
+
+ /**
+ The parent of this node.
+ */
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException);
+
+ /**
+ The namespace prefix of this node, or null if it is unspecified.
+ */
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException);
+
+ /**
+ The node immediately preceding this node.
+ */
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException);
+
+ /**
+ Returns whether this node (if it is an element) has any attributes.
+ */
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException);
+
+ /**
+ Returns whether this node has any children.
+ */
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException);
+
+ /**
+ Inserts the node newChild before the existing child node refChild.
+ */
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Tests whether the DOM implementation implements a specific feature and
+ that feature is supported by this node.
+ */
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException);
+
+ /**
+ Puts all Text nodes in the full depth of the sub-tree underneath this
+ Node, including attribute nodes, into a "normal" form where only structure
+ (e.g., elements, comments, processing instructions, CDATA sections, and
+ entity references) separates Text nodes, i.e., there are neither adjacent
+ Text nodes nor empty Text nodes.
+ */
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException);
+
+ /**
+ Removes the child node indicated by oldChild from the list of children,
+ and returns it.
+ */
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException);
+
+ /**
+ Replaces the child node oldChild with newChild in the list of children,
+ and returns the oldChild node.
+ */
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException);
+
+ /**
+ The value of this node, depending on its type; see the table above.
+ */
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException);
+
+ /**
+ The namespace prefix of this node, or null if it is unspecified.
+ */
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException);
+
+
+ // --- XEventTarget
+ virtual void SAL_CALL addEventListener(const OUString& eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException);
+
+ virtual void SAL_CALL removeEventListener(const OUString& eventType,
+ const Reference< XEventListener >& listener,
+ sal_Bool useCapture)
+ throw (RuntimeException);
+
+ virtual sal_Bool SAL_CALL dispatchEvent(const Reference< XEvent >& evt)
+ throw(RuntimeException, EventException);
+
+ // --- XUnoTunnel
+ virtual ::sal_Int64 SAL_CALL getSomething(const Sequence< ::sal_Int8 >& aIdentifier)
+ throw (RuntimeException);
+ };
+
+ /// eliminate redundant namespace declarations
+ void _nscleanup(const xmlNodePtr aNode, const xmlNodePtr aParent);
+}
+
+#endif
diff --git a/unoxml/source/dom/notation.cxx b/unoxml/source/dom/notation.cxx
new file mode 100644
index 000000000000..9781b6877eef
--- /dev/null
+++ b/unoxml/source/dom/notation.cxx
@@ -0,0 +1,70 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "notation.hxx"
+#include <string.h>
+
+namespace DOM
+{
+ CNotation::CNotation(const xmlNotationPtr aNotationPtr)
+ {
+ m_aNodeType = NodeType_NOTATION_NODE;
+ m_aNotationPtr = aNotationPtr;
+ init_node((xmlNodePtr)aNotationPtr);
+ }
+
+ OUString SAL_CALL CNotation::getPublicId() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+ /**
+ The system identifier of this notation.
+ */
+ OUString SAL_CALL CNotation::getSystemId() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+
+ OUString SAL_CALL CNotation::getNodeName()throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ const xmlChar* xName = m_aNodePtr->name;
+ aName = OUString((sal_Char*)xName, strlen((char*)xName), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+ OUString SAL_CALL CNotation::getNodeValue() throw (RuntimeException)
+ {
+ return OUString();
+ }
+}
diff --git a/unoxml/source/dom/notation.hxx b/unoxml/source/dom/notation.hxx
new file mode 100644
index 000000000000..a8fdf7994fc4
--- /dev/null
+++ b/unoxml/source/dom/notation.hxx
@@ -0,0 +1,191 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _NOTATION_HXX
+#define _NOTATION_HXX
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNotation.hpp>
+#include "node.hxx"
+#include <libxml/tree.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CNotation : public cppu::ImplInheritanceHelper1< CNode, XNotation >
+ {
+ friend class CNode;
+ private:
+ xmlNotationPtr m_aNotationPtr;
+
+ protected:
+ CNotation(const xmlNotationPtr);
+
+ /**
+ The public identifier of this notation.
+ */
+ virtual OUString SAL_CALL getPublicId() throw (RuntimeException);
+
+ /**
+ The system identifier of this notation.
+ */
+ virtual OUString SAL_CALL getSystemId() throw (RuntimeException);
+
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/notationsmap.cxx b/unoxml/source/dom/notationsmap.cxx
new file mode 100644
index 000000000000..477d40277374
--- /dev/null
+++ b/unoxml/source/dom/notationsmap.cxx
@@ -0,0 +1,101 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "notationsmap.hxx"
+
+namespace DOM
+{
+ CNotationsMap::CNotationsMap(const CDocumentType* aDocType)
+ : m_pDocType(aDocType)
+ {
+ }
+
+ /**
+ The number of nodes in this map.
+ */
+ sal_Int32 SAL_CALL CNotationsMap::getLength() throw (RuntimeException)
+ {
+ return 0;
+ }
+
+ /**
+ Retrieves a node specified by local name
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::getNamedItem(const OUString& /* name */) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::getNamedItemNS(const OUString& /*namespaceURI*/, const OUString& /*localName*/)
+throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Returns the indexth item in the map.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::item(sal_Int32 /*index*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Removes a node specified by name.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::removeNamedItem(const OUString& /*name*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::removeNamedItemNS(const OUString& /*namespaceURI*/, const OUString& /*localName*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::setNamedItem(const Reference< XNode >& /*arg*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ Reference< XNode > SAL_CALL CNotationsMap::setNamedItemNS(const Reference< XNode >& /*arg*/) throw (RuntimeException)
+ {
+ return Reference< XNode >();
+ }
+}
diff --git a/unoxml/source/dom/notationsmap.hxx b/unoxml/source/dom/notationsmap.hxx
new file mode 100644
index 000000000000..9c950c64de4c
--- /dev/null
+++ b/unoxml/source/dom/notationsmap.hxx
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _NOTATIONSMAP_HXX
+#define _NOTATIONSMAP_HXX
+
+#include <map>
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
+#include "document.hxx"
+#include "documenttype.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CNotationsMap : public cppu::WeakImplHelper1< XNamedNodeMap >
+ {
+ private:
+ const CDocumentType* m_pDocType;
+
+ public:
+ CNotationsMap(const CDocumentType* aDocType);
+
+ /**
+ The number of nodes in this map.
+ */
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ Retrieves a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL getNamedItemNS(const OUString& namespaceURI,const OUString& localName) throw (RuntimeException);
+
+ /**
+ Returns the indexth item in the map.
+ */
+ virtual Reference< XNode > SAL_CALL item(sal_Int32 index) throw (RuntimeException);
+
+ /**
+ Removes a node specified by name.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItem(const OUString& name) throw (RuntimeException);
+
+ /**
+ // Removes a node specified by local name and namespace URI.
+ */
+ virtual Reference< XNode > SAL_CALL removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException);
+
+ /**
+ // Adds a node using its nodeName attribute.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItem(const Reference< XNode >& arg) throw (RuntimeException);
+
+ /**
+ Adds a node using its namespaceURI and localName.
+ */
+ virtual Reference< XNode > SAL_CALL setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException);
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/processinginstruction.cxx b/unoxml/source/dom/processinginstruction.cxx
new file mode 100644
index 000000000000..37e52086cbd8
--- /dev/null
+++ b/unoxml/source/dom/processinginstruction.cxx
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "processinginstruction.hxx"
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+#include <string.h>
+
+namespace DOM
+{
+ CProcessingInstruction::CProcessingInstruction(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_PROCESSING_INSTRUCTION_NODE;
+ init_node(aNodePtr);
+ }
+
+ void SAL_CALL CProcessingInstruction::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY);
+ if (xExtended.is()) {
+ xExtended->processingInstruction(getTarget(), getData());
+ }
+ }
+
+ /**
+ The content of this processing instruction.
+ */
+ OUString SAL_CALL CProcessingInstruction::getData() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+ /**
+ The target of this processing instruction.
+ */
+ OUString SAL_CALL CProcessingInstruction::getTarget() throw (RuntimeException)
+ {
+ // XXX
+ return OUString();
+ }
+
+
+ /**
+ The content of this processing instruction.
+ */
+ void SAL_CALL CProcessingInstruction::setData(const OUString& /*data*/) throw (RuntimeException, DOMException)
+ {
+ // XXX
+ }
+
+
+ OUString SAL_CALL CProcessingInstruction::getNodeName()throw (RuntimeException)
+ {
+ OUString aName;
+ if (m_aNodePtr != NULL)
+ {
+ const xmlChar* xName = m_aNodePtr->name;
+ aName = OUString((sal_Char*)xName, strlen((char*)xName), RTL_TEXTENCODING_UTF8);
+ }
+ return aName;
+ }
+
+ OUString SAL_CALL CProcessingInstruction::getNodeValue() throw (RuntimeException)
+ {
+ return getData();
+ }
+}
diff --git a/unoxml/source/dom/processinginstruction.hxx b/unoxml/source/dom/processinginstruction.hxx
new file mode 100644
index 000000000000..b794d31e159d
--- /dev/null
+++ b/unoxml/source/dom/processinginstruction.hxx
@@ -0,0 +1,198 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _PROCESSINGINSTRUCTION_HXX
+#define _PROCESSINGINSTRUCTION_HXX
+
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XProcessingInstruction.hpp>
+#include "node.hxx"
+#include <libxml/tree.h>
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CProcessingInstruction : public cppu::ImplInheritanceHelper1< CNode, XProcessingInstruction >
+ {
+ friend class CNode;
+
+ protected:
+ CProcessingInstruction(const xmlNodePtr aNodePtr);
+
+ public:
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ /**
+ The content of this processing instruction.
+ */
+ virtual OUString SAL_CALL getData() throw (RuntimeException);
+
+ /**
+ The target of this processing instruction.
+ */
+ virtual OUString SAL_CALL getTarget() throw (RuntimeException);
+
+ /**
+ The content of this processing instruction.
+ */
+ virtual void SAL_CALL setData(const OUString& data) throw (RuntimeException, DOMException);
+
+ // ---- resolve uno inheritance problems...
+ // overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+ virtual OUString SAL_CALL getNodeValue()
+ throw (RuntimeException);
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CNode::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CNode::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CNode::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CNode::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CNode::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CNode::getNodeType();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CNode::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CNode::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CNode::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CNode::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CNode::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CNode::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CNode::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CNode::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CNode::setPrefix(prefix);
+ }
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/saxbuilder.cxx b/unoxml/source/dom/saxbuilder.cxx
new file mode 100644
index 000000000000..e968eee3e2f6
--- /dev/null
+++ b/unoxml/source/dom/saxbuilder.cxx
@@ -0,0 +1,353 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#if defined(_MSC_VER) && (_MSC_VER > 1310)
+#pragma warning(disable : 4701)
+#endif
+
+#include "node.hxx"
+#include "saxbuilder.hxx"
+#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
+#include <libxml/tree.h>
+#include <com/sun/star/uno/Sequence.h>
+
+namespace DOM
+{
+ Reference< XInterface > CSAXDocumentBuilder::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
+ {
+ return static_cast< XSAXDocumentBuilder* >(new CSAXDocumentBuilder(rSMgr));
+ }
+
+ const char* CSAXDocumentBuilder::aImplementationName = "com.sun.star.comp.xml.dom.SAXDocumentBuilder";
+ const char* CSAXDocumentBuilder::aSupportedServiceNames[] = {
+ "com.sun.star.xml.dom.SAXDocumentBuilder",
+ NULL
+ };
+
+ CSAXDocumentBuilder::CSAXDocumentBuilder(const Reference< XMultiServiceFactory >& mgr)
+ : m_aServiceManager(mgr)
+ , m_aState( SAXDocumentBuilderState_READY)
+ {}
+
+ OUString CSAXDocumentBuilder::_getImplementationName()
+ {
+ return OUString::createFromAscii(aImplementationName);
+ }
+ Sequence<OUString> CSAXDocumentBuilder::_getSupportedServiceNames()
+ {
+ Sequence<OUString> aSequence;
+ for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
+ aSequence.realloc(i+1);
+ aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
+ }
+ return aSequence;
+ }
+
+ Sequence< OUString > SAL_CALL CSAXDocumentBuilder::getSupportedServiceNames()
+ throw (RuntimeException)
+ {
+ return CSAXDocumentBuilder::_getSupportedServiceNames();
+ }
+
+ OUString SAL_CALL CSAXDocumentBuilder::getImplementationName()
+ throw (RuntimeException)
+ {
+ return CSAXDocumentBuilder::_getImplementationName();
+ }
+
+ sal_Bool SAL_CALL CSAXDocumentBuilder::supportsService(const OUString& aServiceName)
+ throw (RuntimeException)
+ {
+ Sequence< OUString > supported = CSAXDocumentBuilder::_getSupportedServiceNames();
+ for (sal_Int32 i=0; i<supported.getLength(); i++)
+ {
+ if (supported[i] == aServiceName) return sal_True;
+ }
+ return sal_False;
+ }
+
+
+ SAXDocumentBuilderState SAL_CALL CSAXDocumentBuilder::getState()
+ throw (RuntimeException)
+ {
+ return m_aState;
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::reset()
+ throw (RuntimeException)
+ {
+ m_aDocument = Reference< XDocument >();
+ m_aFragment = Reference< XDocumentFragment >();
+ while (!m_aNodeStack.empty()) m_aNodeStack.pop();
+ while (!m_aNSStack.empty()) m_aNSStack.pop();
+ m_aState = SAXDocumentBuilderState_READY;
+ }
+
+ Reference< XDocument > SAL_CALL CSAXDocumentBuilder::getDocument()
+ throw (RuntimeException)
+ {
+ if (m_aState != SAXDocumentBuilderState_DOCUMENT_FINISHED)
+ throw RuntimeException();
+
+ return m_aDocument;
+ }
+
+ Reference< XDocumentFragment > SAL_CALL CSAXDocumentBuilder::getDocumentFragment()
+ throw (RuntimeException)
+ {
+ if (m_aState != SAXDocumentBuilderState_FRAGMENT_FINISHED)
+ throw RuntimeException();
+ return m_aFragment;
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::startDocumentFragment(const Reference< XDocument >& ownerDoc)
+ throw (RuntimeException)
+ {
+ // start a new document fragment and push it onto the stack
+ // we have to be in a clean state to do this
+ if (!m_aState == SAXDocumentBuilderState_READY)
+ throw RuntimeException();
+
+ m_aDocument = ownerDoc;
+ Reference< XDocumentFragment > aFragment = m_aDocument->createDocumentFragment();
+ m_aNodeStack.push(Reference< XNode >(aFragment, UNO_QUERY));
+ m_aFragment = aFragment;
+ m_aState = SAXDocumentBuilderState_BUILDING_FRAGMENT;
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::endDocumentFragment()
+ throw (RuntimeException)
+ {
+ // there should only be the document left on the node stack
+ if (m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ throw RuntimeException();
+
+ Reference< XNode > aNode = m_aNodeStack.top();
+ if ( aNode->getNodeType() != NodeType_DOCUMENT_FRAGMENT_NODE)
+ throw RuntimeException();
+ m_aNodeStack.pop();
+ m_aState = SAXDocumentBuilderState_FRAGMENT_FINISHED;
+ }
+
+ // document handler
+
+ void SAL_CALL CSAXDocumentBuilder::startDocument() throw (RuntimeException, SAXException)
+ {
+
+ // start a new document and push it onto the stack
+ // we have to be in a clean state to do this
+ if (!m_aState == SAXDocumentBuilderState_READY)
+ throw SAXException();
+
+ Reference< XDocumentBuilder > aBuilder(m_aServiceManager->createInstance(
+ OUString::createFromAscii("com.sun.star.xml.dom.DocumentBuilder")), UNO_QUERY_THROW);
+ Reference< XDocument > aDocument = aBuilder->newDocument();
+ m_aNodeStack.push(Reference< XNode >(aDocument, UNO_QUERY));
+ m_aDocument = aDocument;
+ m_aState = SAXDocumentBuilderState_BUILDING_DOCUMENT;
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::endDocument() throw (RuntimeException, SAXException)
+ {
+ // there should only be the document left on the node stack
+ if (!m_aState == SAXDocumentBuilderState_BUILDING_DOCUMENT)
+ throw SAXException();
+
+ Reference< XNode > aNode = m_aNodeStack.top();
+ if ( aNode->getNodeType() != NodeType_DOCUMENT_NODE)
+ throw SAXException();
+ m_aNodeStack.pop();
+ m_aState = SAXDocumentBuilderState_DOCUMENT_FINISHED;
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::startElement(const OUString& aName, const Reference< XAttributeList>& attribs)
+ throw (RuntimeException, SAXException)
+ {
+ if ( m_aState != SAXDocumentBuilderState_BUILDING_DOCUMENT &&
+ m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ {
+ throw SAXException();
+ }
+
+ // start with mappings in effect for last level
+ NSMap aNSMap;
+ if (!m_aNSStack.empty())
+ aNSMap = NSMap(m_aNSStack.top());
+
+ // handle xmlns: attributes and add to mappings
+ OUString attr_qname;
+ OUString attr_value;
+ OUString newprefix;
+ AttrMap aAttrMap;
+ sal_Int32 idx=-1;
+ sal_Int16 nAttributes = attribs->getLength();
+ for (sal_Int16 i=0; i<nAttributes; i++)
+ {
+ attr_qname = attribs->getNameByIndex(i);
+ attr_value = attribs->getValueByIndex(i);
+ // new prefix mapping
+ if (attr_qname.indexOf(OUString::createFromAscii("xmlns:")) == 0)
+ {
+ newprefix = attr_qname.copy(attr_qname.indexOf(':')+1);
+ aNSMap.insert(NSMap::value_type(newprefix, attr_value));
+ }
+ else if (attr_qname == OUString::createFromAscii("xmlns"))
+ {
+ // new default prefix
+ aNSMap.insert(NSMap::value_type(OUString(), attr_value));
+ }
+ else
+ {
+ aAttrMap.insert(AttrMap::value_type(attr_qname, attr_value));
+ }
+ }
+
+ // does the element have a prefix?
+ OUString aPrefix;
+ OUString aURI;
+ Reference< XElement > aElement;
+ idx = aName.indexOf(':');
+ if (idx != -1)
+ {
+ aPrefix = aName.copy(0, idx);
+ }
+ else
+ aPrefix = OUString();
+
+ NSMap::const_iterator result = aNSMap.find(aPrefix);
+ if ( result != aNSMap.end())
+ {
+ // found a URI for prefix
+ aElement = m_aDocument->createElementNS( result->second, aName); // qualified name
+ }
+ else
+ {
+ // no URI for prefix
+ aElement = m_aDocument->createElement(aName);
+ }
+ aElement = Reference< XElement > (
+ m_aNodeStack.top()->appendChild(Reference< XNode >(aElement, UNO_QUERY)),
+ UNO_QUERY);
+ m_aNodeStack.push(Reference< XNode >(aElement, UNO_QUERY));
+
+ // set non xmlns attributes
+ aPrefix = OUString();
+ aURI = OUString();
+ AttrMap::const_iterator a = aAttrMap.begin();
+ while (a != aAttrMap.end())
+ {
+ attr_qname = a->first;
+ attr_value = a->second;
+ idx = attr_qname.indexOf(':');
+ if(idx != -1)
+ {
+ aPrefix = attr_qname.copy(0, idx);
+ }
+ else
+ aPrefix = OUString();
+
+ result = aNSMap.find(aPrefix);
+ if (result != aNSMap.end())
+ {
+ // set attribute with namespace
+ aElement->setAttributeNS(result->second, attr_qname, attr_value);
+ } else {
+ // set attribute without namespace
+ aElement->setAttribute(attr_qname, attr_value);
+ }
+ a++;
+ }
+ m_aNSStack.push(aNSMap);
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::endElement(const OUString& aName)
+ throw (RuntimeException, SAXException)
+ {
+ // pop the current element from the stack
+ if ( m_aState != SAXDocumentBuilderState_BUILDING_DOCUMENT &&
+ m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ throw SAXException();
+
+ Reference< XNode > aNode(m_aNodeStack.top());
+ if (aNode->getNodeType() != NodeType_ELEMENT_NODE)
+ throw SAXException();
+
+ Reference< XElement > aElement(aNode, UNO_QUERY);
+ OUString aRefName;
+ OUString aPrefix = aElement->getPrefix();
+ if (aPrefix.getLength() > 0)
+ aRefName = aPrefix + OUString::createFromAscii(":") + aElement->getTagName();
+ else
+ aRefName = aElement->getTagName();
+ if (aRefName != aName) // consistency check
+ throw SAXException();
+
+ // pop it
+ m_aNodeStack.pop();
+ m_aNSStack.pop();
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::characters(const OUString& aChars)
+ throw (RuntimeException, SAXException)
+ {
+ // append text node to the current top element
+ if (m_aState != SAXDocumentBuilderState_BUILDING_DOCUMENT &&
+ m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ throw SAXException();
+
+ Reference< XText > aText = m_aDocument->createTextNode(aChars);
+ m_aNodeStack.top()->appendChild(Reference< XNode >(aText, UNO_QUERY));
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::ignorableWhitespace(const OUString& )
+ throw (RuntimeException, SAXException)
+ {
+ // ignore ignorable whitespace
+ if ( m_aState != SAXDocumentBuilderState_BUILDING_DOCUMENT &&
+ m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ throw SAXException();
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::processingInstruction(const OUString& aTarget, const OUString& aData)
+ throw (RuntimeException, SAXException)
+ {
+ // append PI node to the current top
+ if ( m_aState != SAXDocumentBuilderState_BUILDING_DOCUMENT &&
+ m_aState != SAXDocumentBuilderState_BUILDING_FRAGMENT)
+ throw SAXException();
+
+ Reference< XProcessingInstruction > aInstruction = m_aDocument->createProcessingInstruction(
+ aTarget, aData);
+ m_aNodeStack.top()->appendChild(Reference< XNode >(aInstruction, UNO_QUERY));
+ }
+
+ void SAL_CALL CSAXDocumentBuilder::setDocumentLocator(const Reference< XLocator >& aLocator)
+ throw (RuntimeException, SAXException)
+ {
+ // set the document locator...
+ m_aLocator = aLocator;
+ }
+}
diff --git a/unoxml/source/dom/saxbuilder.hxx b/unoxml/source/dom/saxbuilder.hxx
new file mode 100644
index 000000000000..c243877aae2b
--- /dev/null
+++ b/unoxml/source/dom/saxbuilder.hxx
@@ -0,0 +1,150 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SAXBUILDER_HXX
+#define _SAXBUILDER_HXX
+
+#include <stack>
+#include <map>
+
+#include <sal/types.h>
+#include <cppuhelper/implbase3.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Sequence.h>
+
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XSAXDocumentBuilder.hpp>
+#include <com/sun/star/xml/dom/SAXDocumentBuilderState.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
+#include <com/sun/star/xml/dom/XDocumentFragment.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XLocator.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include "libxml/tree.h"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::xml::dom;
+using namespace com::sun::star::xml::sax;
+
+using com::sun::star::lang::XServiceInfo;
+using com::sun::star::lang::XSingleServiceFactory;
+using com::sun::star::lang::XMultiServiceFactory;
+
+namespace DOM
+{
+
+ typedef std::stack< Reference< XNode > > NodeStack;
+ typedef std::map< OUString, OUString > NSMap;
+ typedef std::map< OUString, OUString > AttrMap;
+ typedef std::stack< NSMap > NSStack;
+
+ class CSAXDocumentBuilder
+ : public ::cppu::WeakImplHelper3< XDocumentHandler, XSAXDocumentBuilder, XServiceInfo >
+ {
+
+ private:
+ const Reference< XMultiServiceFactory > m_aServiceManager;
+
+ SAXDocumentBuilderState m_aState;
+ NodeStack m_aNodeStack;
+ NSStack m_aNSStack;
+
+ OUString resolvePrefix(const OUString& aPrefix);
+
+ Reference< XDocument > m_aDocument;
+ Reference< XDocumentFragment > m_aFragment;
+ Reference< XLocator > m_aLocator;
+
+
+ public:
+
+ // call for factory
+ static Reference< XInterface > getInstance(const Reference < XMultiServiceFactory >& xFactory);
+
+ // static helpers for service info and component management
+ static const char* aImplementationName;
+ static const char* aSupportedServiceNames[];
+ static OUString _getImplementationName();
+ static Sequence< OUString > _getSupportedServiceNames();
+ static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr);
+
+ CSAXDocumentBuilder(const Reference< XMultiServiceFactory >& mgr);
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName()
+ throw (RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
+ throw (RuntimeException);
+ virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ()
+ throw (RuntimeException);
+
+ // XDocumentHandler
+ virtual void SAL_CALL startDocument()
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL endDocument()
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL startElement( const OUString& aName,
+ const Reference< XAttributeList >& xAttribs )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL endElement( const OUString& aName )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL characters( const OUString& aChars )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL processingInstruction( const OUString& aTarget,
+ const OUString& aData )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+ virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator )
+ throw( RuntimeException, com::sun::star::xml::sax::SAXException );
+
+
+ // XSAXDocumentBuilder
+ virtual SAXDocumentBuilderState SAL_CALL getState()
+ throw (RuntimeException);
+ virtual void SAL_CALL reset()
+ throw (RuntimeException);
+ virtual Reference< XDocument > SAL_CALL getDocument()
+ throw (RuntimeException);
+ virtual Reference< XDocumentFragment > SAL_CALL getDocumentFragment()
+ throw (RuntimeException);
+ virtual void SAL_CALL startDocumentFragment(const Reference< XDocument >& ownerDoc)
+ throw (RuntimeException);
+ virtual void SAL_CALL endDocumentFragment()
+ throw (RuntimeException);
+
+
+ };
+}
+
+#endif
diff --git a/unoxml/source/dom/text.cxx b/unoxml/source/dom/text.cxx
new file mode 100644
index 000000000000..d60fcf234ebf
--- /dev/null
+++ b/unoxml/source/dom/text.cxx
@@ -0,0 +1,72 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "text.hxx"
+namespace DOM
+{
+ CText::CText(const xmlNodePtr aNodePtr)
+ {
+ m_aNodeType = NodeType_TEXT_NODE;
+ init_characterdata(aNodePtr);
+ }
+
+ void SAL_CALL CText::saxify(
+ const Reference< XDocumentHandler >& i_xHandler) {
+ if (!i_xHandler.is()) throw RuntimeException();
+ i_xHandler->characters(getData());
+ }
+
+ void CText::init_text(const xmlNodePtr aNodePtr)
+ {
+ init_characterdata(aNodePtr);
+ }
+
+ Reference< XText > SAL_CALL CText::splitText(sal_Int32 /*offset*/)
+ throw (RuntimeException)
+ {
+ return Reference< XText >(this);
+ }
+
+ OUString SAL_CALL CText::getNodeName()throw (RuntimeException)
+ {
+ return OUString::createFromAscii("#text");
+ }
+
+ void SAL_CALL CText::fastSaxify( Context& io_rContext )
+ {
+ if( io_rContext.mxCurrentHandler.is() )
+ {
+ try
+ {
+ io_rContext.mxCurrentHandler->characters( getData() );
+ }
+ catch( Exception& )
+ {}
+ }
+ }
+
+}
diff --git a/unoxml/source/dom/text.hxx b/unoxml/source/dom/text.hxx
new file mode 100644
index 000000000000..a99f4ff2aa5d
--- /dev/null
+++ b/unoxml/source/dom/text.hxx
@@ -0,0 +1,241 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _TEXT_HXX
+#define _TEXT_HXX
+
+#include <sal/types.h>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Reference.h>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
+#include <com/sun/star/xml/dom/XText.hpp>
+#include <com/sun/star/xml/dom/XCharacterData.hpp>
+#include <libxml/tree.h>
+#include "characterdata.hxx"
+
+using ::rtl::OUString;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::xml::dom;
+
+namespace DOM
+{
+ class CText : public cppu::ImplInheritanceHelper1< CCharacterData, XText >
+ {
+ friend class CNode;
+
+ protected:
+ CText(){}
+ CText(const xmlNodePtr aNodePtr);
+ void init_text(const xmlNodePtr aNodePtr);
+
+ public:
+
+ virtual void SAL_CALL saxify(
+ const Reference< XDocumentHandler >& i_xHandler);
+
+ virtual void SAL_CALL fastSaxify( Context& io_rContext );
+
+ // Breaks this node into two nodes at the specified offset, keeping
+ // both in the tree as siblings.
+ virtual Reference< XText > SAL_CALL splitText(sal_Int32 offset)
+ throw (RuntimeException);
+
+
+ // --- delegations for XCharacterData
+ virtual void SAL_CALL appendData(const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::appendData(arg);
+ }
+ virtual void SAL_CALL deleteData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::deleteData(offset, count);
+ }
+ virtual OUString SAL_CALL getData() throw (RuntimeException)
+ {
+ return CCharacterData::getData();
+ }
+ virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException)
+ {
+ return CCharacterData::getLength();
+ }
+ virtual void SAL_CALL insertData(sal_Int32 offset, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::insertData(offset, arg);
+ }
+ virtual void SAL_CALL replaceData(sal_Int32 offset, sal_Int32 count, const OUString& arg)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::replaceData(offset, count, arg);
+ }
+ virtual void SAL_CALL setData(const OUString& data)
+ throw (RuntimeException, DOMException)
+ {
+ CCharacterData::setData(data);
+ }
+ virtual OUString SAL_CALL subStringData(sal_Int32 offset, sal_Int32 count)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::subStringData(offset, count);
+ }
+
+
+ // --- overrides for XNode base
+ virtual OUString SAL_CALL getNodeName()
+ throw (RuntimeException);
+
+ // --- resolve uno inheritance problems...
+ // --- delegation for XNde base.
+ virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::appendChild(newChild);
+ }
+ virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
+ throw (RuntimeException)
+ {
+ return CCharacterData::cloneNode(deep);
+ }
+ virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getAttributes();
+ }
+ virtual Reference< XNodeList > SAL_CALL getChildNodes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL getFirstChild()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getFirstChild();
+ }
+ virtual Reference< XNode > SAL_CALL getLastChild()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getLastChild();
+ }
+ virtual OUString SAL_CALL getLocalName()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getLocalName();
+ }
+ virtual OUString SAL_CALL getNamespaceURI()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNamespaceURI();
+ }
+ virtual Reference< XNode > SAL_CALL getNextSibling()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNextSibling();
+ }
+ virtual NodeType SAL_CALL getNodeType()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getNodeType();
+ }
+ virtual OUString SAL_CALL getNodeValue() throw (RuntimeException)
+ {
+ return CCharacterData::getNodeValue();
+ }
+ virtual Reference< XDocument > SAL_CALL getOwnerDocument()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getOwnerDocument();
+ }
+ virtual Reference< XNode > SAL_CALL getParentNode()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getParentNode();
+ }
+ virtual OUString SAL_CALL getPrefix()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getPrefix();
+ }
+ virtual Reference< XNode > SAL_CALL getPreviousSibling()
+ throw (RuntimeException)
+ {
+ return CCharacterData::getPreviousSibling();
+ }
+ virtual sal_Bool SAL_CALL hasAttributes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::hasAttributes();
+ }
+ virtual sal_Bool SAL_CALL hasChildNodes()
+ throw (RuntimeException)
+ {
+ return CCharacterData::hasChildNodes();
+ }
+ virtual Reference< XNode > SAL_CALL insertBefore(
+ const Reference< XNode >& newChild, const Reference< XNode >& refChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::insertBefore(newChild, refChild);
+ }
+ virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
+ throw (RuntimeException)
+ {
+ return CCharacterData::isSupported(feature, ver);
+ }
+ virtual void SAL_CALL normalize()
+ throw (RuntimeException)
+ {
+ CCharacterData::normalize();
+ }
+ virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::removeChild(oldChild);
+ }
+ virtual Reference< XNode > SAL_CALL replaceChild(
+ const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::replaceChild(newChild, oldChild);
+ }
+ virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::setNodeValue(nodeValue);
+ }
+ virtual void SAL_CALL setPrefix(const OUString& prefix)
+ throw (RuntimeException, DOMException)
+ {
+ return CCharacterData::setPrefix(prefix);
+ }
+
+ };
+}
+#endif