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