LCOV - code coverage report
Current view: top level - filter/source/xsltfilter - LibXSLTTransformer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 9 9 100.0 %
Date: 2015-06-13 12:38:46 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #ifndef INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
      11             : #define INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
      12             : 
      13             : #include <list>
      14             : #include <map>
      15             : 
      16             : #include <libxml/parser.h>
      17             : #include <libxml/tree.h>
      18             : #include <libxml/xmlIO.h>
      19             : #include <libxslt/transform.h>
      20             : #include <libxml/xpathInternals.h>
      21             : 
      22             : #include <cppuhelper/factory.hxx>
      23             : #include <cppuhelper/implbase1.hxx>
      24             : 
      25             : #include <rtl/ref.hxx>
      26             : 
      27             : #include <salhelper/thread.hxx>
      28             : 
      29             : #include <com/sun/star/uno/Any.hxx>
      30             : 
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <com/sun/star/io/XInputStream.hpp>
      33             : #include <com/sun/star/io/XOutputStream.hpp>
      34             : #include <com/sun/star/io/XStreamListener.hpp>
      35             : #include <com/sun/star/beans/NamedValue.hpp>
      36             : #include <com/sun/star/xml/xslt/XXSLTTransformer.hpp>
      37             : 
      38             : using namespace ::cppu;
      39             : using namespace ::osl;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::io;
      42             : using namespace ::com::sun::star::uno;
      43             : 
      44             : using ::std::list;
      45             : using ::std::map;
      46             : 
      47             : #define EXT_MODULE_OLE_URI "http://libreoffice.org/2011/xslt/ole"
      48             : 
      49             : namespace XSLT
      50             : {
      51             : 
      52             :     /*
      53             :      * LibXSLTTransformer provides an transforming pipe service to XSLTFilter.
      54             :      *
      55             :      * It implements XActiveDataSource, XActiveDataSink and XActiveDataControl
      56             :      * to consume data. It also notifies upstream of important events such as
      57             :      * begin and end of the transformation and of any errors that occur during
      58             :      * transformation.
      59             :      *
      60             :      * TODO: Error reporting leaves room for improvement, currently.
      61             :      *
      62             :      * The actual transformation is done by a worker thread.
      63             :      *
      64             :      * See Reader below.
      65             :      */
      66             :     class LibXSLTTransformer : public WeakImplHelper1<com::sun::star::xml::xslt::XXSLTTransformer>
      67             :     {
      68             :     private:
      69             :         static const char* const PARAM_SOURCE_URL;
      70             :         static const char* const PARAM_SOURCE_BASE_URL;
      71             :         static const char* const PARAM_TARGET_URL;
      72             :         static const char* const PARAM_TARGET_BASE_URL;
      73             :         static const char* const PARAM_DOCTYPE_PUBLIC;
      74             : 
      75             :         // the UNO ServiceFactory
      76             :         com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> m_xContext;
      77             : 
      78             :         com::sun::star::uno::Reference<XInputStream> m_rInputStream;
      79             : 
      80             :         com::sun::star::uno::Reference<XOutputStream> m_rOutputStream;
      81             : 
      82             :         typedef ::std::list<com::sun::star::uno::Reference<XStreamListener> > ListenerList;
      83             : 
      84             :         ListenerList m_listeners;
      85             : 
      86             :         OString m_styleSheetURL;
      87             : 
      88             :         ::std::map<const char *, OString> m_parameters;
      89             : 
      90             :         rtl::Reference< salhelper::Thread > m_Reader;
      91             : 
      92             :     protected:
      93           6 :         virtual ~LibXSLTTransformer() {
      94           2 :             if (m_Reader.is()) {
      95           2 :                     m_Reader->terminate();
      96           2 :                     m_Reader->join();
      97             :             }
      98           4 :         }
      99             : 
     100             :     public:
     101             : 
     102             :         // ctor...
     103             :         LibXSLTTransformer(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> &r);
     104             : 
     105             :         // XActiveDataSink
     106             :         virtual void SAL_CALL
     107             :         setInputStream(const com::sun::star::uno::Reference<XInputStream>& inputStream)
     108             :                 throw (RuntimeException, std::exception) SAL_OVERRIDE;
     109             :         virtual com::sun::star::uno::Reference<XInputStream> SAL_CALL
     110             :         getInputStream() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     111             :         // XActiveDataSource
     112             :         virtual void SAL_CALL
     113             :         setOutputStream(const com::sun::star::uno::Reference<XOutputStream>& outputStream)
     114             :                 throw (RuntimeException, std::exception) SAL_OVERRIDE;
     115             :         virtual com::sun::star::uno::Reference<XOutputStream> SAL_CALL
     116             :         getOutputStream() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     117             :         // XActiveDataControl
     118             :         virtual void SAL_CALL
     119             :         addListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
     120             :                 throw (RuntimeException, std::exception) SAL_OVERRIDE;
     121             :         virtual void SAL_CALL
     122             :         removeListener(const com::sun::star::uno::Reference<XStreamListener>& listener)
     123             :                 throw (RuntimeException, std::exception) SAL_OVERRIDE;
     124             :         virtual void SAL_CALL
     125             :         start() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     126             :         virtual void SAL_CALL
     127             :         terminate() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     128             :         virtual void SAL_CALL
     129             :         initialize(const Sequence<Any>& params) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     130             : 
     131             :         void SAL_CALL
     132             :         done();
     133             : 
     134             :         void SAL_CALL
     135             :         error(const OUString& msg);
     136             : 
     137             :         const OString SAL_CALL
     138           4 :         getStyleSheetURL() { return m_styleSheetURL; }
     139             : 
     140             :         ::std::map<const char*, OString> SAL_CALL
     141           4 :         getParameters() { return m_parameters; }
     142             : 
     143             :         com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> SAL_CALL
     144           4 :         getComponentContext() {
     145           4 :             return m_xContext;
     146             :         }
     147             : 
     148             :     };
     149             : 
     150             :     /*
     151             :      * Reader provides a worker thread to perform the actual transformation.
     152             :      * It pipes the streams provided by a LibXSLTTransformer
     153             :      * instance through libxslt.
     154             :      */
     155             :     class Reader : public salhelper::Thread
     156             :     {
     157             :     public:
     158             :         Reader(LibXSLTTransformer* transformer);
     159             :         int SAL_CALL
     160             :         read(char * buffer, int len);
     161             :         int SAL_CALL
     162             :         write(const char * buffer, int len);
     163             :         int SAL_CALL
     164             :         closeOutput();
     165             : 
     166             :     private:
     167             :         virtual
     168             :         ~Reader();
     169             : 
     170             :         static const sal_Int32 OUTPUT_BUFFER_SIZE;
     171             :         static const sal_Int32 INPUT_BUFFER_SIZE;
     172             :         LibXSLTTransformer* m_transformer;
     173             :         Sequence<sal_Int8> m_readBuf;
     174             :         Sequence<sal_Int8> m_writeBuf;
     175             : 
     176             :         virtual void execute() SAL_OVERRIDE;
     177             :         static void SAL_CALL registerExtensionModule();
     178             :     };
     179             : 
     180             : }
     181             : ;
     182             : 
     183             : #endif // INCLUDED_FILTER_SOURCE_XSLTFILTER_LIBXSLTTRANSFORMER_HXX
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11