Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


(I'm sending this again directly to the list, as it somehow didn't show up there)
----
Hi Jan, 

sorry for responding late, work and life and everything else have been
keeping me busy. 


Am Mittwoch, den 05.01.2011, 16:32 +0100 schrieb Jan Holesovsky:
Hi Peter,

Jan Holesovsky píše v Út 04. 01. 2011 v 11:13 +0100:

[...]
Thanks a lot - looks great on the first sight :-)  Let me look a bit
better (unless somebody else volunteers to do a deeper review?) now.

Thanks!
 
Before pushing it to the master branch, I'd like to ask you for 2
things:

License: Please, do you agree to license under the MPL / LGPL / GPL
combo, as recommended in
http://cgit.freedesktop.org/libreoffice/build/tree/COPYING.NEWFILES

Done.
Purpose documentation: Can you please add a brief description of the new
classes in the header?  Just something like:

Done.

I looked mainly at the parts that are about defaulting to your
implementation, or the Java xslt filter, and it looks good to me, so I'd
push it as soon as you let us know regarding the license :-)

One more nitpick that I spotted is that you use { and } differently to
the rest of the code base (we use opening { on a new line, and skip
{ and } if an if/for/while has only one command), would be great if you
can change it too; but of course that is not a blocker for pushing your
changes ;-)


That's 10 years of Java. I now discovered Eclipse offers 4 different
formatting styles for source code and the GNU style seems to almost fit,
so I'm just formatting using that now.

Also, is there a special reason for ListenerList l = m_listeners; on few
occasions?  Didn't you want to use a reference?

Again, Java. I changed it to be references now. 

Thank you a lot,
Kendy

Hey, thanks!

I'd propose to proceed as follows: 

- Replace FlatXML Export with a pure XML Filter implementation based on
the SDK example.

@Gioele: my take on the flat xml export is that it's not meant to be
read by humans, but to be fed to some xml processor (like an xslt
transformer for example). So I'd suggest making the XSLT based flat xml
export an extension. But then again I've never been working with flat
xml export, so I might be ignorant of the most important usage
patterns ;-) What do you think?

Then...
- Come up with a better idea to control which implementation is being
used

- Add a libxslt based xslt validation service. 

I've dug a little bit deeper into the existing xslt filters and 3rd
party implementations of xslt transformations for OpenDocument and found
that the wordml/office 2003 xml export uses an xslt 2.0 script (although
I didn't check to what extent xslt 2.0 features are actually beeing
used. It may well be possible that the script can easily be rewritten to
use libxslt's EXSLT functions. But it might as well be not ;-)
As long as I don't figure wether that's possible with reasonable effort
it doesn't make sense to touch the Java implemented Saxon extension
functions.

Text Encoding Initiative (TEI) also uses XSLT 2.0 for their filters
since 2009, so maybe we'll have to keep the java/saxon implementation
around for a while. But maybe it'll be possible to make it an extension,
so the default filter implementation shipped with LibreOffice doesn't
require Java at all. 

And, ah, the patch. I'll prepare that... Ok.

So, thanks again for having a look at the code, and I'm looking forward
to further hacking on this :-)

Cheers, 

Peter



_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


From f3e5ff4c1ec9ecc01f92263f6fbe9a3f35dcfb16 Mon Sep 17 00:00:00 2001
From: Peter Jentsch <pjotr@guineapics.de>
Date: Sun, 2 Jan 2011 14:02:18 +0100
Subject: [PATCH 1/4] Added support for libxslt in xsltfilter

libxslt will be used to perform xsl transformations if either Java is
not available/configured at compile time or the 2nd, currently unused
"UserData" parameter of the xslt filter is "libxslt" (w/o the quotes)
---
 filter/source/xsltfilter/LibXSLTTransformer.cxx |  282 +++++++++++++++++++++++
 filter/source/xsltfilter/LibXSLTTransformer.hxx |  145 ++++++++++++
 filter/source/xsltfilter/XSLTFilter.cxx         |  129 +++++++----
 filter/source/xsltfilter/makefile.mk            |   16 ++-
 4 files changed, 526 insertions(+), 46 deletions(-)
 create mode 100644 filter/source/xsltfilter/LibXSLTTransformer.cxx
 create mode 100644 filter/source/xsltfilter/LibXSLTTransformer.hxx

diff --git a/filter/source/xsltfilter/LibXSLTTransformer.cxx 
b/filter/source/xsltfilter/LibXSLTTransformer.cxx
new file mode 100644
index 0000000..da51908
--- /dev/null
+++ b/filter/source/xsltfilter/LibXSLTTransformer.cxx
@@ -0,0 +1,282 @@
+ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+ #include "precompiled_filter.hxx"
+
+ #include <stdio.h>
+ #include <list>
+ #include <map>
+ #include <iostream>
+ #include <libxml/parser.h>
+ #include <libxml/tree.h>
+ #include <libxml/xmlIO.h>
+ #include <libxslt/transform.h>
+ #include <libxslt/xsltutils.h>
+ #include <libxslt/variables.h>
+
+ #include <cppuhelper/factory.hxx>
+ #include <cppuhelper/servicefactory.hxx>
+ #include <cppuhelper/implbase4.hxx>
+ #include <cppuhelper/implbase.hxx>
+ #include <osl/module.h>
+ #include <osl/file.hxx>
+ #include <osl/process.h>
+ #include <com/sun/star/lang/XComponent.hpp>
+ #include <com/sun/star/lang/XInitialization.hpp>
+ #include <com/sun/star/uno/Any.hxx>
+ #include <com/sun/star/beans/NamedValue.hpp>
+ #include <com/sun/star/io/XInputStream.hpp>
+ #include <com/sun/star/io/XOutputStream.hpp>
+ #include <com/sun/star/io/XActiveDataSource.hpp>
+ #include <com/sun/star/io/XActiveDataSink.hpp>
+ #include <com/sun/star/io/XActiveDataControl.hpp>
+ #include <com/sun/star/io/XStreamListener.hpp>
+
+ #include <LibXSLTTransformer.hxx>
+
+ using namespace ::rtl;
+ using namespace ::cppu;
+ using namespace ::osl;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::io;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::lang;
+ using namespace ::com::sun::star::registry;
+ using ::std::list;
+ using ::std::map;
+ using ::std::pair;
+
+ namespace XSLT {
+     const char* const LibXSLTTransformer::PARAM_SOURCE_URL = "sourceURL";
+     const char* const LibXSLTTransformer::PARAM_SOURCE_BASE_URL = "sourceBaseURL";
+     const char* const LibXSLTTransformer::PARAM_TARGET_URL = "targetURL";
+     const char* const LibXSLTTransformer::PARAM_TARGET_BASE_URL = "targetBaseURL";
+     const char* const LibXSLTTransformer::PARAM_DOCTYPE_SYSTEM = "sytemType";
+     const char* const LibXSLTTransformer::PARAM_DOCTYPE_PUBLIC = "publicType";
+     struct ParserInputBufferCallback {
+         static int on_read(void * context, char * buffer, int len) {
+             Reader * tmp = static_cast<Reader*>(context);
+             return tmp->read(buffer, len);
+         }
+         static int on_close(void * context) {
+             Reader * tmp = static_cast<Reader*>(context);
+             return tmp->closeInput();
+         }
+     };
+     struct ParserOutputBufferCallback {
+         static int on_write(void * context, const char * buffer, int len) {
+             Reader * tmp = static_cast<Reader*>(context);
+             return tmp->write(buffer, len);
+         }
+         static int on_close(void * context) {
+             Reader * tmp = static_cast<Reader*>(context);
+             return tmp->closeOutput();
+         }
+     };
+     Reader::Reader(LibXSLTTransformer* transformer):
+         m_transformer(transformer),
+         m_terminated(false),
+         m_readBuf(INPUT_BUFFER_SIZE),
+         m_writeBuf(OUTPUT_BUFFER_SIZE) {
+         LIBXML_TEST_VERSION;
+     };
+
+     int
+     Reader::read(char * buffer, int len) {
+         //        const char *ptr = (const char *) context;
+         if (buffer == NULL || len < 0) return(-1);
+         sal_Int32 n;
+         Reference<XInputStream> xis = this->m_transformer->getInputStream();
+         n = xis.get()->readBytes(m_readBuf, len);
+         if (n > 0) {
+             memcpy(buffer, m_readBuf.getArray(), n);
+         }
+         return n;
+     }
+     int Reader::write(const char * buffer, int len) {
+         if (buffer == NULL || len < 0) return -1;
+         if (len > 0) {
+             Reference<XOutputStream> xos = m_transformer->getOutputStream();
+             sal_Int32 writeLen = len;
+             sal_Int32 bufLen = ::std::min(writeLen, OUTPUT_BUFFER_SIZE);
+             const sal_uInt8* memPtr = reinterpret_cast< const sal_uInt8* >( buffer );
+             while( writeLen > 0 ) {
+                 sal_Int32 n = ::std::min(writeLen, bufLen);
+                 m_writeBuf.realloc( n );
+                 memcpy( m_writeBuf.getArray(), memPtr, static_cast< size_t >( n ) );
+                 xos.get()->writeBytes(m_writeBuf);
+                 memPtr += n;
+                 writeLen -= n;
+             }
+         }
+         return len;
+     }
+     int Reader::closeInput() {
+         return 0;
+     }
+     int Reader::closeOutput() {
+         Reference<XOutputStream>  xos = m_transformer->getOutputStream();
+         if (xos.is()) {
+             xos.get()->flush();
+             xos.get()->closeOutput();
+         }
+         m_transformer->done();
+         return 0;
+     }
+     void Reader::run() {
+         OSL_ASSERT(m_transformer != NULL);
+         OSL_ASSERT(m_transformer->getInputStream().is());
+         OSL_ASSERT(m_transformer->getOutputStream().is());
+         OSL_ASSERT(m_transformer->getStyleSheetURL());
+         ::std::map<const char*, OString>::iterator pit;
+         ::std::map<const char*, OString> pmap = m_transformer->getParameters();
+         const char* params[pmap.size()*2 + 1]; // build parameters
+         int paramIndex = 0;
+         for (pit = pmap.begin(); pit != pmap.end(); pit++) {
+             params[paramIndex++] = (*pit).first;
+             params[paramIndex++] = (*pit).second.getStr();
+         }
+         params[paramIndex] = NULL;
+         xmlDocPtr doc = xmlReadIO(&ParserInputBufferCallback::on_read,
+                                   &ParserInputBufferCallback::on_close,
+                                   static_cast<void*>(this),
+                                   NULL,
+                                   NULL,
+                                   0);
+         xsltStylesheetPtr styleSheet = xsltParseStylesheetFile((const xmlChar *) 
m_transformer->getStyleSheetURL().getStr());
+         xmlDocPtr result = NULL;
+         xsltTransformContextPtr tcontext = NULL;
+         if (styleSheet) {
+             tcontext = xsltNewTransformContext(styleSheet, doc);
+             xsltQuoteUserParams(tcontext, params);
+             result = xsltApplyStylesheetUser(styleSheet, doc, 0, 0, 0, tcontext);
+         }
+         if (result) {
+             xmlCharEncodingHandlerPtr encoder = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
+             xmlOutputBufferPtr outBuf = xmlAllocOutputBuffer(encoder);
+             outBuf->context = static_cast<void *>(this);
+             outBuf->writecallback = &ParserOutputBufferCallback::on_write;
+             outBuf->closecallback = &ParserOutputBufferCallback::on_close;
+             xsltSaveResultTo(outBuf, result, styleSheet);
+         } else {
+             xmlErrorPtr lastErr = xmlGetLastError();
+             OUString msg;
+             if (lastErr) {
+                 msg = OUString::createFromAscii(lastErr->message);
+             } else {
+                 msg = OUString::createFromAscii("Unknown XSLT transformation error");
+             }
+             m_transformer->error(msg);
+         }
+         closeOutput();
+         xsltFreeStylesheet(styleSheet);
+         xsltFreeTransformContext(tcontext);
+         xmlFreeDoc(doc);
+         xmlFreeDoc(result);
+     };
+     void Reader::onTerminated() {
+         m_terminated = true;
+     };
+     Reader::~Reader() {}
+     LibXSLTTransformer::LibXSLTTransformer( const Reference< XMultiServiceFactory > &r )
+         : m_rServiceFactory(r) {
+     }
+     void LibXSLTTransformer::setInputStream(const Reference<XInputStream>& inputStream)
+         throw (RuntimeException) {
+         m_rInputStream = inputStream;
+     }
+     Reference<XInputStream> LibXSLTTransformer::getInputStream()
+         throw (RuntimeException) {
+         return m_rInputStream;
+     }
+     void LibXSLTTransformer::setOutputStream(const Reference<XOutputStream>& outputStream)
+         throw (RuntimeException) {
+         m_rOutputStream = outputStream;
+     }
+     Reference<XOutputStream> LibXSLTTransformer::getOutputStream()
+         throw (RuntimeException) {
+         return m_rOutputStream;
+     }
+     void LibXSLTTransformer::addListener(const Reference<XStreamListener>& listener)
+         throw (RuntimeException) {
+         m_listeners.insert(m_listeners.begin(), listener);
+     }
+     void LibXSLTTransformer::removeListener(const Reference<XStreamListener>& listener)
+         throw (RuntimeException) {
+         m_listeners.remove(listener);
+     }
+     void LibXSLTTransformer::start()
+         throw (RuntimeException) {
+         ListenerList::iterator it;
+         for (it=m_listeners.begin(); it != m_listeners.end(); it++) {
+             Reference<XStreamListener> xl = *it;
+             xl.get()->started();
+         }
+         Reader* r = new Reader(this);
+         r->create();
+     }
+
+     void LibXSLTTransformer::error(const OUString& msg) {
+         ListenerList l = m_listeners;
+         Any arg;
+         arg <<= Exception(msg, *this);
+         for (ListenerList::iterator it=l.begin(); it != l.end(); it++) {
+             Reference<XStreamListener> xl = *it;
+             if (xl.is()) {
+                 xl.get()->error(arg);
+             }
+         }
+     }
+     void LibXSLTTransformer::done() {
+         ListenerList l = m_listeners;
+         for (ListenerList::iterator it=l.begin(); it != l.end(); it++) {
+             Reference<XStreamListener> xl = *it;
+             if (xl.is()) {
+                 xl.get()->closed();
+             }
+         }
+     }
+     void LibXSLTTransformer::terminate()
+         throw (RuntimeException) {
+         m_parameters.clear();
+     }
+     void LibXSLTTransformer::initialize(const Sequence<Any>& params)
+         throw (RuntimeException) {
+         xmlSubstituteEntitiesDefault(0);
+         m_parameters.clear();
+         for (int i = 0; i < params.getLength(); i++) {
+             NamedValue nv;
+             params[i] >>= nv;
+             OString nameUTF8 = OUStringToOString(nv.Name, RTL_TEXTENCODING_UTF8);
+             OUString value;
+             OString valueUTF8;
+             if (nv.Value >>= value) {
+                 valueUTF8 = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
+             } else {
+                 // ignore non-string parameters
+                 continue;
+             }
+             if (nameUTF8.equals("StylesheetURL")) {
+                 m_styleSheetURL = valueUTF8;
+             } else if (nameUTF8.equals("SourceURL")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_SOURCE_URL, valueUTF8));
+             } else if (nameUTF8.equals("SourceBaseURL")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_SOURCE_BASE_URL, valueUTF8));
+             } else if (nameUTF8.equals("TargetURL")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_TARGET_URL, valueUTF8));
+             } else if (nameUTF8.equals("TargetBaseURL")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_TARGET_BASE_URL, valueUTF8));
+             } else if (nameUTF8.equals("DoctypeSystem")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_DOCTYPE_SYSTEM, valueUTF8));
+             } else if (nameUTF8.equals("DoctypePublic")) {
+                 m_parameters.insert(pair<const char*, OString>(PARAM_DOCTYPE_PUBLIC, valueUTF8));
+             }
+         }
+     }
+     const OString LibXSLTTransformer::getStyleSheetURL() {
+         return m_styleSheetURL;
+     }
+     ::std::map<const char*, OString> LibXSLTTransformer::getParameters() {
+         return m_parameters;
+     }
+ }
+ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/xsltfilter/LibXSLTTransformer.hxx 
b/filter/source/xsltfilter/LibXSLTTransformer.hxx
new file mode 100644
index 0000000..376075e
--- /dev/null
+++ b/filter/source/xsltfilter/LibXSLTTransformer.hxx
@@ -0,0 +1,145 @@
+ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+ #ifndef __LIBXSLTTRANSFORMER_HXX__
+ #define __LIBXSLTTRANSFORMER_HXX__
+ #include "precompiled_filter.hxx"
+
+ #include <stdio.h>
+
+ #include <list>
+ #include <map>
+
+ #include <libxml/parser.h>
+ #include <libxml/tree.h>
+ #include <libxml/xmlIO.h>
+ #include <libxslt/transform.h>
+
+ #include <cppuhelper/factory.hxx>
+ #include <cppuhelper/servicefactory.hxx>
+ #include <cppuhelper/implbase4.hxx>
+ #include <cppuhelper/implbase.hxx>
+
+ #include <osl/thread.hxx>
+
+ #include <com/sun/star/uno/Any.hxx>
+
+ #include <com/sun/star/io/XInputStream.hpp>
+ #include <com/sun/star/io/XOutputStream.hpp>
+ #include <com/sun/star/io/XActiveDataSource.hpp>
+ #include <com/sun/star/io/XActiveDataSink.hpp>
+ #include <com/sun/star/io/XActiveDataControl.hpp>
+ #include <com/sun/star/io/XStreamListener.hpp>
+ #include <com/sun/star/lang/XInitialization.hpp>
+ #include <com/sun/star/beans/NamedValue.hpp>
+
+ #define _INPUT_BUFFER_SIZE 1024
+ #define _OUTPUT_BUFFER_SIZE 1024
+
+ using namespace ::rtl;
+ using namespace ::cppu;
+ using namespace ::osl;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::io;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::lang;
+
+ using ::std::list;
+ using ::std::map;
+
+ namespace XSLT {
+
+
+     class LibXSLTTransformer : public WeakImplHelper4< XActiveDataSink, XActiveDataSource, 
XActiveDataControl, XInitialization>
+     {
+     private:
+         static const char* const PARAM_SOURCE_URL;
+         static const char* const PARAM_SOURCE_BASE_URL;
+         static const char* const PARAM_TARGET_URL;
+         static const char* const PARAM_TARGET_BASE_URL;
+         static const char* const PARAM_DOCTYPE_SYSTEM;
+         static const char* const PARAM_DOCTYPE_PUBLIC;
+
+         // the UNO ServiceFactory
+         Reference< XMultiServiceFactory > m_rServiceFactory;
+
+         Reference< XInputStream> m_rInputStream;
+
+         Reference < XOutputStream > m_rOutputStream;
+
+         typedef ::std::list<Reference< XStreamListener > > ListenerList;
+
+         ListenerList m_listeners;
+
+         OString m_styleSheetURL;
+
+         ::std::map<const char *, OString> m_parameters;
+
+     public:
+
+         // ctor...
+         LibXSLTTransformer( const Reference< XMultiServiceFactory > &r );
+
+
+
+
+         // XActiveDataSink
+         virtual void SAL_CALL setInputStream(const Reference<XInputStream>& inputStream)
+             throw (RuntimeException);
+         virtual Reference<XInputStream> SAL_CALL getInputStream()
+             throw (RuntimeException);
+         // XActiveDataSource
+         virtual void SAL_CALL setOutputStream(const Reference<XOutputStream>& outputStream)
+             throw (RuntimeException);
+         virtual Reference<XOutputStream> SAL_CALL getOutputStream()
+             throw (RuntimeException);
+         // XActiveDataControl
+         virtual void SAL_CALL addListener(const Reference<XStreamListener>& listener)
+             throw (RuntimeException);
+         virtual void SAL_CALL removeListener(const Reference<XStreamListener>& listener)
+             throw (RuntimeException);
+         virtual void SAL_CALL start()
+             throw (RuntimeException);
+         virtual void SAL_CALL terminate()
+             throw (RuntimeException);
+         virtual void SAL_CALL initialize(const Sequence<Any>& params)
+             throw (RuntimeException);
+
+         void SAL_CALL done();
+
+         void SAL_CALL error(const OUString& msg);
+
+         const OString SAL_CALL getStyleSheetURL();
+
+         ::std::map<const char*, OString> SAL_CALL getParameters();
+
+     };
+
+     class Reader: public osl::Thread
+     {
+     public:
+         Reader(LibXSLTTransformer* transformer);
+         int SAL_CALL read(char * buffer, int len);
+         int SAL_CALL write(const char * buffer, int len);
+         int SAL_CALL closeInput();
+         int SAL_CALL closeOutput();
+
+     protected:
+         virtual ~Reader();
+
+     private:
+         static const sal_Int32 OUTPUT_BUFFER_SIZE = _OUTPUT_BUFFER_SIZE;
+         static const sal_Int32 INPUT_BUFFER_SIZE = _INPUT_BUFFER_SIZE;
+         LibXSLTTransformer* m_transformer;
+         sal_Bool m_terminated;
+         Sequence<sal_Int8> m_readBuf;
+         Sequence<sal_Int8> m_writeBuf;
+         virtual void SAL_CALL run();
+         virtual void SAL_CALL onTerminated();
+     };
+
+ }
+
+
+ #endif // __LIBXSLTTRANSFORMER_HXX__
+
+ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/xsltfilter/XSLTFilter.cxx b/filter/source/xsltfilter/XSLTFilter.cxx
index b2c2858..2e3f5af 100644
--- a/filter/source/xsltfilter/XSLTFilter.cxx
+++ b/filter/source/xsltfilter/XSLTFilter.cxx
@@ -76,6 +76,13 @@
 
 #include <xmloff/attrlist.hxx>
 #include <fla.hxx>
