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 <editsh.hxx>
25 : #include <unotxdoc.hxx>
26 :
27 : #include <comphelper/mediadescriptor.hxx>
28 : #include <unotools/ucbstreamhelper.hxx>
29 :
30 : using namespace ::comphelper;
31 : using namespace ::com::sun::star;
32 :
33 29 : RtfExportFilter::RtfExportFilter( const uno::Reference< uno::XComponentContext >& xCtx) :
34 29 : m_xCtx( xCtx )
35 : {
36 29 : }
37 :
38 58 : RtfExportFilter::~RtfExportFilter()
39 : {
40 58 : }
41 :
42 29 : sal_Bool RtfExportFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
43 : throw (uno::RuntimeException)
44 : {
45 : SAL_INFO("sw.rtf", OSL_THIS_FUNC);
46 :
47 29 : MediaDescriptor aMediaDesc = aDescriptor;
48 : ::uno::Reference< io::XStream > xStream =
49 29 : aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STREAMFOROUTPUT(), uno::Reference< io::XStream >() );
50 29 : m_pStream = utl::UcbStreamHelper::CreateStream( xStream, sal_True );
51 29 : m_aWriter.SetStream(m_pStream);
52 :
53 : // get SwDoc*
54 29 : uno::Reference< uno::XInterface > xIfc( m_xSrcDoc, uno::UNO_QUERY );
55 29 : SwXTextDocument *pTxtDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
56 29 : if ( !pTxtDoc ) {
57 0 : return sal_False;
58 : }
59 :
60 29 : SwDoc *pDoc = pTxtDoc->GetDocShell()->GetDoc();
61 29 : if ( !pDoc ) {
62 0 : return sal_False;
63 : }
64 :
65 : // fdo#37161 - update layout (if present), for SwWriteTable
66 29 : ViewShell* pViewShell = NULL;
67 29 : pDoc->GetEditShell(&pViewShell);
68 29 : if (pViewShell != NULL)
69 29 : pViewShell->CalcLayout();
70 :
71 : // get SwPaM*
72 : // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
73 29 : SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
74 29 : aPam.SetMark();
75 29 : aPam.Move( fnMoveBackward, fnGoDoc );
76 :
77 29 : SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() );
78 :
79 : // export the document
80 : // (in a separate block so that it's destructed before the commit)
81 : {
82 29 : RtfExport aExport( this, pDoc, pCurPam, &aPam, NULL );
83 29 : aExport.ExportDocument( true );
84 : }
85 :
86 : // delete the pCurPam
87 29 : if ( pCurPam )
88 : {
89 58 : while ( pCurPam->GetNext() != pCurPam )
90 0 : delete pCurPam->GetNext();
91 29 : delete pCurPam;
92 : }
93 29 : delete m_pStream;
94 :
95 29 : return sal_True;
96 : }
97 :
98 :
99 0 : void RtfExportFilter::cancel( ) throw (uno::RuntimeException)
100 : {
101 0 : }
102 :
103 29 : void RtfExportFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
104 : throw (lang::IllegalArgumentException, uno::RuntimeException)
105 : {
106 29 : m_xSrcDoc = xDoc;
107 29 : }
108 :
109 : //////////////////////////////////////////////////////////////////////////
110 : // UNO helpers
111 : //////////////////////////////////////////////////////////////////////////
112 :
113 2 : OUString RtfExport_getImplementationName()
114 : {
115 2 : return OUString( IMPL_NAME_RTFEXPORT );
116 : }
117 :
118 1 : uno::Sequence< OUString > SAL_CALL RtfExport_getSupportedServiceNames() throw()
119 : {
120 1 : const OUString aServiceName( "com.sun.star.document.ExportFilter" );
121 1 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
122 1 : return aSeq;
123 : }
124 :
125 29 : uno::Reference< uno::XInterface > SAL_CALL RtfExport_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
126 : {
127 29 : return (cppu::OWeakObject*) new RtfExportFilter( xCtx );
128 : }
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|