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