bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / xsltfilter / LibXSLTTransformer.hxx
blob2479c5b1f6d22f166d3378cc07d716754441afa9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef __LIBXSLTTRANSFORMER_HXX__
11 #define __LIBXSLTTRANSFORMER_HXX__
13 #include <stdio.h>
15 #include <list>
16 #include <map>
18 #include <libxml/parser.h>
19 #include <libxml/tree.h>
20 #include <libxml/xmlIO.h>
21 #include <libxslt/transform.h>
22 #include <libxml/xpathInternals.h>
24 #include <cppuhelper/factory.hxx>
25 #include <cppuhelper/implbase1.hxx>
26 #include <cppuhelper/implbase.hxx>
28 #include <rtl/ref.hxx>
30 #include <salhelper/thread.hxx>
32 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/io/XInputStream.hpp>
36 #include <com/sun/star/io/XOutputStream.hpp>
37 #include <com/sun/star/io/XStreamListener.hpp>
38 #include <com/sun/star/beans/NamedValue.hpp>
39 #include <com/sun/star/xml/xslt/XXSLTTransformer.hpp>
41 using namespace ::rtl;
42 using namespace ::cppu;
43 using namespace ::osl;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::io;
46 using namespace ::com::sun::star::uno;
48 using ::std::list;
49 using ::std::map;
51 #define EXT_MODULE_OLE_URI "http://libreoffice.org/2011/xslt/ole"
53 namespace XSLT
57 * LibXSLTTransformer provides an transforming pipe service to XSLTFilter.
59 * It implements XActiveDataSource, XActiveDataSink and XActiveDataControl
60 * to consume data. It also notifies upstream of important events such as
61 * begin and end of the transformation and of any errors that occur during
62 * transformation.
64 * TODO: Error reporting leaves room for improvement, currently.
66 * The actual transformation is done by a worker thread.
68 * See Reader below.
70 class LibXSLTTransformer : public WeakImplHelper1<com::sun::star::xml::xslt::XXSLTTransformer>
72 private:
73 static const char* const PARAM_SOURCE_URL;
74 static const char* const PARAM_SOURCE_BASE_URL;
75 static const char* const PARAM_TARGET_URL;
76 static const char* const PARAM_TARGET_BASE_URL;
77 static const char* const PARAM_DOCTYPE_PUBLIC;
79 // the UNO ServiceFactory
80 com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> m_rServiceFactory;
82 com::sun::star::uno::Reference<XInputStream> m_rInputStream;
84 com::sun::star::uno::Reference<XOutputStream> m_rOutputStream;
86 typedef ::std::list<com::sun::star::uno::Reference<XStreamListener> > ListenerList;
88 ListenerList m_listeners;
90 OString m_styleSheetURL;
92 ::std::map<const char *, OString> m_parameters;
94 rtl::Reference< salhelper::Thread > m_Reader;
96 protected:
97 virtual ~LibXSLTTransformer() {
98 if (m_Reader.is()) {
99 m_Reader->terminate();
100 m_Reader->join();
104 public:
106 // ctor...
107 LibXSLTTransformer(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> &r);
109 // XActiveDataSink
110 virtual void SAL_CALL
111 setInputStream(const com::sun::star::uno::Reference<XInputStream>& inputStream)
112 throw (RuntimeException);
113 virtual com::sun::star::uno::Reference<XInputStream> SAL_CALL
114 getInputStream() throw (RuntimeException);
115 // XActiveDataSource
116 virtual void SAL_CALL
117 setOutputStream(const com::sun::star::uno::Reference<XOutputStream>& outputStream)
118 throw (RuntimeException);
119 virtual com::sun::star::uno::Reference<XOutputStream> SAL_CALL
120 getOutputStream() throw (RuntimeException);
121 // XActiveDataControl
122 virtual void SAL_CALL
123 addListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
124 throw (RuntimeException);
125 virtual void SAL_CALL
126 removeListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
127 throw (RuntimeException);
128 virtual void SAL_CALL
129 start() throw (RuntimeException);
130 virtual void SAL_CALL
131 terminate() throw (RuntimeException);
132 virtual void SAL_CALL
133 initialize(const Sequence<Any>& params) throw (RuntimeException);
135 void SAL_CALL
136 done();
138 void SAL_CALL
139 error(const OUString& msg);
141 const OString SAL_CALL
142 getStyleSheetURL();
144 ::std::map<const char*, OString> SAL_CALL
145 getParameters();
147 virtual com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> SAL_CALL
148 getServiceFactory() {
149 return m_rServiceFactory;
155 * Reader provides a worker thread to perform the actual transformation.
156 * It pipes the streams provided by a LibXSLTTransformer
157 * instance through libxslt.
159 class Reader : public salhelper::Thread
161 public:
162 Reader(LibXSLTTransformer* transformer);
163 int SAL_CALL
164 read(char * buffer, int len);
165 int SAL_CALL
166 write(const char * buffer, int len);
167 int SAL_CALL
168 closeInput();
169 int SAL_CALL
170 closeOutput();
172 private:
173 virtual
174 ~Reader();
176 static const sal_Int32 OUTPUT_BUFFER_SIZE;
177 static const sal_Int32 INPUT_BUFFER_SIZE;
178 LibXSLTTransformer* m_transformer;
179 Sequence<sal_Int8> m_readBuf;
180 Sequence<sal_Int8> m_writeBuf;
182 virtual void
183 execute();
184 void SAL_CALL
185 registerExtensionModule();
191 #endif // __LIBXSLTTRANSFORMER_HXX__
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */