LCOV - code coverage report
Current view: top level - sw/source/core/layout - dumpfilter.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 66 3.0 %
Date: 2014-04-11 Functions: 1 15 6.7 %
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             : 
      10             : #include "dumpfilter.hxx"
      11             : 
      12             : #include <wrtsh.hxx>
      13             : #include <cppuhelper/supportsservice.hxx>
      14             : #include <docsh.hxx>
      15             : #include <rootfrm.hxx>
      16             : #include <unotxdoc.hxx>
      17             : 
      18             : #include <unotools/mediadescriptor.hxx>
      19             : 
      20             : #include <libxml/xmlwriter.h>
      21             : 
      22             : using namespace ::com::sun::star;
      23             : 
      24           2 : OUString SAL_CALL LayoutDumpFilter_getImplementationName() throw( uno::RuntimeException )
      25             : {
      26           2 :     return OUString( "com.sun.star.comp.Writer.LayoutDump" );
      27             : }
      28             : 
      29           0 : uno::Sequence< OUString > SAL_CALL LayoutDumpFilter_getSupportedServiceNames() throw( uno::RuntimeException )
      30             : {
      31           0 :     uno::Sequence< OUString > aSeq( 1 );
      32           0 :     aSeq[0] = "com.sun.star.document.ExportFilter";
      33           0 :     return aSeq;
      34             : }
      35             : 
      36           0 : uno::Reference< uno::XInterface > SAL_CALL LayoutDumpFilter_createInstance(
      37             :                 const uno::Reference< lang::XMultiServiceFactory > & )
      38             : {
      39           0 :     return static_cast< cppu::OWeakObject* >( new sw::LayoutDumpFilter( ) );
      40             : }
      41             : 
      42             : namespace
      43             : {
      44           0 :     int writeCallback( void* pContext, const char* sBuffer, int nLen )
      45             :     {
      46           0 :         int written = nLen;
      47             : 
      48             :         // Actually write bytes to XOutputSream
      49             :         try
      50             :         {
      51           0 :             uno::XInterface* pObj = ( uno::XInterface* )pContext;
      52           0 :             uno::Reference< io::XOutputStream > xOut( pObj, uno::UNO_QUERY_THROW );
      53             : 
      54             :             // Don't output the terminating \0 to the xml or the file will be invalid
      55           0 :             uno::Sequence< sal_Int8 > seq( nLen );
      56           0 :             strncpy( ( char * ) seq.getArray() , sBuffer, nLen );
      57           0 :             xOut->writeBytes( seq );
      58             :         }
      59           0 :         catch (const uno::Exception&)
      60             :         {
      61           0 :             written = -1;
      62             :         }
      63             : 
      64           0 :         return written;
      65             :     }
      66             : 
      67           0 :     int closeCallback( void* pContext )
      68             :     {
      69           0 :         int result = 0;
      70             :         try
      71             :         {
      72           0 :             uno::XInterface* pObj = ( uno::XInterface* )pContext;
      73           0 :             uno::Reference< io::XOutputStream > xOut( pObj, uno::UNO_QUERY_THROW );
      74           0 :             xOut->closeOutput( );
      75             :         }
      76           0 :         catch (const uno::Exception&)
      77             :         {
      78           0 :             result = -1;
      79             :         }
      80           0 :         return result;
      81             :     }
      82             : }
      83             : 
      84             : namespace sw
      85             : {
      86             : 
      87           0 :     LayoutDumpFilter::LayoutDumpFilter( )
      88             :     {
      89           0 :     }
      90             : 
      91           0 :     LayoutDumpFilter::~LayoutDumpFilter( )
      92             :     {
      93           0 :     }
      94             : 
      95             :     // XFilter
      96           0 :     sal_Bool LayoutDumpFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
      97             :         throw (uno::RuntimeException, std::exception)
      98             :     {
      99           0 :         sal_Bool bRet = sal_False;
     100             : 
     101           0 :         utl::MediaDescriptor aMediaDesc = aDescriptor;
     102             : 
     103             :         // Get the output stream
     104             :         uno::Reference< io::XOutputStream > xOut = aMediaDesc.getUnpackedValueOrDefault(
     105           0 :                 utl::MediaDescriptor::PROP_OUTPUTSTREAM(),
     106           0 :                 uno::Reference< io::XOutputStream >() );
     107             : 
     108             :         // Actually get the SwRootFrm to call dumpAsXml
     109           0 :         uno::Reference< lang::XUnoTunnel > xDocTunnel( m_xSrcDoc, uno::UNO_QUERY );
     110           0 :         SwXTextDocument* pXDoc = UnoTunnelGetImplementation< SwXTextDocument >( xDocTunnel );
     111           0 :         if ( pXDoc )
     112             :         {
     113           0 :             SwRootFrm* pLayout = pXDoc->GetDocShell()->GetWrtShell()->GetLayout();
     114             : 
     115             :             // Get sure that the whole layout is processed: set a visible area
     116             :             // even though there isn't any need of it
     117           0 :             pXDoc->GetDocShell()->GetWrtShell()->StartAction();
     118           0 :             Rectangle aRect( 0, 0, 26000, 21000 );
     119           0 :             pXDoc->GetDocShell()->SetVisArea( aRect );
     120           0 :             pLayout->InvalidateAllCntnt( );
     121           0 :             pXDoc->GetDocShell()->GetWrtShell()->EndAction();
     122             : 
     123             :             // Dump the layout XML into the XOutputStream
     124             :             xmlOutputBufferPtr outBuffer = xmlOutputBufferCreateIO(
     125           0 :                     writeCallback, closeCallback, ( void* ) xOut.get(), NULL );
     126             : 
     127           0 :             xmlTextWriterPtr writer = xmlNewTextWriter( outBuffer );
     128           0 :             xmlTextWriterSetIndent(writer, 1);
     129           0 :             xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
     130             : 
     131             :             // TODO This doesn't export the whole XML file, whereas dumpAsXML() does it nicely
     132           0 :             pLayout->dumpAsXml( writer );
     133             : 
     134           0 :             xmlTextWriterEndDocument( writer );
     135           0 :             xmlFreeTextWriter( writer );
     136             : 
     137           0 :             bRet = sal_True;
     138             :         }
     139             : 
     140           0 :         return bRet;
     141             :     }
     142             : 
     143           0 :     void LayoutDumpFilter::cancel(  ) throw (uno::RuntimeException, std::exception)
     144             :     {
     145           0 :     }
     146             : 
     147             :     // XExporter
     148           0 :     void LayoutDumpFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
     149             :         throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     150             :     {
     151           0 :         m_xSrcDoc = xDoc;
     152           0 :     }
     153             : 
     154             :     // XInitialization
     155           0 :     void LayoutDumpFilter::initialize( const uno::Sequence< uno::Any >& )
     156             :         throw (uno::Exception, uno::RuntimeException, std::exception)
     157             :     {
     158           0 :     }
     159             : 
     160             :     // XServiceInfo
     161           0 :     OUString LayoutDumpFilter::getImplementationName(  )
     162             :         throw (uno::RuntimeException, std::exception)
     163             :     {
     164           0 :         return LayoutDumpFilter_getImplementationName();
     165             :     }
     166             : 
     167           0 :     sal_Bool LayoutDumpFilter::supportsService( const OUString& rServiceName )
     168             :         throw (uno::RuntimeException, std::exception)
     169             :     {
     170           0 :         return cppu::supportsService(this, rServiceName);
     171             :     }
     172             : 
     173           0 :     uno::Sequence< OUString > LayoutDumpFilter::getSupportedServiceNames()
     174             :         throw (uno::RuntimeException, std::exception)
     175             :     {
     176           0 :         return LayoutDumpFilter_getSupportedServiceNames();
     177             :     }
     178             : 
     179             : } // Namespace sw
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10