+#include <LibXSLTTransformer.hxx>
+
+#ifdef SOLAR_JAVA
+#define USE_LIBXSLT_DEFAULT sal_False
+#else
+#define USE_LIBXSLT_DEFAULT sal_True
+#endif
 
 using namespace ::rtl;
 using namespace ::cppu;
@@ -221,6 +228,9 @@ void FLABridge::setDocumentLocator(const Reference<XLocator>& doclocator)
 class XSLTFilter : public WeakImplHelper4< XImportFilter, XExportFilter, XDocumentHandler, 
XStreamListener>
 {
 private:
+    static const OUString JAXT_HELPER_SERVICE_IMPL;
+    static const OUString LIBXSLT_HELPER_SERVICE_IMPL;
+
     // the UNO ServiceFactory
     Reference< XMultiServiceFactory > m_rServiceFactory;
 
@@ -232,12 +242,12 @@ private:
     sal_Bool m_bPrettyPrint;
 
     Reference< XActiveDataControl > m_tcontrol;
+
     oslCondition  m_cTransformed;
     sal_Bool m_bTerminated;
     sal_Bool m_bError;
 
     OUString m_aExportBaseUrl;
-    OUString m_aOldBaseUrl;
 
     OUString rel2abs(const OUString&);
     OUString expandUrl(const OUString&);
@@ -287,6 +297,9 @@ public:
         throw (SAXException,RuntimeException);
 };
 
+const OUString XSLTFilter::JAXT_HELPER_SERVICE_IMPL = 
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.JAXTHelper"));
+const OUString XSLTFilter::LIBXSLT_HELPER_SERVICE_IMPL = 
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.documentconversion.LibXSLTTransformer"));
+
 XSLTFilter::XSLTFilter( const Reference< XMultiServiceFactory > &r )
     : m_rServiceFactory(r)
     , m_bPrettyPrint(sal_True)
@@ -411,8 +424,17 @@ sal_Bool XSLTFilter::importer(
     nv.Value <<= OUString(INetURLObject(aURL).getBase());
     args[2] <<= nv;
 
-    m_tcontrol = Reference< XActiveDataControl >(m_rServiceFactory->createInstanceWithArguments(
-        OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.JAXTHelper" )), args), 
UNO_QUERY);
+    sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
+    if (!useLibXSLT) {
+        useLibXSLT = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
+    }
+    if (useLibXSLT) {
+        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
+        LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+    } else {
+        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
+        JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+    }
 
     OSL_ASSERT(xHandler.is());
     OSL_ASSERT(xInputStream.is());
@@ -538,8 +560,17 @@ sal_Bool XSLTFilter::exporter(
     nv.Value <<= m_aExportBaseUrl;
     args[3] <<= nv;
 
-    m_tcontrol = Reference< XActiveDataControl >(m_rServiceFactory->createInstanceWithArguments(
-        OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.JAXTHelper" )), args), 
UNO_QUERY);
+    sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
+    if (!useLibXSLT) {
+        useLibXSLT = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
+    }
+    if (useLibXSLT) {
+        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
+        LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+    } else {
+        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
+        JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+    }
 
     OSL_ASSERT(m_rDocumentHandler.is());
     OSL_ASSERT(m_rOutputStream.is());
@@ -647,28 +678,19 @@ void XSLTFilter::setDocumentLocator(const Reference<XLocator>& doclocator)
 // --------------------------------------
 // Component management
 // --------------------------------------
-#define SERVICE_NAME "com.sun.star.documentconversion.XSLTFilter"
-#define IMPLEMENTATION_NAME "com.sun.star.comp.documentconversion.XSLTFilter"
+#define FILTER_SERVICE_NAME "com.sun.star.documentconversion.XSLTFilter"
+#define FILTER_IMPL_NAME "com.sun.star.comp.documentconversion.XSLTFilter"
+#define TRANSFORMER_SERVICE_NAME "com.sun.star.documentconversion.LibXSLTTransformer"
+#define TRANSFORMER_IMPL_NAME "com.sun.star.comp.documentconversion.LibXSLTTransformer"
 
-static Reference< XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r)
+static Reference< XInterface > SAL_CALL CreateTransformerInstance( const Reference< 
XMultiServiceFactory > &r)
 {
-    return Reference< XInterface >(( OWeakObject *)new XSLTFilter(r));
+    return Reference< XInterface >(( OWeakObject *)new LibXSLTTransformer(r));
 }
 
-static Sequence< OUString > getSupportedServiceNames()
+static Reference< XInterface > SAL_CALL CreateFilterInstance( const Reference< 
XMultiServiceFactory > &r)
 {
-    static Sequence < OUString > *pNames = 0;
-    if( ! pNames )
-    {
-        MutexGuard guard( Mutex::getGlobalMutex() );
-        if( !pNames )
-        {
-            static Sequence< OUString > seqNames(1);
-                seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME));
-            pNames = &seqNames;
-        }
-    }
-    return *pNames;
+    return Reference< XInterface >(( OWeakObject *)new XSLTFilter(r));
 }
 
 }
@@ -685,27 +707,26 @@ void SAL_CALL component_getImplementationEnvironment(
 
 sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey )
 {
+    sal_Bool bRetVal = sal_False;
     if (pRegistryKey)
     {
         try
         {
-            Reference< XRegistryKey > xNewKey(
-                reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
-                    OUString( RTL_CONSTASCII_USTRINGPARAM( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" 
)) ) );
+            Reference< XRegistryKey > pXNewKey( static_cast< XRegistryKey* >( pRegistryKey ) );
+            pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" FILTER_IMPL_NAME 
"/UNO/SERVICES/" FILTER_SERVICE_NAME ) ) );
+            bRetVal = sal_True;
 
-            const Sequence< OUString > & rSNL = getSupportedServiceNames();
-            const OUString * pArray = rSNL.getConstArray();
-            for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
-                xNewKey->createKey( pArray[nPos] );
-
-            return sal_True;
+            pXNewKey=  static_cast< XRegistryKey* >( pRegistryKey );
+            pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" TRANSFORMER_IMPL_NAME 
"/UNO/SERVICES/" TRANSFORMER_SERVICE_NAME ) ) );
+            bRetVal = sal_True;
         }
-        catch (InvalidRegistryException &)
+        catch( InvalidRegistryException& )
         {
-            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+            OSL_ENSURE(sal_False, "InvalidRegistryException caught");
+            bRetVal = sal_False;
         }
     }
-    return sal_False;
+    return bRetVal;
 }
 
 void * SAL_CALL component_getFactory(
@@ -713,17 +734,37 @@ void * SAL_CALL component_getFactory(
 {
     void * pRet = 0;
 
-    if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
-    {
-        Reference< XSingleServiceFactory > xFactory( createSingleFactory(
-            reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
-            OUString::createFromAscii( pImplName ),
-            CreateInstance, getSupportedServiceNames() ) );
+    if (pServiceManager) {
+        if (rtl_str_compare( pImplName, FILTER_IMPL_NAME ) == 0) {
+            Sequence< OUString > serviceNames( 1 );
+            serviceNames.getArray( )[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( 
FILTER_SERVICE_NAME ) );
+
+            Reference< XSingleServiceFactory > xFactory(
+                                                        createSingleFactory(
+                                                                            reinterpret_cast< 
XMultiServiceFactory * >( pServiceManager ),
+                                                                            
OUString::createFromAscii( pImplName ),
+                                                                            CreateFilterInstance, 
serviceNames ) );
+
+            if (xFactory.is())
+                {
+                    xFactory->acquire();
+                    pRet = xFactory.get();
+                }
+        } else if (rtl_str_compare( pImplName, TRANSFORMER_IMPL_NAME ) == 0) {
+            Sequence< OUString > serviceNames( 1 );
+            serviceNames.getArray( )[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( 
TRANSFORMER_SERVICE_NAME ) );
+            Reference< XSingleServiceFactory > xFactory(
+                                                        createSingleFactory(
+                                                                            reinterpret_cast< 
XMultiServiceFactory * >( pServiceManager ),
+                                                                            
OUString::createFromAscii( pImplName ),
+                                                                            
CreateTransformerInstance, serviceNames ) );
+
+            if (xFactory.is())
+                {
+                    xFactory->acquire();
+                    pRet = xFactory.get();
+                }
 
-        if (xFactory.is())
-        {
-            xFactory->acquire();
-            pRet = xFactory.get();
         }
     }
     return pRet;
diff --git a/filter/source/xsltfilter/makefile.mk b/filter/source/xsltfilter/makefile.mk
index a5e2713..ee23cfd 100644
--- a/filter/source/xsltfilter/makefile.mk
+++ b/filter/source/xsltfilter/makefile.mk
@@ -33,9 +33,19 @@ LIBTARGET=NO
 
 # --- Settings -----------------------------------------------------
 CLASSDIR!:=$(CLASSDIR)$/$(TARGET)
+
 .INCLUDE: settings.mk
 
-SLOFILES=$(SLO)$/XSLTFilter.obj $(SLO)$/fla.obj
+.IF "$(SYSTEM_LIBXSLT)" == "YES"
+CFLAGS+= $(LIBXSLT_CFLAGS)
+.ELSE
+LIBXSLTINCDIR=external$/libxslt
+CFLAGS+= -I$(SOLARINCDIR)$/$(LIBXSLTINCDIR)
+.ENDIF
+
+
+
+SLOFILES=$(SLO)$/XSLTFilter.obj $(SLO)$/LibXSLTTransformer.obj $(SLO)$/fla.obj
 LIBNAME=xsltfilter
 SHL1TARGETDEPN=makefile.mk
 SHL1OBJS=$(SLOFILES)
@@ -50,7 +60,9 @@ SHL1STDLIBS= \
     $(CPPUHELPERLIB)    \
     $(CPPULIB)          \
     $(XMLOFFLIB) \
-    $(SALLIB)
+    $(SALLIB) \
+    $(LIBXML2LIB) \
+    $(XSLTLIB)
 
 .IF "$(SOLAR_JAVA)"!=""
 
-- 
1.7.1


From 74d639d3158a38afdfc3b0ce1d7e0c384724fb93 Mon Sep 17 00:00:00 2001
From: Peter Jentsch <pjotr@guineapics.de>
Date: Mon, 3 Jan 2011 20:38:17 +0100
Subject: [PATCH 2/4] Fixed constant definitions for LibXSLTFilter buffers

---
 filter/source/xsltfilter/LibXSLTTransformer.cxx |   29 ++++++++++++++++++++++-
 filter/source/xsltfilter/LibXSLTTransformer.hxx |    7 +----
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/filter/source/xsltfilter/LibXSLTTransformer.cxx 
b/filter/source/xsltfilter/LibXSLTTransformer.cxx
index da51908..2d40381 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.cxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.cxx
@@ -45,6 +45,9 @@
  using ::std::map;
  using ::std::pair;
 
+ #define _INPUT_BUFFER_SIZE 4096
+ #define _OUTPUT_BUFFER_SIZE 4096
+
  namespace XSLT {
      const char* const LibXSLTTransformer::PARAM_SOURCE_URL = "sourceURL";
      const char* const LibXSLTTransformer::PARAM_SOURCE_BASE_URL = "sourceBaseURL";
@@ -52,6 +55,11 @@
      const char* const LibXSLTTransformer::PARAM_TARGET_BASE_URL = "targetBaseURL";
      const char* const LibXSLTTransformer::PARAM_DOCTYPE_SYSTEM = "sytemType";
      const char* const LibXSLTTransformer::PARAM_DOCTYPE_PUBLIC = "publicType";
+
+     const sal_Int32 Reader::OUTPUT_BUFFER_SIZE = _OUTPUT_BUFFER_SIZE;
+
+     const sal_Int32 Reader::INPUT_BUFFER_SIZE = _INPUT_BUFFER_SIZE;
+
      struct ParserInputBufferCallback {
          static int on_read(void * context, char * buffer, int len) {
              Reader * tmp = static_cast<Reader*>(context);
@@ -72,6 +80,7 @@
              return tmp->closeOutput();
          }
      };
+
      Reader::Reader(LibXSLTTransformer* transformer):
          m_transformer(transformer),
          m_terminated(false),
@@ -92,12 +101,13 @@
          }
          return n;
      }
+
      int Reader::write(const char * buffer, int len) {
          if (buffer == NULL || len < 0) return -1;
          if (len > 0) {
              Reference<XOutputStream> xos = m_transformer->getOutputStream();
              sal_Int32 writeLen = len;
-             sal_Int32 bufLen = ::std::min(writeLen, OUTPUT_BUFFER_SIZE);
+             sal_Int32 bufLen = ::std::min(writeLen, this->OUTPUT_BUFFER_SIZE);
              const sal_uInt8* memPtr = reinterpret_cast< const sal_uInt8* >( buffer );
              while( writeLen > 0 ) {
                  sal_Int32 n = ::std::min(writeLen, bufLen);
@@ -110,9 +120,11 @@
          }
          return len;
      }
+
      int Reader::closeInput() {
          return 0;
      }
+
      int Reader::closeOutput() {
          Reference<XOutputStream>  xos = m_transformer->getOutputStream();
          if (xos.is()) {
@@ -122,6 +134,7 @@
          m_transformer->done();
          return 0;
      }
+
      void Reader::run() {
          OSL_ASSERT(m_transformer != NULL);
          OSL_ASSERT(m_transformer->getInputStream().is());
@@ -150,6 +163,7 @@
              xsltQuoteUserParams(tcontext, params);
              result = xsltApplyStylesheetUser(styleSheet, doc, 0, 0, 0, tcontext);
          }
+
          if (result) {
              xmlCharEncodingHandlerPtr encoder = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
              xmlOutputBufferPtr outBuf = xmlAllocOutputBuffer(encoder);
@@ -173,37 +187,47 @@
          xmlFreeDoc(doc);
          xmlFreeDoc(result);
      };
+
      void Reader::onTerminated() {
          m_terminated = true;
      };
+
      Reader::~Reader() {}
+
      LibXSLTTransformer::LibXSLTTransformer( const Reference< XMultiServiceFactory > &r )
          : m_rServiceFactory(r) {
      }
+
      void LibXSLTTransformer::setInputStream(const Reference<XInputStream>& inputStream)
          throw (RuntimeException) {
          m_rInputStream = inputStream;
      }
+
      Reference<XInputStream> LibXSLTTransformer::getInputStream()
          throw (RuntimeException) {
          return m_rInputStream;
      }
+
      void LibXSLTTransformer::setOutputStream(const Reference<XOutputStream>& outputStream)
          throw (RuntimeException) {
          m_rOutputStream = outputStream;
      }
+
      Reference<XOutputStream> LibXSLTTransformer::getOutputStream()
          throw (RuntimeException) {
          return m_rOutputStream;
      }
+
      void LibXSLTTransformer::addListener(const Reference<XStreamListener>& listener)
          throw (RuntimeException) {
          m_listeners.insert(m_listeners.begin(), listener);
      }
+
      void LibXSLTTransformer::removeListener(const Reference<XStreamListener>& listener)
          throw (RuntimeException) {
          m_listeners.remove(listener);
      }
+
      void LibXSLTTransformer::start()
          throw (RuntimeException) {
          ListenerList::iterator it;
@@ -226,6 +250,7 @@
              }
          }
      }
+
      void LibXSLTTransformer::done() {
          ListenerList l = m_listeners;
          for (ListenerList::iterator it=l.begin(); it != l.end(); it++) {
@@ -235,10 +260,12 @@
              }
          }
      }
+
      void LibXSLTTransformer::terminate()
          throw (RuntimeException) {
          m_parameters.clear();
      }
+
      void LibXSLTTransformer::initialize(const Sequence<Any>& params)
          throw (RuntimeException) {
          xmlSubstituteEntitiesDefault(0);
diff --git a/filter/source/xsltfilter/LibXSLTTransformer.hxx 
b/filter/source/xsltfilter/LibXSLTTransformer.hxx
index 376075e..64073c0 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.hxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.hxx
@@ -32,9 +32,6 @@
  #include <com/sun/star/lang/XInitialization.hpp>
  #include <com/sun/star/beans/NamedValue.hpp>
 
- #define _INPUT_BUFFER_SIZE 1024
- #define _OUTPUT_BUFFER_SIZE 1024
-
  using namespace ::rtl;
  using namespace ::cppu;
  using namespace ::osl;
@@ -127,8 +124,8 @@
          virtual ~Reader();
 
      private:
-         static const sal_Int32 OUTPUT_BUFFER_SIZE = _OUTPUT_BUFFER_SIZE;
-         static const sal_Int32 INPUT_BUFFER_SIZE = _INPUT_BUFFER_SIZE;
+         static const sal_Int32 OUTPUT_BUFFER_SIZE;
+         static const sal_Int32 INPUT_BUFFER_SIZE;
          LibXSLTTransformer* m_transformer;
          sal_Bool m_terminated;
          Sequence<sal_Int8> m_readBuf;
-- 
1.7.1


From c9fb0a722209bc9352dd832a3a2eb1829987a049 Mon Sep 17 00:00:00 2001
From: Peter Jentsch <pjotr@guineapics.de>
Date: Fri, 7 Jan 2011 21:46:19 +0100
Subject: [PATCH 3/4] Added copyright header and some documentation to LibXSLTFilter

Also fixed indentation and replaced copy assigment of list to references.
---
 filter/source/xsltfilter/LibXSLTTransformer.cxx |  750 ++++++++-----
 filter/source/xsltfilter/LibXSLTTransformer.hxx |  342 ++++---
 filter/source/xsltfilter/XSLTFilter.cxx         | 1364 +++++++++++++----------
 3 files changed, 1396 insertions(+), 1060 deletions(-)

diff --git a/filter/source/xsltfilter/LibXSLTTransformer.cxx 
b/filter/source/xsltfilter/LibXSLTTransformer.cxx
index 2d40381..08fff37 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.cxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.cxx
@@ -1,309 +1,441 @@
- /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
- // MARKER(update_precomp.py): autogen include statement, do not remove
- #include "precompiled_filter.hxx"
-
- #include <stdio.h>
- #include <list>
- #include <map>
- #include <iostream>
- #include <libxml/parser.h>
- #include <libxml/tree.h>
- #include <libxml/xmlIO.h>
- #include <libxslt/transform.h>
- #include <libxslt/xsltutils.h>
- #include <libxslt/variables.h>
-
- #include <cppuhelper/factory.hxx>
- #include <cppuhelper/servicefactory.hxx>
- #include <cppuhelper/implbase4.hxx>
- #include <cppuhelper/implbase.hxx>
- #include <osl/module.h>
- #include <osl/file.hxx>
- #include <osl/process.h>
- #include <com/sun/star/lang/XComponent.hpp>
- #include <com/sun/star/lang/XInitialization.hpp>
- #include <com/sun/star/uno/Any.hxx>
- #include <com/sun/star/beans/NamedValue.hpp>
- #include <com/sun/star/io/XInputStream.hpp>
- #include <com/sun/star/io/XOutputStream.hpp>
- #include <com/sun/star/io/XActiveDataSource.hpp>
- #include <com/sun/star/io/XActiveDataSink.hpp>
- #include <com/sun/star/io/XActiveDataControl.hpp>
- #include <com/sun/star/io/XStreamListener.hpp>
-
- #include <LibXSLTTransformer.hxx>
-
- using namespace ::rtl;
- using namespace ::cppu;
- using namespace ::osl;
- using namespace ::com::sun::star::beans;
- using namespace ::com::sun::star::io;
- using namespace ::com::sun::star::uno;
- using namespace ::com::sun::star::lang;
- using namespace ::com::sun::star::registry;
- using ::std::list;
- using ::std::map;
- using ::std::pair;
-
- #define _INPUT_BUFFER_SIZE 4096
- #define _OUTPUT_BUFFER_SIZE 4096
-
- namespace XSLT {
-     const char* const LibXSLTTransformer::PARAM_SOURCE_URL = "sourceURL";
-     const char* const LibXSLTTransformer::PARAM_SOURCE_BASE_URL = "sourceBaseURL";
-     const char* const LibXSLTTransformer::PARAM_TARGET_URL = "targetURL";
-     const char* const LibXSLTTransformer::PARAM_TARGET_BASE_URL = "targetBaseURL";
-     const char* const LibXSLTTransformer::PARAM_DOCTYPE_SYSTEM = "sytemType";
-     const char* const LibXSLTTransformer::PARAM_DOCTYPE_PUBLIC = "publicType";
-
-     const sal_Int32 Reader::OUTPUT_BUFFER_SIZE = _OUTPUT_BUFFER_SIZE;
-
-     const sal_Int32 Reader::INPUT_BUFFER_SIZE = _INPUT_BUFFER_SIZE;
-
-     struct ParserInputBufferCallback {
-         static int on_read(void * context, char * buffer, int len) {
-             Reader * tmp = static_cast<Reader*>(context);
-             return tmp->read(buffer, len);
-         }
-         static int on_close(void * context) {
-             Reader * tmp = static_cast<Reader*>(context);
-             return tmp->closeInput();
-         }
-     };
-     struct ParserOutputBufferCallback {
-         static int on_write(void * context, const char * buffer, int len) {
-             Reader * tmp = static_cast<Reader*>(context);
-             return tmp->write(buffer, len);
-         }
-         static int on_close(void * context) {
-             Reader * tmp = static_cast<Reader*>(context);
-             return tmp->closeOutput();
-         }
-     };
-
-     Reader::Reader(LibXSLTTransformer* transformer):
-         m_transformer(transformer),
-         m_terminated(false),
-         m_readBuf(INPUT_BUFFER_SIZE),
-         m_writeBuf(OUTPUT_BUFFER_SIZE) {
-         LIBXML_TEST_VERSION;
-     };
-
-     int
-     Reader::read(char * buffer, int len) {
-         //        const char *ptr = (const char *) context;
-         if (buffer == NULL || len < 0) return(-1);
-         sal_Int32 n;
-         Reference<XInputStream> xis = this->m_transformer->getInputStream();
-         n = xis.get()->readBytes(m_readBuf, len);
-         if (n > 0) {
-             memcpy(buffer, m_readBuf.getArray(), n);
-         }
-         return n;
-     }
-
-     int Reader::write(const char * buffer, int len) {
-         if (buffer == NULL || len < 0) return -1;
-         if (len > 0) {
-             Reference<XOutputStream> xos = m_transformer->getOutputStream();
-             sal_Int32 writeLen = len;
-             sal_Int32 bufLen = ::std::min(writeLen, this->OUTPUT_BUFFER_SIZE);
-             const sal_uInt8* memPtr = reinterpret_cast< const sal_uInt8* >( buffer );
-             while( writeLen > 0 ) {
-                 sal_Int32 n = ::std::min(writeLen, bufLen);
-                 m_writeBuf.realloc( n );
-                 memcpy( m_writeBuf.getArray(), memPtr, static_cast< size_t >( n ) );
-                 xos.get()->writeBytes(m_writeBuf);
-                 memPtr += n;
-                 writeLen -= n;
-             }
-         }
-         return len;
-     }
-
-     int Reader::closeInput() {
-         return 0;
-     }
-
-     int Reader::closeOutput() {
-         Reference<XOutputStream>  xos = m_transformer->getOutputStream();
-         if (xos.is()) {
-             xos.get()->flush();
-             xos.get()->closeOutput();
-         }
-         m_transformer->done();
-         return 0;
-     }
-
-     void Reader::run() {
-         OSL_ASSERT(m_transformer != NULL);
-         OSL_ASSERT(m_transformer->getInputStream().is());
-         OSL_ASSERT(m_transformer->getOutputStream().is());
-         OSL_ASSERT(m_transformer->getStyleSheetURL());
-         ::std::map<const char*, OString>::iterator pit;
-         ::std::map<const char*, OString> pmap = m_transformer->getParameters();
-         const char* params[pmap.size()*2 + 1]; // build parameters
-         int paramIndex = 0;
-         for (pit = pmap.begin(); pit != pmap.end(); pit++) {
-             params[paramIndex++] = (*pit).first;
-             params[paramIndex++] = (*pit).second.getStr();
-         }
-         params[paramIndex] = NULL;
-         xmlDocPtr doc = xmlReadIO(&ParserInputBufferCallback::on_read,
-                                   &ParserInputBufferCallback::on_close,
-                                   static_cast<void*>(this),
-                                   NULL,
-                                   NULL,
-                                   0);
-         xsltStylesheetPtr styleSheet = xsltParseStylesheetFile((const xmlChar *) 
m_transformer->getStyleSheetURL().getStr());
-         xmlDocPtr result = NULL;
-         xsltTransformContextPtr tcontext = NULL;
-         if (styleSheet) {
-             tcontext = xsltNewTransformContext(styleSheet, doc);
-             xsltQuoteUserParams(tcontext, params);
-             result = xsltApplyStylesheetUser(styleSheet, doc, 0, 0, 0, tcontext);
-         }
-
-         if (result) {
-             xmlCharEncodingHandlerPtr encoder = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
-             xmlOutputBufferPtr outBuf = xmlAllocOutputBuffer(encoder);
-             outBuf->context = static_cast<void *>(this);
-             outBuf->writecallback = &ParserOutputBufferCallback::on_write;
-             outBuf->closecallback = &ParserOutputBufferCallback::on_close;
-             xsltSaveResultTo(outBuf, result, styleSheet);
-         } else {
-             xmlErrorPtr lastErr = xmlGetLastError();
-             OUString msg;
-             if (lastErr) {
-                 msg = OUString::createFromAscii(lastErr->message);
-             } else {
-                 msg = OUString::createFromAscii("Unknown XSLT transformation error");
-             }
-             m_transformer->error(msg);
-         }
-         closeOutput();
-         xsltFreeStylesheet(styleSheet);
-         xsltFreeTransformContext(tcontext);
-         xmlFreeDoc(doc);
-         xmlFreeDoc(result);
-     };
-
-     void Reader::onTerminated() {
-         m_terminated = true;
-     };
-
-     Reader::~Reader() {}
-
-     LibXSLTTransformer::LibXSLTTransformer( const Reference< XMultiServiceFactory > &r )
-         : m_rServiceFactory(r) {
-     }
-
-     void LibXSLTTransformer::setInputStream(const Reference<XInputStream>& inputStream)
-         throw (RuntimeException) {
-         m_rInputStream = inputStream;
-     }
-
-     Reference<XInputStream> LibXSLTTransformer::getInputStream()
-         throw (RuntimeException) {
-         return m_rInputStream;
-     }
-
-     void LibXSLTTransformer::setOutputStream(const Reference<XOutputStream>& outputStream)
-         throw (RuntimeException) {
-         m_rOutputStream = outputStream;
-     }
-
-     Reference<XOutputStream> LibXSLTTransformer::getOutputStream()
-         throw (RuntimeException) {
-         return m_rOutputStream;
-     }
-
-     void LibXSLTTransformer::addListener(const Reference<XStreamListener>& listener)
-         throw (RuntimeException) {
-         m_listeners.insert(m_listeners.begin(), listener);
-     }
-
-     void LibXSLTTransformer::removeListener(const Reference<XStreamListener>& listener)
-         throw (RuntimeException) {
-         m_listeners.remove(listener);
-     }
-
-     void LibXSLTTransformer::start()
-         throw (RuntimeException) {
-         ListenerList::iterator it;
-         for (it=m_listeners.begin(); it != m_listeners.end(); it++) {
-             Reference<XStreamListener> xl = *it;
-             xl.get()->started();
-         }
-         Reader* r = new Reader(this);
-         r->create();
-     }
-
-     void LibXSLTTransformer::error(const OUString& msg) {
-         ListenerList l = m_listeners;
-         Any arg;
-         arg <<= Exception(msg, *this);
-         for (ListenerList::iterator it=l.begin(); it != l.end(); it++) {
-             Reference<XStreamListener> xl = *it;
-             if (xl.is()) {
-                 xl.get()->error(arg);
-             }
-         }
-     }
-
-     void LibXSLTTransformer::done() {
-         ListenerList l = m_listeners;
-         for (ListenerList::iterator it=l.begin(); it != l.end(); it++) {
-             Reference<XStreamListener> xl = *it;
-             if (xl.is()) {
-                 xl.get()->closed();
-             }
-         }
-     }
-
-     void LibXSLTTransformer::terminate()
-         throw (RuntimeException) {
-         m_parameters.clear();
-     }
-
-     void LibXSLTTransformer::initialize(const Sequence<Any>& params)
-         throw (RuntimeException) {
-         xmlSubstituteEntitiesDefault(0);
-         m_parameters.clear();
-         for (int i = 0; i < params.getLength(); i++) {
-             NamedValue nv;
-             params[i] >>= nv;
-             OString nameUTF8 = OUStringToOString(nv.Name, RTL_TEXTENCODING_UTF8);
-             OUString value;
-             OString valueUTF8;
-             if (nv.Value >>= value) {
-                 valueUTF8 = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
-             } else {
-                 // ignore non-string parameters
-                 continue;
-             }
-             if (nameUTF8.equals("StylesheetURL")) {
-                 m_styleSheetURL = valueUTF8;
-             } else if (nameUTF8.equals("SourceURL")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_SOURCE_URL, valueUTF8));
-             } else if (nameUTF8.equals("SourceBaseURL")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_SOURCE_BASE_URL, valueUTF8));
-             } else if (nameUTF8.equals("TargetURL")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_TARGET_URL, valueUTF8));
-             } else if (nameUTF8.equals("TargetBaseURL")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_TARGET_BASE_URL, valueUTF8));
-             } else if (nameUTF8.equals("DoctypeSystem")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_DOCTYPE_SYSTEM, valueUTF8));
-             } else if (nameUTF8.equals("DoctypePublic")) {
-                 m_parameters.insert(pair<const char*, OString>(PARAM_DOCTYPE_PUBLIC, valueUTF8));
-             }
-         }
-     }
-     const OString LibXSLTTransformer::getStyleSheetURL() {
-         return m_styleSheetURL;
-     }
-     ::std::map<const char*, OString> LibXSLTTransformer::getParameters() {
-         return m_parameters;
-     }
- }
- /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Peter Jentsch <pjotr@guineapics.de> ]
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Peter Jentsch <pjotr@guineapics.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_filter.hxx"
+
+#include <stdio.h>
+#include <list>
+#include <map>
+#include <iostream>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlIO.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/variables.h>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <cppuhelper/implbase4.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <osl/module.h>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XActiveDataControl.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+
+#include <LibXSLTTransformer.hxx>
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::osl;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using ::std::list;
+using ::std::map;
+using ::std::pair;
+
+#define _INPUT_BUFFER_SIZE 4096
+#define _OUTPUT_BUFFER_SIZE 4096
+
+namespace XSLT
+{
+    const char* const LibXSLTTransformer::PARAM_SOURCE_URL = "sourceURL";
+    const char* const LibXSLTTransformer::PARAM_SOURCE_BASE_URL =
+            "sourceBaseURL";
+    const char* const LibXSLTTransformer::PARAM_TARGET_URL = "targetURL";
+    const char* const LibXSLTTransformer::PARAM_TARGET_BASE_URL =
+            "targetBaseURL";
+    const char* const LibXSLTTransformer::PARAM_DOCTYPE_SYSTEM = "sytemType";
+    const char* const LibXSLTTransformer::PARAM_DOCTYPE_PUBLIC = "publicType";
+
+    const sal_Int32 Reader::OUTPUT_BUFFER_SIZE = _OUTPUT_BUFFER_SIZE;
+
+    const sal_Int32 Reader::INPUT_BUFFER_SIZE = _INPUT_BUFFER_SIZE;
+
+    struct ParserInputBufferCallback
+    {
+        static int
+        on_read(void * context, char * buffer, int len)
+        {
+            Reader * tmp = static_cast<Reader*> (context);
+            return tmp->read(buffer, len);
+        }
+        static int
+        on_close(void * context)
+        {
+            Reader * tmp = static_cast<Reader*> (context);
+            return tmp->closeInput();
+        }
+    };
+    struct ParserOutputBufferCallback
+    {
+        static int
+        on_write(void * context, const char * buffer, int len)
+        {
+            Reader * tmp = static_cast<Reader*> (context);
+            return tmp->write(buffer, len);
+        }
+        static int
+        on_close(void * context)
+        {
+            Reader * tmp = static_cast<Reader*> (context);
+            return tmp->closeOutput();
+        }
+    };
+
+    Reader::Reader(LibXSLTTransformer* transformer) :
+        m_transformer(transformer), m_terminated(false), m_readBuf(
+                INPUT_BUFFER_SIZE), m_writeBuf(OUTPUT_BUFFER_SIZE)
+    {
+        LIBXML_TEST_VERSION;
+    }
+    ;
+
+    int
+    Reader::read(char * buffer, int len)
+    {
+        //        const char *ptr = (const char *) context;
+        if (buffer == NULL || len < 0)
+            return (-1);
+        sal_Int32 n;
+        Reference<XInputStream> xis = this->m_transformer->getInputStream();
+        n = xis.get()->readBytes(m_readBuf, len);
+        if (n > 0)
+            {
+                memcpy(buffer, m_readBuf.getArray(), n);
+            }
+        return n;
+    }
+
+    int
+    Reader::write(const char * buffer, int len)
+    {
+        if (buffer == NULL || len < 0)
+            return -1;
+        if (len > 0)
+            {
+                Reference<XOutputStream> xos = m_transformer->getOutputStream();
+                sal_Int32 writeLen = len;
+                sal_Int32 bufLen = ::std::min(writeLen,
+                        this->OUTPUT_BUFFER_SIZE);
+                const sal_uInt8* memPtr =
+                        reinterpret_cast<const sal_uInt8*> (buffer);
+                while (writeLen > 0)
+                    {
+                        sal_Int32 n = ::std::min(writeLen, bufLen);
+                        m_writeBuf.realloc(n);
+                        memcpy(m_writeBuf.getArray(), memPtr,
+                                static_cast<size_t> (n));
+                        xos.get()->writeBytes(m_writeBuf);
+                        memPtr += n;
+                        writeLen -= n;
+                    }
+            }
+        return len;
+    }
+
+    int
+    Reader::closeInput()
+    {
+        return 0;
+    }
+
+    int
+    Reader::closeOutput()
+    {
+        Reference<XOutputStream> xos = m_transformer->getOutputStream();
+        if (xos.is())
+            {
+                xos.get()->flush();
+                xos.get()->closeOutput();
+            }
+        m_transformer->done();
+        return 0;
+    }
+
+    void
+    Reader::run()
+    {
+        OSL_ASSERT(m_transformer != NULL);
+        OSL_ASSERT(m_transformer->getInputStream().is());
+        OSL_ASSERT(m_transformer->getOutputStream().is());
+        OSL_ASSERT(m_transformer->getStyleSheetURL());
+        ::std::map<const char*, OString>::iterator pit;
+        ::std::map<const char*, OString> pmap = m_transformer->getParameters();
+        const char* params[pmap.size() * 2 + 1]; // build parameters
+        int paramIndex = 0;
+        for (pit = pmap.begin(); pit != pmap.end(); pit++)
+            {
+                params[paramIndex++] = (*pit).first;
+                params[paramIndex++] = (*pit).second.getStr();
+            }
+        params[paramIndex] = NULL;
+        xmlDocPtr doc = xmlReadIO(&ParserInputBufferCallback::on_read,
+                &ParserInputBufferCallback::on_close,
+                static_cast<void*> (this), NULL, NULL, 0);
+        xsltStylesheetPtr styleSheet = xsltParseStylesheetFile(
+                (const xmlChar *) m_transformer->getStyleSheetURL().getStr());
+        xmlDocPtr result = NULL;
+        xsltTransformContextPtr tcontext = NULL;
+        if (styleSheet)
+            {
+                tcontext = xsltNewTransformContext(styleSheet, doc);
+                xsltQuoteUserParams(tcontext, params);
+                result = xsltApplyStylesheetUser(styleSheet, doc, 0, 0, 0,
+                        tcontext);
+            }
+
+        if (result)
+            {
+                xmlCharEncodingHandlerPtr encoder = xmlGetCharEncodingHandler(
+                        XML_CHAR_ENCODING_UTF8);
+                xmlOutputBufferPtr outBuf = xmlAllocOutputBuffer(encoder);
+                outBuf->context = static_cast<void *> (this);
+                outBuf->writecallback = &ParserOutputBufferCallback::on_write;
+                outBuf->closecallback = &ParserOutputBufferCallback::on_close;
+                xsltSaveResultTo(outBuf, result, styleSheet);
+            }
+        else
+            {
+                xmlErrorPtr lastErr = xmlGetLastError();
+                OUString msg;
+                if (lastErr)
+                    msg = OUString::createFromAscii(lastErr->message);
+                else
+                    msg = OUString::createFromAscii(
+                            "Unknown XSLT transformation error");
+
+                m_transformer->error(msg);
+            }
+        closeOutput();
+        xsltFreeStylesheet(styleSheet);
+        xsltFreeTransformContext(tcontext);
+        xmlFreeDoc(doc);
+        xmlFreeDoc(result);
+    }
+    ;
+
+    void
+    Reader::onTerminated()
+    {
+        m_terminated = true;
+    }
+    ;
+
+    Reader::~Reader()
+    {
+    }
+
+    LibXSLTTransformer::LibXSLTTransformer(
+            const Reference<XMultiServiceFactory> &r) :
+        m_rServiceFactory(r)
+    {
+    }
+
+    void
+    LibXSLTTransformer::setInputStream(
+            const Reference<XInputStream>& inputStream)
+            throw (RuntimeException)
+    {
+        m_rInputStream = inputStream;
+    }
+
+    Reference<XInputStream>
+    LibXSLTTransformer::getInputStream() throw (RuntimeException)
+    {
+        return m_rInputStream;
+    }
+
+    void
+    LibXSLTTransformer::setOutputStream(
+            const Reference<XOutputStream>& outputStream)
+            throw (RuntimeException)
+    {
+        m_rOutputStream = outputStream;
+    }
+
+    Reference<XOutputStream>
+    LibXSLTTransformer::getOutputStream() throw (RuntimeException)
+    {
+        return m_rOutputStream;
+    }
+
+    void
+    LibXSLTTransformer::addListener(const Reference<XStreamListener>& listener)
+            throw (RuntimeException)
+    {
+        m_listeners.insert(m_listeners.begin(), listener);
+    }
+
+    void
+    LibXSLTTransformer::removeListener(
+            const Reference<XStreamListener>& listener)
+            throw (RuntimeException)
+    {
+        m_listeners.remove(listener);
+    }
+
+    void
+    LibXSLTTransformer::start() throw (RuntimeException)
+    {
+        ListenerList::iterator it;
+        ListenerList* l = &m_listeners;
+        for (it = l->begin(); it != l->end(); it++)
+            {
+                Reference<XStreamListener> xl = *it;
+                xl.get()->started();
+            }
+        Reader* r = new Reader(this);
+        r->create();
+    }
+
+    void
+    LibXSLTTransformer::error(const OUString& msg)
+    {
+        ListenerList* l = &m_listeners;
+        Any arg;
+        arg <<= Exception(msg, *this);
+        for (ListenerList::iterator it = l->begin(); it != l->end(); it++)
+            {
+                Reference<XStreamListener> xl = *it;
+                if (xl.is())
+                    {
+                        xl.get()->error(arg);
+                    }
+            }
+    }
+
+    void
+    LibXSLTTransformer::done()
+    {
+        ListenerList* l = &m_listeners;
+        for (ListenerList::iterator it = l->begin(); it != l->end(); it++)
+            {
+                Reference<XStreamListener> xl = *it;
+                if (xl.is())
+                    {
+                        xl.get()->closed();
+                    }
+            }
+    }
+
+    void
+    LibXSLTTransformer::terminate() throw (RuntimeException)
+    {
+        m_parameters.clear();
+    }
+
+    void
+    LibXSLTTransformer::initialize(const Sequence<Any>& params)
+            throw (RuntimeException)
+    {
+        xmlSubstituteEntitiesDefault(0);
+        m_parameters.clear();
+        for (int i = 0; i < params.getLength(); i++)
+            {
+                NamedValue nv;
+                params[i] >>= nv;
+                OString nameUTF8 = OUStringToOString(nv.Name,
+                        RTL_TEXTENCODING_UTF8);
+                OUString value;
+                OString valueUTF8;
+                if (nv.Value >>= value)
+                    {
+                        valueUTF8 = OUStringToOString(value,
+                                RTL_TEXTENCODING_UTF8);
+                    }
+                else
+                    {
+                        // ignore non-string parameters
+                        continue;
+                    }
+                if (nameUTF8.equals("StylesheetURL"))
+                    {
+                        m_styleSheetURL = valueUTF8;
+                    }
+                else if (nameUTF8.equals("SourceURL"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_SOURCE_URL, valueUTF8));
+                    }
+                else if (nameUTF8.equals("SourceBaseURL"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_SOURCE_BASE_URL, valueUTF8));
+                    }
+                else if (nameUTF8.equals("TargetURL"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_TARGET_URL, valueUTF8));
+                    }
+                else if (nameUTF8.equals("TargetBaseURL"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_TARGET_BASE_URL, valueUTF8));
+                    }
+                else if (nameUTF8.equals("DoctypeSystem"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_DOCTYPE_SYSTEM, valueUTF8));
+                    }
+                else if (nameUTF8.equals("DoctypePublic"))
+                    {
+                        m_parameters.insert(pair<const char*, OString> (
+                                PARAM_DOCTYPE_PUBLIC, valueUTF8));
+                    }
+            }
+    }
+
+    const OString
+    LibXSLTTransformer::getStyleSheetURL()
+    {
+        return m_styleSheetURL;
+    }
+
+    ::std::map<const char*, OString>
+    LibXSLTTransformer::getParameters()
+    {
+        return m_parameters;
+    }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/filter/source/xsltfilter/LibXSLTTransformer.hxx 
b/filter/source/xsltfilter/LibXSLTTransformer.hxx
index 64073c0..c6c644e 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.hxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.hxx
@@ -1,142 +1,200 @@
- /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
- // MARKER(update_precomp.py): autogen include statement, do not remove
- #ifndef __LIBXSLTTRANSFORMER_HXX__
- #define __LIBXSLTTRANSFORMER_HXX__
- #include "precompiled_filter.hxx"
-
- #include <stdio.h>
-
- #include <list>
- #include <map>
-
- #include <libxml/parser.h>
- #include <libxml/tree.h>
- #include <libxml/xmlIO.h>
- #include <libxslt/transform.h>
-
- #include <cppuhelper/factory.hxx>
- #include <cppuhelper/servicefactory.hxx>
- #include <cppuhelper/implbase4.hxx>
- #include <cppuhelper/implbase.hxx>
-
- #include <osl/thread.hxx>
-
- #include <com/sun/star/uno/Any.hxx>
-
- #include <com/sun/star/io/XInputStream.hpp>
- #include <com/sun/star/io/XOutputStream.hpp>
- #include <com/sun/star/io/XActiveDataSource.hpp>
- #include <com/sun/star/io/XActiveDataSink.hpp>
- #include <com/sun/star/io/XActiveDataControl.hpp>
- #include <com/sun/star/io/XStreamListener.hpp>
- #include <com/sun/star/lang/XInitialization.hpp>
- #include <com/sun/star/beans/NamedValue.hpp>
-
- using namespace ::rtl;
- using namespace ::cppu;
- using namespace ::osl;
- using namespace ::com::sun::star::beans;
- using namespace ::com::sun::star::io;
- using namespace ::com::sun::star::uno;
- using namespace ::com::sun::star::lang;
-
- using ::std::list;
- using ::std::map;
-
- namespace XSLT {
-
-
-     class LibXSLTTransformer : public WeakImplHelper4< XActiveDataSink, XActiveDataSource, 
XActiveDataControl, XInitialization>
-     {
-     private:
-         static const char* const PARAM_SOURCE_URL;
-         static const char* const PARAM_SOURCE_BASE_URL;
-         static const char* const PARAM_TARGET_URL;
-         static const char* const PARAM_TARGET_BASE_URL;
-         static const char* const PARAM_DOCTYPE_SYSTEM;
-         static const char* const PARAM_DOCTYPE_PUBLIC;
-
-         // the UNO ServiceFactory
-         Reference< XMultiServiceFactory > m_rServiceFactory;
-
-         Reference< XInputStream> m_rInputStream;
-
-         Reference < XOutputStream > m_rOutputStream;
-
-         typedef ::std::list<Reference< XStreamListener > > ListenerList;
-
-         ListenerList m_listeners;
-
-         OString m_styleSheetURL;
-
-         ::std::map<const char *, OString> m_parameters;
-
-     public:
-
-         // ctor...
-         LibXSLTTransformer( const Reference< XMultiServiceFactory > &r );
-
-
-
-
-         // XActiveDataSink
-         virtual void SAL_CALL setInputStream(const Reference<XInputStream>& inputStream)
-             throw (RuntimeException);
-         virtual Reference<XInputStream> SAL_CALL getInputStream()
-             throw (RuntimeException);
-         // XActiveDataSource
-         virtual void SAL_CALL setOutputStream(const Reference<XOutputStream>& outputStream)
-             throw (RuntimeException);
-         virtual Reference<XOutputStream> SAL_CALL getOutputStream()
-             throw (RuntimeException);
-         // XActiveDataControl
-         virtual void SAL_CALL addListener(const Reference<XStreamListener>& listener)
-             throw (RuntimeException);
-         virtual void SAL_CALL removeListener(const Reference<XStreamListener>& listener)
-             throw (RuntimeException);
-         virtual void SAL_CALL start()
-             throw (RuntimeException);
-         virtual void SAL_CALL terminate()
-             throw (RuntimeException);
-         virtual void SAL_CALL initialize(const Sequence<Any>& params)
-             throw (RuntimeException);
-
-         void SAL_CALL done();
-
-         void SAL_CALL error(const OUString& msg);
-
-         const OString SAL_CALL getStyleSheetURL();
-
-         ::std::map<const char*, OString> SAL_CALL getParameters();
-
-     };
-
-     class Reader: public osl::Thread
-     {
-     public:
-         Reader(LibXSLTTransformer* transformer);
-         int SAL_CALL read(char * buffer, int len);
-         int SAL_CALL write(const char * buffer, int len);
-         int SAL_CALL closeInput();
-         int SAL_CALL closeOutput();
-
-     protected:
-         virtual ~Reader();
-
-     private:
-         static const sal_Int32 OUTPUT_BUFFER_SIZE;
-         static const sal_Int32 INPUT_BUFFER_SIZE;
-         LibXSLTTransformer* m_transformer;
-         sal_Bool m_terminated;
-         Sequence<sal_Int8> m_readBuf;
-         Sequence<sal_Int8> m_writeBuf;
-         virtual void SAL_CALL run();
-         virtual void SAL_CALL onTerminated();
-     };
-
- }
-
-
- #endif // __LIBXSLTTRANSFORMER_HXX__
-
- /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Peter Jentsch <pjotr@guineapics.de> ]
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Peter Jentsch <pjotr@guineapics.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#ifndef __LIBXSLTTRANSFORMER_HXX__
+#define __LIBXSLTTRANSFORMER_HXX__
+#include "precompiled_filter.hxx"
+
+#include <stdio.h>
+
+#include <list>
+#include <map>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlIO.h>
+#include <libxslt/transform.h>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <cppuhelper/implbase4.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#include <osl/thread.hxx>
+
+#include <com/sun/star/uno/Any.hxx>
+
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XActiveDataControl.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::osl;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+
+using ::std::list;
+using ::std::map;
+
+namespace XSLT
+{
+
+    /*
+     * LibXSLTTransformer provides an transforming pipe service to XSLTFilter.
+     *
+     * It implements XActiveDataSource, XActiveDataSink and XActiveDataControl
+     * to consume data. It also notifies upstream of important events such as
+     * begin and end of the transformation and of any errors that occur during
+     * transformation.
+     *
+     * TODO: Error reporting leaves room for improvement, currently.
+     *
+     * The actual transformation is done by a worker thread.
+     *
+     * See Reader below.
+     */
+    class LibXSLTTransformer : public WeakImplHelper4<XActiveDataSink,
+            XActiveDataSource, XActiveDataControl, XInitialization>
+    {
+    private:
+        static const char* const PARAM_SOURCE_URL;
+        static const char* const PARAM_SOURCE_BASE_URL;
+        static const char* const PARAM_TARGET_URL;
+        static const char* const PARAM_TARGET_BASE_URL;
+        static const char* const PARAM_DOCTYPE_SYSTEM;
+        static const char* const PARAM_DOCTYPE_PUBLIC;
+
+        // the UNO ServiceFactory
+        Reference<XMultiServiceFactory> m_rServiceFactory;
+
+        Reference<XInputStream> m_rInputStream;
+
+        Reference<XOutputStream> m_rOutputStream;
+
+        typedef ::std::list<Reference<XStreamListener> > ListenerList;
+
+        ListenerList m_listeners;
+
+        OString m_styleSheetURL;
+
+        ::std::map<const char *, OString> m_parameters;
+
+    public:
+
+        // ctor...
+        LibXSLTTransformer(const Reference<XMultiServiceFactory> &r);
+
+        // XActiveDataSink
+        virtual void SAL_CALL
+        setInputStream(const Reference<XInputStream>& inputStream)
+                throw (RuntimeException);
+        virtual Reference<XInputStream> SAL_CALL
+        getInputStream() throw (RuntimeException);
+        // XActiveDataSource
+        virtual void SAL_CALL
+        setOutputStream(const Reference<XOutputStream>& outputStream)
+                throw (RuntimeException);
+        virtual Reference<XOutputStream> SAL_CALL
+        getOutputStream() throw (RuntimeException);
+        // XActiveDataControl
+        virtual void SAL_CALL
+        addListener(const Reference<XStreamListener>& listener)
+                throw (RuntimeException);
+        virtual void SAL_CALL
+        removeListener(const Reference<XStreamListener>& listener)
+                throw (RuntimeException);
+        virtual void SAL_CALL
+        start() throw (RuntimeException);
+        virtual void SAL_CALL
+        terminate() throw (RuntimeException);
+        virtual void SAL_CALL
+        initialize(const Sequence<Any>& params) throw (RuntimeException);
+
+        void SAL_CALL
+        done();
+
+        void SAL_CALL
+        error(const OUString& msg);
+
+        const OString SAL_CALL
+        getStyleSheetURL();
+
+        ::std::map<const char*, OString> SAL_CALL
+        getParameters();
+
+    };
+
+    /*
+     * Reader provides a worker thread to perform the actual transformation.
+     * It pipes the streams provided by a LibXSLTTransformer
+     * instance through libxslt.
+     */
+    class Reader : public osl::Thread
+    {
+    public:
+        Reader(LibXSLTTransformer* transformer);
+        int SAL_CALL
+        read(char * buffer, int len);
+        int SAL_CALL
+        write(const char * buffer, int len);
+        int SAL_CALL
+        closeInput();
+        int SAL_CALL
+        closeOutput();
+
+    protected:
+        virtual
+        ~Reader();
+
+    private:
+        static const sal_Int32 OUTPUT_BUFFER_SIZE;
+        static const sal_Int32 INPUT_BUFFER_SIZE;
+        LibXSLTTransformer* m_transformer;
+        sal_Bool m_terminated;
+        Sequence<sal_Int8> m_readBuf;
+        Sequence<sal_Int8> m_writeBuf;
+        virtual void SAL_CALL
+        run();
+        virtual void SAL_CALL
+        onTerminated();
+    };
+
+}
+;
+
+#endif // __LIBXSLTTRANSFORMER_HXX__
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/xsltfilter/XSLTFilter.cxx b/filter/source/xsltfilter/XSLTFilter.cxx
index 2e3f5af..00ef373 100644
--- a/filter/source/xsltfilter/XSLTFilter.cxx
+++ b/filter/source/xsltfilter/XSLTFilter.cxx
@@ -96,602 +96,726 @@ using namespace ::com::sun::star::xml;
 using namespace ::com::sun::star::xml::sax;
 using namespace ::com::sun::star::util;
 
-namespace XSLT {
-
-
-class FLABridge : public WeakImplHelper1< XDocumentHandler>
-{
-private:
-    const Reference<XDocumentHandler>& m_rDocumentHandler;
-    const sal_Unicode *eval(const sal_Unicode *expr, sal_Int32 exprLen);
-    FLA::Evaluator ev;
-    bool active;
-
-public:
-    FLABridge(const Reference<XDocumentHandler>& m_rDocumentHandler);
-
-    // XDocumentHandler
-    virtual void SAL_CALL startDocument()
-        throw (SAXException,RuntimeException);
-    virtual void SAL_CALL endDocument()
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL startElement(const OUString& str, const Reference<XAttributeList>& 
attriblist)
-        throw (SAXException,RuntimeException);
-    virtual void SAL_CALL endElement(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL characters(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL ignorableWhitespace(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL processingInstruction(const OUString& str, const OUString& str2)
-        throw (com::sun::star::xml::sax::SAXException,RuntimeException);
-    virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator)
-        throw (SAXException,RuntimeException);
-
-};
-
-FLABridge::FLABridge(const Reference<XDocumentHandler>& _rDocumentHandler) : 
m_rDocumentHandler(_rDocumentHandler), active(false)
+namespace XSLT
 {
-}
 
-void FLABridge::startDocument() throw (SAXException,RuntimeException){
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->startDocument();
-}
+    /*
+     * FLABridge provides some obscure attribute mangling to wordml2000 import/export filters.
+     * In the long run, you might want to replace this with an XSLT extension function.
+     */
+    class FLABridge : public WeakImplHelper1<XDocumentHandler>
+    {
+    private:
+        const Reference<XDocumentHandler>& m_rDocumentHandler;
+        const sal_Unicode *
+        eval(const sal_Unicode *expr, sal_Int32 exprLen);
+        FLA::Evaluator ev;
+        bool active;
+
+    public:
+        FLABridge(const Reference<XDocumentHandler>& m_rDocumentHandler);
+
+        // XDocumentHandler
+        virtual void SAL_CALL
+        startDocument() throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        endDocument() throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        startElement(const OUString& str,
+                const Reference<XAttributeList>& attriblist)
+                throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        endElement(const OUString& str) throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        characters(const OUString& str) throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        ignorableWhitespace(const OUString& str) throw (SAXException,
+                RuntimeException);
+        virtual void SAL_CALL
+        processingInstruction(const OUString& str, const OUString& str2)
+                throw (com::sun::star::xml::sax::SAXException,
+                RuntimeException);
+        virtual void SAL_CALL
+        setDocumentLocator(const Reference<XLocator>& doclocator)
+                throw (SAXException, RuntimeException);
+
+    };
+
+    FLABridge::FLABridge(const Reference<XDocumentHandler>& _rDocumentHandler) :
+        m_rDocumentHandler(_rDocumentHandler), active(false)
+    {
+    }
 
-void FLABridge::endDocument() throw (SAXException,RuntimeException){
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->endDocument();
+    void
+    FLABridge::startDocument() throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->startDocument();
+    }
 
-}
+    void
+    FLABridge::endDocument() throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->endDocument();
 
+    }
 
-void FLABridge::startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    if (active)
-    {
-//             SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
-        const int len=attriblist->getLength();
-        SvXMLAttributeList *_newattriblist= new SvXMLAttributeList();
-        for(int i=0;i<len;i++)
-        {
-            const OUString& name=attriblist->getNameByIndex( sal::static_int_cast<sal_Int16>( i ) 
);
-            sal_Int32 pos;
-            static const OUString _value_(".value", 6, RTL_TEXTENCODING_ASCII_US);
-            if ((pos=name.lastIndexOf(L'.'))!=-1 && name.match(_value_, pos))
+    void
+    FLABridge::startElement(const OUString& str,
+            const Reference<XAttributeList>& attriblist) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        if (active)
             {
-                const OUString newName(name, pos);
-                const OUString& value=attriblist->getValueByIndex( 
sal::static_int_cast<sal_Int16>( i ) );
-                const OUString newValue(ev.eval(value.getStr(), value.getLength()));
-                if (newValue.getLength()>0)
-                {
-                    _newattriblist->AddAttribute(newName, newValue);
-                }
+                //             SvXMLAttributeList* 
_attriblist=SvXMLAttributeList::getImplementation(attriblist);
+                const int len = attriblist->getLength();
+                SvXMLAttributeList *_newattriblist = new SvXMLAttributeList();
+                for (int i = 0; i < len; i++)
+                    {
+                        const OUString& name = attriblist->getNameByIndex(
+                                sal::static_int_cast<sal_Int16>(i));
+                        sal_Int32 pos;
+                        static const OUString _value_(".value", 6,
+                                RTL_TEXTENCODING_ASCII_US);
+                        if ((pos = name.lastIndexOf(L'.')) != -1 && name.match(
+                                _value_, pos))
+                            {
+                                const OUString newName(name, pos);
+                                const OUString
+                                        & value =
+                                                attriblist->getValueByIndex(
+                                                        sal::static_int_cast<
+                                                                sal_Int16>(i));
+                                const OUString newValue(ev.eval(value.getStr(),
+                                        value.getLength()));
+                                if (newValue.getLength() > 0)
+                                    {
+                                        _newattriblist->AddAttribute(newName,
+                                                newValue);
+                                    }
+                            }
+                        else
+                            {
+                                _newattriblist->AddAttribute(
+                                        name,
+                                        attriblist->getValueByIndex(
+                                                sal::static_int_cast<sal_Int16>(
+                                                        i)));
+                            }
+                    };
+                const Reference<XAttributeList> newattriblist(_newattriblist);
+                m_rDocumentHandler->startElement(str, newattriblist);
             }
-            else
+        else
             {
-                _newattriblist->AddAttribute(name, attriblist->getValueByIndex( 
sal::static_int_cast<sal_Int16>( i )));
+                if (str.compareToAscii("fla:fla.activate") == 0)
+                    {
+                        active = 1;
+                    }
+                m_rDocumentHandler->startElement(str, attriblist);
             }
-        };
-        const Reference<XAttributeList> newattriblist(_newattriblist);
-        m_rDocumentHandler->startElement(str, newattriblist);
     }
-    else
+
+    void
+    FLABridge::endElement(const OUString& str) throw (SAXException,
+            RuntimeException)
     {
-        if (str.compareToAscii("fla:fla.activate")==0) 
-        {
-            active=1;
-        }
-        m_rDocumentHandler->startElement(str, attriblist);
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->endElement(str);
     }
-}
 
-void FLABridge::endElement(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->endElement(str);
-}
+    void
+    FLABridge::characters(const OUString& str) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->characters(str);
+    }
 
-void FLABridge::characters(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->characters(str);
-}
+    void
+    FLABridge::ignorableWhitespace(const OUString& str) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->ignorableWhitespace(str);
+    }
 
-void FLABridge::ignorableWhitespace(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->ignorableWhitespace(str);
-}
+    void
+    FLABridge::processingInstruction(const OUString& str, const OUString& str2)
+            throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->processingInstruction(str, str2);
+    }
 
-void  FLABridge::processingInstruction(const OUString& str, const OUString& str2)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->processingInstruction(str, str2);
-}
+    void
+    FLABridge::setDocumentLocator(const Reference<XLocator>& doclocator)
+            throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->setDocumentLocator(doclocator);
+    }
 
-void FLABridge::setDocumentLocator(const Reference<XLocator>& doclocator)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->setDocumentLocator(doclocator);
-}
+    class XSLTFilter : public WeakImplHelper4<XImportFilter, XExportFilter,
+            XDocumentHandler, XStreamListener>
+    {
+    private:
+        static const OUString JAXT_HELPER_SERVICE_IMPL;
+        static const OUString LIBXSLT_HELPER_SERVICE_IMPL;
+
+        // the UNO ServiceFactory
+        Reference<XMultiServiceFactory> m_rServiceFactory;
+
+        // DocumentHandler interface of the css::xml::sax::Writer service
+        Reference<XExtendedDocumentHandler> m_rDocumentHandler;
+        Reference<XOutputStream> m_rOutputStream;
+
+        // controls pretty-printing
+        sal_Bool m_bPrettyPrint;
+
+        Reference<XActiveDataControl> m_tcontrol;
+
+        oslCondition m_cTransformed;
+        sal_Bool m_bTerminated;
+        sal_Bool m_bError;
+
+        OUString m_aExportBaseUrl;
+
+        OUString
+        rel2abs(const OUString&);
+        OUString
+        expandUrl(const OUString&);
+
+    public:
+
+        // ctor...
+        XSLTFilter(const Reference<XMultiServiceFactory> &r);
+
+        // XStreamListener
+        virtual void SAL_CALL
+        error(const Any& a) throw (RuntimeException);
+        virtual void SAL_CALL
+        closed() throw (RuntimeException);
+        virtual void SAL_CALL
+        terminated() throw (RuntimeException);
+        virtual void SAL_CALL
+        started() throw (RuntimeException);
+        virtual void SAL_CALL
+        disposing(const EventObject& e) throw (RuntimeException);
+
+        // XImportFilter
+        virtual sal_Bool SAL_CALL
+        importer(const Sequence<PropertyValue>& aSourceData, const Reference<
+                XDocumentHandler>& xHandler,
+                const Sequence<OUString>& msUserData) throw (RuntimeException);
+
+        // XExportFilter
+        virtual sal_Bool SAL_CALL
+        exporter(const Sequence<PropertyValue>& aSourceData, const Sequence<
+                OUString>& msUserData) throw (RuntimeException);
+
+        // XDocumentHandler
+        virtual void SAL_CALL
+        startDocument() throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        endDocument() throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        startElement(const OUString& str,
+                const Reference<XAttributeList>& attriblist)
+                throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        endElement(const OUString& str) throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        characters(const OUString& str) throw (SAXException, RuntimeException);
+        virtual void SAL_CALL
+        ignorableWhitespace(const OUString& str) throw (SAXException,
+                RuntimeException);
+        virtual void SAL_CALL
+        processingInstruction(const OUString& str, const OUString& str2)
+                throw (com::sun::star::xml::sax::SAXException,
+                RuntimeException);
+        virtual void SAL_CALL
+        setDocumentLocator(const Reference<XLocator>& doclocator)
+                throw (SAXException, RuntimeException);
+    };
+
+    const OUString XSLTFilter::JAXT_HELPER_SERVICE_IMPL = OUString(
+            RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.JAXTHelper"));
+    const OUString
+            XSLTFilter::LIBXSLT_HELPER_SERVICE_IMPL =
+                    OUString(
+                            
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.documentconversion.LibXSLTTransformer"));
+
+    XSLTFilter::XSLTFilter(const Reference<XMultiServiceFactory> &r) :
+        m_rServiceFactory(r), m_bPrettyPrint(sal_True),
+                m_bTerminated(sal_False), m_bError(sal_False)
+    {
+        m_cTransformed = osl_createCondition();
+    }
 
+    void
+    XSLTFilter::disposing(const EventObject&) throw (RuntimeException)
+    {
+    }
 
+    ::rtl::OUString
+    XSLTFilter::expandUrl(const ::rtl::OUString& sUrl)
+    {
+        ::rtl::OUString sExpandedUrl;
+        try
+            {
+                Reference<XComponentContext> xContext;
+                Reference<XPropertySet> xProps(m_rServiceFactory,
+                        UNO_QUERY_THROW);
+                xContext.set(xProps->getPropertyValue(::rtl::OUString(
+                        RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
+                        UNO_QUERY_THROW);
+                Reference<XMacroExpander>
+                        xMacroExpander(
+                                xContext->getValueByName(
+                                        ::rtl::OUString(
+                                                RTL_CONSTASCII_USTRINGPARAM( 
"/singletons/com.sun.star.util.theMacroExpander" ))),
+                                UNO_QUERY_THROW);
+                sExpandedUrl = xMacroExpander->expandMacros(sUrl);
+                sal_Int32 nPos = sExpandedUrl.indexOf(::rtl::OUString(
+                        RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.expand:" )));
+                if (nPos != -1)
+                    sExpandedUrl = sExpandedUrl.copy(nPos + 20);
+            }
+        catch (Exception&)
+            {
+            }
+        return sExpandedUrl;
+    }
 
-class XSLTFilter : public WeakImplHelper4< XImportFilter, XExportFilter, XDocumentHandler, 
XStreamListener>
-{
-private:
-    static const OUString JAXT_HELPER_SERVICE_IMPL;
-    static const OUString LIBXSLT_HELPER_SERVICE_IMPL;
-
-    // the UNO ServiceFactory
-    Reference< XMultiServiceFactory > m_rServiceFactory;
-
-    // DocumentHandler interface of the css::xml::sax::Writer service
-    Reference < XExtendedDocumentHandler > m_rDocumentHandler;
-    Reference < XOutputStream > m_rOutputStream;
-
-    // controls pretty-printing
-    sal_Bool m_bPrettyPrint;
-
-    Reference< XActiveDataControl > m_tcontrol;
-
-    oslCondition  m_cTransformed;
-    sal_Bool m_bTerminated;
-    sal_Bool m_bError;
-
-    OUString m_aExportBaseUrl;
-
-    OUString rel2abs(const OUString&);
-    OUString expandUrl(const OUString&);
-
-public:
-
-    // ctor...
-    XSLTFilter( const Reference< XMultiServiceFactory > &r );
-
-    // XStreamListener
-    virtual void SAL_CALL error(const Any& a) throw (RuntimeException);
-    virtual void SAL_CALL closed() throw (RuntimeException);
-    virtual void SAL_CALL terminated() throw (RuntimeException);
-    virtual void SAL_CALL started() throw (RuntimeException);
-    virtual void SAL_CALL disposing(const EventObject& e) throw (RuntimeException);
-
-
-    // XImportFilter
-    virtual sal_Bool SAL_CALL importer(
-            const Sequence<PropertyValue>& aSourceData,
-            const Reference<XDocumentHandler>& xHandler,
-            const Sequence<OUString>& msUserData)
-        throw(RuntimeException);
-
-    // XExportFilter
-    virtual sal_Bool SAL_CALL exporter(
-            const Sequence<PropertyValue>& aSourceData,
-            const Sequence<OUString>& msUserData)
-        throw(RuntimeException);
-
-    // XDocumentHandler
-    virtual void SAL_CALL startDocument()
-        throw (SAXException,RuntimeException);
-    virtual void SAL_CALL endDocument()
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL startElement(const OUString& str, const Reference<XAttributeList>& 
attriblist)
-        throw (SAXException,RuntimeException);
-    virtual void SAL_CALL endElement(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL characters(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL ignorableWhitespace(const OUString& str)
-        throw (SAXException, RuntimeException);
-    virtual void SAL_CALL processingInstruction(const OUString& str, const OUString& str2)
-        throw (com::sun::star::xml::sax::SAXException,RuntimeException);
-    virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator)
-        throw (SAXException,RuntimeException);
-};
-
-const OUString XSLTFilter::JAXT_HELPER_SERVICE_IMPL = 
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.JAXTHelper"));
-const OUString XSLTFilter::LIBXSLT_HELPER_SERVICE_IMPL = 
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.documentconversion.LibXSLTTransformer"));
-
-XSLTFilter::XSLTFilter( const Reference< XMultiServiceFactory > &r )
-    : m_rServiceFactory(r)
-    , m_bPrettyPrint(sal_True)
-    , m_bTerminated(sal_False)
-    , m_bError(sal_False)
-{
-    m_cTransformed = osl_createCondition();
-}
+    void
+    XSLTFilter::started() throw (RuntimeException)
+    {
+        osl_resetCondition(m_cTransformed);
+    }
+    void
+    XSLTFilter::error(const Any& a) throw (RuntimeException)
+    {
+        Exception e;
+        if (a >>= e)
+            {
+                OString aMessage("XSLTFilter::error was called: ");
+                aMessage += OUStringToOString(e.Message,
+                        RTL_TEXTENCODING_ASCII_US);
+                OSL_ENSURE(sal_False, aMessage);
+            }
+        m_bError = sal_True;
+        osl_setCondition(m_cTransformed);
+    }
+    void
+    XSLTFilter::closed() throw (RuntimeException)
+    {
+        osl_setCondition(m_cTransformed);
+    }
+    void
+    XSLTFilter::terminated() throw (RuntimeException)
+    {
+        m_bTerminated = sal_True;
+        osl_setCondition(m_cTransformed);
+    }
 
-void XSLTFilter::disposing(const EventObject& ) throw (RuntimeException)
-{
-}
+    OUString
+    XSLTFilter::rel2abs(const OUString& s)
+    {
 
-::rtl::OUString XSLTFilter::expandUrl( const ::rtl::OUString& sUrl )
-{
-    ::rtl::OUString sExpandedUrl;
-    try
-    {
-        Reference< XComponentContext > xContext;
-        Reference< XPropertySet > xProps( m_rServiceFactory, UNO_QUERY_THROW );
-        xContext.set( xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"DefaultContext" )) ), UNO_QUERY_THROW );
-        Reference< XMacroExpander > xMacroExpander( xContext->getValueByName( ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander" )) ), UNO_QUERY_THROW 
);
-        sExpandedUrl = xMacroExpander->expandMacros(sUrl);
-        sal_Int32 nPos = sExpandedUrl.indexOf(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"vnd.sun.star.expand:" )));
-        if ( nPos != -1 )
-            sExpandedUrl = sExpandedUrl.copy(nPos+20);
-    }
-    catch (Exception&) {}
-    return sExpandedUrl;
-}
+        Reference<XStringSubstitution>
+                subs(
+                        m_rServiceFactory->createInstance(
+                                OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.util.PathSubstitution" ))),
+                        UNO_QUERY);
+        OUString aWorkingDir(subs->getSubstituteVariableValue(OUString(
+                RTL_CONSTASCII_USTRINGPARAM("$(progurl)"))));
+        INetURLObject aObj(aWorkingDir);
+        aObj.setFinalSlash();
+        bool bWasAbsolute;
+        INetURLObject aURL = aObj.smartRel2Abs(s, bWasAbsolute, false,
+                INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8, true);
+        return aURL.GetMainURL(INetURLObject::NO_DECODE);
+    }
 
-void XSLTFilter::started() throw (RuntimeException)
-{
-    osl_resetCondition(m_cTransformed);
-}
-void XSLTFilter::error(const Any& a) throw (RuntimeException)
-{
-    Exception e;
-    if ( a >>= e)
+    sal_Bool
+    XSLTFilter::importer(const Sequence<PropertyValue>& aSourceData,
+            const Reference<XDocumentHandler>& xHandler, const Sequence<
+                    OUString>& msUserData) throw (RuntimeException)
     {
-        OString aMessage("XSLTFilter::error was called: ");
-        aMessage += OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
-        OSL_ENSURE(sal_False, aMessage);
-    }
-    m_bError = sal_True;
-    osl_setCondition(m_cTransformed);
-}
-void XSLTFilter::closed() throw (RuntimeException)
-{
-    osl_setCondition(m_cTransformed);
-}
-void XSLTFilter::terminated() throw (RuntimeException)
-{
-    m_bTerminated = sal_True;
-    osl_setCondition(m_cTransformed);
-}
+        if (msUserData.getLength() < 5)
+            return sal_False;
 
-OUString XSLTFilter::rel2abs(const OUString& s)
-{
+        OUString udImport = msUserData[2];
+        OUString udStyleSheet = rel2abs(msUserData[4]);
+
+        // get information from media descriptor
+        // the imput stream that represents the imported file
+        // is most important here since we need to supply it to
+        // the sax parser that drives the supplied document handler
+        sal_Int32 nLength = aSourceData.getLength();
+        OUString aName, aFileName, aURL;
+        Reference<XInputStream> xInputStream;
+        for (sal_Int32 i = 0; i < nLength; i++)
+            {
+                aName = aSourceData[i].Name;
+                if (aName.equalsAscii("InputStream"))
+                    aSourceData[i].Value >>= xInputStream;
+                else if (aName.equalsAscii("FileName"))
+                    aSourceData[i].Value >>= aFileName;
+                else if (aName.equalsAscii("URL"))
+                    aSourceData[i].Value >>= aURL;
+            }
+        OSL_ASSERT(xInputStream.is());
+        if (!xInputStream.is())
+            return sal_False;
 
-    Reference< XStringSubstitution > subs(m_rServiceFactory->createInstance(
-        OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.PathSubstitution" ))), 
UNO_QUERY);
-    OUString 
aWorkingDir(subs->getSubstituteVariableValue(OUString(RTL_CONSTASCII_USTRINGPARAM("$(progurl)"))));
-    INetURLObject aObj( aWorkingDir );
-    aObj.setFinalSlash();
-    bool bWasAbsolute;
-    INetURLObject aURL = aObj.smartRel2Abs(
-        s, bWasAbsolute, false, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8, true );
-    return aURL.GetMainURL(INetURLObject::NO_DECODE);
-}
+        // create SAX parser that will read the document file
+        // and provide events to xHandler passed to this call
+        Reference<XParser>
+                xSaxParser(
+                        m_rServiceFactory->createInstance(
+                                OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" 
))),
+                        UNO_QUERY);
+        OSL_ASSERT(xSaxParser.is());
+        if (!xSaxParser.is())
+            return sal_False;
 
+        // create transformer
+        Sequence<Any> args(3);
+        NamedValue nv;
+
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "StylesheetURL" ));
+        nv.Value <<= expandUrl(udStyleSheet);
+        args[0] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "SourceURL" ));
+        nv.Value <<= aURL;
+        args[1] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "SourceBaseURL" ));
+        nv.Value <<= OUString(INetURLObject(aURL).getBase());
+        args[2] <<= nv;
+
+        sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
+        if (!useLibXSLT)
+            {
+                useLibXSLT
+                        = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
+            }
+        if (useLibXSLT)
+            {
+                m_tcontrol = Reference<XActiveDataControl> (
+                        m_rServiceFactory->createInstanceWithArguments(
+                                LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+            }
+        else
+            {
+                m_tcontrol = Reference<XActiveDataControl> (
+                        m_rServiceFactory->createInstanceWithArguments(
+                                JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+            }
 
+        OSL_ASSERT(xHandler.is());
+        OSL_ASSERT(xInputStream.is());
+        OSL_ASSERT(m_tcontrol.is());
+        if (xHandler.is() && xInputStream.is() && m_tcontrol.is())
+            {
+                try
+                    {
+                        // we want to be notfied when the processing is done...
+                        m_tcontrol->addListener(Reference<XStreamListener> (
+                                this));
+
+                        // connect input to transformer
+                        Reference<XActiveDataSink> tsink(m_tcontrol, UNO_QUERY);
+                        tsink->setInputStream(xInputStream);
+
+                        // create pipe
+                        Reference<XOutputStream>
+                                pipeout(
+                                        m_rServiceFactory->createInstance(
+                                                OUString(
+                                                        RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.io.Pipe" ))),
+                                        UNO_QUERY);
+                        Reference<XInputStream> pipein(pipeout, UNO_QUERY);
+
+                        //connect transformer to pipe
+                        Reference<XActiveDataSource> tsource(m_tcontrol,
+                                UNO_QUERY);
+                        tsource->setOutputStream(pipeout);
+
+                        // connect pipe to sax parser
+                        InputSource aInput;
+                        aInput.sSystemId = aURL;
+                        aInput.sPublicId = aURL;
+                        aInput.aInputStream = pipein;
+
+                        // set doc handler
+                        xSaxParser->setDocumentHandler(new FLABridge(xHandler));
+
+                        // transform
+                        m_tcontrol->start();
+                        // osl_waitCondition(m_cTransformed, 0);
+                        if (!m_bError && !m_bTerminated)
+                            {
+                                // parse the transformed XML buffered in the pipe
+                                xSaxParser->parseStream(aInput);
+                                osl_waitCondition(m_cTransformed, 0);
+                                return sal_True;
+                            }
+                        else
+                            {
+                                return sal_False;
+                            }
+                    }
+#if OSL_DEBUG_LEVEL > 0
+                catch( Exception& exc)
+#else
+                catch (Exception&)
+#endif
+                    {
+                        // something went wrong
+                        OSL_ENSURE(0, OUStringToOString(exc.Message, 
RTL_TEXTENCODING_ASCII_US).getStr());
+                        return sal_False;
+                    }
+            }
+        else
+            {
+                return sal_False;
+            }
+    }
 
-sal_Bool XSLTFilter::importer(
-        const Sequence<PropertyValue>& aSourceData,
-        const Reference<XDocumentHandler>& xHandler,
-        const Sequence<OUString>& msUserData)
-    throw (RuntimeException)
-{
-    if ( msUserData.getLength() < 5 )
-        return sal_False;
-
-    OUString udImport = msUserData[2];
-    OUString udStyleSheet = rel2abs(msUserData[4]);
-
-    // get information from media descriptor
-    // the imput stream that represents the imported file
-    // is most important here since we need to supply it to
-    // the sax parser that drives the supplied document handler
-    sal_Int32 nLength = aSourceData.getLength();
-    OUString aName, aFileName, aURL;
-    Reference< XInputStream > xInputStream;
-    for ( sal_Int32 i = 0 ; i < nLength; i++)
-    {
-        aName = aSourceData[i].Name;
-        if (aName.equalsAscii("InputStream"))
-            aSourceData[i].Value >>= xInputStream;
-        else if ( aName.equalsAscii("FileName"))
-            aSourceData[i].Value >>= aFileName;
-        else if ( aName.equalsAscii("URL"))
-            aSourceData[i].Value >>= aURL;
-    }
-    OSL_ASSERT(xInputStream.is());
-    if (!xInputStream.is()) return sal_False;
-
-    // create SAX parser that will read the document file
-    // and provide events to xHandler passed to this call
-    Reference < XParser > xSaxParser( m_rServiceFactory->createInstance(
-        OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ))), UNO_QUERY );
-    OSL_ASSERT(xSaxParser.is());
-    if(!xSaxParser.is())return sal_False;
-
-    // create transformer
-    Sequence< Any > args(3);
-    NamedValue nv;
-
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "StylesheetURL" ));
-    nv.Value <<= expandUrl(udStyleSheet); args[0] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SourceURL" ));
-    nv.Value <<= aURL; args[1] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SourceBaseURL" ));
-    nv.Value <<= OUString(INetURLObject(aURL).getBase());
-    args[2] <<= nv;
-
-    sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
-    if (!useLibXSLT) {
-        useLibXSLT = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
-    }
-    if (useLibXSLT) {
-        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
-        LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
-    } else {
-        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
-        JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
-    }
-
-    OSL_ASSERT(xHandler.is());
-    OSL_ASSERT(xInputStream.is());
-    OSL_ASSERT(m_tcontrol.is());
-    if (xHandler.is() && xInputStream.is() && m_tcontrol.is())
+    sal_Bool
+    XSLTFilter::exporter(const Sequence<PropertyValue>& aSourceData,
+            const Sequence<OUString>& msUserData) throw (RuntimeException)
     {
-        try
-        {
-            // we want to be notfied when the processing is done...
-            m_tcontrol->addListener(Reference< XStreamListener >(this));
-
-            // connect input to transformer
-            Reference< XActiveDataSink > tsink(m_tcontrol, UNO_QUERY);
-            tsink->setInputStream(xInputStream);
-
-            // create pipe
-            Reference< XOutputStream > pipeout(m_rServiceFactory->createInstance(
-                OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.Pipe" ))), UNO_QUERY);
-            Reference< XInputStream > pipein(pipeout, UNO_QUERY);
-
-            //connect transformer to pipe
-            Reference< XActiveDataSource > tsource(m_tcontrol, UNO_QUERY);
-            tsource->setOutputStream(pipeout);
-
-            // connect pipe to sax parser
-            InputSource aInput;
-            aInput.sSystemId = aURL;
-            aInput.sPublicId = aURL;
-            aInput.aInputStream = pipein;
-
-            // set doc handler
-            xSaxParser->setDocumentHandler(new FLABridge(xHandler));
-
-            // transform
-            m_tcontrol->start();
-            // osl_waitCondition(m_cTransformed, 0);
-            if (!m_bError && !m_bTerminated)
+        if (msUserData.getLength() < 6)
+            return sal_False;
+
+        // get interesting values from user data
+        OUString udImport = msUserData[2];
+        OUString udStyleSheet = rel2abs(msUserData[5]);
+
+        // read source data
+        // we are especialy interested in the output stream
+        // since that is where our xml-writer will push the data
+        // from it's data-source interface
+        OUString aName, sURL;
+        sal_Bool bIndent = sal_False;
+        OUString aDoctypePublic;
+        OUString aDoctypeSystem;
+        // Reference<XOutputStream> rOutputStream;
+        sal_Int32 nLength = aSourceData.getLength();
+        for (sal_Int32 i = 0; i < nLength; i++)
+            {
+                aName = aSourceData[i].Name;
+                if (aName.equalsAscii("Indent"))
+                    aSourceData[i].Value >>= bIndent;
+                if (aName.equalsAscii("DocType_Public"))
+                    aSourceData[i].Value >>= aDoctypePublic;
+                if (aName.equalsAscii("DocType_System"))
+                    aSourceData[i].Value >>= aDoctypeSystem;
+                if (aName.equalsAscii("OutputStream"))
+                    aSourceData[i].Value >>= m_rOutputStream;
+                else if (aName.equalsAscii("URL"))
+                    aSourceData[i].Value >>= sURL;
+            }
+
+        if (!m_rDocumentHandler.is())
             {
-                // parse the transformed XML buffered in the pipe
-                xSaxParser->parseStream(aInput);
-                osl_waitCondition(m_cTransformed, 0);
+                // get the document writer
+                m_rDocumentHandler
+                        = Reference<XExtendedDocumentHandler> (
+                                m_rServiceFactory->createInstance(
+                                        OUString(
+                                                RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.xml.sax.Writer" ))),
+                                UNO_QUERY);
+            }
+
+        // create transformer
+        Sequence<Any> args(4);
+        NamedValue nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "StylesheetURL" ));
+        nv.Value <<= expandUrl(udStyleSheet);
+        args[0] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "TargetURL" ));
+        nv.Value <<= sURL;
+        args[1] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "DoctypeSystem" ));
+        nv.Value <<= aDoctypeSystem;
+        args[2] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "DoctypePublic" ));
+        nv.Value <<= aDoctypePublic;
+        args[3] <<= nv;
+        nv.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "TargetBaseURL" ));
+        INetURLObject ineturl(sURL);
+        ineturl.removeSegment();
+        m_aExportBaseUrl = ineturl.GetMainURL(INetURLObject::NO_DECODE);
+        nv.Value <<= m_aExportBaseUrl;
+        args[3] <<= nv;
+
+        sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
+        if (!useLibXSLT)
+            {
+                useLibXSLT
+                        = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
+            }
+        if (useLibXSLT)
+            {
+                m_tcontrol = Reference<XActiveDataControl> (
+                        m_rServiceFactory->createInstanceWithArguments(
+                                LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+            }
+        else
+            {
+                m_tcontrol = Reference<XActiveDataControl> (
+                        m_rServiceFactory->createInstanceWithArguments(
+                                JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
+            }
+
+        OSL_ASSERT(m_rDocumentHandler.is());
+        OSL_ASSERT(m_rOutputStream.is());
+        OSL_ASSERT(m_tcontrol.is());
+        if (m_tcontrol.is() && m_rOutputStream.is() && m_rDocumentHandler.is())
+            {
+                // we want to be notfied when the processing is done...
+                m_tcontrol->addListener(Reference<XStreamListener> (this));
+
+                // create pipe
+                Reference<XOutputStream>
+                        pipeout(
+                                m_rServiceFactory->createInstance(
+                                        OUString(
+                                                RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.io.Pipe" ))),
+                                UNO_QUERY);
+                Reference<XInputStream> pipein(pipeout, UNO_QUERY);
+
+                // connect sax writer to pipe
+                Reference<XActiveDataSource> xmlsource(m_rDocumentHandler,
+                        UNO_QUERY);
+                xmlsource->setOutputStream(pipeout);
+
+                // connect pipe to transformer
+                Reference<XActiveDataSink> tsink(m_tcontrol, UNO_QUERY);
+                tsink->setInputStream(pipein);
+
+                // connect transformer to output
+                Reference<XActiveDataSource> tsource(m_tcontrol, UNO_QUERY);
+                tsource->setOutputStream(m_rOutputStream);
+
+                // we will start receiving events after returning 'true'.
+                // we will start the transformation as soon as we receive the startDocument
+                // event.
                 return sal_True;
-            } else {
+            }
+        else
+            {
                 return sal_False;
             }
-        }
-#if OSL_DEBUG_LEVEL > 0
-        catch( Exception& exc)
-#else
-        catch( Exception& )
-#endif
-        {
-            // something went wrong
-            OSL_ENSURE(0, OUStringToOString(exc.Message, RTL_TEXTENCODING_ASCII_US).getStr());
-            return sal_False;
-        }
-    } else
-    {
-        return sal_False;
     }
-}
 
-sal_Bool XSLTFilter::exporter(
-        const Sequence<PropertyValue>& aSourceData,
-        const Sequence<OUString>& msUserData)
-    throw (RuntimeException)
-{
-    if ( msUserData.getLength() < 6 )
-        return sal_False;
-
-    // get interesting values from user data
-    OUString udImport = msUserData[2];
-    OUString udStyleSheet = rel2abs(msUserData[5]);
-
-    // read source data
-    // we are especialy interested in the output stream
-    // since that is where our xml-writer will push the data
-    // from it's data-source interface
-    OUString aName, sURL;
-    sal_Bool bIndent = sal_False;
-    OUString aDoctypePublic;
-    OUString aDoctypeSystem;
-    // Reference<XOutputStream> rOutputStream;
-    sal_Int32 nLength = aSourceData.getLength();
-    for ( sal_Int32 i = 0 ; i < nLength; i++)
-    {
-        aName = aSourceData[i].Name;
-        if ( aName.equalsAscii("Indent"))
-            aSourceData[i].Value >>= bIndent;
-        if ( aName.equalsAscii("DocType_Public"))
-            aSourceData[i].Value >>= aDoctypePublic;
-        if ( aName.equalsAscii("DocType_System"))
-            aSourceData[i].Value >>= aDoctypeSystem;
-        if ( aName.equalsAscii("OutputStream"))
-            aSourceData[i].Value >>= m_rOutputStream;
-        else if ( aName.equalsAscii("URL" ))
-            aSourceData[i].Value >>= sURL;
-    }
-
-    if (!m_rDocumentHandler.is()) {
-        // get the document writer
-        m_rDocumentHandler = Reference<XExtendedDocumentHandler>(
-            m_rServiceFactory->createInstance(
-            OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ))),
-                UNO_QUERY);
-    }
-
-    // create transformer
-    Sequence< Any > args(4);
-    NamedValue nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "StylesheetURL" ));
-    nv.Value <<= expandUrl(udStyleSheet); args[0] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "TargetURL" ));
-    nv.Value <<= sURL; args[1] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DoctypeSystem" ));
-    nv.Value <<= aDoctypeSystem; args[2] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "DoctypePublic" ));
-    nv.Value <<= aDoctypePublic; args[3] <<= nv;
-    nv.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "TargetBaseURL" ));
-    INetURLObject ineturl(sURL);
-    ineturl.removeSegment();
-    m_aExportBaseUrl = ineturl.GetMainURL(INetURLObject::NO_DECODE);
-    nv.Value <<= m_aExportBaseUrl;
-    args[3] <<= nv;
-
-    sal_Bool useLibXSLT = USE_LIBXSLT_DEFAULT;
-    if (!useLibXSLT) {
-        useLibXSLT = msUserData[1].equalsIgnoreAsciiCaseAscii("libxslt");
-    }
-    if (useLibXSLT) {
-        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
-        LIBXSLT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
-    } else {
-        m_tcontrol = Reference< XActiveDataControl 
(m_rServiceFactory->createInstanceWithArguments(
-        JAXT_HELPER_SERVICE_IMPL, args), UNO_QUERY);
-    }
-
-    OSL_ASSERT(m_rDocumentHandler.is());
-    OSL_ASSERT(m_rOutputStream.is());
-    OSL_ASSERT(m_tcontrol.is());
-    if (m_tcontrol.is() && m_rOutputStream.is() && m_rDocumentHandler.is())
-    {
-        // we want to be notfied when the processing is done...
-        m_tcontrol->addListener(Reference< XStreamListener >(this));
-
-        // create pipe
-        Reference< XOutputStream > pipeout(m_rServiceFactory->createInstance(
-            OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.Pipe" ))), UNO_QUERY);
-        Reference< XInputStream > pipein(pipeout, UNO_QUERY);
-
-        // connect sax writer to pipe
-        Reference< XActiveDataSource > xmlsource(m_rDocumentHandler, UNO_QUERY);
-        xmlsource->setOutputStream(pipeout);
-
-        // connect pipe to transformer
-        Reference< XActiveDataSink > tsink(m_tcontrol, UNO_QUERY);
-        tsink->setInputStream(pipein);
-
-        // connect transformer to output
-        Reference< XActiveDataSource > tsource(m_tcontrol, UNO_QUERY);
-        tsource->setOutputStream(m_rOutputStream);
-
-        // we will start receiving events after returning 'true'.
-        // we will start the transformation as soon as we receive the startDocument 
-        // event.
-        return sal_True;
-    }
-    else
-    {
-        return sal_False;
+    // for the DocumentHandler implementation, we just proxy the the
+    // events to the XML writer that we created upon the output stream
+    // that was provided by the XMLFilterAdapter
+    void
+    XSLTFilter::startDocument() throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->startDocument();
+        m_tcontrol->start();
     }
-}
-
-// for the DocumentHandler implementation, we just proxy the the
-// events to the XML writer that we created upon the output stream
-// that was provided by the XMLFilterAdapter
-void XSLTFilter::startDocument() throw (SAXException,RuntimeException){
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->startDocument();
-    m_tcontrol->start();
-}
 
-void XSLTFilter::endDocument() throw (SAXException, RuntimeException){
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->endDocument();
-    // wait for the transformer to finish
-    osl_waitCondition(m_cTransformed, 0);
-    if (!m_bError && !m_bTerminated)
+    void
+    XSLTFilter::endDocument() throw (SAXException, RuntimeException)
     {
-        return;
-    } else {        
-        throw RuntimeException();
-    }
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->endDocument();
+        // wait for the transformer to finish
+        osl_waitCondition(m_cTransformed, 0);
+        if (!m_bError && !m_bTerminated)
+            {
+                return;
+            }
+        else
+            {
+                throw RuntimeException();
+            }
 
-}
+    }
 
-void XSLTFilter::startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-//     SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
-    m_rDocumentHandler->startElement(str, attriblist);
-}
+    void
+    XSLTFilter::startElement(const OUString& str, const Reference<
+            XAttributeList>& attriblist) throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        //     SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
+        m_rDocumentHandler->startElement(str, attriblist);
+    }
 
-void XSLTFilter::endElement(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->endElement(str);
-}
+    void
+    XSLTFilter::endElement(const OUString& str) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->endElement(str);
+    }
 
-void XSLTFilter::characters(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->characters(str);
-}
+    void
+    XSLTFilter::characters(const OUString& str) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->characters(str);
+    }
 
-void XSLTFilter::ignorableWhitespace(const OUString& str)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    if (!m_bPrettyPrint) return;
-    m_rDocumentHandler->ignorableWhitespace(str);
-}
+    void
+    XSLTFilter::ignorableWhitespace(const OUString& str) throw (SAXException,
+            RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        if (!m_bPrettyPrint)
+            return;
+        m_rDocumentHandler->ignorableWhitespace(str);
+    }
 
-void  XSLTFilter::processingInstruction(const OUString& str, const OUString& str2)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->processingInstruction(str, str2);
-}
+    void
+    XSLTFilter::processingInstruction(const OUString& str, const OUString& str2)
+            throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->processingInstruction(str, str2);
+    }
 
-void XSLTFilter::setDocumentLocator(const Reference<XLocator>& doclocator)
-    throw (SAXException, RuntimeException)
-{
-    OSL_ASSERT(m_rDocumentHandler.is());
-    m_rDocumentHandler->setDocumentLocator(doclocator);
-}
+    void
+    XSLTFilter::setDocumentLocator(const Reference<XLocator>& doclocator)
+            throw (SAXException, RuntimeException)
+    {
+        OSL_ASSERT(m_rDocumentHandler.is());
+        m_rDocumentHandler->setDocumentLocator(doclocator);
+    }
 
-// --------------------------------------
-// Component management
-// --------------------------------------
+    // --------------------------------------
+    // Component management
+    // --------------------------------------
 #define FILTER_SERVICE_NAME "com.sun.star.documentconversion.XSLTFilter"
 #define FILTER_IMPL_NAME "com.sun.star.comp.documentconversion.XSLTFilter"
 #define TRANSFORMER_SERVICE_NAME "com.sun.star.documentconversion.LibXSLTTransformer"
 #define TRANSFORMER_IMPL_NAME "com.sun.star.comp.documentconversion.LibXSLTTransformer"
 
-static Reference< XInterface > SAL_CALL CreateTransformerInstance( const Reference< 
XMultiServiceFactory > &r)
-{
-    return Reference< XInterface >(( OWeakObject *)new LibXSLTTransformer(r));
-}
+    static Reference<XInterface> SAL_CALL
+    CreateTransformerInstance(const Reference<XMultiServiceFactory> &r)
+    {
+        return Reference<XInterface> ((OWeakObject *) new LibXSLTTransformer(r));
+    }
 
-static Reference< XInterface > SAL_CALL CreateFilterInstance( const Reference< 
XMultiServiceFactory > &r)
-{
-    return Reference< XInterface >(( OWeakObject *)new XSLTFilter(r));
-}
+    static Reference<XInterface> SAL_CALL
+    CreateFilterInstance(const Reference<XMultiServiceFactory> &r)
+    {
+        return Reference<XInterface> ((OWeakObject *) new XSLTFilter(r));
+    }
 
 }
 
@@ -699,76 +823,98 @@ using namespace XSLT;
 
 extern "C"
 {
-void SAL_CALL component_getImplementationEnvironment(
-    const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ )
-{
-    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
-}
+    void SAL_CALL
+    component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,
+            uno_Environment ** /* ppEnv */)
+    {
+        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+    }
 
-sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey )
-{
-    sal_Bool bRetVal = sal_False;
-    if (pRegistryKey)
+    sal_Bool SAL_CALL
+    component_writeInfo(void * /* pServiceManager */, void * pRegistryKey)
     {
-        try
-        {
-            Reference< XRegistryKey > pXNewKey( static_cast< XRegistryKey* >( pRegistryKey ) );
-            pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" FILTER_IMPL_NAME 
"/UNO/SERVICES/" FILTER_SERVICE_NAME ) ) );
-            bRetVal = sal_True;
-
-            pXNewKey=  static_cast< XRegistryKey* >( pRegistryKey );
-            pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" TRANSFORMER_IMPL_NAME 
"/UNO/SERVICES/" TRANSFORMER_SERVICE_NAME ) ) );
-            bRetVal = sal_True;
-        }
-        catch( InvalidRegistryException& )
-        {
-            OSL_ENSURE(sal_False, "InvalidRegistryException caught");
-            bRetVal = sal_False;
-        }
-    }
-    return bRetVal;
-}
+        sal_Bool bRetVal = sal_False;
+        if (pRegistryKey)
+            {
+                try
+                    {
+                        Reference<XRegistryKey> pXNewKey(
+                                static_cast<XRegistryKey*> (pRegistryKey));
+                        pXNewKey->createKey(
+                                OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( "/" FILTER_IMPL_NAME 
"/UNO/SERVICES/" FILTER_SERVICE_NAME )));
+                        bRetVal = sal_True;
+
+                        pXNewKey = static_cast<XRegistryKey*> (pRegistryKey);
+                        pXNewKey->createKey(
+                                OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( "/" TRANSFORMER_IMPL_NAME 
"/UNO/SERVICES/" TRANSFORMER_SERVICE_NAME )));
+                        bRetVal = sal_True;
+                    }
+                catch (InvalidRegistryException&)
+                    {
+                        OSL_ENSURE(sal_False, "InvalidRegistryException caught");
+                        bRetVal = sal_False;
+                    }
+            }
+        return bRetVal;
+    }
 
-void * SAL_CALL component_getFactory(
-    const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
-{
-    void * pRet = 0;
-
-    if (pServiceManager) {
-        if (rtl_str_compare( pImplName, FILTER_IMPL_NAME ) == 0) {
-            Sequence< OUString > serviceNames( 1 );
-            serviceNames.getArray( )[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( 
FILTER_SERVICE_NAME ) );
-
-            Reference< XSingleServiceFactory > xFactory(
-                                                        createSingleFactory(
-                                                                            reinterpret_cast< 
XMultiServiceFactory * >( pServiceManager ),
-                                                                            
OUString::createFromAscii( pImplName ),
-                                                                            CreateFilterInstance, 
serviceNames ) );
-
-            if (xFactory.is())
-                {
-                    xFactory->acquire();
-                    pRet = xFactory.get();
-                }
-        } else if (rtl_str_compare( pImplName, TRANSFORMER_IMPL_NAME ) == 0) {
-            Sequence< OUString > serviceNames( 1 );
-            serviceNames.getArray( )[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( 
TRANSFORMER_SERVICE_NAME ) );
-            Reference< XSingleServiceFactory > xFactory(
-                                                        createSingleFactory(
-                                                                            reinterpret_cast< 
XMultiServiceFactory * >( pServiceManager ),
-                                                                            
OUString::createFromAscii( pImplName ),
-                                                                            
CreateTransformerInstance, serviceNames ) );
-
-            if (xFactory.is())
-                {
-                    xFactory->acquire();
-                    pRet = xFactory.get();
-                }
-
-        }
-    }
-    return pRet;
-}
+    void *
+    SAL_CALL component_getFactory(const sal_Char * pImplName,
+            void * pServiceManager, void * /* pRegistryKey */)
+    {
+        void * pRet = 0;
+
+        if (pServiceManager)
+            {
+                if (rtl_str_compare(pImplName, FILTER_IMPL_NAME) == 0)
+                    {
+                        Sequence<OUString> serviceNames(1);
+                        serviceNames.getArray()[0]
+                                = OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( FILTER_SERVICE_NAME ));
+
+                        Reference<XSingleServiceFactory>
+                                xFactory(
+                                        createSingleFactory(
+                                                reinterpret_cast<XMultiServiceFactory *> 
(pServiceManager),
+                                                OUString::createFromAscii(
+                                                        pImplName),
+                                                CreateFilterInstance,
+                                                serviceNames));
+
+                        if (xFactory.is())
+                            {
+                                xFactory->acquire();
+                                pRet = xFactory.get();
+                            }
+                    }
+                else if (rtl_str_compare(pImplName, TRANSFORMER_IMPL_NAME) == 0)
+                    {
+                        Sequence<OUString> serviceNames(1);
+                        serviceNames.getArray()[0]
+                                = OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( TRANSFORMER_SERVICE_NAME ));
+                        Reference<XSingleServiceFactory>
+                                xFactory(
+                                        createSingleFactory(
+                                                reinterpret_cast<XMultiServiceFactory *> 
(pServiceManager),
+                                                OUString::createFromAscii(
+                                                        pImplName),
+                                                CreateTransformerInstance,
+                                                serviceNames));
+
+                        if (xFactory.is())
+                            {
+                                xFactory->acquire();
+                                pRet = xFactory.get();
+                            }
+
+                    }
+            }
+        return pRet;
+    }
 
 } // extern "C"
 
-- 
1.7.1


From d0e3dace797e62c950de14d25ac50b8c6a1a8654 Mon Sep 17 00:00:00 2001
From: Peter Jentsch <pjotr@guineapics.de>
Date: Fri, 7 Jan 2011 21:52:38 +0100
Subject: [PATCH 4/4] More documentation for XSLTFilter.

---
 filter/source/xsltfilter/XSLTFilter.cxx |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/filter/source/xsltfilter/XSLTFilter.cxx b/filter/source/xsltfilter/XSLTFilter.cxx
index 00ef373..991df63 100644
--- a/filter/source/xsltfilter/XSLTFilter.cxx
+++ b/filter/source/xsltfilter/XSLTFilter.cxx
@@ -258,6 +258,18 @@ namespace XSLT
         m_rDocumentHandler->setDocumentLocator(doclocator);
     }
 
+    /*
+     * XSLTFilter reads flat xml streams from the XML filter framework and passes
+     * them to an XSLT transformation service. XSLT transformation errors are
+     * reported to XSLTFilter.
+     *
+     * Currently, two implemations for the XSLT transformation service exist:
+     * a java based service (see XSLTransformer.java) and  a libxslt based
+     * service (LibXSLTTransformer.cxx).
+     *
+     * The libxslt implementation will be used, if the value of the 2nd "UserData"
+     * parameter of the filter configuration is "libxslt"
+     */
     class XSLTFilter : public WeakImplHelper4<XImportFilter, XExportFilter,
             XDocumentHandler, XStreamListener>
     {
-- 
1.7.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.