LCOV - code coverage report
Current view: top level - writerfilter/source/filter - RtfFilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 65 84.6 %
Date: 2012-08-25 Functions: 12 16 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50 98 51.0 %

           Branch data     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                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <rtl/oustringostreaminserter.hxx>
      21                 :            : #include <cppuhelper/implementationentry.hxx>
      22                 :            : #include <osl/module.hxx>
      23                 :            : #include <tools/solar.h>
      24                 :            : #include <RtfFilter.hxx>
      25                 :            : #include <comphelper/mediadescriptor.hxx>
      26                 :            : #include <dmapper/DomainMapper.hxx>
      27                 :            : #include <rtftok/RTFDocument.hxx>
      28                 :            : #include <com/sun/star/frame/XFrame.hpp>
      29                 :            : #include <com/sun/star/task/XStatusIndicator.hpp>
      30                 :            : 
      31                 :            : using namespace ::rtl;
      32                 :            : using namespace ::cppu;
      33                 :            : using namespace ::com::sun::star;
      34                 :            : using ::comphelper::MediaDescriptor;
      35                 :            : 
      36                 :        363 : RtfFilter::RtfFilter( const uno::Reference< uno::XComponentContext >& rxContext)  :
      37                 :        363 :     m_xContext( rxContext )
      38                 :            : {
      39                 :        363 : }
      40                 :            : 
      41                 :        363 : RtfFilter::~RtfFilter()
      42                 :            : {
      43         [ -  + ]:        726 : }
      44                 :            : 
      45                 :        393 : sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
      46                 :            :    throw (uno::RuntimeException)
      47                 :            : {
      48         [ +  - ]:        393 :     sal_uInt32 nStartTime = osl_getGlobalTimer();
      49         [ +  + ]:        393 :     if( m_xSrcDoc.is() )
      50                 :            :     {
      51 [ +  - ][ +  - ]:         78 :         uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
                 [ +  - ]
      52 [ +  - ][ +  - ]:         78 :         uno::Reference< uno::XInterface > xIfc( xMSF->createInstance("com.sun.star.comp.Writer.RtfExport"), uno::UNO_QUERY_THROW);
                 [ +  - ]
      53         [ -  + ]:         78 :         if (!xIfc.is())
      54                 :          0 :             return sal_False;
      55         [ +  - ]:         78 :         uno::Reference< document::XExporter > xExprtr(xIfc, uno::UNO_QUERY_THROW);
      56         [ +  - ]:         78 :         uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
      57 [ +  - ][ -  + ]:         78 :         if (!xExprtr.is() || !xFltr.is())
                 [ -  + ]
      58                 :          0 :             return sal_False;
      59 [ +  - ][ +  - ]:         78 :         xExprtr->setSourceDocument(m_xSrcDoc);
      60 [ +  - ][ +  - ]:         78 :         return xFltr->filter(aDescriptor);
      61                 :            :     }
      62                 :            : 
      63                 :        315 :     sal_Bool bResult(sal_False);
      64                 :        315 :     uno::Reference<task::XStatusIndicator> xStatusIndicator;
      65                 :            : 
      66                 :            :     try
      67                 :            :     {
      68         [ +  - ]:        315 :         MediaDescriptor aMediaDesc( aDescriptor );
      69                 :            : #ifdef DEBUG_IMPORT
      70                 :            :         OUString sURL = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() );
      71                 :            :         ::std::string sURLc = OUStringToOString(sURL, RTL_TEXTENCODING_ASCII_US).getStr();
      72                 :            : 
      73                 :            :         writerfilter::TagLogger::Pointer_t dmapperLogger
      74                 :            :             (writerfilter::TagLogger::getInstance("DOMAINMAPPER"));
      75                 :            :         dmapperLogger->setFileName(sURLc);
      76                 :            :         dmapperLogger->startDocument();
      77                 :            : #endif
      78                 :        315 :         uno::Reference< io::XInputStream > xInputStream;
      79                 :            : 
      80         [ +  - ]:        315 :         aMediaDesc.addInputStream();
      81 [ +  - ][ +  - ]:        315 :         aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] >>= xInputStream;
                 [ +  - ]
      82                 :            : 
      83         [ +  - ]:        315 :         uno::Reference<frame::XFrame> xFrame = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_FRAME(),
      84         [ +  - ]:        630 :                 uno::Reference<frame::XFrame>());
      85                 :            : 
      86         [ +  - ]:        315 :         xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_STATUSINDICATOR(),
      87 [ +  - ][ +  - ]:        630 :                 uno::Reference<task::XStatusIndicator>());
      88                 :            : 
      89                 :            :         writerfilter::Stream::Pointer_t pStream(
      90 [ +  - ][ +  - ]:        315 :                 new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, writerfilter::dmapper::DOCUMENT_RTF));
                 [ +  - ]
      91                 :            :         writerfilter::rtftok::RTFDocument::Pointer_t const pDocument(
      92         [ +  - ]:        315 :                 writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, m_xDstDoc, xFrame, xStatusIndicator));
      93         [ +  + ]:        315 :         pDocument->resolve(*pStream);
      94                 :        306 :         bResult = sal_True;
      95                 :            : #ifdef DEBUG_IMPORT
      96                 :            :         dmapperLogger->endDocument();
      97                 :            : #endif
      98         [ +  - ]:        306 :         sal_uInt32 nEndTime = osl_getGlobalTimer();
      99 [ +  - ][ +  - ]:        315 :         SAL_INFO("writerfilter.profile", OSL_THIS_FUNC << " finished in " << nEndTime - nStartTime << " ms");
         [ +  - ][ -  + ]
     100                 :            :     }
     101         [ +  - ]:          9 :     catch (const uno::Exception& e)
     102                 :            :     {
     103                 :            :         SAL_INFO("writerfilter", "Exception caught: " << e.Message);
     104                 :            :     }
     105                 :            : 
     106         [ +  + ]:        315 :     if (xStatusIndicator.is())
     107 [ +  - ][ +  - ]:        282 :         xStatusIndicator->end();
     108                 :        393 :     return bResult;
     109                 :            : }
     110                 :            : 
     111                 :          0 : void RtfFilter::cancel(  ) throw (uno::RuntimeException)
     112                 :            : {
     113                 :          0 : }
     114                 :            : 
     115                 :         78 : void RtfFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
     116                 :            :    throw (lang::IllegalArgumentException, uno::RuntimeException)
     117                 :            : {
     118                 :         78 :    m_xSrcDoc = xDoc;
     119                 :         78 : }
     120                 :            : 
     121                 :        282 : void RtfFilter::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
     122                 :            :    throw (lang::IllegalArgumentException, uno::RuntimeException)
     123                 :            : {
     124                 :        282 :    m_xDstDoc = xDoc;
     125                 :        282 : }
     126                 :            : 
     127                 :        360 : void RtfFilter::initialize( const uno::Sequence< uno::Any >& /*aArguments*/ ) throw (uno::Exception, uno::RuntimeException)
     128                 :            : {
     129                 :            :     // The DOCX exporter here extracts 'type' of the filter, ie 'Word' or
     130                 :            :     // 'Word Template' but we don't need it for RTF.
     131                 :        360 : }
     132                 :            : 
     133                 :          0 : OUString RtfFilter::getImplementationName(  ) throw (uno::RuntimeException)
     134                 :            : {
     135                 :          0 :    return RtfFilter_getImplementationName();
     136                 :            : }
     137                 :            : 
     138                 :            : #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
     139                 :            : #define SERVICE_NAME2 "com.sun.star.document.ExportFilter"
     140                 :          0 : sal_Bool RtfFilter::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException)
     141                 :            : {
     142 [ #  # ][ #  # ]:          0 :     return ( rServiceName == SERVICE_NAME1 || rServiceName == SERVICE_NAME2 );
     143                 :            : }
     144                 :            : 
     145                 :          0 : uno::Sequence< OUString > RtfFilter::getSupportedServiceNames(  ) throw (uno::RuntimeException)
     146                 :            : {
     147                 :          0 :     return RtfFilter_getSupportedServiceNames();
     148                 :            : }
     149                 :            : 
     150                 :            : /* Helpers, used by shared lib exports. */
     151                 :            : 
     152                 :         17 : OUString RtfFilter_getImplementationName () throw (uno::RuntimeException)
     153                 :            : {
     154                 :         17 :    return OUString ( "com.sun.star.comp.Writer.RtfFilter" );
     155                 :            : }
     156                 :            : 
     157                 :          9 : uno::Sequence< OUString > RtfFilter_getSupportedServiceNames(  ) throw (uno::RuntimeException)
     158                 :            : {
     159                 :          9 :    uno::Sequence < OUString > aRet(2);
     160         [ +  - ]:          9 :    OUString* pArray = aRet.getArray();
     161                 :          9 :    pArray[0] =  SERVICE_NAME1;
     162                 :          9 :    pArray[1] =  SERVICE_NAME2;
     163                 :          9 :    return aRet;
     164                 :            : }
     165                 :            : #undef SERVICE_NAME1
     166                 :            : #undef SERVICE_NAME2
     167                 :            : 
     168                 :        363 : uno::Reference< uno::XInterface > RtfFilter_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
     169                 :            :                 throw( uno::Exception )
     170                 :            : {
     171         [ +  - ]:        363 :    return (cppu::OWeakObject*) new RtfFilter( xContext );
     172 [ +  - ][ +  - ]:         60 : }
     173                 :            : 
     174                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10