LCOV - code coverage report
Current view: top level - filter/source/xsltfilter - XSLTFilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 239 0.0 %
Date: 2012-08-25 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <stdio.h>
      31                 :            : 
      32                 :            : #include <cppuhelper/factory.hxx>
      33                 :            : #include <cppuhelper/servicefactory.hxx>
      34                 :            : #include <cppuhelper/implbase4.hxx>
      35                 :            : #include <cppuhelper/implbase.hxx>
      36                 :            : 
      37                 :            : #include <sax/tools/documenthandleradapter.hxx>
      38                 :            : 
      39                 :            : #include <osl/time.h>
      40                 :            : #include <osl/conditn.h>
      41                 :            : #include <rtl/strbuf.hxx>
      42                 :            : #include <tools/urlobj.hxx>
      43                 :            : 
      44                 :            : #include <comphelper/componentcontext.hxx>
      45                 :            : #include <comphelper/interaction.hxx>
      46                 :            : 
      47                 :            : #include <com/sun/star/lang/XComponent.hpp>
      48                 :            : #include <com/sun/star/lang/EventObject.hpp>
      49                 :            : 
      50                 :            : #include <com/sun/star/uno/Any.hxx>
      51                 :            : 
      52                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      53                 :            : 
      54                 :            : #include <com/sun/star/xml/sax/XParser.hpp>
      55                 :            : #include <com/sun/star/xml/sax/InputSource.hpp>
      56                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      57                 :            : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      58                 :            : #include <com/sun/star/xml/sax/SAXException.hpp>
      59                 :            : #include <com/sun/star/xml/XImportFilter.hpp>
      60                 :            : #include <com/sun/star/xml/XExportFilter.hpp>
      61                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      62                 :            : 
      63                 :            : #include <com/sun/star/util/XMacroExpander.hpp>
      64                 :            : 
      65                 :            : #include <com/sun/star/io/XInputStream.hpp>
      66                 :            : #include <com/sun/star/io/XOutputStream.hpp>
      67                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      68                 :            : #include <com/sun/star/io/XActiveDataSink.hpp>
      69                 :            : #include <com/sun/star/io/XActiveDataControl.hpp>
      70                 :            : #include <com/sun/star/io/XStreamListener.hpp>
      71                 :            : #include <com/sun/star/util/PathSubstitution.hpp>
      72                 :            : #include <com/sun/star/util/XStringSubstitution.hpp>
      73                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      74                 :            : #include <com/sun/star/task/XInteractionHandler.hpp>
      75                 :            : #include <com/sun/star/task/XInteractionRequest.hpp>
      76                 :            : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      77                 :            : 
      78                 :            : #include <xmloff/attrlist.hxx>
      79                 :            : 
      80                 :            : #include <LibXSLTTransformer.hxx>
      81                 :            : 
      82                 :            : #define TRANSFORMATION_TIMEOUT_SEC 60
      83                 :            : 
      84                 :            : using namespace ::rtl;
      85                 :            : using namespace ::cppu;
      86                 :            : using namespace ::osl;
      87                 :            : using namespace ::sax;
      88                 :            : using namespace ::com::sun::star::beans;
      89                 :            : using namespace ::com::sun::star::io;
      90                 :            : using namespace ::com::sun::star::uno;
      91                 :            : using namespace ::com::sun::star::lang;
      92                 :            : using namespace ::com::sun::star::registry;
      93                 :            : using namespace ::com::sun::star::xml;
      94                 :            : using namespace ::com::sun::star::xml::sax;
      95                 :            : using namespace ::com::sun::star::util;
      96                 :            : using namespace ::com::sun::star::task;
      97                 :            : 
      98                 :            : namespace css = com::sun::star;
      99                 :            : 
     100                 :            : namespace XSLT
     101                 :            : {
     102                 :            :     /*
     103                 :            :      * XSLTFilter reads flat XML streams from the XML filter framework and passes
     104                 :            :      * them to an XSLT transformation service. XSLT transformation errors are
     105                 :            :      * reported to XSLTFilter.
     106                 :            :      *
     107                 :            :      * Currently, two implementations for the XSLT transformation service exist:
     108                 :            :      * a java based service (see XSLTransformer.java) and  a libxslt based
     109                 :            :      * service (LibXSLTTransformer.cxx).
     110                 :            :      *
     111                 :            :      * The libxslt implementation will be used by default.
     112                 :            :      *
     113                 :            :      * If the value of the 2nd "UserData" parameter of the filter configuration is
     114                 :            :      * not empty, the service name given there will be used.
     115                 :            :      */
     116                 :          0 :     class XSLTFilter : public WeakImplHelper4<XImportFilter, XExportFilter,
     117                 :            :             XStreamListener, ExtendedDocumentHandlerAdapter>
     118                 :            :     {
     119                 :            :     private:
     120                 :            : 
     121                 :            :         // the UNO ServiceFactory
     122                 :            :         css::uno::Reference<XMultiServiceFactory> m_rServiceFactory;
     123                 :            : 
     124                 :            :         // DocumentHandler interface of the css::xml::sax::Writer service
     125                 :            :         css::uno::Reference<XOutputStream> m_rOutputStream;
     126                 :            : 
     127                 :            :         css::uno::Reference<XActiveDataControl> m_tcontrol;
     128                 :            : 
     129                 :            :         oslCondition m_cTransformed;
     130                 :            :         sal_Bool m_bTerminated;
     131                 :            :         sal_Bool m_bError;
     132                 :            : 
     133                 :            :         OUString m_aExportBaseUrl;
     134                 :            : 
     135                 :            :         OUString
     136                 :            :         rel2abs(const OUString&);
     137                 :            :         OUString
     138                 :            :         expandUrl(const OUString&);
     139                 :            : 
     140                 :            :     public:
     141                 :            : 
     142                 :            :         // ctor...
     143                 :            :         XSLTFilter(const css::uno::Reference<XMultiServiceFactory> &r);
     144                 :            : 
     145                 :            :         // XStreamListener
     146                 :            :         virtual void SAL_CALL
     147                 :            :         error(const Any& a) throw (RuntimeException);
     148                 :            :         virtual void SAL_CALL
     149                 :            :         closed() throw (RuntimeException);
     150                 :            :         virtual void SAL_CALL
     151                 :            :         terminated() throw (RuntimeException);
     152                 :            :         virtual void SAL_CALL
     153                 :            :         started() throw (RuntimeException);
     154                 :            :         virtual void SAL_CALL
     155                 :            :         disposing(const EventObject& e) throw (RuntimeException);
     156                 :            : 
     157                 :            :         // XImportFilter
     158                 :            :         virtual sal_Bool SAL_CALL
     159                 :            :         importer(const Sequence<PropertyValue>& aSourceData, const css::uno::Reference<
     160                 :            :                 XDocumentHandler>& xHandler,
     161                 :            :                 const Sequence<OUString>& msUserData) throw (RuntimeException);
     162                 :            : 
     163                 :            :         // XExportFilter
     164                 :            :         virtual sal_Bool SAL_CALL
     165                 :            :         exporter(const Sequence<PropertyValue>& aSourceData, const Sequence<
     166                 :            :                 OUString>& msUserData) throw (RuntimeException);
     167                 :            : 
     168                 :            :         // XDocumentHandler
     169                 :            :         virtual void SAL_CALL
     170                 :            :         startDocument() throw (SAXException, RuntimeException);
     171                 :            :         virtual void SAL_CALL
     172                 :            :         endDocument() throw (SAXException, RuntimeException);
     173                 :            :     };
     174                 :            : 
     175                 :          0 :     XSLTFilter::XSLTFilter(const css::uno::Reference<XMultiServiceFactory> &r):
     176                 :          0 : m_rServiceFactory(r), m_bTerminated(sal_False), m_bError(sal_False)
     177                 :            :     {
     178                 :          0 :         m_cTransformed = osl_createCondition();
     179                 :          0 :     }
     180                 :            : 
     181                 :            :     void
     182                 :          0 :     XSLTFilter::disposing(const EventObject&) throw (RuntimeException)
     183                 :            :     {
     184                 :          0 :     }
     185                 :            : 
     186                 :            :     ::rtl::OUString
     187                 :          0 :     XSLTFilter::expandUrl(const ::rtl::OUString& sUrl)
     188                 :            :     {
     189                 :          0 :         ::rtl::OUString sExpandedUrl;
     190                 :            :         try
     191                 :            :             {
     192                 :          0 :                 css::uno::Reference<XComponentContext> xContext;
     193                 :            :                 css::uno::Reference<XPropertySet> xProps(m_rServiceFactory,
     194                 :          0 :                         UNO_QUERY_THROW);
     195                 :          0 :                 xContext.set(xProps->getPropertyValue(::rtl::OUString(
     196                 :          0 :                          "DefaultContext" )),
     197                 :          0 :                         UNO_QUERY_THROW);
     198                 :            :                 css::uno::Reference<XMacroExpander>
     199                 :            :                         xMacroExpander(
     200                 :          0 :                                 xContext->getValueByName(
     201                 :            :                                         ::rtl::OUString(
     202                 :          0 :                                                  "/singletons/com.sun.star.util.theMacroExpander" )),
     203                 :          0 :                                 UNO_QUERY_THROW);
     204                 :          0 :                 sExpandedUrl = xMacroExpander->expandMacros(sUrl);
     205                 :          0 :                 sal_Int32 nPos = sExpandedUrl.indexOf( "vnd.sun.star.expand:" );
     206                 :          0 :                 if (nPos != -1)
     207                 :          0 :                     sExpandedUrl = sExpandedUrl.copy(nPos + 20);
     208                 :            :             }
     209                 :          0 :         catch (const Exception&)
     210                 :            :             {
     211                 :            :             }
     212                 :          0 :         return sExpandedUrl;
     213                 :            :     }
     214                 :            : 
     215                 :            :     void
     216                 :          0 :     XSLTFilter::started() throw (RuntimeException)
     217                 :            :     {
     218                 :          0 :         osl_resetCondition(m_cTransformed);
     219                 :          0 :     }
     220                 :            :     void
     221                 :          0 :     XSLTFilter::error(const Any& a) throw (RuntimeException)
     222                 :            :     {
     223                 :          0 :         Exception e;
     224                 :          0 :         if (a >>= e)
     225                 :            :         {
     226                 :          0 :             rtl::OStringBuffer aMessage(RTL_CONSTASCII_STRINGPARAM("XSLTFilter::error was called: "));
     227                 :          0 :             aMessage.append(rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US));
     228                 :          0 :             OSL_FAIL(aMessage.getStr());
     229                 :            :         }
     230                 :          0 :         m_bError = sal_True;
     231                 :          0 :         osl_setCondition(m_cTransformed);
     232                 :          0 :     }
     233                 :            :     void
     234                 :          0 :     XSLTFilter::closed() throw (RuntimeException)
     235                 :            :     {
     236                 :          0 :         osl_setCondition(m_cTransformed);
     237                 :          0 :     }
     238                 :            :     void
     239                 :          0 :     XSLTFilter::terminated() throw (RuntimeException)
     240                 :            :     {
     241                 :          0 :         m_bTerminated = sal_True;
     242                 :          0 :         osl_setCondition(m_cTransformed);
     243                 :          0 :     }
     244                 :            : 
     245                 :            :     OUString
     246                 :          0 :     XSLTFilter::rel2abs(const OUString& s)
     247                 :            :     {
     248                 :            : 
     249                 :          0 :         css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::ComponentContext(m_rServiceFactory).getUNOContext() );
     250                 :            :         css::uno::Reference<XStringSubstitution>
     251                 :          0 :                 subs(css::util::PathSubstitution::create(xContext));
     252                 :          0 :         OUString aWorkingDir(subs->getSubstituteVariableValue(OUString( "$(progurl)")));
     253                 :          0 :         INetURLObject aObj(aWorkingDir);
     254                 :          0 :         aObj.setFinalSlash();
     255                 :            :         bool bWasAbsolute;
     256                 :            :         INetURLObject aURL = aObj.smartRel2Abs(s, bWasAbsolute, false,
     257                 :          0 :                 INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8, true);
     258                 :          0 :         return aURL.GetMainURL(INetURLObject::NO_DECODE);
     259                 :            :     }
     260                 :            : 
     261                 :            :     sal_Bool
     262                 :          0 :     XSLTFilter::importer(const Sequence<PropertyValue>& aSourceData,
     263                 :            :             const css::uno::Reference<XDocumentHandler>& xHandler, const Sequence<
     264                 :            :                     OUString>& msUserData) throw (RuntimeException)
     265                 :            :     {
     266                 :          0 :         if (msUserData.getLength() < 5)
     267                 :          0 :             return sal_False;
     268                 :            : 
     269                 :          0 :         OUString udImport = msUserData[2];
     270                 :          0 :         OUString udStyleSheet = rel2abs(msUserData[4]);
     271                 :            : 
     272                 :            :         // get information from media descriptor
     273                 :            :         // the imput stream that represents the imported file
     274                 :            :         // is most important here since we need to supply it to
     275                 :            :         // the sax parser that drives the supplied document handler
     276                 :          0 :         sal_Int32 nLength = aSourceData.getLength();
     277                 :          0 :         OUString aName, aFileName, aURL;
     278                 :          0 :         css::uno::Reference<XInputStream> xInputStream;
     279                 :          0 :         css::uno::Reference<XInteractionHandler> xInterActionHandler;
     280                 :          0 :         for (sal_Int32 i = 0; i < nLength; i++)
     281                 :            :             {
     282                 :          0 :                 aName = aSourceData[i].Name;
     283                 :          0 :                 Any value = aSourceData[i].Value;
     284                 :          0 :                 if ( aName == "InputStream" )
     285                 :          0 :                     value >>= xInputStream;
     286                 :          0 :                 else if ( aName == "FileName" )
     287                 :          0 :                     value >>= aFileName;
     288                 :          0 :                 else if ( aName == "URL" )
     289                 :          0 :                     value >>= aURL;
     290                 :          0 :                 else if ( aName == "InteractionHandler" )
     291                 :          0 :                     value >>= xInterActionHandler;
     292                 :          0 :             }
     293                 :            :         OSL_ASSERT(xInputStream.is());
     294                 :          0 :         if (!xInputStream.is())
     295                 :          0 :             return sal_False;
     296                 :            : 
     297                 :            :         // create SAX parser that will read the document file
     298                 :            :         // and provide events to xHandler passed to this call
     299                 :            :         css::uno::Reference<XParser>
     300                 :            :                 xSaxParser(
     301                 :          0 :                         m_rServiceFactory->createInstance(
     302                 :            :                                 OUString(
     303                 :          0 :                                          "com.sun.star.xml.sax.Parser" )),
     304                 :          0 :                         UNO_QUERY);
     305                 :            :         OSL_ASSERT(xSaxParser.is());
     306                 :          0 :         if (!xSaxParser.is())
     307                 :          0 :             return sal_False;
     308                 :            : 
     309                 :            :         // create transformer
     310                 :          0 :         Sequence<Any> args(3);
     311                 :          0 :         NamedValue nv;
     312                 :            : 
     313                 :          0 :         nv.Name = OUString( "StylesheetURL" );
     314                 :          0 :         nv.Value <<= expandUrl(udStyleSheet);
     315                 :          0 :         args[0] <<= nv;
     316                 :          0 :         nv.Name = OUString( "SourceURL" );
     317                 :          0 :         nv.Value <<= aURL;
     318                 :          0 :         args[1] <<= nv;
     319                 :          0 :         nv.Name = OUString( "SourceBaseURL" );
     320                 :          0 :         nv.Value <<= OUString(INetURLObject(aURL).getBase());
     321                 :          0 :         args[2] <<= nv;
     322                 :            : 
     323                 :          0 :         OUString serviceName("com.sun.star.comp.documentconversion.LibXSLTTransformer");
     324                 :          0 :         if (!msUserData[1].isEmpty())
     325                 :          0 :             serviceName = msUserData[1];
     326                 :            : 
     327                 :          0 :         m_tcontrol = css::uno::Reference<XActiveDataControl> (m_rServiceFactory->createInstanceWithArguments(serviceName, args), UNO_QUERY);
     328                 :            : 
     329                 :            :         OSL_ASSERT(xHandler.is());
     330                 :            :         OSL_ASSERT(xInputStream.is());
     331                 :            :         OSL_ASSERT(m_tcontrol.is());
     332                 :          0 :         if (xHandler.is() && xInputStream.is() && m_tcontrol.is())
     333                 :            :             {
     334                 :            :                 try
     335                 :            :                     {
     336                 :            :                         // we want to be notfied when the processing is done...
     337                 :          0 :                         m_tcontrol->addListener(css::uno::Reference<XStreamListener> (
     338                 :          0 :                                 this));
     339                 :            : 
     340                 :            :                         // connect input to transformer
     341                 :          0 :                         css::uno::Reference<XActiveDataSink> tsink(m_tcontrol, UNO_QUERY);
     342                 :          0 :                         tsink->setInputStream(xInputStream);
     343                 :            : 
     344                 :            :                         // create pipe
     345                 :            :                         css::uno::Reference<XOutputStream>
     346                 :            :                                 pipeout(
     347                 :          0 :                                         m_rServiceFactory->createInstance(
     348                 :            :                                                 OUString(
     349                 :          0 :                                                          "com.sun.star.io.Pipe" )),
     350                 :          0 :                                         UNO_QUERY);
     351                 :          0 :                         css::uno::Reference<XInputStream> pipein(pipeout, UNO_QUERY);
     352                 :            : 
     353                 :            :                         //connect transformer to pipe
     354                 :            :                         css::uno::Reference<XActiveDataSource> tsource(m_tcontrol,
     355                 :          0 :                                 UNO_QUERY);
     356                 :          0 :                         tsource->setOutputStream(pipeout);
     357                 :            : 
     358                 :            :                         // connect pipe to sax parser
     359                 :          0 :                         InputSource aInput;
     360                 :          0 :                         aInput.sSystemId = aURL;
     361                 :          0 :                         aInput.sPublicId = aURL;
     362                 :          0 :                         aInput.aInputStream = pipein;
     363                 :            : 
     364                 :            :                         // set doc handler
     365                 :          0 :                         xSaxParser->setDocumentHandler(xHandler);
     366                 :            : 
     367                 :            :                         // transform
     368                 :          0 :                         m_tcontrol->start();
     369                 :          0 :                         TimeValue timeout = { TRANSFORMATION_TIMEOUT_SEC, 0};
     370                 :          0 :                         oslConditionResult result(osl_waitCondition(m_cTransformed, &timeout));
     371                 :          0 :                         while (osl_cond_result_timeout == result) {
     372                 :          0 :                                 if (xInterActionHandler.is()) {
     373                 :          0 :                                         Sequence<Any> excArgs(0);
     374                 :            :                                         ::com::sun::star::ucb::InteractiveAugmentedIOException exc(
     375                 :            :                                                 rtl::OUString("Timeout!"),
     376                 :            :                                                 static_cast< OWeakObject * >( this ),
     377                 :            :                                                 InteractionClassification_ERROR,
     378                 :            :                                                 ::com::sun::star::ucb::IOErrorCode_GENERAL,
     379                 :          0 :                                                  excArgs);
     380                 :          0 :                                         Any r;
     381                 :          0 :                                         r <<= exc;
     382                 :          0 :                                         ::comphelper::OInteractionRequest* pRequest = new ::comphelper::OInteractionRequest(r);
     383                 :          0 :                                         css::uno::Reference< XInteractionRequest > xRequest(pRequest);
     384                 :          0 :                                         ::comphelper::OInteractionRetry* pRetry = new ::comphelper::OInteractionRetry;
     385                 :          0 :                                         ::comphelper::OInteractionAbort* pAbort = new ::comphelper::OInteractionAbort;
     386                 :          0 :                                         pRequest->addContinuation(pRetry);
     387                 :          0 :                                         pRequest->addContinuation(pAbort);
     388                 :          0 :                                         xInterActionHandler->handle(xRequest);
     389                 :          0 :                                         if (pAbort->wasSelected()) {
     390                 :          0 :                                                 m_bError = sal_True;
     391                 :          0 :                                                 osl_setCondition(m_cTransformed);
     392                 :          0 :                                         }
     393                 :            :                                 }
     394                 :          0 :                                 result = osl_waitCondition(m_cTransformed, &timeout);
     395                 :            :                         };
     396                 :          0 :                         if (!m_bError) {
     397                 :          0 :                                 xSaxParser->parseStream(aInput);
     398                 :            :                         }
     399                 :          0 :                         m_tcontrol->terminate();
     400                 :          0 :                         return !m_bError;
     401                 :            :                     }
     402                 :            : #if OSL_DEBUG_LEVEL > 0
     403                 :            :                 catch( const Exception& exc)
     404                 :            : #else
     405                 :          0 :                 catch (const Exception&)
     406                 :            : #endif
     407                 :            :                     {
     408                 :            :                         // something went wrong
     409                 :            :                         OSL_FAIL(OUStringToOString(exc.Message, RTL_TEXTENCODING_ASCII_US).getStr());
     410                 :          0 :                         return sal_False;
     411                 :            :                     }
     412                 :            :             }
     413                 :            :         else
     414                 :            :             {
     415                 :          0 :                 return sal_False;
     416                 :          0 :             }
     417                 :            :     }
     418                 :            : 
     419                 :            :     sal_Bool
     420                 :          0 :     XSLTFilter::exporter(const Sequence<PropertyValue>& aSourceData,
     421                 :            :             const Sequence<OUString>& msUserData) throw (RuntimeException)
     422                 :            :     {
     423                 :          0 :         if (msUserData.getLength() < 6)
     424                 :          0 :             return sal_False;
     425                 :            : 
     426                 :            :         // get interesting values from user data
     427                 :          0 :         OUString udImport = msUserData[2];
     428                 :          0 :         OUString udStyleSheet = rel2abs(msUserData[5]);
     429                 :            : 
     430                 :            :         // read source data
     431                 :            :         // we are especialy interested in the output stream
     432                 :            :         // since that is where our xml-writer will push the data
     433                 :            :         // from it's data-source interface
     434                 :          0 :         OUString aName, sURL;
     435                 :          0 :         sal_Bool bIndent = sal_False;
     436                 :          0 :         OUString aDoctypePublic;
     437                 :          0 :         OUString aDoctypeSystem;
     438                 :            :         // css::uno::Reference<XOutputStream> rOutputStream;
     439                 :          0 :         sal_Int32 nLength = aSourceData.getLength();
     440                 :          0 :         for (sal_Int32 i = 0; i < nLength; i++)
     441                 :            :             {
     442                 :          0 :                 aName = aSourceData[i].Name;
     443                 :          0 :                 if ( aName == "Indent" )
     444                 :          0 :                     aSourceData[i].Value >>= bIndent;
     445                 :          0 :                 if ( aName == "DocType_Public" )
     446                 :          0 :                     aSourceData[i].Value >>= aDoctypePublic;
     447                 :          0 :                 if ( aName == "DocType_System" )
     448                 :          0 :                     aSourceData[i].Value >>= aDoctypeSystem;
     449                 :          0 :                 if ( aName == "OutputStream" )
     450                 :          0 :                     aSourceData[i].Value >>= m_rOutputStream;
     451                 :          0 :                 else if ( aName == "URL" )
     452                 :          0 :                     aSourceData[i].Value >>= sURL;
     453                 :            :             }
     454                 :            : 
     455                 :          0 :         if (!getDelegate().is())
     456                 :            :             {
     457                 :            :                 // get the document writer
     458                 :            :                 setDelegate(css::uno::Reference<XExtendedDocumentHandler> (
     459                 :          0 :                                 m_rServiceFactory->createInstance(
     460                 :            :                                         OUString(
     461                 :          0 :                                                  "com.sun.star.xml.sax.Writer" )),
     462                 :          0 :                                 UNO_QUERY));
     463                 :            :             }
     464                 :            : 
     465                 :            :         // create transformer
     466                 :          0 :         Sequence<Any> args(4);
     467                 :          0 :         NamedValue nv;
     468                 :          0 :         nv.Name = OUString( "StylesheetURL" );
     469                 :          0 :         nv.Value <<= expandUrl(udStyleSheet);
     470                 :          0 :         args[0] <<= nv;
     471                 :          0 :         nv.Name = OUString( "TargetURL" );
     472                 :          0 :         nv.Value <<= sURL;
     473                 :          0 :         args[1] <<= nv;
     474                 :          0 :         nv.Name = OUString( "DoctypeSystem" );
     475                 :          0 :         nv.Value <<= aDoctypeSystem;
     476                 :          0 :         args[2] <<= nv;
     477                 :          0 :         nv.Name = OUString( "DoctypePublic" );
     478                 :          0 :         nv.Value <<= aDoctypePublic;
     479                 :          0 :         args[3] <<= nv;
     480                 :          0 :         nv.Name = OUString( "TargetBaseURL" );
     481                 :          0 :         INetURLObject ineturl(sURL);
     482                 :          0 :         ineturl.removeSegment();
     483                 :          0 :         m_aExportBaseUrl = ineturl.GetMainURL(INetURLObject::NO_DECODE);
     484                 :          0 :         nv.Value <<= m_aExportBaseUrl;
     485                 :          0 :         args[3] <<= nv;
     486                 :            : 
     487                 :          0 :         OUString serviceName("com.sun.star.comp.documentconversion.LibXSLTTransformer");
     488                 :          0 :         if (!msUserData[1].isEmpty())
     489                 :          0 :             serviceName = msUserData[1];
     490                 :            : 
     491                 :          0 :         m_tcontrol = css::uno::Reference<XActiveDataControl> (m_rServiceFactory->createInstanceWithArguments(serviceName, args), UNO_QUERY);
     492                 :            : 
     493                 :            :         OSL_ASSERT(m_rOutputStream.is());
     494                 :            :         OSL_ASSERT(m_tcontrol.is());
     495                 :          0 :         if (m_tcontrol.is() && m_rOutputStream.is())
     496                 :            :             {
     497                 :            :                 // we want to be notfied when the processing is done...
     498                 :          0 :                 m_tcontrol->addListener(css::uno::Reference<XStreamListener> (this));
     499                 :            : 
     500                 :            :                 // create pipe
     501                 :            :                 css::uno::Reference<XOutputStream>
     502                 :            :                         pipeout(
     503                 :          0 :                                 m_rServiceFactory->createInstance(
     504                 :            :                                         OUString(
     505                 :          0 :                                                  "com.sun.star.io.Pipe" )),
     506                 :          0 :                                 UNO_QUERY);
     507                 :          0 :                 css::uno::Reference<XInputStream> pipein(pipeout, UNO_QUERY);
     508                 :            : 
     509                 :            :                 // connect sax writer to pipe
     510                 :          0 :                 css::uno::Reference<XActiveDataSource> xmlsource(getDelegate(),
     511                 :          0 :                         UNO_QUERY);
     512                 :          0 :                 xmlsource->setOutputStream(pipeout);
     513                 :            : 
     514                 :            :                 // connect pipe to transformer
     515                 :          0 :                 css::uno::Reference<XActiveDataSink> tsink(m_tcontrol, UNO_QUERY);
     516                 :          0 :                 tsink->setInputStream(pipein);
     517                 :            : 
     518                 :            :                 // connect transformer to output
     519                 :          0 :                 css::uno::Reference<XActiveDataSource> tsource(m_tcontrol, UNO_QUERY);
     520                 :          0 :                 tsource->setOutputStream(m_rOutputStream);
     521                 :            : 
     522                 :            :                 // we will start receiving events after returning 'true'.
     523                 :            :                 // we will start the transformation as soon as we receive the startDocument
     524                 :            :                 // event.
     525                 :          0 :                 return sal_True;
     526                 :            :             }
     527                 :            :         else
     528                 :            :             {
     529                 :          0 :                 return sal_False;
     530                 :          0 :             }
     531                 :            :     }
     532                 :            : 
     533                 :            :     // for the DocumentHandler implementation, we just proxy the the
     534                 :            :     // events to the XML writer that we created upon the output stream
     535                 :            :     // that was provided by the XMLFilterAdapter
     536                 :            :     void
     537                 :          0 :     XSLTFilter::startDocument() throw (SAXException, RuntimeException)
     538                 :            :     {
     539                 :          0 :         ExtendedDocumentHandlerAdapter::startDocument();
     540                 :          0 :         m_tcontrol->start();
     541                 :          0 :     }
     542                 :            : 
     543                 :            :     void
     544                 :          0 :     XSLTFilter::endDocument() throw (SAXException, RuntimeException)
     545                 :            :     {
     546                 :          0 :         ExtendedDocumentHandlerAdapter::endDocument();
     547                 :            :         // wait for the transformer to finish
     548                 :          0 :         osl_waitCondition(m_cTransformed, 0);
     549                 :          0 :         m_tcontrol->terminate();
     550                 :          0 :         if (!m_bError && !m_bTerminated)
     551                 :            :             {
     552                 :          0 :                 return;
     553                 :            :             }
     554                 :            :         else
     555                 :            :             {
     556                 :          0 :                 throw RuntimeException();
     557                 :            :             }
     558                 :            : 
     559                 :            :     }
     560                 :            : 
     561                 :            : 
     562                 :            :     // --------------------------------------
     563                 :            :     // Component management
     564                 :            :     // --------------------------------------
     565                 :            : #define FILTER_SERVICE_NAME "com.sun.star.documentconversion.XSLTFilter"
     566                 :            : #define FILTER_IMPL_NAME "com.sun.star.comp.documentconversion.XSLTFilter"
     567                 :            : #define TRANSFORMER_SERVICE_NAME "com.sun.star.documentconversion.LibXSLTTransformer"
     568                 :            : #define TRANSFORMER_IMPL_NAME "com.sun.star.comp.documentconversion.LibXSLTTransformer"
     569                 :            : 
     570                 :            :     static css::uno::Reference<XInterface> SAL_CALL
     571                 :          0 :     CreateTransformerInstance(const css::uno::Reference<XMultiServiceFactory> &r)
     572                 :            :     {
     573                 :          0 :         return css::uno::Reference<XInterface> ((OWeakObject *) new LibXSLTTransformer(r));
     574                 :            :     }
     575                 :            : 
     576                 :            :     static css::uno::Reference<XInterface> SAL_CALL
     577                 :          0 :     CreateFilterInstance(const css::uno::Reference<XMultiServiceFactory> &r)
     578                 :            :     {
     579                 :          0 :         return css::uno::Reference<XInterface> ((OWeakObject *) new XSLTFilter(r));
     580                 :            :     }
     581                 :            : 
     582                 :            : }
     583                 :            : 
     584                 :            : using namespace XSLT;
     585                 :            : 
     586                 :            : extern "C"
     587                 :            : {
     588                 :          0 :     SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const sal_Char * pImplName,
     589                 :            :             void * pServiceManager, void * /* pRegistryKey */)
     590                 :            :     {
     591                 :          0 :         void * pRet = 0;
     592                 :            : 
     593                 :          0 :         if (pServiceManager)
     594                 :            :             {
     595                 :          0 :                 if (rtl_str_compare(pImplName, FILTER_IMPL_NAME) == 0)
     596                 :            :                     {
     597                 :          0 :                         Sequence<OUString> serviceNames(1);
     598                 :            :                         serviceNames.getArray()[0]
     599                 :            :                                 = OUString(
     600                 :          0 :                                          FILTER_SERVICE_NAME );
     601                 :            : 
     602                 :            :                         css::uno::Reference<XSingleServiceFactory>
     603                 :            :                                 xFactory(
     604                 :            :                                         createSingleFactory(
     605                 :            :                                                 reinterpret_cast<XMultiServiceFactory *> (pServiceManager),
     606                 :            :                                                 OUString::createFromAscii(
     607                 :            :                                                         pImplName),
     608                 :            :                                                 CreateFilterInstance,
     609                 :          0 :                                                 serviceNames));
     610                 :            : 
     611                 :          0 :                         if (xFactory.is())
     612                 :            :                             {
     613                 :          0 :                                 xFactory->acquire();
     614                 :          0 :                                 pRet = xFactory.get();
     615                 :          0 :                             }
     616                 :            :                     }
     617                 :          0 :                 else if (rtl_str_compare(pImplName, TRANSFORMER_IMPL_NAME) == 0)
     618                 :            :                     {
     619                 :          0 :                         Sequence<OUString> serviceNames(1);
     620                 :            :                         serviceNames.getArray()[0]
     621                 :            :                                 = OUString(
     622                 :          0 :                                          TRANSFORMER_SERVICE_NAME );
     623                 :            :                         css::uno::Reference<XSingleServiceFactory>
     624                 :            :                                 xFactory(
     625                 :            :                                         createSingleFactory(
     626                 :            :                                                 reinterpret_cast<XMultiServiceFactory *> (pServiceManager),
     627                 :            :                                                 OUString::createFromAscii(
     628                 :            :                                                         pImplName),
     629                 :            :                                                 CreateTransformerInstance,
     630                 :          0 :                                                 serviceNames));
     631                 :            : 
     632                 :          0 :                         if (xFactory.is())
     633                 :            :                             {
     634                 :          0 :                                 xFactory->acquire();
     635                 :          0 :                                 pRet = xFactory.get();
     636                 :          0 :                             }
     637                 :            : 
     638                 :            :                     }
     639                 :            :             }
     640                 :          0 :         return pRet;
     641                 :            :     }
     642                 :            : 
     643                 :            : } // extern "C"
     644                 :            : 
     645                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10