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