LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - rtfexportfilter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 45 88.9 %
Date: 2015-06-13 12:38:46 Functions: 10 11 90.9 %
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             :  * 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 <rtfexportfilter.hxx>
      21             : #include <rtfexport.hxx>
      22             : 
      23             : #include <docsh.hxx>
      24             : #include <IDocumentLayoutAccess.hxx>
      25             : #include <editsh.hxx>
      26             : #include <unotxdoc.hxx>
      27             : 
      28             : #include <unotools/mediadescriptor.hxx>
      29             : #include <unotools/ucbstreamhelper.hxx>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33          95 : RtfExportFilter::RtfExportFilter(const uno::Reference< uno::XComponentContext >& xCtx)
      34          95 :     : m_xCtx(xCtx)
      35             : {
      36          95 : }
      37             : 
      38         190 : RtfExportFilter::~RtfExportFilter()
      39             : {
      40         190 : }
      41             : 
      42          95 : sal_Bool RtfExportFilter::filter(const uno::Sequence< beans::PropertyValue >& aDescriptor) throw(uno::RuntimeException, std::exception)
      43             : {
      44          95 :     utl::MediaDescriptor aMediaDesc = aDescriptor;
      45         190 :     uno::Reference<io::XStream> xStream = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STREAMFOROUTPUT(), uno::Reference< io::XStream >());
      46          95 :     SvStream* pStream = utl::UcbStreamHelper::CreateStream(xStream, true);
      47          95 :     m_aWriter.SetStream(pStream);
      48             : 
      49             :     // get SwDoc*
      50         190 :     uno::Reference< uno::XInterface > xIfc(m_xSrcDoc, uno::UNO_QUERY);
      51          95 :     SwXTextDocument* pTextDoc = dynamic_cast< SwXTextDocument* >(xIfc.get());
      52          95 :     if (!pTextDoc)
      53             :     {
      54           0 :         return sal_False;
      55             :     }
      56             : 
      57          95 :     SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
      58          95 :     if (!pDoc)
      59             :     {
      60           0 :         return sal_False;
      61             :     }
      62             : 
      63             :     // fdo#37161 - update layout (if present), for SwWriteTable
      64          95 :     SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
      65          95 :     if (pViewShell != NULL)
      66          90 :         pViewShell->CalcLayout();
      67             : 
      68             :     // get SwPaM*
      69             :     // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
      70         190 :     SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
      71          95 :     aPam.SetMark();
      72          95 :     aPam.Move(fnMoveBackward, fnGoDoc);
      73             : 
      74          95 :     SwPaM* pCurPam = new SwPaM(*aPam.End(), *aPam.Start());
      75             : 
      76             :     // export the document
      77             :     // (in a separate block so that it's destructed before the commit)
      78             :     {
      79          95 :         RtfExport aExport(this, pDoc, pCurPam, &aPam, NULL);
      80          95 :         aExport.ExportDocument(true);
      81             :     }
      82             : 
      83             :     // delete the pCurPam
      84         190 :     while (pCurPam->GetNext() != pCurPam)
      85           0 :         delete pCurPam->GetNext();
      86          95 :     delete pCurPam;
      87          95 :     delete pStream;
      88             : 
      89         190 :     return sal_True;
      90             : }
      91             : 
      92           0 : void RtfExportFilter::cancel() throw(uno::RuntimeException, std::exception)
      93             : {
      94           0 : }
      95             : 
      96          95 : void RtfExportFilter::setSourceDocument(const uno::Reference< lang::XComponent >& xDoc) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
      97             : {
      98          95 :     m_xSrcDoc = xDoc;
      99          95 : }
     100             : 
     101             : // UNO helpers
     102             : 
     103          16 : OUString RtfExport_getImplementationName()
     104             : {
     105          16 :     return OUString(IMPL_NAME_RTFEXPORT);
     106             : }
     107             : 
     108           3 : uno::Sequence< OUString > SAL_CALL RtfExport_getSupportedServiceNames() throw()
     109             : {
     110           3 :     const OUString aServiceName("com.sun.star.document.ExportFilter");
     111           3 :     const uno::Sequence< OUString > aSeq(&aServiceName, 1);
     112           3 :     return aSeq;
     113             : }
     114             : 
     115          95 : uno::Reference< uno::XInterface > SAL_CALL RtfExport_createInstance(const uno::Reference< uno::XComponentContext >& xCtx) throw(uno::Exception)
     116             : {
     117          95 :     return static_cast<cppu::OWeakObject*>(new RtfExportFilter(xCtx));
     118          60 : }
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11