LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - rtfexportfilter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 46 89.1 %
Date: 2012-08-25 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 78 47.4 %

           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                 :            :  * Copyright 2010 Miklos Vajna.
       8                 :            :  *
       9                 :            :  * OpenOffice.org - a multi-platform office productivity suite
      10                 :            :  *
      11                 :            :  * This file is part of OpenOffice.org.
      12                 :            :  *
      13                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      14                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      15                 :            :  * only, as published by the Free Software Foundation.
      16                 :            :  *
      17                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      18                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      19                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20                 :            :  * GNU Lesser General Public License version 3 for more details
      21                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      22                 :            :  *
      23                 :            :  * You should have received a copy of the GNU Lesser General Public License
      24                 :            :  * version 3 along with OpenOffice.org.  If not, see
      25                 :            :  * <http://www.openoffice.org/license.html>
      26                 :            :  * for a copy of the LGPLv3 License.
      27                 :            :  *
      28                 :            :  ************************************************************************/
      29                 :            : 
      30                 :            : #include <rtfexportfilter.hxx>
      31                 :            : #include <rtfexport.hxx>
      32                 :            : 
      33                 :            : #include <docsh.hxx>
      34                 :            : #include <editsh.hxx>
      35                 :            : #include <unotxdoc.hxx>
      36                 :            : 
      37                 :            : #include <comphelper/mediadescriptor.hxx>
      38                 :            : #include <unotools/ucbstreamhelper.hxx>
      39                 :            : 
      40                 :            : using namespace ::comphelper;
      41                 :            : using namespace ::com::sun::star;
      42                 :            : 
      43                 :         78 : RtfExportFilter::RtfExportFilter( const uno::Reference< uno::XComponentContext >& xCtx) :
      44         [ +  - ]:         78 :     m_xCtx( xCtx )
      45                 :            : {
      46                 :         78 : }
      47                 :            : 
      48         [ +  - ]:         78 : RtfExportFilter::~RtfExportFilter()
      49                 :            : {
      50         [ -  + ]:        156 : }
      51                 :            : 
      52                 :         78 : sal_Bool RtfExportFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
      53                 :            :     throw (uno::RuntimeException)
      54                 :            : {
      55                 :            :     SAL_INFO("sw.rtf", OSL_THIS_FUNC);
      56                 :            : 
      57         [ +  - ]:         78 :     MediaDescriptor aMediaDesc = aDescriptor;
      58                 :            :     ::uno::Reference< io::XStream > xStream =
      59 [ +  - ][ +  - ]:         78 :         aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STREAMFOROUTPUT(), uno::Reference< io::XStream >() );
      60         [ +  - ]:         78 :     m_pStream = utl::UcbStreamHelper::CreateStream( xStream, sal_True );
      61         [ +  - ]:         78 :     m_aWriter.SetStream(m_pStream);
      62                 :            : 
      63                 :            :     // get SwDoc*
      64         [ +  - ]:         78 :     uno::Reference< uno::XInterface > xIfc( m_xSrcDoc, uno::UNO_QUERY );
      65 [ +  - ][ -  + ]:         78 :     SwXTextDocument *pTxtDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
      66         [ -  + ]:         78 :     if ( !pTxtDoc ) {
      67                 :          0 :         return sal_False;
      68                 :            :     }
      69                 :            : 
      70                 :         78 :     SwDoc *pDoc = pTxtDoc->GetDocShell()->GetDoc();
      71         [ -  + ]:         78 :     if ( !pDoc ) {
      72                 :          0 :         return sal_False;
      73                 :            :     }
      74                 :            : 
      75                 :            :     // fdo#37161 - update layout (if present), for SwWriteTable
      76                 :         78 :     ViewShell* pViewShell = NULL;
      77         [ +  - ]:         78 :     pDoc->GetEditShell(&pViewShell);
      78         [ +  - ]:         78 :     if (pViewShell != NULL)
      79         [ +  - ]:         78 :         pViewShell->CalcLayout();
      80                 :            : 
      81                 :            :     // get SwPaM*
      82                 :            :     // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
      83 [ +  - ][ +  - ]:         78 :     SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
      84         [ +  - ]:         78 :     aPam.SetMark();
      85         [ +  - ]:         78 :     aPam.Move( fnMoveBackward, fnGoDoc );
      86                 :            : 
      87 [ +  - ][ +  - ]:         78 :     SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() );
         [ +  - ][ +  - ]
      88                 :            : 
      89                 :            :     // export the document
      90                 :            :     // (in a separate block so that it's destructed before the commit)
      91                 :            :     {
      92         [ +  - ]:         78 :         RtfExport aExport( this, pDoc, pCurPam, &aPam, NULL );
      93 [ +  - ][ +  - ]:         78 :         aExport.ExportDocument( true );
      94                 :            :     }
      95                 :            : 
      96                 :            :     // delete the pCurPam
      97         [ +  - ]:         78 :     if ( pCurPam )
      98                 :            :     {
      99         [ -  + ]:         78 :         while ( pCurPam->GetNext() != pCurPam )
     100 [ #  # ][ #  # ]:          0 :             delete pCurPam->GetNext();
     101 [ +  - ][ +  - ]:         78 :         delete pCurPam;
     102                 :            :     }
     103 [ +  - ][ +  - ]:         78 :     delete m_pStream;
     104                 :            : 
     105 [ +  - ][ +  - ]:         78 :     return sal_True;
     106                 :            : }
     107                 :            : 
     108                 :            : 
     109                 :          0 : void RtfExportFilter::cancel(  ) throw (uno::RuntimeException)
     110                 :            : {
     111                 :          0 : }
     112                 :            : 
     113                 :         78 : void RtfExportFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
     114                 :            :     throw (lang::IllegalArgumentException, uno::RuntimeException)
     115                 :            : {
     116                 :         78 :     m_xSrcDoc = xDoc;
     117                 :         78 : }
     118                 :            : 
     119                 :            : //////////////////////////////////////////////////////////////////////////
     120                 :            : // UNO helpers
     121                 :            : //////////////////////////////////////////////////////////////////////////
     122                 :            : 
     123                 :          6 : OUString RtfExport_getImplementationName()
     124                 :            : {
     125                 :          6 :     return OUString( IMPL_NAME_RTFEXPORT );
     126                 :            : }
     127                 :            : 
     128                 :          3 : uno::Sequence< OUString > SAL_CALL RtfExport_getSupportedServiceNames() throw()
     129                 :            : {
     130                 :          3 :     const OUString aServiceName( "com.sun.star.document.ExportFilter" );
     131         [ +  - ]:          3 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     132                 :          3 :     return aSeq;
     133                 :            : }
     134                 :            : 
     135                 :         78 : uno::Reference< uno::XInterface > SAL_CALL RtfExport_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
     136                 :            : {
     137         [ +  - ]:         78 :     return (cppu::OWeakObject*) new RtfExportFilter( xCtx );
     138                 :            : }
     139                 :            : 
     140                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10