Bump for 4.0-15
[LibreOffice.git] / filter / source / xsltfilter / LibXSLTTransformer.hxx
blob3e7bf28167269fdb09c58a506f618f19364e2406
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Initial Developer of the Original Code is
16 * [ Peter Jentsch <pjotr@guineapics.de> ]
17 * Portions created by the Initial Developer are Copyright (C) 2010 the
18 * Initial Developer. All Rights Reserved.
20 * Contributor(s): Peter Jentsch <pjotr@guineapics.de>
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #ifndef __LIBXSLTTRANSFORMER_HXX__
30 #define __LIBXSLTTRANSFORMER_HXX__
32 #include <stdio.h>
34 #include <list>
35 #include <map>
37 #include <libxml/parser.h>
38 #include <libxml/tree.h>
39 #include <libxml/xmlIO.h>
40 #include <libxslt/transform.h>
41 #include <libxml/xpathInternals.h>
43 #include <cppuhelper/factory.hxx>
44 #include <cppuhelper/servicefactory.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 #include <cppuhelper/implbase.hxx>
48 #include <rtl/ref.hxx>
50 #include <salhelper/thread.hxx>
52 #include <com/sun/star/uno/Any.hxx>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/io/XInputStream.hpp>
56 #include <com/sun/star/io/XOutputStream.hpp>
57 #include <com/sun/star/io/XStreamListener.hpp>
58 #include <com/sun/star/beans/NamedValue.hpp>
59 #include <com/sun/star/xml/xslt/XXSLTTransformer.hpp>
61 using namespace ::rtl;
62 using namespace ::cppu;
63 using namespace ::osl;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::io;
66 using namespace ::com::sun::star::uno;
68 using ::std::list;
69 using ::std::map;
71 #define EXT_MODULE_OLE_URI "http://libreoffice.org/2011/xslt/ole"
73 namespace XSLT
77 * LibXSLTTransformer provides an transforming pipe service to XSLTFilter.
79 * It implements XActiveDataSource, XActiveDataSink and XActiveDataControl
80 * to consume data. It also notifies upstream of important events such as
81 * begin and end of the transformation and of any errors that occur during
82 * transformation.
84 * TODO: Error reporting leaves room for improvement, currently.
86 * The actual transformation is done by a worker thread.
88 * See Reader below.
90 class LibXSLTTransformer : public WeakImplHelper1<com::sun::star::xml::xslt::XXSLTTransformer>
92 private:
93 static const char* const PARAM_SOURCE_URL;
94 static const char* const PARAM_SOURCE_BASE_URL;
95 static const char* const PARAM_TARGET_URL;
96 static const char* const PARAM_TARGET_BASE_URL;
97 static const char* const PARAM_DOCTYPE_PUBLIC;
99 // the UNO ServiceFactory
100 com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> m_rServiceFactory;
102 com::sun::star::uno::Reference<XInputStream> m_rInputStream;
104 com::sun::star::uno::Reference<XOutputStream> m_rOutputStream;
106 typedef ::std::list<com::sun::star::uno::Reference<XStreamListener> > ListenerList;
108 ListenerList m_listeners;
110 OString m_styleSheetURL;
112 ::std::map<const char *, OString> m_parameters;
114 rtl::Reference< salhelper::Thread > m_Reader;
116 protected:
117 virtual ~LibXSLTTransformer() {
118 if (m_Reader.is()) {
119 m_Reader->terminate();
120 m_Reader->join();
124 public:
126 // ctor...
127 LibXSLTTransformer(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> &r);
129 // XActiveDataSink
130 virtual void SAL_CALL
131 setInputStream(const com::sun::star::uno::Reference<XInputStream>& inputStream)
132 throw (RuntimeException);
133 virtual com::sun::star::uno::Reference<XInputStream> SAL_CALL
134 getInputStream() throw (RuntimeException);
135 // XActiveDataSource
136 virtual void SAL_CALL
137 setOutputStream(const com::sun::star::uno::Reference<XOutputStream>& outputStream)
138 throw (RuntimeException);
139 virtual com::sun::star::uno::Reference<XOutputStream> SAL_CALL
140 getOutputStream() throw (RuntimeException);
141 // XActiveDataControl
142 virtual void SAL_CALL
143 addListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
144 throw (RuntimeException);
145 virtual void SAL_CALL
146 removeListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
147 throw (RuntimeException);
148 virtual void SAL_CALL
149 start() throw (RuntimeException);
150 virtual void SAL_CALL
151 terminate() throw (RuntimeException);
152 virtual void SAL_CALL
153 initialize(const Sequence<Any>& params) throw (RuntimeException);
155 void SAL_CALL
156 done();
158 void SAL_CALL
159 error(const OUString& msg);
161 const OString SAL_CALL
162 getStyleSheetURL();
164 ::std::map<const char*, OString> SAL_CALL
165 getParameters();
167 virtual com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> SAL_CALL
168 getServiceFactory() {
169 return m_rServiceFactory;
175 * Reader provides a worker thread to perform the actual transformation.
176 * It pipes the streams provided by a LibXSLTTransformer
177 * instance through libxslt.
179 class Reader : public salhelper::Thread
181 public:
182 Reader(LibXSLTTransformer* transformer);
183 int SAL_CALL
184 read(char * buffer, int len);
185 int SAL_CALL
186 write(const char * buffer, int len);
187 int SAL_CALL
188 closeInput();
189 int SAL_CALL
190 closeOutput();
192 private:
193 virtual
194 ~Reader();
196 static const sal_Int32 OUTPUT_BUFFER_SIZE;
197 static const sal_Int32 INPUT_BUFFER_SIZE;
198 LibXSLTTransformer* m_transformer;
199 Sequence<sal_Int8> m_readBuf;
200 Sequence<sal_Int8> m_writeBuf;
202 virtual void
203 execute();
204 void SAL_CALL
205 registerExtensionModule();
211 #endif // __LIBXSLTTRANSFORMER_HXX__
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */