Update to m13
[ooovba.git] / applied_patches / 0850-unoxml-fast-sax-serializable.diff
blob9cf0e8e323c8dcf7470a093b93c9914004027457
1 make fastsax ifc serializable
3 From: Thorsten Behrens <thb@openoffice.org>
6 ---
8 .../com/sun/star/xml/sax/XFastSAXSerializable.idl | 102 +++++
9 offapi/com/sun/star/xml/sax/makefile.mk | 1
10 unoxml/source/dom/attr.hxx | 2
11 unoxml/source/dom/attributesmap.hxx | 2
12 unoxml/source/dom/cdatasection.cxx | 2
13 unoxml/source/dom/cdatasection.hxx | 2
14 unoxml/source/dom/characterdata.hxx | 2
15 unoxml/source/dom/childlist.hxx | 2
16 unoxml/source/dom/comment.cxx | 2
17 unoxml/source/dom/comment.hxx | 2
18 unoxml/source/dom/document.cxx | 57 +++
19 unoxml/source/dom/document.hxx | 24 +
20 unoxml/source/dom/documentfragment.hxx | 2
21 unoxml/source/dom/documenttype.hxx | 2
22 unoxml/source/dom/domimplementation.hxx | 2
23 unoxml/source/dom/element.cxx | 100 +++++
24 unoxml/source/dom/element.hxx | 4
25 unoxml/source/dom/elementlist.hxx | 2
26 unoxml/source/dom/entitiesmap.hxx | 2
27 unoxml/source/dom/entity.hxx | 2
28 unoxml/source/dom/entityreference.hxx | 2
29 unoxml/source/dom/node.cxx | 104 ++++-
30 unoxml/source/dom/node.hxx | 68 +++
31 unoxml/source/dom/notation.hxx | 2
32 unoxml/source/dom/notationsmap.hxx | 2
33 unoxml/source/dom/processinginstruction.cxx | 1
34 unoxml/source/dom/processinginstruction.hxx | 2
35 unoxml/source/dom/saxbuilder.cxx | 1
36 unoxml/source/dom/saxbuilder.hxx | 2
37 unoxml/source/dom/text.cxx | 13 +
38 unoxml/source/dom/text.hxx | 4
39 unoxml/source/events/mouseevent.hxx | 2
40 unoxml/source/events/mutationevent.hxx | 2
41 unoxml/source/events/testlistener.hxx | 2
42 unoxml/source/events/uievent.hxx | 2
43 unoxml/source/service/makefile.mk | 1
44 unoxml/source/xpath/nodelist.hxx | 2
45 unoxml/source/xpath/xpathapi.hxx | 3
46 unoxml/source/xpath/xpathobject.hxx | 2
47 unoxml/test/domtest.cxx | 402 ++++++++++++++++++++
48 unoxml/test/export.map | 38 ++
49 unoxml/test/makefile.mk | 106 +++++
50 42 files changed, 1017 insertions(+), 62 deletions(-)
51 create mode 100644 offapi/com/sun/star/xml/sax/XFastSAXSerializable.idl
52 create mode 100644 unoxml/test/domtest.cxx
53 create mode 100644 unoxml/test/export.map
54 create mode 100644 unoxml/test/makefile.mk
57 diff --git offapi/com/sun/star/xml/sax/XFastSAXSerializable.idl offapi/com/sun/star/xml/sax/XFastSAXSerializable.idl
58 new file mode 100644
59 index 0000000..6d815ce
60 --- /dev/null
61 +++ offapi/com/sun/star/xml/sax/XFastSAXSerializable.idl
62 @@ -0,0 +1,102 @@
63 +/*************************************************************************
64 + *
65 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66 + *
67 + * Copyright 2008 by Sun Microsystems, Inc.
68 + *
69 + * OpenOffice.org - a multi-platform office productivity suite
70 + *
71 + * $RCSfile: XSAXSerializable.idl,v $
72 + * $Revision: 1.3 $
73 + *
74 + * This file is part of OpenOffice.org.
75 + *
76 + * OpenOffice.org is free software: you can redistribute it and/or modify
77 + * it under the terms of the GNU Lesser General Public License version 3
78 + * only, as published by the Free Software Foundation.
79 + *
80 + * OpenOffice.org is distributed in the hope that it will be useful,
81 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
82 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83 + * GNU Lesser General Public License version 3 for more details
84 + * (a copy is included in the LICENSE file that accompanied this code).
85 + *
86 + * You should have received a copy of the GNU Lesser General Public License
87 + * version 3 along with OpenOffice.org. If not, see
88 + * <http://www.openoffice.org/license.html>
89 + * for a copy of the LGPLv3 License.
90 + *
91 + ************************************************************************/
93 +#ifndef __com_sun_star_xml_sax_XFastSAXSerializable_idl__
94 +#define __com_sun_star_xml_sax_XFastSAXSerializable_idl__
96 +#ifndef __com_sun_star_xml_sax_XFastDocumentHandler_idl__
97 +#include <com/sun/star/xml/sax/XFastDocumentHandler.idl>
98 +#endif
100 +#ifndef __com_sun_star_xml_sax_XFastTokenHandler_idl__
101 +#include <com/sun/star/xml/sax/XFastTokenHandler.idl>
102 +#endif
104 +#ifndef __com_sun_star_beans_StringPair_idl__
105 +#include <com/sun/star/beans/StringPair.idl>
106 +#endif
108 +#ifndef __com_sun_star_beans_Pair_idl__
109 +#include <com/sun/star/beans/Pair.idl>
110 +#endif
112 +module com { module sun { module star { module xml { module sax {
114 +//=============================================================================
115 +/** serializes a DOM tree by generating FastSAX events.
117 + <p>
118 + </p>
120 + @since OOo 3.1
123 +interface XFastSAXSerializable
126 + //-------------------------------------------------------------------------
127 + /** serializes an object (e.g. a DOM tree) that represents an XML document
128 + by generating fast SAX events.
130 + @param handler
131 + the SAX event handler that should receive the generated events
132 + @param tokenHandler
133 + the fast SAX token handler that is used to translate names
134 + @param namespaces
135 + a list of namespace declarations that will be added to the root
136 + element node of the XML document
137 + <p>
138 + This is necessary mostly because the DOM implementation does
139 + not permit attaching namespaces declarations directly to nodes,
140 + which may lead to duplicate namespace declarations on export,
141 + and thus larger documents.
142 + Note that the first part of each tuple is the prefix,
143 + e.g. "office", and the second is the numeric namespace identifier.
144 + </p>
145 + @param registerNamespaces
146 + a list of namespace url / namespace token pairs. you need
147 + to register all namespace in order to have them recognized
148 + during export. Namespace tokens must be greater than
149 + FastToken::NAMESPACE.
150 + </p>
152 + @throws com::sun::star::xml::sax::SAXException
153 + if serializing the XML document fails
154 + */
155 + void fastSerialize([in] sax::XFastDocumentHandler handler,
156 + [in] sax::XFastTokenHandler tokenHandler,
157 + [in] sequence< beans::StringPair > namespaces,
158 + [in] sequence< beans::Pair<string, long> > registerNamespaces)
159 + raises( com::sun::star::xml::sax::SAXException );
162 +}; }; }; }; };
164 +#endif
165 diff --git offapi/com/sun/star/xml/sax/makefile.mk offapi/com/sun/star/xml/sax/makefile.mk
166 index 41d3d19..33425dd 100644
167 --- offapi/com/sun/star/xml/sax/makefile.mk
168 +++ offapi/com/sun/star/xml/sax/makefile.mk
169 @@ -58,6 +58,7 @@ IDLFILES=\
170 XFastParser.idl\
171 XFastDocumentHandler.idl\
172 XFastContextHandler.idl\
173 + XFastSAXSerializable.idl\
174 XFastSerializer.idl\
175 XFastShapeContextHandler.idl\
176 XFastTokenHandler.idl\
177 diff --git unoxml/source/dom/attr.hxx unoxml/source/dom/attr.hxx
178 index efb61c7..bbe4dba 100644
179 --- unoxml/source/dom/attr.hxx
180 +++ unoxml/source/dom/attr.hxx
181 @@ -39,7 +39,7 @@
182 #include "node.hxx"
183 #include <libxml/tree.h>
185 -using namespace rtl;
186 +using ::rtl::OUString;
187 using namespace com::sun::star::uno;
188 using namespace com::sun::star::xml::dom;
190 diff --git unoxml/source/dom/attributesmap.hxx unoxml/source/dom/attributesmap.hxx
191 index 1858e1a..970336f 100644
192 --- unoxml/source/dom/attributesmap.hxx
193 +++ unoxml/source/dom/attributesmap.hxx
194 @@ -42,7 +42,7 @@
195 #include "element.hxx"
196 #include "attr.hxx"
198 -using namespace rtl;
199 +using ::rtl::OUString;
200 using namespace com::sun::star::uno;
201 using namespace com::sun::star::xml::dom;
203 diff --git unoxml/source/dom/cdatasection.cxx unoxml/source/dom/cdatasection.cxx
204 index 5eeaddc..e26f741 100644
205 --- unoxml/source/dom/cdatasection.cxx
206 +++ unoxml/source/dom/cdatasection.cxx
207 @@ -30,6 +30,8 @@
209 #include "cdatasection.hxx"
211 +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
213 namespace DOM
215 CCDATASection::CCDATASection(const xmlNodePtr aNodePtr)
216 diff --git unoxml/source/dom/cdatasection.hxx unoxml/source/dom/cdatasection.hxx
217 index d4d24c6..524a50d 100644
218 --- unoxml/source/dom/cdatasection.hxx
219 +++ unoxml/source/dom/cdatasection.hxx
220 @@ -37,7 +37,7 @@
222 #include "text.hxx"
224 -using namespace rtl;
225 +using ::rtl::OUString;
226 using namespace com::sun::star::uno;
227 using namespace com::sun::star::xml::dom;
229 diff --git unoxml/source/dom/characterdata.hxx unoxml/source/dom/characterdata.hxx
230 index c23c309..509b471 100644
231 --- unoxml/source/dom/characterdata.hxx
232 +++ unoxml/source/dom/characterdata.hxx
233 @@ -42,7 +42,7 @@
234 #include <libxml/tree.h>
235 #include "node.hxx"
237 -using namespace rtl;
238 +using ::rtl::OUString;
239 using namespace com::sun::star::uno;
240 using namespace com::sun::star::xml::dom;
242 diff --git unoxml/source/dom/childlist.hxx unoxml/source/dom/childlist.hxx
243 index 6f85b35..8ac44a7 100644
244 --- unoxml/source/dom/childlist.hxx
245 +++ unoxml/source/dom/childlist.hxx
246 @@ -41,7 +41,7 @@
247 #include "node.hxx"
248 #include "libxml/tree.h"
250 -using namespace rtl;
251 +using ::rtl::OUString;
252 using namespace com::sun::star::uno;
253 using namespace com::sun::star::xml::dom;
255 diff --git unoxml/source/dom/comment.cxx unoxml/source/dom/comment.cxx
256 index 8d3f9ab..7781ed5 100644
257 --- unoxml/source/dom/comment.cxx
258 +++ unoxml/source/dom/comment.cxx
259 @@ -30,6 +30,8 @@
261 #include "comment.hxx"
263 +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
265 namespace DOM
267 CComment::CComment(const xmlNodePtr aNodePtr)
268 diff --git unoxml/source/dom/comment.hxx unoxml/source/dom/comment.hxx
269 index 8651c1a..33dd667 100644
270 --- unoxml/source/dom/comment.hxx
271 +++ unoxml/source/dom/comment.hxx
272 @@ -36,7 +36,7 @@
273 #include <com/sun/star/xml/dom/XComment.hpp>
274 #include "characterdata.hxx"
276 -using namespace rtl;
277 +using ::rtl::OUString;
278 using namespace com::sun::star::uno;
279 using namespace com::sun::star::xml::dom;
281 diff --git unoxml/source/dom/document.cxx unoxml/source/dom/document.cxx
282 index 2cc7141..e69352b 100644
283 --- unoxml/source/dom/document.cxx
284 +++ unoxml/source/dom/document.cxx
285 @@ -51,13 +51,11 @@
287 #include <string.h>
289 +#include <com/sun/star/xml/sax/FastToken.hpp>
290 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
293 namespace DOM
297 void CDocument::addnode(xmlNodePtr aNode)
299 if (aNode != (xmlNodePtr)m_aDocPtr)
300 @@ -122,6 +120,17 @@ namespace DOM
301 i_xHandler->endDocument();
304 + void SAL_CALL CDocument::fastSaxify( Context& rContext ) {
305 + rContext.mxDocHandler->startDocument();
306 + for (xmlNodePtr pChild = m_aNodePtr->children;
307 + pChild != 0; pChild = pChild->next) {
308 + CNode * pNode = CNode::get(pChild);
309 + OSL_ENSURE(pNode != 0, "CNode::get returned 0");
310 + pNode->fastSaxify(rContext);
312 + rContext.mxDocHandler->endDocument();
315 void SAL_CALL CDocument::addListener(const Reference< XStreamListener >& aListener )
316 throw (RuntimeException)
318 @@ -699,7 +708,47 @@ namespace DOM
319 // eliminate duplicate namespace declarations
320 _nscleanup(pRoot->children, pRoot);
322 - // serialize via SAX handler
323 saxify(i_xHandler);
326 + // ::com::sun::star::xml::sax::XFastSAXSerializable
327 + void SAL_CALL CDocument::fastSerialize( const Reference< XFastDocumentHandler >& i_xHandler,
328 + const Reference< XFastTokenHandler >& i_xTokenHandler,
329 + const Sequence< beans::StringPair >& i_rNamespaces,
330 + const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& i_rRegisterNamespaces )
331 + throw (SAXException, RuntimeException)
333 + // add new namespaces to root node
334 + xmlNodePtr pRoot = _getDocumentRootPtr(m_aDocPtr);
335 + if (0 != pRoot) {
336 + const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
337 + for (const beans::StringPair *pNsDef = pSeq;
338 + pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
339 + OString prefix = OUStringToOString(pNsDef->First,
340 + RTL_TEXTENCODING_UTF8);
341 + OString href = OUStringToOString(pNsDef->Second,
342 + RTL_TEXTENCODING_UTF8);
343 + // this will only add the ns if it does not exist already
344 + xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
345 + reinterpret_cast<const xmlChar*>(prefix.getStr()));
347 + // eliminate duplicate namespace declarations
348 + _nscleanup(pRoot->children, pRoot);
351 + Context aContext(i_xHandler,
352 + i_xTokenHandler);
354 + // register namespace ids
355 + const beans::Pair<OUString,sal_Int32>* pSeq = i_rRegisterNamespaces.getConstArray();
356 + for (const beans::Pair<OUString,sal_Int32>* pNs = pSeq;
357 + pNs < pSeq + i_rRegisterNamespaces.getLength(); ++pNs)
359 + OSL_ENSURE(pNs->Second >= FastToken::NAMESPACE,
360 + "CDocument::fastSerialize(): invalid NS token id");
361 + aContext.maNamespaceMap[ pNs->First ] = pNs->Second;
364 + fastSaxify(aContext);
367 diff --git unoxml/source/dom/document.hxx unoxml/source/dom/document.hxx
368 index 13b09ee..e902269 100644
369 --- unoxml/source/dom/document.hxx
370 +++ unoxml/source/dom/document.hxx
371 @@ -34,7 +34,7 @@
372 #include <list>
373 #include <set>
374 #include <sal/types.h>
375 -#include <cppuhelper/implbase5.hxx>
376 +#include <cppuhelper/implbase6.hxx>
377 #include <com/sun/star/uno/Reference.h>
378 #include <com/sun/star/uno/Exception.hpp>
379 #include <com/sun/star/beans/StringPair.hpp>
380 @@ -45,7 +45,9 @@
381 #include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
382 #include <com/sun/star/xml/dom/events/XEvent.hpp>
383 #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
384 +#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
385 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
386 +#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
387 #include <com/sun/star/io/XActiveDataSource.hpp>
388 #include <com/sun/star/io/XActiveDataControl.hpp>
389 #include <com/sun/star/io/XOutputStream.hpp>
390 @@ -68,9 +70,9 @@ using namespace com::sun::star::xml::dom::events;
391 namespace DOM
394 - class CDocument : public cppu::ImplInheritanceHelper5<
395 + class CDocument : public cppu::ImplInheritanceHelper6<
396 CNode, XDocument, XDocumentEvent,
397 - XActiveDataControl, XActiveDataSource, XSAXSerializable>
398 + XActiveDataControl, XActiveDataSource, XSAXSerializable, XFastSAXSerializable>
400 friend class CNode;
401 typedef std::list< Reference< XNode >* > nodereflist_t;
402 @@ -97,6 +99,8 @@ namespace DOM
403 virtual void SAL_CALL saxify(
404 const Reference< XDocumentHandler >& i_xHandler);
406 + virtual void SAL_CALL fastSaxify( Context& rContext );
409 Creates an Attr of the given name.
411 @@ -347,12 +351,18 @@ namespace DOM
412 return CNode::setPrefix(prefix);
416 - // ::com::sun::star::xml::sax::XSAXSerializable
417 - virtual void SAL_CALL serialize(
418 + // ::com::sun::star::xml::sax::XSAXSerializable
419 + virtual void SAL_CALL serialize(
420 const Reference< XDocumentHandler >& i_xHandler,
421 const Sequence< beans::StringPair >& i_rNamespaces)
422 - throw (RuntimeException, SAXException);
423 + throw (RuntimeException, SAXException);
425 + // ::com::sun::star::xml::sax::XFastSAXSerializable
426 + virtual void SAL_CALL fastSerialize( const Reference< XFastDocumentHandler >& handler,
427 + const Reference< XFastTokenHandler >& tokenHandler,
428 + const Sequence< beans::StringPair >& i_rNamespaces,
429 + const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& namespaces )
430 + throw (SAXException, RuntimeException);
434 diff --git unoxml/source/dom/documentfragment.hxx unoxml/source/dom/documentfragment.hxx
435 index 67778c2..4d037ca 100644
436 --- unoxml/source/dom/documentfragment.hxx
437 +++ unoxml/source/dom/documentfragment.hxx
438 @@ -37,7 +37,7 @@
440 #include "node.hxx"
442 -using namespace rtl;
443 +using ::rtl::OUString;
444 using namespace com::sun::star::uno;
445 using namespace com::sun::star::xml::dom;
447 diff --git unoxml/source/dom/documenttype.hxx unoxml/source/dom/documenttype.hxx
448 index e995713..15a2417 100644
449 --- unoxml/source/dom/documenttype.hxx
450 +++ unoxml/source/dom/documenttype.hxx
451 @@ -42,7 +42,7 @@
453 #include <libxml/tree.h>
455 -using namespace rtl;
456 +using ::rtl::OUString;
457 using namespace com::sun::star::uno;
458 using namespace com::sun::star::xml::dom;
460 diff --git unoxml/source/dom/domimplementation.hxx unoxml/source/dom/domimplementation.hxx
461 index a5f1b02..0dd4cfb 100644
462 --- unoxml/source/dom/domimplementation.hxx
463 +++ unoxml/source/dom/domimplementation.hxx
464 @@ -41,7 +41,7 @@
465 #include <com/sun/star/xml/dom/XDOMImplementation.hpp>
466 #include <com/sun/star/xml/dom/XDOMImplementation.hpp>
468 -using namespace rtl;
469 +using ::rtl::OUString;
470 using namespace com::sun::star::uno;
471 using namespace com::sun::star::xml::dom;
473 diff --git unoxml/source/dom/element.cxx unoxml/source/dom/element.cxx
474 index fe099b4..17ac26d 100644
475 --- unoxml/source/dom/element.cxx
476 +++ unoxml/source/dom/element.cxx
477 @@ -36,6 +36,7 @@
478 #include "../events/mutationevent.hxx"
480 #include "comphelper/attributelist.hxx"
481 +#include <com/sun/star/xml/sax/FastToken.hdl>
483 #include <string.h>
485 @@ -98,6 +99,105 @@ namespace DOM
486 i_xHandler->endElement(name);
489 + void SAL_CALL CElement::fastSaxify( Context& i_rContext ) {
490 + if (!i_rContext.mxDocHandler.is()) throw RuntimeException();
491 + pushContext(i_rContext);
492 + addNamespaces(i_rContext,m_aNodePtr);
494 + // add attributes
495 + i_rContext.mxAttribList->clear();
496 + for (xmlAttrPtr pAttr = m_aNodePtr->properties;
497 + pAttr != 0; pAttr = pAttr->next) {
498 + CNode * pNode = CNode::get(reinterpret_cast<xmlNodePtr>(pAttr));
499 + OSL_ENSURE(pNode != 0, "CNode::get returned 0");
501 + const xmlChar* xName = pAttr->name;
502 + sal_Int32 nAttributeToken=FastToken::DONTKNOW;
504 + if( pAttr->ns && strlen((char*)pAttr->ns->prefix) )
505 + nAttributeToken = getTokenWithPrefix( i_rContext,
506 + (sal_Char*)pAttr->ns->prefix,
507 + (sal_Char*)xName );
508 + else
509 + nAttributeToken = getToken( i_rContext, (sal_Char*)xName );
511 + if( nAttributeToken != FastToken::DONTKNOW )
512 + i_rContext.mxAttribList->add( nAttributeToken,
513 + OUStringToOString(pNode->getNodeValue(),
514 + RTL_TEXTENCODING_UTF8));
517 + const xmlChar* xPrefix = m_aNodePtr->ns ? m_aNodePtr->ns->prefix : (const xmlChar*)"";
518 + const xmlChar* xName = m_aNodePtr->name;
519 + sal_Int32 nElementToken=FastToken::DONTKNOW;
520 + if( strlen((char*)xPrefix) )
521 + nElementToken = getTokenWithPrefix( i_rContext, (sal_Char*)xPrefix, (sal_Char*)xName );
522 + else
523 + nElementToken = getToken( i_rContext, (sal_Char*)xName );
525 + Reference<XFastContextHandler> xParentHandler(i_rContext.mxCurrentHandler);
526 + try
528 + Reference< XFastAttributeList > xAttr( i_rContext.mxAttribList.get() );
529 + if( nElementToken == FastToken::DONTKNOW )
531 + const OUString aNamespace;
532 + const OUString aElementName( (sal_Char*)xPrefix,
533 + strlen((char*)xPrefix),
534 + RTL_TEXTENCODING_UTF8 );
536 + if( xParentHandler.is() )
537 + i_rContext.mxCurrentHandler = xParentHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
538 + else
539 + i_rContext.mxCurrentHandler = i_rContext.mxDocHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
541 + if( i_rContext.mxCurrentHandler.is() )
542 + i_rContext.mxCurrentHandler->startUnknownElement( aNamespace, aElementName, xAttr );
544 + else
546 + if( xParentHandler.is() )
547 + i_rContext.mxCurrentHandler = xParentHandler->createFastChildContext( nElementToken, xAttr );
548 + else
549 + i_rContext.mxCurrentHandler = i_rContext.mxDocHandler->createFastChildContext( nElementToken, xAttr );
551 + if( i_rContext.mxCurrentHandler.is() )
552 + i_rContext.mxCurrentHandler->startFastElement( nElementToken, xAttr );
555 + catch( Exception& )
556 + {}
558 + // recurse
559 + for (xmlNodePtr pChild = m_aNodePtr->children;
560 + pChild != 0; pChild = pChild->next) {
561 + CNode * pNode = CNode::get(pChild);
562 + OSL_ENSURE(pNode != 0, "CNode::get returned 0");
563 + pNode->fastSaxify(i_rContext);
566 + if( i_rContext.mxCurrentHandler.is() ) try
568 + if( nElementToken != FastToken::DONTKNOW )
569 + i_rContext.mxCurrentHandler->endFastElement( nElementToken );
570 + else
572 + const OUString aNamespace;
573 + const OUString aElementName( (sal_Char*)xPrefix,
574 + strlen((char*)xPrefix),
575 + RTL_TEXTENCODING_UTF8 );
577 + i_rContext.mxCurrentHandler->endUnknownElement( aNamespace, aElementName );
580 + catch( Exception& )
581 + {}
583 + // restore after children have been processed
584 + i_rContext.mxCurrentHandler = xParentHandler;
585 + popContext(i_rContext);
589 Retrieves an attribute value by name.
590 return empty string if attribute is not set
591 diff --git unoxml/source/dom/element.hxx unoxml/source/dom/element.hxx
592 index c6ba0ee..a4c0026 100644
593 --- unoxml/source/dom/element.hxx
594 +++ unoxml/source/dom/element.hxx
595 @@ -39,7 +39,7 @@
596 #include <libxml/tree.h>
597 #include "node.hxx"
599 -using namespace rtl;
600 +using ::rtl::OUString;
601 using namespace com::sun::star::uno;
602 using namespace com::sun::star::xml::dom;
604 @@ -60,6 +60,8 @@ namespace DOM
605 virtual void SAL_CALL saxify(
606 const Reference< XDocumentHandler >& i_xHandler);
608 + virtual void SAL_CALL fastSaxify( Context& i_rContext );
611 Retrieves an attribute value by name.
613 diff --git unoxml/source/dom/elementlist.hxx unoxml/source/dom/elementlist.hxx
614 index e78c8bb..4e6d8c7 100644
615 --- unoxml/source/dom/elementlist.hxx
616 +++ unoxml/source/dom/elementlist.hxx
617 @@ -45,7 +45,7 @@
618 #include "document.hxx"
619 #include "libxml/tree.h"
621 -using namespace rtl;
622 +using ::rtl::OUString;
623 using namespace com::sun::star::uno;
624 using namespace com::sun::star::xml::dom;
625 using namespace com::sun::star::xml::dom::events;
626 diff --git unoxml/source/dom/entitiesmap.hxx unoxml/source/dom/entitiesmap.hxx
627 index f207d81..f3f7f3d 100644
628 --- unoxml/source/dom/entitiesmap.hxx
629 +++ unoxml/source/dom/entitiesmap.hxx
630 @@ -41,7 +41,7 @@
631 #include "document.hxx"
632 #include "documenttype.hxx"
634 -using namespace rtl;
635 +using ::rtl::OUString;
636 using namespace com::sun::star::uno;
637 using namespace com::sun::star::lang;
638 using namespace com::sun::star::xml::dom;
639 diff --git unoxml/source/dom/entity.hxx unoxml/source/dom/entity.hxx
640 index fd269bc..f4b5855 100644
641 --- unoxml/source/dom/entity.hxx
642 +++ unoxml/source/dom/entity.hxx
643 @@ -39,7 +39,7 @@
644 #include <libxml/tree.h>
645 #include <libxml/entities.h>
647 -using namespace rtl;
648 +using ::rtl::OUString;
649 using namespace com::sun::star::uno;
650 using namespace com::sun::star::xml::dom;
652 diff --git unoxml/source/dom/entityreference.hxx unoxml/source/dom/entityreference.hxx
653 index 5535374..02d9f7b 100644
654 --- unoxml/source/dom/entityreference.hxx
655 +++ unoxml/source/dom/entityreference.hxx
656 @@ -36,7 +36,7 @@
657 #include "node.hxx"
658 #include <libxml/tree.h>
660 -using namespace rtl;
661 +using ::rtl::OUString;
662 using namespace com::sun::star::uno;
663 using namespace com::sun::star::xml::dom;
665 diff --git unoxml/source/dom/node.cxx unoxml/source/dom/node.cxx
666 index f7599f8..e25c4d7 100644
667 --- unoxml/source/dom/node.cxx
668 +++ unoxml/source/dom/node.cxx
669 @@ -45,11 +45,91 @@
670 #include "childlist.hxx"
671 #include "attr.hxx"
673 +#include <com/sun/star/xml/sax/FastToken.hpp>
675 #include "../events/eventdispatcher.hxx"
676 #include "../events/mutationevent.hxx"
678 +#include <boost/bind.hpp>
679 +#include <algorithm>
681 namespace DOM
683 + void pushContext(Context& io_rContext)
685 + io_rContext.maNamespaces.push_back(
686 + io_rContext.maNamespaces.back());
689 + void popContext(Context& io_rContext)
691 + io_rContext.maNamespaces.pop_back();
694 + void addNamespaces(Context& io_rContext, xmlNodePtr pNode)
696 + // add node's namespaces to current context
697 + for (xmlNsPtr pNs = pNode->nsDef; pNs != 0; pNs = pNs->next) {
698 + const xmlChar *pPrefix = pNs->prefix;
699 + OString prefix(reinterpret_cast<const sal_Char*>(pPrefix),
700 + strlen(reinterpret_cast<const char*>(pPrefix)));
701 + const xmlChar *pHref = pNs->href;
702 + OUString val(reinterpret_cast<const sal_Char*>(pHref),
703 + strlen(reinterpret_cast<const char*>(pHref)),
704 + RTL_TEXTENCODING_UTF8);
706 + OSL_TRACE("Trying to add namespace %s (prefix %s)",
707 + (const char*)pHref, (const char*)pPrefix);
709 + Context::NamespaceMapType::iterator aIter=
710 + io_rContext.maNamespaceMap.find(val);
711 + if( aIter != io_rContext.maNamespaceMap.end() )
713 + Context::Namespace aNS;
714 + aNS.maPrefix = prefix;
715 + aNS.mnToken = aIter->second;
716 + aNS.maNamespaceURL = val;
718 + io_rContext.maNamespaces.back().push_back(aNS);
720 + OSL_TRACE("Added with token 0x%x", aIter->second);
725 + sal_Int32 getToken( const Context& rContext, const sal_Char* pToken )
727 + const Sequence<sal_Int8> aSeq( (sal_Int8*)pToken, strlen( pToken ) );
728 + return rContext.mxTokenHandler->getTokenFromUTF8( aSeq );
731 + sal_Int32 getTokenWithPrefix( const Context& rContext, const sal_Char* pPrefix, const sal_Char* pName )
733 + sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
734 + OString prefix(pPrefix,
735 + strlen(reinterpret_cast<const char*>(pPrefix)));
737 + OSL_TRACE("getTokenWithPrefix(): prefix %s, name %s",
738 + (const char*)pPrefix, (const char*)pName);
740 + Context::NamespaceVectorType::value_type::const_iterator aIter;
741 + if( (aIter=std::find_if(rContext.maNamespaces.back().begin(),
742 + rContext.maNamespaces.back().end(),
743 + boost::bind(std::equal_to<OString>(),
744 + boost::bind(&Context::Namespace::getPrefix,
745 + _1),
746 + boost::cref(prefix)))) != rContext.maNamespaces.back().end() )
748 + nNamespaceToken = aIter->mnToken;
749 + sal_Int32 nNameToken = getToken( rContext, pName );
750 + if( nNameToken != FastToken::DONTKNOW )
751 + nNamespaceToken |= nNameToken;
754 + return nNamespaceToken;
758 nodemap_t CNode::theNodeMap;
760 void CNode::remove(const xmlNodePtr aNode)
761 @@ -167,14 +247,13 @@ namespace DOM
763 xmlNodePtr CNode::getNodePtr(const Reference< XNode >& aNode)
765 - xmlNodePtr aNodePtr = 0;
766 try {
767 - Reference< XUnoTunnel > aTunnel(aNode, UNO_QUERY_THROW);
768 - sal_Int64 rawPtr = aTunnel->getSomething(Sequence<sal_Int8>());
769 - aNodePtr = reinterpret_cast<xmlNodePtr>(sal::static_int_cast<sal_IntPtr>(rawPtr));
770 - } catch ( ... ) {
771 + CNode* pNode=dynamic_cast<CNode*>(aNode.get());
772 + if( pNode )
773 + return pNode->m_aNodePtr;
775 - return aNodePtr;
776 + catch(...) {}
777 + return 0;
780 CNode::CNode()
781 @@ -280,6 +359,11 @@ namespace DOM
782 // default: do nothing
785 + void SAL_CALL CNode::fastSaxify(Context& io_rContext) {
786 + if (!io_rContext.mxDocHandler.is()) throw RuntimeException();
787 + // default: do nothing
790 /**
791 Adds the node newChild to the end of the list of children of this node.
793 @@ -894,14 +978,6 @@ namespace DOM
797 - sal_Int64 SAL_CALL CNode::getSomething(const Sequence< sal_Int8 >& /*id*/) throw (RuntimeException)
799 - // XXX check ID
800 - return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(m_aNodePtr));
801 - // return (sal_Int64)m_aNodePtr;
805 // --- XEventTarget
806 void SAL_CALL CNode::addEventListener(const OUString& eventType,
807 const Reference< com::sun::star::xml::dom::events::XEventListener >& listener,
808 diff --git unoxml/source/dom/node.hxx unoxml/source/dom/node.hxx
809 index 8752dad..8a22fbd 100644
810 --- unoxml/source/dom/node.hxx
811 +++ unoxml/source/dom/node.hxx
812 @@ -31,18 +31,19 @@
813 #ifndef _NODE_HXX
814 #define _NODE_HXX
816 -#include <map>
817 +#include <rtl/ref.hxx>
818 +#include <rtl/string.hxx>
819 +#include <rtl/ustring.hxx>
820 #include <sal/types.h>
821 +#include <sax/fastattribs.hxx>
822 #include <cppuhelper/implbase1.hxx>
823 #include <cppuhelper/implbase2.hxx>
824 -#include <cppuhelper/implbase3.hxx>
825 #include <com/sun/star/uno/Reference.h>
826 #include <com/sun/star/uno/Exception.hpp>
827 #include <com/sun/star/xml/dom/XNode.hpp>
828 #include <com/sun/star/xml/dom/XNodeList.hpp>
829 #include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
830 #include <com/sun/star/xml/dom/NodeType.hpp>
831 -#include <com/sun/star/lang/XUnoTunnel.hpp>
832 #include <com/sun/star/uno/Sequence.h>
833 #include <com/sun/star/xml/dom/events/XEventTarget.hpp>
834 #include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
835 @@ -51,23 +52,72 @@
836 #include <com/sun/star/xml/dom/events/XUIEvent.hpp>
837 #include <com/sun/star/xml/dom/events/XMouseEvent.hpp>
838 #include <com/sun/star/xml/dom/DOMException.hpp>
839 -#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
840 +#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
841 +#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
842 #include <libxml/tree.h>
844 +#include <map>
845 +#include <hash_map>
847 using ::rtl::OUString;
848 +using ::rtl::OString;
849 +using namespace sax_fastparser;
850 using namespace com::sun::star::uno;
851 using namespace com::sun::star::xml::sax;
852 using namespace com::sun::star::xml::dom;
853 using namespace com::sun::star::xml::dom::events;
854 -using com::sun::star::lang::XUnoTunnel;
856 namespace DOM
858 + struct Context
860 + Context( const Reference< XFastDocumentHandler >& i_xHandler,
861 + const Reference< XFastTokenHandler >& i_xTokenHandler ) :
862 + maNamespaces( 1, std::vector<Namespace>() ),
863 + maNamespaceMap(101),
864 + mxAttribList(new FastAttributeList(i_xTokenHandler)),
865 + mxCurrentHandler(i_xHandler, UNO_QUERY_THROW),
866 + mxDocHandler(i_xHandler),
867 + mxTokenHandler(i_xTokenHandler)
868 + {}
870 + struct Namespace
872 + OString maPrefix;
873 + sal_Int32 mnToken;
874 + OUString maNamespaceURL;
876 + const OString& getPrefix() const { return maPrefix; }
877 + };
879 + typedef std::vector< std::vector<Namespace> > NamespaceVectorType;
880 + typedef std::hash_map< OUString,
881 + sal_Int32,
882 + rtl::OUStringHash > NamespaceMapType;
884 + /// outer vector: xml context; inner vector: current NS
885 + NamespaceVectorType maNamespaces;
886 + NamespaceMapType maNamespaceMap;
887 + ::rtl::Reference<FastAttributeList> mxAttribList;
888 + Reference<XFastContextHandler> mxCurrentHandler;
889 + Reference<XFastDocumentHandler> mxDocHandler;
890 + Reference<XFastTokenHandler> mxTokenHandler;
891 + };
893 + void pushContext(Context& io_rContext);
894 + void popContext(Context& io_rContext);
896 + sal_Int32 getTokenWithPrefix( const Context& rContext, const sal_Char* xPrefix, const sal_Char* xName );
897 + sal_Int32 getToken( const Context& rContext, const sal_Char* xName );
899 + /// add namespaces on this node to context
900 + void addNamespaces(Context& io_rContext, xmlNodePtr pNode);
902 class CNode;
903 typedef std::map< const xmlNodePtr, CNode* > nodemap_t;
906 - class CNode : public cppu::WeakImplHelper3< XNode, XUnoTunnel, XEventTarget >
907 + class CNode : public cppu::WeakImplHelper2< XNode, XEventTarget >
909 friend class CDocument;
910 friend class CElement;
911 @@ -109,6 +159,9 @@ namespace DOM
912 virtual void SAL_CALL saxify(
913 const Reference< XDocumentHandler >& i_xHandler);
915 + // recursively create SAX events
916 + virtual void SAL_CALL fastSaxify( Context& io_rContext );
918 // ---- DOM interfaces
921 @@ -275,9 +328,6 @@ namespace DOM
922 throw (RuntimeException, DOMException);
925 - // --- XUnoTunnel
926 - virtual sal_Int64 SAL_CALL getSomething(const Sequence< sal_Int8 >& id) throw (RuntimeException);
928 // --- XEventTarget
929 virtual void SAL_CALL addEventListener(const OUString& eventType,
930 const Reference< XEventListener >& listener,
931 diff --git unoxml/source/dom/notation.hxx unoxml/source/dom/notation.hxx
932 index 13cd6be..d25d501 100644
933 --- unoxml/source/dom/notation.hxx
934 +++ unoxml/source/dom/notation.hxx
935 @@ -37,7 +37,7 @@
936 #include "node.hxx"
937 #include <libxml/tree.h>
939 -using namespace rtl;
940 +using ::rtl::OUString;
941 using namespace com::sun::star::uno;
942 using namespace com::sun::star::xml::dom;
944 diff --git unoxml/source/dom/notationsmap.hxx unoxml/source/dom/notationsmap.hxx
945 index 2adbbc0..170c3b2 100644
946 --- unoxml/source/dom/notationsmap.hxx
947 +++ unoxml/source/dom/notationsmap.hxx
948 @@ -41,7 +41,7 @@
949 #include "document.hxx"
950 #include "documenttype.hxx"
952 -using namespace rtl;
953 +using ::rtl::OUString;
954 using namespace com::sun::star::uno;
955 using namespace com::sun::star::xml::dom;
957 diff --git unoxml/source/dom/processinginstruction.cxx unoxml/source/dom/processinginstruction.cxx
958 index f06d153..791b408 100644
959 --- unoxml/source/dom/processinginstruction.cxx
960 +++ unoxml/source/dom/processinginstruction.cxx
961 @@ -29,6 +29,7 @@
962 ************************************************************************/
964 #include "processinginstruction.hxx"
965 +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
966 #include <string.h>
968 namespace DOM
969 diff --git unoxml/source/dom/processinginstruction.hxx unoxml/source/dom/processinginstruction.hxx
970 index 1ae7657..780fe55 100644
971 --- unoxml/source/dom/processinginstruction.hxx
972 +++ unoxml/source/dom/processinginstruction.hxx
973 @@ -37,7 +37,7 @@
974 #include "node.hxx"
975 #include <libxml/tree.h>
977 -using namespace rtl;
978 +using ::rtl::OUString;
979 using namespace com::sun::star::uno;
980 using namespace com::sun::star::xml::dom;
982 diff --git unoxml/source/dom/saxbuilder.cxx unoxml/source/dom/saxbuilder.cxx
983 index 5f42666..e1169cc 100644
984 --- unoxml/source/dom/saxbuilder.cxx
985 +++ unoxml/source/dom/saxbuilder.cxx
986 @@ -35,7 +35,6 @@
987 #include "saxbuilder.hxx"
988 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
989 #include <libxml/tree.h>
990 -#include <com/sun/star/lang/XUnoTunnel.hpp>
991 #include <com/sun/star/uno/Sequence.h>
993 namespace DOM
994 diff --git unoxml/source/dom/saxbuilder.hxx unoxml/source/dom/saxbuilder.hxx
995 index a955035..afa8320 100644
996 --- unoxml/source/dom/saxbuilder.hxx
997 +++ unoxml/source/dom/saxbuilder.hxx
998 @@ -54,7 +54,7 @@
1000 #include "libxml/tree.h"
1002 -using namespace rtl;
1003 +using ::rtl::OUString;
1004 using namespace com::sun::star::uno;
1005 using namespace com::sun::star::xml::dom;
1006 using namespace com::sun::star::xml::sax;
1007 diff --git unoxml/source/dom/text.cxx unoxml/source/dom/text.cxx
1008 index 250b31e..6574a45 100644
1009 --- unoxml/source/dom/text.cxx
1010 +++ unoxml/source/dom/text.cxx
1011 @@ -58,5 +58,18 @@ namespace DOM
1013 return OUString::createFromAscii("#text");
1016 + void SAL_CALL CText::fastSaxify( Context& io_rContext )
1018 + if( io_rContext.mxCurrentHandler.is() )
1020 + try
1022 + io_rContext.mxCurrentHandler->characters( getData() );
1024 + catch( Exception& )
1025 + {}
1030 diff --git unoxml/source/dom/text.hxx unoxml/source/dom/text.hxx
1031 index 27596f3..ff84a62 100644
1032 --- unoxml/source/dom/text.hxx
1033 +++ unoxml/source/dom/text.hxx
1034 @@ -41,7 +41,7 @@
1035 #include <libxml/tree.h>
1036 #include "characterdata.hxx"
1038 -using namespace rtl;
1039 +using ::rtl::OUString;
1040 using namespace com::sun::star::uno;
1041 using namespace com::sun::star::lang;
1042 using namespace com::sun::star::xml::dom;
1043 @@ -62,6 +62,8 @@ namespace DOM
1044 virtual void SAL_CALL saxify(
1045 const Reference< XDocumentHandler >& i_xHandler);
1047 + virtual void SAL_CALL fastSaxify( Context& io_rContext );
1049 // Breaks this node into two nodes at the specified offset, keeping
1050 // both in the tree as siblings.
1051 virtual Reference< XText > SAL_CALL splitText(sal_Int32 offset)
1052 diff --git unoxml/source/events/mouseevent.hxx unoxml/source/events/mouseevent.hxx
1053 index a3d4f37..b4a9ade 100644
1054 --- unoxml/source/events/mouseevent.hxx
1055 +++ unoxml/source/events/mouseevent.hxx
1056 @@ -15,7 +15,7 @@
1057 #include "event.hxx"
1058 #include "uievent.hxx"
1060 -using namespace rtl;
1061 +using ::rtl::OUString;
1063 namespace DOM { namespace events {
1065 diff --git unoxml/source/events/mutationevent.hxx unoxml/source/events/mutationevent.hxx
1066 index d20c246..5ff545f 100644
1067 --- unoxml/source/events/mutationevent.hxx
1068 +++ unoxml/source/events/mutationevent.hxx
1069 @@ -13,7 +13,7 @@
1070 #include <com/sun/star/xml/dom/events/XMutationEvent.hpp>
1071 #include "event.hxx"
1073 -using namespace rtl;
1074 +using ::rtl::OUString;
1076 namespace DOM { namespace events {
1078 diff --git unoxml/source/events/testlistener.hxx unoxml/source/events/testlistener.hxx
1079 index 7a9d16c..2e12a1a 100644
1080 --- unoxml/source/events/testlistener.hxx
1081 +++ unoxml/source/events/testlistener.hxx
1082 @@ -54,7 +54,7 @@
1084 #include "libxml/tree.h"
1086 -using namespace rtl;
1087 +using ::rtl::OUString;
1088 using namespace com::sun::star::uno;
1089 using namespace com::sun::star::lang;
1090 using namespace com::sun::star::xml::dom;
1091 diff --git unoxml/source/events/uievent.hxx unoxml/source/events/uievent.hxx
1092 index ba34a96..d9cd5cc 100644
1093 --- unoxml/source/events/uievent.hxx
1094 +++ unoxml/source/events/uievent.hxx
1095 @@ -14,7 +14,7 @@
1096 #include <com/sun/star/xml/dom/views/XAbstractView.hpp>
1097 #include "event.hxx"
1099 -using namespace rtl;
1100 +using ::rtl::OUString;
1101 using namespace com::sun::star::xml::dom::views;
1103 namespace DOM { namespace events {
1104 diff --git unoxml/source/service/makefile.mk unoxml/source/service/makefile.mk
1105 index 4cc13a4..363f4b3 100644
1106 --- unoxml/source/service/makefile.mk
1107 +++ unoxml/source/service/makefile.mk
1108 @@ -73,6 +73,7 @@ SHL1STDLIBS= \
1109 $(COMPHELPERLIB) \
1110 $(CPPUHELPERLIB) \
1111 $(CPPULIB) \
1112 + $(SAXLIB) \
1113 $(SALLIB)\
1114 $(EXPATASCII3RDLIB)
1116 diff --git unoxml/source/xpath/nodelist.hxx unoxml/source/xpath/nodelist.hxx
1117 index 6b94f99..336a611 100644
1118 --- unoxml/source/xpath/nodelist.hxx
1119 +++ unoxml/source/xpath/nodelist.hxx
1120 @@ -43,7 +43,7 @@
1121 #include "libxml/xpath.h"
1122 #include <boost/shared_ptr.hpp>
1124 -using namespace rtl;
1125 +using ::rtl::OUString;
1126 using namespace com::sun::star::uno;
1127 using namespace com::sun::star::lang;
1128 using namespace com::sun::star::xml::dom;
1129 diff --git unoxml/source/xpath/xpathapi.hxx unoxml/source/xpath/xpathapi.hxx
1130 index 4291728..29e5461 100644
1131 --- unoxml/source/xpath/xpathapi.hxx
1132 +++ unoxml/source/xpath/xpathapi.hxx
1133 @@ -52,11 +52,10 @@
1134 #include <com/sun/star/lang/XServiceInfo.hpp>
1135 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
1136 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
1137 -#include <com/sun/star/lang/XUnoTunnel.hpp>
1139 #include "libxml/tree.h"
1141 -using namespace rtl;
1142 +using ::rtl::OUString;
1143 using namespace com::sun::star::uno;
1144 using namespace com::sun::star::lang;
1145 using namespace com::sun::star::xml::dom;
1146 diff --git unoxml/source/xpath/xpathobject.hxx unoxml/source/xpath/xpathobject.hxx
1147 index 94cba5f..ac7e5fb 100644
1148 --- unoxml/source/xpath/xpathobject.hxx
1149 +++ unoxml/source/xpath/xpathobject.hxx
1150 @@ -43,7 +43,7 @@
1151 #include <libxml/xpath.h>
1152 #include <boost/shared_ptr.hpp>
1154 -using namespace rtl;
1155 +using ::rtl::OUString;
1156 using namespace com::sun::star::uno;
1157 using namespace com::sun::star::lang;
1158 using namespace com::sun::star::xml::dom;
1159 diff --git unoxml/test/domtest.cxx unoxml/test/domtest.cxx
1160 new file mode 100644
1161 index 0000000..9b9c302
1162 --- /dev/null
1163 +++ unoxml/test/domtest.cxx
1164 @@ -0,0 +1,402 @@
1165 +/*************************************************************************
1167 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1168 + *
1169 + * Copyright 2008 by Sun Microsystems, Inc.
1171 + * OpenOffice.org - a multi-platform office productivity suite
1173 + * $RCSfile: basictest.cxx,v $
1174 + * $Revision: 1.12 $
1176 + * This file is part of OpenOffice.org.
1178 + * OpenOffice.org is free software: you can redistribute it and/or modify
1179 + * it under the terms of the GNU Lesser General Public License version 3
1180 + * only, as published by the Free Software Foundation.
1182 + * OpenOffice.org is distributed in the hope that it will be useful,
1183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1185 + * GNU Lesser General Public License version 3 for more details
1186 + * (a copy is included in the LICENSE file that accompanied this code).
1188 + * You should have received a copy of the GNU Lesser General Public License
1189 + * version 3 along with OpenOffice.org. If not, see
1190 + * <http://www.openoffice.org/license.html>
1191 + * for a copy of the LGPLv3 License.
1193 + ************************************************************************/
1195 +// autogenerated file with codegen.pl
1197 +#include <cppunit/simpleheader.hxx>
1199 +#include <rtl/ref.hxx>
1200 +#include <osl/file.hxx>
1201 +#include <osl/process.h>
1202 +#include <comphelper/seqstream.hxx>
1203 +#include <comphelper/sequence.hxx>
1204 +#include <cppuhelper/compbase1.hxx>
1205 +#include <cppuhelper/bootstrap.hxx>
1206 +#include <cppuhelper/basemutex.hxx>
1208 +#include <com/sun/star/xml/sax/FastToken.hpp>
1209 +#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
1210 +#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
1212 +#include "../source/dom/documentbuilder.hxx"
1215 +using namespace ::DOM;
1216 +using namespace ::comphelper;
1217 +using namespace ::com::sun::star;
1219 +namespace
1222 +// valid xml
1223 +static const char validTestFile[] =
1224 +"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
1225 + <office:document-content \
1226 + xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
1227 + xmlns:xlink=\"http://www.w3.org/1999/xlink\" \
1228 + office:version=\"1.0\"> \
1229 + <office:scripts/> \
1230 + <xlink:test/> \
1231 + <office:automatic-styles teststyle=\"test\"/> \
1232 + <moretest/> \
1233 + some text öäü \
1234 + </office:document-content> \
1237 +// generates a warning: unsupported xml version, unknown xml:space
1238 +// value
1239 +static const char warningTestFile[] =
1240 +"<?xml version=\"47-11.0\" encoding=\"UTF-8\"?> \
1241 + <office:document-content \
1242 + xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
1243 + xml:space=\"blafasl\" \
1244 + office:version=\"1.0\"> \
1245 + <office:scripts/> \
1246 + <office:automatic-styles/> \
1247 + </office:document-content> \
1250 +// <?xml not at start of file
1251 +static const char errorTestFile[] =
1252 +" <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
1253 + <office:document-content \
1254 + xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" \
1255 + office:version=\"1.0\"> \
1256 + <office:scripts/> \
1257 + <office:automatic-styles/> \
1258 + </office:document-content> \
1261 +// plain empty
1262 +static const char fatalTestFile[] = "";
1264 +struct ErrorHandler
1265 + : public ::cppu::WeakImplHelper1< xml::sax::XErrorHandler >
1267 + sal_uInt32 mnErrCount;
1268 + sal_uInt32 mnFatalCount;
1269 + sal_uInt32 mnWarnCount;
1271 + bool noErrors() const { return !mnErrCount && !mnFatalCount && !mnWarnCount; }
1273 + ErrorHandler() : mnErrCount(0), mnFatalCount(0), mnWarnCount(0)
1274 + {}
1276 + virtual void SAL_CALL error( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
1278 + ++mnErrCount;
1281 + virtual void SAL_CALL fatalError( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
1283 + ++mnFatalCount;
1286 + virtual void SAL_CALL warning( const uno::Any& ) throw (xml::sax::SAXException, uno::RuntimeException)
1288 + ++mnWarnCount;
1292 +struct DocumentHandler
1293 + : public ::cppu::WeakImplHelper1< xml::sax::XFastDocumentHandler >
1295 + // XFastContextHandler
1296 + virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList >& Attribs ) throw (xml::sax::SAXException, uno::RuntimeException)
1298 + OSL_TRACE("Seen element: %c with namespace 0x%x",
1299 + Element & 0xFFFF, Element & 0xFFFF0000);
1302 + 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)
1306 + virtual void SAL_CALL endFastElement( ::sal_Int32 Element ) throw (xml::sax::SAXException, uno::RuntimeException)
1310 + virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name ) throw (xml::sax::SAXException, uno::RuntimeException)
1314 + 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)
1316 + return this;
1319 + 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)
1321 + return this;
1324 + virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException)
1328 + // XFastDocumentHandler
1329 + virtual void SAL_CALL startDocument( ) throw (xml::sax::SAXException, uno::RuntimeException)
1333 + virtual void SAL_CALL endDocument( ) throw (xml::sax::SAXException, uno::RuntimeException)
1337 + virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException)
1342 +struct TokenHandler
1343 + : public ::cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
1345 + virtual ::sal_Int32 SAL_CALL getToken( const ::rtl::OUString& Identifier ) throw (uno::RuntimeException)
1347 + CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getToken() unexpected call",
1348 + false );
1349 + return -1;
1352 + virtual ::rtl::OUString SAL_CALL getIdentifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
1354 + CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getIdentifier() unexpected call",
1355 + false );
1356 + return rtl::OUString();
1359 + virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) throw (uno::RuntimeException)
1361 + OSL_TRACE("getTokenFromUTF8() %s", (const char*)Identifier.getConstArray());
1362 + return Identifier.getLength() ? Identifier[0] : 0;
1365 + virtual uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier( ::sal_Int32 Token ) throw (uno::RuntimeException)
1367 + CPPUNIT_ASSERT_MESSAGE( "TokenHandler::getUTF8Identifier() unexpected call",
1368 + false );
1369 + return uno::Sequence<sal_Int8>();
1373 +struct BasicTest : public CppUnit::TestFixture
1375 + rtl::Reference<CDocumentBuilder> mxDomBuilder;
1376 + rtl::Reference<ErrorHandler> mxErrHandler;
1377 + rtl::Reference<SequenceInputStream> mxValidInStream;
1378 + rtl::Reference<SequenceInputStream> mxWarningInStream;
1379 + rtl::Reference<SequenceInputStream> mxErrorInStream;
1380 + rtl::Reference<SequenceInputStream> mxFatalInStream;
1382 + void setUp()
1384 + // luckily, DOM builder doesn't use service fac, so we need
1385 + // not bootstrap uno here
1386 + mxErrHandler.set( new ErrorHandler() );
1387 + mxDomBuilder.set( new CDocumentBuilder(Reference< XMultiServiceFactory >() ));
1388 + mxValidInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
1389 + sizeof(validTestFile)/sizeof(*validTestFile))) );
1390 + mxWarningInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)warningTestFile,
1391 + sizeof(warningTestFile)/sizeof(*warningTestFile))) );
1392 + mxErrorInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)errorTestFile,
1393 + sizeof(errorTestFile)/sizeof(*errorTestFile))) );
1394 + mxFatalInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)fatalTestFile,
1395 + sizeof(fatalTestFile)/sizeof(*fatalTestFile))) );
1396 + mxDomBuilder->setErrorHandler(mxErrHandler.get());
1399 + void validInputTest()
1400 + {
1401 + CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #1",
1402 + mxDomBuilder->parse(
1403 + uno::Reference<io::XInputStream>(
1404 + mxValidInStream.get())).is() );
1405 + CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
1406 + mxErrHandler->noErrors() );
1409 + void warningInputTest()
1411 + CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #2",
1412 + mxDomBuilder->parse(
1413 + uno::Reference<io::XInputStream>(
1414 + mxWarningInStream.get())).is() );
1415 + CPPUNIT_ASSERT_MESSAGE( "No parse warnings in unclean input file",
1416 + mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
1419 + void errorInputTest()
1420 + {
1421 + CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument #3",
1422 + mxDomBuilder->parse(
1423 + uno::Reference<io::XInputStream>(
1424 + mxErrorInStream.get())).is() );
1425 + CPPUNIT_ASSERT_MESSAGE( "No parse errors in unclean input file",
1426 + !mxErrHandler->mnWarnCount && mxErrHandler->mnErrCount && !mxErrHandler->mnFatalCount );
1429 + void fatalInputTest()
1430 + {
1431 + CPPUNIT_ASSERT_MESSAGE( "Broken input file resulted in XDocument",
1432 + !mxDomBuilder->parse(
1433 + uno::Reference<io::XInputStream>(
1434 + mxFatalInStream.get())).is() );
1435 + CPPUNIT_ASSERT_MESSAGE( "No fatal parse errors in unclean input file",
1436 + !mxErrHandler->mnWarnCount && !mxErrHandler->mnErrCount && mxErrHandler->mnFatalCount );
1437 + };
1439 + // Change the following lines only, if you add, remove or rename
1440 + // member functions of the current class,
1441 + // because these macros are need by auto register mechanism.
1442 + CPPUNIT_TEST_SUITE(BasicTest);
1443 + CPPUNIT_TEST(validInputTest);
1444 + CPPUNIT_TEST(warningInputTest);
1445 + CPPUNIT_TEST(errorInputTest);
1446 + CPPUNIT_TEST(fatalInputTest);
1447 + CPPUNIT_TEST_SUITE_END();
1450 +struct SerializerTest : public CppUnit::TestFixture
1452 + SerializerTest() : mbUnoInitialized(false) {}
1454 + uno::Reference<uno::XComponentContext> mxCtx;
1455 + rtl::Reference<CDocumentBuilder> mxDomBuilder;
1456 + rtl::Reference<ErrorHandler> mxErrHandler;
1457 + rtl::Reference<SequenceInputStream> mxInStream;
1458 + rtl::Reference<DocumentHandler> mxHandler;
1459 + rtl::Reference<TokenHandler> mxTokHandler;
1460 + uno::Sequence< beans::Pair< rtl::OUString, sal_Int32 > > maRegisteredNamespaces;
1461 + bool mbUnoInitialized;
1463 + void setUp()
1465 + // need working typelib, bootstrap UNO now
1466 + if( !mbUnoInitialized )
1468 + const char* pArgs( getForwardString() );
1469 + CPPUNIT_ASSERT_MESSAGE("Test file parameter", pArgs);
1471 + const rtl::OUString sBaseDir=rtl::OUString::createFromAscii(pArgs);
1473 + // bootstrap UNO
1474 + try
1476 + ::rtl::OUString aIniUrl;
1477 + CPPUNIT_ASSERT_MESSAGE(
1478 + "Converting ini file to URL",
1479 + osl_getFileURLFromSystemPath(
1480 + (sBaseDir+rtl::OUString::createFromAscii("unoxml_unittest_test.ini")).pData,
1481 + &aIniUrl.pData ) == osl_File_E_None );
1483 + mxCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
1484 + CPPUNIT_ASSERT_MESSAGE("Getting component context", mxCtx.is());
1486 + catch( uno::Exception& )
1488 + CPPUNIT_ASSERT_MESSAGE("Bootstrapping UNO", false);
1491 + mbUnoInitialized = true;
1494 + mxErrHandler.set( new ErrorHandler() );
1495 + mxDomBuilder.set( new CDocumentBuilder(
1496 + uno::Reference< lang::XMultiServiceFactory >(
1497 + mxCtx->getServiceManager(),
1498 + uno::UNO_QUERY )));
1499 + mxInStream.set( new SequenceInputStream(ByteSequence((sal_Int8*)validTestFile,
1500 + sizeof(validTestFile)/sizeof(*validTestFile))) );
1501 + mxDomBuilder->setErrorHandler(mxErrHandler.get());
1503 + mxHandler.set( new DocumentHandler() );
1504 + mxTokHandler.set( new TokenHandler() );
1506 + maRegisteredNamespaces.realloc(2);
1507 + maRegisteredNamespaces[0] = beans::make_Pair(
1508 + rtl::OUString(
1509 + RTL_CONSTASCII_USTRINGPARAM(
1510 + "urn:oasis:names:tc:opendocument:xmlns:office:1.0") ),
1511 + xml::sax::FastToken::NAMESPACE);
1512 + maRegisteredNamespaces[1] = beans::make_Pair(
1513 + rtl::OUString(
1514 + RTL_CONSTASCII_USTRINGPARAM(
1515 + "http://www.w3.org/1999/xlink") ),
1516 + 2*xml::sax::FastToken::NAMESPACE);
1519 + void serializerTest ()
1520 + {
1521 + uno::Reference< xml::dom::XDocument > xDoc=
1522 + mxDomBuilder->parse(
1523 + uno::Reference<io::XInputStream>(
1524 + mxInStream.get()));
1525 + CPPUNIT_ASSERT_MESSAGE( "Valid input file did not result in XDocument",
1526 + xDoc.is() );
1527 + CPPUNIT_ASSERT_MESSAGE( "Valid input file resulted in parse errors",
1528 + mxErrHandler->noErrors() );
1530 + uno::Reference< xml::sax::XSAXSerializable > xSaxSerializer(
1531 + xDoc, uno::UNO_QUERY);
1532 + CPPUNIT_ASSERT_MESSAGE( "XSAXSerializable not supported",
1533 + xSaxSerializer.is() );
1535 + uno::Reference< xml::sax::XFastSAXSerializable > xFastSaxSerializer(
1536 + xDoc, uno::UNO_QUERY);
1537 + CPPUNIT_ASSERT_MESSAGE( "XFastSAXSerializable not supported",
1538 + xSaxSerializer.is() );
1540 + xFastSaxSerializer->fastSerialize( mxHandler.get(),
1541 + mxTokHandler.get(),
1542 + uno::Sequence< beans::StringPair >(),
1543 + maRegisteredNamespaces );
1546 + // Change the following lines only, if you add, remove or rename
1547 + // member functions of the current class,
1548 + // because these macros are need by auto register mechanism.
1550 + CPPUNIT_TEST_SUITE(SerializerTest);
1551 + CPPUNIT_TEST(serializerTest);
1552 + CPPUNIT_TEST_SUITE_END();
1555 +// -----------------------------------------------------------------------------
1556 +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
1557 +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SerializerTest, "SerializerTest");
1561 +// -----------------------------------------------------------------------------
1563 +// this macro creates an empty function, which will called by the RegisterAllFunctions()
1564 +// to let the user the possibility to also register some functions by hand.
1565 +NOADDITIONAL;
1567 diff --git unoxml/test/export.map unoxml/test/export.map
1568 new file mode 100644
1569 index 0000000..0bc81ba
1570 --- /dev/null
1571 +++ unoxml/test/export.map
1572 @@ -0,0 +1,38 @@
1573 +#*************************************************************************
1575 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1577 +# Copyright 2008 by Sun Microsystems, Inc.
1579 +# OpenOffice.org - a multi-platform office productivity suite
1581 +# $RCSfile: export.map,v $
1583 +# $Revision: 1.2 $
1585 +# This file is part of OpenOffice.org.
1587 +# OpenOffice.org is free software: you can redistribute it and/or modify
1588 +# it under the terms of the GNU Lesser General Public License version 3
1589 +# only, as published by the Free Software Foundation.
1591 +# OpenOffice.org is distributed in the hope that it will be useful,
1592 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1593 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1594 +# GNU Lesser General Public License version 3 for more details
1595 +# (a copy is included in the LICENSE file that accompanied this code).
1597 +# You should have received a copy of the GNU Lesser General Public License
1598 +# version 3 along with OpenOffice.org. If not, see
1599 +# <http://www.openoffice.org/license.html>
1600 +# for a copy of the LGPLv3 License.
1602 +#*************************************************************************
1604 +UDK_3.1 {
1605 + global:
1606 + registerAllTestFunction;
1608 + local:
1609 + *;
1611 diff --git unoxml/test/makefile.mk unoxml/test/makefile.mk
1612 new file mode 100644
1613 index 0000000..2c1c784
1614 --- /dev/null
1615 +++ unoxml/test/makefile.mk
1616 @@ -0,0 +1,106 @@
1617 +#*************************************************************************
1619 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1621 +# Copyright 2008 by Sun Microsystems, Inc.
1623 +# OpenOffice.org - a multi-platform office productivity suite
1625 +# $RCSfile: makefile.mk,v $
1627 +# $Revision: 1.9 $
1629 +# This file is part of OpenOffice.org.
1631 +# OpenOffice.org is free software: you can redistribute it and/or modify
1632 +# it under the terms of the GNU Lesser General Public License version 3
1633 +# only, as published by the Free Software Foundation.
1635 +# OpenOffice.org is distributed in the hope that it will be useful,
1636 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1637 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1638 +# GNU Lesser General Public License version 3 for more details
1639 +# (a copy is included in the LICENSE file that accompanied this code).
1641 +# You should have received a copy of the GNU Lesser General Public License
1642 +# version 3 along with OpenOffice.org. If not, see
1643 +# <http://www.openoffice.org/license.html>
1644 +# for a copy of the LGPLv3 License.
1646 +#*************************************************************************
1648 +PRJ=..
1650 +PRJNAME=unoxml
1651 +TARGET=tests
1652 +TARGETTYPE=GUI
1654 +ENABLE_EXCEPTIONS=TRUE
1656 +# --- Settings -----------------------------------------------------
1658 +.INCLUDE : settings.mk
1660 +# --- Common ----------------------------------------------------------
1662 +# BEGIN ----------------------------------------------------------------
1663 +# auto generated Target:tests by codegen.pl
1664 +SHL1OBJS= \
1665 + $(SLO)$/domtest.obj
1667 +# the following three libs are a bit of a hack: cannot link against
1668 +# unoxml here, because not yet delivered (and does not export
1669 +# ~anything). Need the functionality to test, so we're linking it in
1670 +# statically. Need to keep this in sync with
1671 +# source/services/makefile.mk
1672 +SHL1LIBS= \
1673 + $(SLB)$/domimpl.lib \
1674 + $(SLB)$/xpathimpl.lib \
1675 + $(SLB)$/eventsimpl.lib
1677 +SHL1TARGET= tests
1678 +SHL1STDLIBS= \
1679 + $(UCBHELPERLIB) \
1680 + $(LIBXML2LIB) \
1681 + $(TOOLSLIB) \
1682 + $(COMPHELPERLIB) \
1683 + $(CPPUHELPERLIB) \
1684 + $(CPPUNITLIB) \
1685 + $(CPPULIB) \
1686 + $(SAXLIB) \
1687 + $(SALLIB)\
1688 + $(EXPATASCII3RDLIB)
1690 +SHL1IMPLIB= i$(SHL1TARGET)
1692 +DEF1NAME =$(SHL1TARGET)
1693 +SHL1VERSIONMAP = export.map
1695 +# END ------------------------------------------------------------------
1697 +#------------------------------- All object files -------------------------------
1698 +# do this here, so we get right dependencies
1699 +SLOFILES=$(SHL1OBJS)
1701 +# --- Targets ------------------------------------------------------
1703 +.INCLUDE : target.mk
1704 +.INCLUDE : _cppunit.mk
1706 +# --- Fake uno bootstrap ------------------------
1708 +$(BIN)$/unoxml_unittest_test.ini : makefile.mk
1709 + rm -f $@
1710 + @echo UNO_SERVICES= > $@
1711 + @echo UNO_TYPES=$(UNOUCRRDB:s/\/\\/) >> $@
1713 +# --- Enable testshl2 execution in normal build ------------------------
1715 +$(MISC)$/unoxml_unittest_succeeded : $(SHL1TARGETN) $(BIN)$/unoxml_unittest_test.ini
1716 + @echo ----------------------------------------------------------
1717 + @echo - start unit test on library $(SHL1TARGETN)
1718 + @echo ----------------------------------------------------------
1719 + testshl2 -forward $(BIN)$/ -sf $(mktmp ) $(SHL1TARGETN)
1720 + $(TOUCH) $@
1722 +ALLTAR : $(MISC)$/unoxml_unittest_succeeded