LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - rtfexportfilter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 41 46 89.1 %
Date: 2014-11-03 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         136 : RtfExportFilter::RtfExportFilter(const uno::Reference< uno::XComponentContext >& xCtx)
      34         136 :     : m_xCtx(xCtx)
      35             : {
      36         136 : }
      37             : 
      38         272 : RtfExportFilter::~RtfExportFilter()
      39             : {
      40         272 : }
      41             : 
      42         136 : sal_Bool RtfExportFilter::filter(const uno::Sequence< beans::PropertyValue >& aDescriptor) throw(uno::RuntimeException, std::exception)
      43             : {
      44         136 :     utl::MediaDescriptor aMediaDesc = aDescriptor;
      45         272 :     uno::Reference<io::XStream> xStream = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STREAMFOROUTPUT(), uno::Reference< io::XStream >());
      46         136 :     SvStream* pStream = utl::UcbStreamHelper::CreateStream(xStream, true);
      47         136 :     m_aWriter.SetStream(pStream);
      48             : 
      49             :     // get SwDoc*
      50         272 :     uno::Reference< uno::XInterface > xIfc(m_xSrcDoc, uno::UNO_QUERY);
      51         136 :     SwXTextDocument* pTxtDoc = dynamic_cast< SwXTextDocument* >(xIfc.get());
      52         136 :     if (!pTxtDoc)
      53             :     {
      54           0 :         return sal_False;
      55             :     }
      56             : 
      57         136 :     SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
      58         136 :     if (!pDoc)
      59             :     {
      60           0 :         return sal_False;
      61             :     }
      62             : 
      63             :     // fdo#37161 - update layout (if present), for SwWriteTable
      64         136 :     SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
      65         136 :     if (pViewShell != NULL)
      66         126 :         pViewShell->CalcLayout();
      67             : 
      68             :     // get SwPaM*
      69             :     // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
      70         272 :     SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
      71         136 :     aPam.SetMark();
      72         136 :     aPam.Move(fnMoveBackward, fnGoDoc);
      73             : 
      74         136 :     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         136 :         RtfExport aExport(this, pDoc, pCurPam, &aPam, NULL);
      80         136 :         aExport.ExportDocument(true);
      81             :     }
      82             : 
      83             :     // delete the pCurPam
      84         136 :     if (pCurPam)
      85             :     {
      86         272 :         while (pCurPam->GetNext() != pCurPam)
      87           0 :             delete pCurPam->GetNext();
      88         136 :         delete pCurPam;
      89             :     }
      90         136 :     delete pStream;
      91             : 
      92         272 :     return sal_True;
      93             : }
      94             : 
      95           0 : void RtfExportFilter::cancel() throw(uno::RuntimeException, std::exception)
      96             : {
      97           0 : }
      98             : 
      99         136 : void RtfExportFilter::setSourceDocument(const uno::Reference< lang::XComponent >& xDoc) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     100             : {
     101         136 :     m_xSrcDoc = xDoc;
     102         136 : }
     103             : 
     104             : // UNO helpers
     105             : 
     106          24 : OUString RtfExport_getImplementationName()
     107             : {
     108          24 :     return OUString(IMPL_NAME_RTFEXPORT);
     109             : }
     110             : 
     111           4 : uno::Sequence< OUString > SAL_CALL RtfExport_getSupportedServiceNames() throw()
     112             : {
     113           4 :     const OUString aServiceName("com.sun.star.document.ExportFilter");
     114           4 :     const uno::Sequence< OUString > aSeq(&aServiceName, 1);
     115           4 :     return aSeq;
     116             : }
     117             : 
     118         136 : uno::Reference< uno::XInterface > SAL_CALL RtfExport_createInstance(const uno::Reference< uno::XComponentContext >& xCtx) throw(uno::Exception)
     119             : {
     120         136 :     return (cppu::OWeakObject*) new RtfExportFilter(xCtx);
     121         102 : }
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10