Bump version to 6.4-15
[LibreOffice.git] / filter / source / xsltfilter / LibXSLTTransformer.hxx
blobd646d5dbfc4364720e53fd3f2430c45f66fa788d
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 INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
11 #define INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
13 #include <deque>
14 #include <map>
15 #include <mutex>
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
19 #include <libxml/xmlIO.h>
20 #include <libxslt/transform.h>
21 #include <libxml/xpathInternals.h>
23 #include <cppuhelper/factory.hxx>
24 #include <cppuhelper/implbase.hxx>
26 #include <rtl/ref.hxx>
28 #include <salhelper/thread.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <com/sun/star/io/XStreamListener.hpp>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/xml/xslt/XXSLTTransformer.hpp>
37 using namespace ::cppu;
38 using namespace ::osl;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::io;
41 using namespace ::com::sun::star::uno;
43 using ::std::map;
45 #define EXT_MODULE_OLE_URI "http://libreoffice.org/2011/xslt/ole"
47 namespace XSLT
50 class LibXSLTTransformer;
53 * Reader provides a worker thread to perform the actual transformation.
54 * It pipes the streams provided by a LibXSLTTransformer
55 * instance through libxslt.
57 class Reader : public salhelper::Thread
59 public:
60 Reader(LibXSLTTransformer* transformer);
61 int read(char * buffer, int len);
62 int write(const char * buffer, int len);
63 void forceStateStopped();
64 void closeOutput();
66 private:
67 virtual ~Reader() override;
69 static const sal_Int32 OUTPUT_BUFFER_SIZE;
70 static const sal_Int32 INPUT_BUFFER_SIZE;
71 LibXSLTTransformer* m_transformer;
72 Sequence<sal_Int8> m_readBuf;
73 Sequence<sal_Int8> m_writeBuf;
75 std::mutex m_mutex;
76 xsltTransformContextPtr m_tcontext;
78 virtual void execute() override;
79 static void registerExtensionModule();
83 * LibXSLTTransformer provides a transforming pipe service to XSLTFilter.
85 * It implements XActiveDataSource, XActiveDataSink and XActiveDataControl
86 * to consume data. It also notifies upstream of important events such as
87 * begin and end of the transformation and of any errors that occur during
88 * transformation.
90 * TODO: Error reporting leaves room for improvement, currently.
92 * The actual transformation is done by a worker thread.
94 * See Reader below.
96 class LibXSLTTransformer : public WeakImplHelper<css::xml::xslt::XXSLTTransformer>
98 private:
99 static const char* const PARAM_SOURCE_URL;
100 static const char* const PARAM_SOURCE_BASE_URL;
101 static const char* const PARAM_TARGET_URL;
102 static const char* const PARAM_TARGET_BASE_URL;
103 static const char* const PARAM_DOCTYPE_PUBLIC;
105 // the UNO ServiceFactory
106 css::uno::Reference<css::uno::XComponentContext> m_xContext;
108 css::uno::Reference<XInputStream> m_rInputStream;
110 css::uno::Reference<XOutputStream> m_rOutputStream;
112 typedef ::std::deque<css::uno::Reference<XStreamListener> > ListenerList;
114 ListenerList m_listeners;
116 OString m_styleSheetURL;
118 ::std::map<const char *, OString> m_parameters;
120 rtl::Reference<Reader> m_Reader;
122 protected:
123 virtual ~LibXSLTTransformer() override {
124 if (m_Reader.is()) {
125 m_Reader->terminate();
126 m_Reader->forceStateStopped();
127 m_Reader->join();
131 public:
133 // ctor...
134 LibXSLTTransformer(const css::uno::Reference<css::uno::XComponentContext> &r);
136 // XActiveDataSink
137 virtual void SAL_CALL
138 setInputStream(const css::uno::Reference<XInputStream>& inputStream) override;
139 virtual css::uno::Reference<XInputStream> SAL_CALL
140 getInputStream() override;
141 // XActiveDataSource
142 virtual void SAL_CALL
143 setOutputStream(const css::uno::Reference<XOutputStream>& outputStream) override;
144 virtual css::uno::Reference<XOutputStream> SAL_CALL
145 getOutputStream() override;
146 // XActiveDataControl
147 virtual void SAL_CALL
148 addListener(const css::uno::Reference<XStreamListener>& listener) override;
149 virtual void SAL_CALL
150 removeListener(const css::uno::Reference<XStreamListener>& listener) override;
151 virtual void SAL_CALL
152 start() override;
153 virtual void SAL_CALL
154 terminate() override;
155 virtual void SAL_CALL
156 initialize(const Sequence<Any>& params) override;
158 void
159 done();
161 void
162 error(const OUString& msg);
164 const OString&
165 getStyleSheetURL() const { return m_styleSheetURL; }
167 const ::std::map<const char*, OString>&
168 getParameters() const { return m_parameters; }
170 const css::uno::Reference<css::uno::XComponentContext>&
171 getComponentContext() const {
172 return m_xContext;
178 #endif // INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */