summaryrefslogtreecommitdiff
path: root/unoxml
diff options
context:
space:
mode:
Diffstat (limited to 'unoxml')
-rw-r--r--unoxml/source/dom/attr.hxx2
-rw-r--r--unoxml/source/dom/attributesmap.hxx2
-rw-r--r--unoxml/source/dom/cdatasection.cxx2
-rw-r--r--unoxml/source/dom/cdatasection.hxx2
-rw-r--r--unoxml/source/dom/characterdata.hxx2
-rw-r--r--unoxml/source/dom/childlist.hxx2
-rw-r--r--unoxml/source/dom/comment.cxx2
-rw-r--r--unoxml/source/dom/comment.hxx2
-rw-r--r--unoxml/source/dom/document.cxx57
-rw-r--r--unoxml/source/dom/document.hxx24
-rw-r--r--unoxml/source/dom/documentfragment.hxx2
-rw-r--r--unoxml/source/dom/documenttype.hxx2
-rw-r--r--unoxml/source/dom/domimplementation.hxx2
-rw-r--r--unoxml/source/dom/element.cxx100
-rw-r--r--unoxml/source/dom/element.hxx4
-rw-r--r--unoxml/source/dom/elementlist.hxx2
-rw-r--r--unoxml/source/dom/entitiesmap.hxx2
-rw-r--r--unoxml/source/dom/entity.hxx2
-rw-r--r--unoxml/source/dom/entityreference.hxx2
-rw-r--r--unoxml/source/dom/node.cxx104
-rw-r--r--unoxml/source/dom/node.hxx68
-rw-r--r--unoxml/source/dom/notation.hxx2
-rw-r--r--unoxml/source/dom/notationsmap.hxx2
-rw-r--r--unoxml/source/dom/processinginstruction.cxx1
-rw-r--r--unoxml/source/dom/processinginstruction.hxx2
-rw-r--r--unoxml/source/dom/saxbuilder.cxx1
-rw-r--r--unoxml/source/dom/saxbuilder.hxx2
-rw-r--r--unoxml/source/dom/text.cxx13
-rw-r--r--unoxml/source/dom/text.hxx4
-rw-r--r--unoxml/source/events/mouseevent.hxx2
-rw-r--r--unoxml/source/events/mutationevent.hxx2
-rw-r--r--unoxml/source/events/testlistener.hxx2
-rw-r--r--unoxml/source/events/uievent.hxx2
-rw-r--r--unoxml/source/service/makefile.mk1
-rw-r--r--unoxml/source/xpath/nodelist.hxx2
-rw-r--r--unoxml/source/xpath/xpathapi.hxx3
-rw-r--r--unoxml/source/xpath/xpathobject.hxx2
-rw-r--r--unoxml/test/domtest.cxx402
-rw-r--r--unoxml/test/export.map38
-rw-r--r--unoxml/test/makefile.mk106
40 files changed, 914 insertions, 62 deletions
diff --git a/unoxml/source/dom/attr.hxx b/unoxml/source/dom/attr.hxx
index b014a2634ef8..394a60357197 100644
--- a/unoxml/source/dom/attr.hxx
+++ b/unoxml/source/dom/attr.hxx
@@ -39,7 +39,7 @@
#include "node.hxx"
#include <libxml/tree.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/attributesmap.hxx b/unoxml/source/dom/attributesmap.hxx
index a99dcfa9bc54..95badb12985b 100644
--- a/unoxml/source/dom/attributesmap.hxx
+++ b/unoxml/source/dom/attributesmap.hxx
@@ -42,7 +42,7 @@
#include "element.hxx"
#include "attr.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/cdatasection.cxx b/unoxml/source/dom/cdatasection.cxx
index 0ed93ab562e6..3613f1b68704 100644
--- a/unoxml/source/dom/cdatasection.cxx
+++ b/unoxml/source/dom/cdatasection.cxx
@@ -30,6 +30,8 @@
#include "cdatasection.hxx"
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+
namespace DOM
{
CCDATASection::CCDATASection(const xmlNodePtr aNodePtr)
diff --git a/unoxml/source/dom/cdatasection.hxx b/unoxml/source/dom/cdatasection.hxx
index 48801ef47b53..67aedbdbeee2 100644
--- a/unoxml/source/dom/cdatasection.hxx
+++ b/unoxml/source/dom/cdatasection.hxx
@@ -37,7 +37,7 @@
#include "text.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/characterdata.hxx b/unoxml/source/dom/characterdata.hxx
index 7613d17379bf..b32a085ed8e4 100644
--- a/unoxml/source/dom/characterdata.hxx
+++ b/unoxml/source/dom/characterdata.hxx
@@ -42,7 +42,7 @@
#include <libxml/tree.h>
#include "node.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/childlist.hxx b/unoxml/source/dom/childlist.hxx
index ac91a6409797..b5ce420ed947 100644
--- a/unoxml/source/dom/childlist.hxx
+++ b/unoxml/source/dom/childlist.hxx
@@ -41,7 +41,7 @@
#include "node.hxx"
#include "libxml/tree.h"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/comment.cxx b/unoxml/source/dom/comment.cxx
index bd73991be623..1469bb08ab11 100644
--- a/unoxml/source/dom/comment.cxx
+++ b/unoxml/source/dom/comment.cxx
@@ -30,6 +30,8 @@
#include "comment.hxx"
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+
namespace DOM
{
CComment::CComment(const xmlNodePtr aNodePtr)
diff --git a/unoxml/source/dom/comment.hxx b/unoxml/source/dom/comment.hxx
index 6904c0fe796d..0b464b2517cf 100644
--- a/unoxml/source/dom/comment.hxx
+++ b/unoxml/source/dom/comment.hxx
@@ -36,7 +36,7 @@
#include <com/sun/star/xml/dom/XComment.hpp>
#include "characterdata.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/document.cxx b/unoxml/source/dom/document.cxx
index 9417667e1b39..9a1216376dcc 100644
--- a/unoxml/source/dom/document.cxx
+++ b/unoxml/source/dom/document.cxx
@@ -51,13 +51,11 @@
#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)
@@ -122,6 +120,17 @@ namespace DOM
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)
{
@@ -699,7 +708,47 @@ namespace DOM
// eliminate duplicate namespace declarations
_nscleanup(pRoot->children, pRoot);
}
- // serialize via SAX handler
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
index 88ad24896621..9cbf4dac3115 100644
--- a/unoxml/source/dom/document.hxx
+++ b/unoxml/source/dom/document.hxx
@@ -34,7 +34,7 @@
#include <list>
#include <set>
#include <sal/types.h>
-#include <cppuhelper/implbase5.hxx>
+#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>
@@ -45,7 +45,9 @@
#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>
@@ -68,9 +70,9 @@ using namespace com::sun::star::xml::dom::events;
namespace DOM
{
- class CDocument : public cppu::ImplInheritanceHelper5<
+ class CDocument : public cppu::ImplInheritanceHelper6<
CNode, XDocument, XDocumentEvent,
- XActiveDataControl, XActiveDataSource, XSAXSerializable>
+ XActiveDataControl, XActiveDataSource, XSAXSerializable, XFastSAXSerializable>
{
friend class CNode;
typedef std::list< Reference< XNode >* > nodereflist_t;
@@ -97,6 +99,8 @@ namespace DOM
virtual void SAL_CALL saxify(
const Reference< XDocumentHandler >& i_xHandler);
+ virtual void SAL_CALL fastSaxify( Context& rContext );
+
/**
Creates an Attr of the given name.
*/
@@ -347,12 +351,18 @@ namespace DOM
return CNode::setPrefix(prefix);
}
-
- // ::com::sun::star::xml::sax::XSAXSerializable
- virtual void SAL_CALL serialize(
+ // ::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);
+ 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);
};
}
diff --git a/unoxml/source/dom/documentfragment.hxx b/unoxml/source/dom/documentfragment.hxx
index c21f809e938c..96b8f2fac4fe 100644
--- a/unoxml/source/dom/documentfragment.hxx
+++ b/unoxml/source/dom/documentfragment.hxx
@@ -37,7 +37,7 @@
#include "node.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/documenttype.hxx b/unoxml/source/dom/documenttype.hxx
index 123510d62797..79914d3d50b1 100644
--- a/unoxml/source/dom/documenttype.hxx
+++ b/unoxml/source/dom/documenttype.hxx
@@ -42,7 +42,7 @@
#include <libxml/tree.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/domimplementation.hxx b/unoxml/source/dom/domimplementation.hxx
index b7899380784d..c335ab7c2ec8 100644
--- a/unoxml/source/dom/domimplementation.hxx
+++ b/unoxml/source/dom/domimplementation.hxx
@@ -41,7 +41,7 @@
#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
#include <com/sun/star/xml/dom/XDOMImplementation.hpp>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/element.cxx b/unoxml/source/dom/element.cxx
index 96de86d507ef..87ec048570d8 100644
--- a/unoxml/source/dom/element.cxx
+++ b/unoxml/source/dom/element.cxx
@@ -36,6 +36,7 @@
#include "../events/mutationevent.hxx"
#include "comphelper/attributelist.hxx"
+#include <com/sun/star/xml/sax/FastToken.hdl>
#include <string.h>
@@ -98,6 +99,105 @@ namespace DOM
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
diff --git a/unoxml/source/dom/element.hxx b/unoxml/source/dom/element.hxx
index 10568de87162..b56939f41ae0 100644
--- a/unoxml/source/dom/element.hxx
+++ b/unoxml/source/dom/element.hxx
@@ -39,7 +39,7 @@
#include <libxml/tree.h>
#include "node.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
@@ -60,6 +60,8 @@ namespace DOM
virtual void SAL_CALL saxify(
const Reference< XDocumentHandler >& i_xHandler);
+ virtual void SAL_CALL fastSaxify( Context& i_rContext );
+
/**
Retrieves an attribute value by name.
*/
diff --git a/unoxml/source/dom/elementlist.hxx b/unoxml/source/dom/elementlist.hxx
index 1d9d0cdeb86b..2c3976063d85 100644
--- a/unoxml/source/dom/elementlist.hxx
+++ b/unoxml/source/dom/elementlist.hxx
@@ -45,7 +45,7 @@
#include "document.hxx"
#include "libxml/tree.h"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
using namespace com::sun::star::xml::dom::events;
diff --git a/unoxml/source/dom/entitiesmap.hxx b/unoxml/source/dom/entitiesmap.hxx
index bafb603db63c..002721b926a6 100644
--- a/unoxml/source/dom/entitiesmap.hxx
+++ b/unoxml/source/dom/entitiesmap.hxx
@@ -41,7 +41,7 @@
#include "document.hxx"
#include "documenttype.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/entity.hxx b/unoxml/source/dom/entity.hxx
index e603d3956e1b..ffbdb770fa00 100644
--- a/unoxml/source/dom/entity.hxx
+++ b/unoxml/source/dom/entity.hxx
@@ -39,7 +39,7 @@
#include <libxml/tree.h>
#include <libxml/entities.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/entityreference.hxx b/unoxml/source/dom/entityreference.hxx
index 18a3cb3fc15d..834476fe88c9 100644
--- a/unoxml/source/dom/entityreference.hxx
+++ b/unoxml/source/dom/entityreference.hxx
@@ -36,7 +36,7 @@
#include "node.hxx"
#include <libxml/tree.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx
index b7ab5af1eb81..b9e3a6346310 100644
--- a/unoxml/source/dom/node.cxx
+++ b/unoxml/source/dom/node.cxx
@@ -45,11 +45,91 @@
#include "childlist.hxx"
#include "attr.hxx"
+#include <com/sun/star/xml/sax/FastToken.hpp>
+
#include "../events/eventdispatcher.hxx"
#include "../events/mutationevent.hxx"
+#include <boost/bind.hpp>
+#include <algorithm>
+
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)
@@ -167,14 +247,13 @@ namespace DOM
xmlNodePtr CNode::getNodePtr(const Reference< XNode >& aNode)
{
- xmlNodePtr aNodePtr = 0;
try {
- Reference< XUnoTunnel > aTunnel(aNode, UNO_QUERY_THROW);
- sal_Int64 rawPtr = aTunnel->getSomething(Sequence<sal_Int8>());
- aNodePtr = reinterpret_cast<xmlNodePtr>(sal::static_int_cast<sal_IntPtr>(rawPtr));
- } catch ( ... ) {
+ CNode* pNode=dynamic_cast<CNode*>(aNode.get());
+ if( pNode )
+ return pNode->m_aNodePtr;
}
- return aNodePtr;
+ catch(...) {}
+ return 0;
}
CNode::CNode()
@@ -280,6 +359,11 @@ namespace DOM
// 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.
*/
@@ -894,14 +978,6 @@ namespace DOM
}
- sal_Int64 SAL_CALL CNode::getSomething(const Sequence< sal_Int8 >& /*id*/) throw (RuntimeException)
- {
- // XXX check ID
- return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(m_aNodePtr));
- // return (sal_Int64)m_aNodePtr;
- }
-
-
// --- XEventTarget
void SAL_CALL CNode::addEventListener(const OUString& eventType,
const Reference< com::sun::star::xml::dom::events::XEventListener >& listener,
diff --git a/unoxml/source/dom/node.hxx b/unoxml/source/dom/node.hxx
index 68e5c06e9a77..51adbd3100be 100644
--- a/unoxml/source/dom/node.hxx
+++ b/unoxml/source/dom/node.hxx
@@ -31,18 +31,19 @@
#ifndef _NODE_HXX
#define _NODE_HXX
-#include <map>
+#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/implbase2.hxx>
-#include <cppuhelper/implbase3.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 <com/sun/star/lang/XUnoTunnel.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>
@@ -51,23 +52,72 @@
#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/XExtendedDocumentHandler.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 >
+ class CNode : public cppu::WeakImplHelper2< XNode, XEventTarget >
{
friend class CDocument;
friend class CElement;
@@ -109,6 +159,9 @@ namespace DOM
virtual void SAL_CALL saxify(
const Reference< XDocumentHandler >& i_xHandler);
+ // recursively create SAX events
+ virtual void SAL_CALL fastSaxify( Context& io_rContext );
+
// ---- DOM interfaces
/**
@@ -275,9 +328,6 @@ namespace DOM
throw (RuntimeException, DOMException);
- // --- XUnoTunnel
- virtual sal_Int64 SAL_CALL getSomething(const Sequence< sal_Int8 >& id) throw (RuntimeException);
-
// --- XEventTarget
virtual void SAL_CALL addEventListener(const OUString& eventType,
const Reference< XEventListener >& listener,
diff --git a/unoxml/source/dom/notation.hxx b/unoxml/source/dom/notation.hxx
index 12e5072f80ae..1dfa6bf22c72 100644
--- a/unoxml/source/dom/notation.hxx
+++ b/unoxml/source/dom/notation.hxx
@@ -37,7 +37,7 @@
#include "node.hxx"
#include <libxml/tree.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/notationsmap.hxx b/unoxml/source/dom/notationsmap.hxx
index a3eabc7d44d7..86f838fff713 100644
--- a/unoxml/source/dom/notationsmap.hxx
+++ b/unoxml/source/dom/notationsmap.hxx
@@ -41,7 +41,7 @@
#include "document.hxx"
#include "documenttype.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/processinginstruction.cxx b/unoxml/source/dom/processinginstruction.cxx
index af47d4f2b18e..089cccb80131 100644
--- a/unoxml/source/dom/processinginstruction.cxx
+++ b/unoxml/source/dom/processinginstruction.cxx
@@ -29,6 +29,7 @@
************************************************************************/
#include "processinginstruction.hxx"
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
#include <string.h>
namespace DOM
diff --git a/unoxml/source/dom/processinginstruction.hxx b/unoxml/source/dom/processinginstruction.hxx
index cb3be510532a..95dcf647ba0f 100644
--- a/unoxml/source/dom/processinginstruction.hxx
+++ b/unoxml/source/dom/processinginstruction.hxx
@@ -37,7 +37,7 @@
#include "node.hxx"
#include <libxml/tree.h>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/dom/saxbuilder.cxx b/unoxml/source/dom/saxbuilder.cxx
index cca9085d75f0..e06a3915b851 100644
--- a/unoxml/source/dom/saxbuilder.cxx
+++ b/unoxml/source/dom/saxbuilder.cxx
@@ -35,7 +35,6 @@
#include "saxbuilder.hxx"
#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
#include <libxml/tree.h>
-#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Sequence.h>
namespace DOM
diff --git a/unoxml/source/dom/saxbuilder.hxx b/unoxml/source/dom/saxbuilder.hxx
index 20775172a5f6..454b22f2d457 100644
--- a/unoxml/source/dom/saxbuilder.hxx
+++ b/unoxml/source/dom/saxbuilder.hxx
@@ -54,7 +54,7 @@
#include "libxml/tree.h"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::xml::dom;
using namespace com::sun::star::xml::sax;
diff --git a/unoxml/source/dom/text.cxx b/unoxml/source/dom/text.cxx
index d926d9691d1d..68eb775981e4 100644
--- a/unoxml/source/dom/text.cxx
+++ b/unoxml/source/dom/text.cxx
@@ -59,4 +59,17 @@ namespace DOM
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
index 415a0328eaab..8d97365ba744 100644
--- a/unoxml/source/dom/text.hxx
+++ b/unoxml/source/dom/text.hxx
@@ -41,7 +41,7 @@
#include <libxml/tree.h>
#include "characterdata.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
@@ -62,6 +62,8 @@ namespace DOM
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)
diff --git a/unoxml/source/events/mouseevent.hxx b/unoxml/source/events/mouseevent.hxx
index 9ec0efc79523..d70f1c1ac605 100644
--- a/unoxml/source/events/mouseevent.hxx
+++ b/unoxml/source/events/mouseevent.hxx
@@ -15,7 +15,7 @@
#include "event.hxx"
#include "uievent.hxx"
-using namespace rtl;
+using ::rtl::OUString;
namespace DOM { namespace events {
diff --git a/unoxml/source/events/mutationevent.hxx b/unoxml/source/events/mutationevent.hxx
index 09878bd7a999..e28613ad5df9 100644
--- a/unoxml/source/events/mutationevent.hxx
+++ b/unoxml/source/events/mutationevent.hxx
@@ -13,7 +13,7 @@
#include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
#include "event.hxx"
-using namespace rtl;
+using ::rtl::OUString;
namespace DOM { namespace events {
diff --git a/unoxml/source/events/testlistener.hxx b/unoxml/source/events/testlistener.hxx
index 3999a83357f3..7a9808e25235 100644
--- a/unoxml/source/events/testlistener.hxx
+++ b/unoxml/source/events/testlistener.hxx
@@ -54,7 +54,7 @@
#include "libxml/tree.h"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/events/uievent.hxx b/unoxml/source/events/uievent.hxx
index a38a8068aeaa..f7c5806e48e0 100644
--- a/unoxml/source/events/uievent.hxx
+++ b/unoxml/source/events/uievent.hxx
@@ -14,7 +14,7 @@
#include <com/sun/star/xml/dom/views/XAbstractView.hpp>
#include "event.hxx"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::xml::dom::views;
namespace DOM { namespace events {
diff --git a/unoxml/source/service/makefile.mk b/unoxml/source/service/makefile.mk
index 6c3df1aa9ee7..e86e07f1c89e 100644
--- a/unoxml/source/service/makefile.mk
+++ b/unoxml/source/service/makefile.mk
@@ -72,6 +72,7 @@ SHL1STDLIBS= \
$(COMPHELPERLIB) \
$(CPPUHELPERLIB) \
$(CPPULIB) \
+ $(SAXLIB) \
$(SALLIB)\
$(EXPATASCII3RDLIB)
diff --git a/unoxml/source/xpath/nodelist.hxx b/unoxml/source/xpath/nodelist.hxx
index 2d3fc8c0db70..b81e2726c341 100644
--- a/unoxml/source/xpath/nodelist.hxx
+++ b/unoxml/source/xpath/nodelist.hxx
@@ -43,7 +43,7 @@
#include "libxml/xpath.h"
#include <boost/shared_ptr.hpp>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/xpath/xpathapi.hxx b/unoxml/source/xpath/xpathapi.hxx
index 95cc18ed612b..127f765f30f3 100644
--- a/unoxml/source/xpath/xpathapi.hxx
+++ b/unoxml/source/xpath/xpathapi.hxx
@@ -52,11 +52,10 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/lang/XUnoTunnel.hpp>
#include "libxml/tree.h"
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/source/xpath/xpathobject.hxx b/unoxml/source/xpath/xpathobject.hxx
index 885a8db2b489..5fc7bf8a8661 100644
--- a/unoxml/source/xpath/xpathobject.hxx
+++ b/unoxml/source/xpath/xpathobject.hxx
@@ -43,7 +43,7 @@
#include <libxml/xpath.h>
#include <boost/shared_ptr.hpp>
-using namespace rtl;
+using ::rtl::OUString;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::xml::dom;
diff --git a/unoxml/test/domtest.cxx b/unoxml/test/domtest.cxx
new file mode 100644
index 000000000000..6687669fd875
--- /dev/null
+++ b/unoxml/test/domtest.cxx
@@ -0,0 +1,402 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: basictest.cxx,v $
+ * $Revision: 1.12 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+// autogenerated file with codegen.pl
+
+#include <cppunit/simpleheader.hxx>
+
+#include <rtl/ref.hxx>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <comphelper/seqstream.hxx>
+#include <comphelper/sequence.hxx>
+#include <cppuhelper/compbase1.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <cppuhelper/basemutex.hxx>
+
+#include <com/sun/star/xml/sax/FastToken.hpp>
+#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
+#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
+
+#include "../source/dom/documentbuilder.hxx"
+
+
+using namespace ::DOM;
+using namespace ::comphelper;
+using namespace ::com::sun::star;
+
+namespace
+{
+
+// valid xml
+static const char validTestFile[] =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
+ <office:document-content \
+ xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
+ xmlns:xlink=\"http://www.w3.org/1999/xlink\" \
+ office:version=\"1.0\"> \
+ <office:scripts/> \
+ <xlink:test/> \
+ <office:automatic-styles teststyle=\"test\"/> \
+ <moretest/> \
+ some text öäü \
+ </office:document-content> \
+";
+
+// generates a warning: unsupported xml version, unknown xml:space
+// value
+static const char warningTestFile[] =
+"<?xml version=\"47-11.0\" encoding=\"UTF-8\"?> \
+ <office:document-content \
+ xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
+ xml:space=\"blafasl\" \
+ office:version=\"1.0\"> \
+ <office:scripts/> \
+ <office:automatic-styles/> \
+ </office:document-content> \
+";
+
+// <?xml not at start of file
+static const char errorTestFile[] =
+" <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
+ <office:document-content \
+ xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
+ office:version=\"1.0\"> \
+ <office:scripts/> \
+ <office:automatic-styles/> \
+ </office:document-content> \
+";
+
+// plain empty
+static const char fatalTestFile[] = "";
+
+struct ErrorHandler
+ : public ::cppu::WeakImplHelper1< xml::sax::XErrorHandler >
+{
+ sal_uInt32 mnErrCount;
+ sal_uInt32 mnFatalCount;
+ sal_uInt32 mnWarnCount;
+
+ bool noErrors() const { return !mnErrCount && !mnFatalCount && !mnWarnCount; }
+
+ ErrorHandler() : mnErrCount(0), mnFatalCount(0), mnWarnCount(0)
+ {}
+
+ virtual void SAL_CALL error( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ ++mnErrCount;
+ }
+
+ virtual void SAL_CALL fatalError( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ ++mnFatalCount;
+ }
+
+ virtual void SAL_CALL warning( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ ++mnWarnCount;
+ }
+};
+
+struct DocumentHandler
+ : public ::cppu::WeakImplHelper1< xml::sax::XFastDocumentHandler >
+{
+ // XFastContextHandler
+ virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ OSL_TRACE("Seen element: %c with namespace 0x%x",
+ Element & 0xFFFF, Element & 0xFFFF0000);
+ }
+
+ virtual void SAL_CALL startUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL endFastElement( ::sal_Int32 Element ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ return this;
+ }
+
+ virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ return this;
+ }
+
+ virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ // XFastDocumentHandler
+ virtual void SAL_CALL startDocument( ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL endDocument( ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException)
+ {
+ }
+};
+
+struct TokenHandler
+ : public ::cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
+{
+ virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException)
+ {
+ CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getToken() unexpected call",
+ false );
+ return -1;
+ }
+
+ virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
+ {
+ CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getIdentifier() unexpected call",
+ false );
+ return rtl::OUString();
+ }
+
+ virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) throw (uno::RuntimeException)
+ {
+ OSL_TRACE("getTokenFromUTF8() %s", (const char*)Identifier.getConstArray());
+ return Identifier.getLength() ? Identifier[0] : 0;
+ }
+
+ virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
+ {
+ CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getUTF8Identifier() unexpected call",
+ false );
+ return uno::Sequence<sal_Int8>();
+ }
+};
+
+struct BasicTest : public CppUnit::TestFixture
+{
+ rtl::Reference<CDocumentBuilder> mxDomBuilder;
+ rtl::Reference<ErrorHandler> mxErrHandler;
+ rtl::Reference<SequenceInputStream> mxValidInStream;
+ rtl::Reference<SequenceInputStream> mxWarningInStream;
+ rtl::Reference<SequenceInputStream> mxErrorInStream;
+ rtl::Reference<SequenceInputStream> mxFatalInStream;
+
+ void setUp()
+ {
+ // luckily, DOM builder doesn't use service fac, so we need
+ // not bootstrap uno here
+ mxErrHandler.set( new ErrorHandler() );
+ mxDomBuilder.set( new CDocumentBuilder(Reference< XMultiServiceFactory >() ));
+ mxValidInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
+ sizeof(validTestFile)/sizeof(*validTestFile))) );
+ mxWarningInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)warningTestFile,
+ sizeof(warningTestFile)/sizeof(*warningTestFile))) );
+ mxErrorInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)errorTestFile,
+ sizeof(errorTestFile)/sizeof(*errorTestFile))) );
+ mxFatalInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)fatalTestFile,
+ sizeof(fatalTestFile)/sizeof(*fatalTestFile))) );
+ mxDomBuilder->setErrorHandler(mxErrHandler.get());
+ }
+
+ void validInputTest()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #1",
+ mxDomBuilder->parse(
+ uno::Reference<io::XInputStream>(
+ mxValidInStream.get())).is() );
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
+ mxErrHandler->noErrors() );
+ }
+
+ void warningInputTest()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #2",
+ mxDomBuilder->parse(
+ uno::Reference<io::XInputStream>(
+ mxWarningInStream.get())).is() );
+ CPPUNIT_ASSERT_MESSAGE( "No parse warnings in unclean input file",
+ mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
+ }
+
+ void errorInputTest()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #3",
+ mxDomBuilder->parse(
+ uno::Reference<io::XInputStream>(
+ mxErrorInStream.get())).is() );
+ CPPUNIT_ASSERT_MESSAGE( "No parse errors in unclean input file",
+ !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
+ }
+
+ void fatalInputTest()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Broken input file resulted in XDocument",
+ !mxDomBuilder->parse(
+ uno::Reference<io::XInputStream>(
+ mxFatalInStream.get())).is() );
+ CPPUNIT_ASSERT_MESSAGE( "No fatal parse errors in unclean input file",
+ !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount );
+ };
+
+ // Change the following lines only, if you add, remove or rename
+ // member functions of the current class,
+ // because these macros are need by auto register mechanism.
+ CPPUNIT_TEST_SUITE(BasicTest);
+ CPPUNIT_TEST(validInputTest);
+ CPPUNIT_TEST(warningInputTest);
+ CPPUNIT_TEST(errorInputTest);
+ CPPUNIT_TEST(fatalInputTest);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+struct SerializerTest : public CppUnit::TestFixture
+{
+ SerializerTest() : mbUnoInitialized(false) {}
+
+ uno::Reference<uno::XComponentContext> mxCtx;
+ rtl::Reference<CDocumentBuilder> mxDomBuilder;
+ rtl::Reference<ErrorHandler> mxErrHandler;
+ rtl::Reference<SequenceInputStream> mxInStream;
+ rtl::Reference<DocumentHandler> mxHandler;
+ rtl::Reference<TokenHandler> mxTokHandler;
+ uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces;
+ bool mbUnoInitialized;
+
+ void setUp()
+ {
+ // need working typelib, bootstrap UNO now
+ if( !mbUnoInitialized )
+ {
+ const char* pArgs( getForwardString() );
+ CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs);
+
+ const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs);
+
+ // bootstrap UNO
+ try
+ {
+ ::rtl::OUString aIniUrl;
+ CPPUNIT_ASSERT_MESSAGE(
+ "Converting ini file to URL",
+ osl_getFileURLFromSystemPath(
+ (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData,
+ &aIniUrl.pData ) == osl_File_E_None );
+
+ mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
+ CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is());
+ }
+ catch( uno::Exception& )
+ {
+ CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false);
+ }
+
+ mbUnoInitialized = true;
+ }
+
+ mxErrHandler.set( new ErrorHandler() );
+ mxDomBuilder.set( new CDocumentBuilder(
+ uno::Reference< lang::XMultiServiceFactory >(
+ mxCtx->getServiceManager(),
+ uno::UNO_QUERY )));
+ mxInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
+ sizeof(validTestFile)/sizeof(*validTestFile))) );
+ mxDomBuilder->setErrorHandler(mxErrHandler.get());
+
+ mxHandler.set( new DocumentHandler() );
+ mxTokHandler.set( new TokenHandler() );
+
+ maRegisteredNamespaces.realloc(2);
+ maRegisteredNamespaces[0] = beans::make_Pair(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "urn:oasis:names:tc:opendocument:xmlns:office:1.0") ),
+ xml::sax::FastToken::NAMESPACE);
+ maRegisteredNamespaces[1] = beans::make_Pair(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "http://www.w3.org/1999/xlink") ),
+ 2*xml::sax::FastToken::NAMESPACE);
+ }
+
+ void serializerTest ()
+ {
+ uno::Reference< xml::dom::XDocument > xDoc=
+ mxDomBuilder->parse(
+ uno::Reference<io::XInputStream>(
+ mxInStream.get()));
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument",
+ xDoc.is() );
+ CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
+ mxErrHandler->noErrors() );
+
+ uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer(
+ xDoc, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_MESSAGE( "XSAXSerializable not supported",
+ xSaxSerializer.is() );
+
+ uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer(
+ xDoc, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_MESSAGE( "XFastSAXSerializable not supported",
+ xSaxSerializer.is() );
+
+ xFastSaxSerializer->fastSerialize( mxHandler.get(),
+ mxTokHandler.get(),
+ uno::Sequence< beans::StringPair >(),
+ maRegisteredNamespaces );
+ }
+
+ // Change the following lines only, if you add, remove or rename
+ // member functions of the current class,
+ // because these macros are need by auto register mechanism.
+
+ CPPUNIT_TEST_SUITE(SerializerTest);
+ CPPUNIT_TEST(serializerTest);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+// -----------------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SerializerTest, "SerializerTest");
+}
+
+
+// -----------------------------------------------------------------------------
+
+// this macro creates an empty function, which will called by the RegisterAllFunctions()
+// to let the user the possibility to also register some functions by hand.
+NOADDITIONAL;
+
diff --git a/unoxml/test/export.map b/unoxml/test/export.map
new file mode 100644
index 000000000000..bfd13f454044
--- /dev/null
+++ b/unoxml/test/export.map
@@ -0,0 +1,38 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2008 by Sun Microsystems, Inc.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# $RCSfile: export.map,v $
+#
+# $Revision: 1.2 $
+#
+# 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.
+#
+#*************************************************************************
+
+UDK_3.1 {
+ global:
+ registerAllTestFunction;
+
+ local:
+ *;
+};
diff --git a/unoxml/test/makefile.mk b/unoxml/test/makefile.mk
new file mode 100644
index 000000000000..781f8a46bf96
--- /dev/null
+++ b/unoxml/test/makefile.mk
@@ -0,0 +1,106 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2008 by Sun Microsystems, Inc.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.9 $
+#
+# 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=tests
+TARGETTYPE=GUI
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Common ----------------------------------------------------------
+
+# BEGIN ----------------------------------------------------------------
+# auto generated Target:tests by codegen.pl
+SHL1OBJS= \
+ $(SLO)$/domtest.obj
+
+# the following three libs are a bit of a hack: cannot link against
+# unoxml here, because not yet delivered (and does not export
+# ~anything). Need the functionality to test, so we're linking it in
+# statically. Need to keep this in sync with
+# source/services/makefile.mk
+SHL1LIBS= \
+ $(SLB)$/domimpl.lib \
+ $(SLB)$/xpathimpl.lib \
+ $(SLB)$/eventsimpl.lib
+
+SHL1TARGET= tests
+SHL1STDLIBS= \
+ $(UCBHELPERLIB) \
+ $(LIBXML2LIB) \
+ $(TOOLSLIB) \
+ $(COMPHELPERLIB) \
+ $(CPPUHELPERLIB) \
+ $(CPPUNITLIB) \
+ $(CPPULIB) \
+ $(SAXLIB) \
+ $(SALLIB)\
+ $(EXPATASCII3RDLIB)
+
+SHL1IMPLIB= i$(SHL1TARGET)
+
+DEF1NAME =$(SHL1TARGET)
+SHL1VERSIONMAP = export.map
+
+# END ------------------------------------------------------------------
+
+#------------------------------- All object files -------------------------------
+# do this here, so we get right dependencies
+SLOFILES=$(SHL1OBJS)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+.INCLUDE : _cppunit.mk
+
+# --- Fake uno bootstrap ------------------------
+
+$(BIN)$/unoxml_unittest_test.ini : makefile.mk
+ rm -f $@
+ @echo UNO_SERVICES= > $@
+ @echo UNO_TYPES=$(UNOUCRRDB:s/\/\\/) >> $@
+
+# --- Enable testshl2 execution in normal build ------------------------
+
+$(MISC)$/unoxml_unittest_succeeded : $(SHL1TARGETN) $(BIN)$/unoxml_unittest_test.ini
+ @echo ----------------------------------------------------------
+ @echo - start unit test on library $(SHL1TARGETN)
+ @echo ----------------------------------------------------------
+ testshl2 -forward $(BIN)$/ -sf $(mktmp ) $(SHL1TARGETN)
+ $(TOUCH) $@
+
+ALLTAR : $(MISC)$/unoxml_unittest_succeeded