Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : * Copyright 2010 Miklos Vajna.
8 : : *
9 : : * OpenOffice.org - a multi-platform office productivity suite
10 : : *
11 : : * This file is part of OpenOffice.org.
12 : : *
13 : : * OpenOffice.org is free software: you can redistribute it and/or modify
14 : : * it under the terms of the GNU Lesser General Public License version 3
15 : : * only, as published by the Free Software Foundation.
16 : : *
17 : : * OpenOffice.org is distributed in the hope that it will be useful,
18 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : : * GNU Lesser General Public License version 3 for more details
21 : : * (a copy is included in the LICENSE file that accompanied this code).
22 : : *
23 : : * You should have received a copy of the GNU Lesser General Public License
24 : : * version 3 along with OpenOffice.org. If not, see
25 : : * <http://www.openoffice.org/license.html>
26 : : * for a copy of the LGPLv3 License.
27 : : *
28 : : ************************************************************************/
29 : :
30 : : #include "rtfimportfilter.hxx"
31 : : #include "../rtf/swparrtf.hxx"
32 : :
33 : : #include <docsh.hxx>
34 : : #include <doc.hxx>
35 : : #include <unotxdoc.hxx>
36 : :
37 : : #include <comphelper/mediadescriptor.hxx>
38 : : #include <unotools/ucbstreamhelper.hxx>
39 : :
40 : : using namespace ::comphelper;
41 : : using namespace ::com::sun::star;
42 : :
43 : 0 : RtfImportFilter::RtfImportFilter( const uno::Reference< uno::XComponentContext > &xCtx ) :
44 : 0 : m_xCtx( xCtx )
45 : : {
46 : 0 : }
47 : :
48 : 0 : RtfImportFilter::~RtfImportFilter()
49 : : {
50 [ # # ]: 0 : }
51 : :
52 : 0 : sal_Bool RtfImportFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
53 : : throw (uno::RuntimeException)
54 : : {
55 : : SAL_INFO("sw.rtf", OSL_THIS_FUNC);
56 : :
57 [ # # ]: 0 : MediaDescriptor aMediaDesc = aDescriptor;
58 : : ::uno::Reference< io::XInputStream > xInputStream =
59 [ # # ][ # # ]: 0 : aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INPUTSTREAM(), uno::Reference< io::XInputStream >() );
60 [ # # ]: 0 : SvStream* pStream = utl::UcbStreamHelper::CreateStream( xInputStream, sal_True );
61 [ # # ]: 0 : if (!pStream)
62 : 0 : return sal_False;
63 : :
64 : : // get SwDoc*
65 [ # # ]: 0 : uno::Reference< uno::XInterface > xIfc( m_xDstDoc, uno::UNO_QUERY );
66 [ # # ][ # # ]: 0 : SwXTextDocument *pTxtDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
67 [ # # ]: 0 : if (!pTxtDoc)
68 : 0 : return sal_False;
69 : 0 : SwDoc *pDoc = pTxtDoc->GetDocShell()->GetDoc();
70 [ # # ]: 0 : if (!pDoc)
71 : 0 : return sal_False;
72 : :
73 : : // get SwPaM*
74 : : // NEEDSWORK should we care about partial imports? For now we just import
75 : : // the whole document
76 [ # # ][ # # ]: 0 : SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
77 [ # # ]: 0 : aPam.SetMark();
78 [ # # ]: 0 : aPam.Move( fnMoveBackward, fnGoDoc );
79 [ # # ][ # # ]: 0 : SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() );
[ # # ][ # # ]
80 : :
81 [ # # ]: 0 : String aURL;
82 : 0 : OUString sTemp;
83 [ # # ]: 0 : for ( sal_Int32 i = 0; i < aDescriptor.getLength(); i++ )
84 : : {
85 [ # # ]: 0 : if( aDescriptor[i].Name == "URL" )
86 : : {
87 : 0 : aDescriptor[i].Value >>= sTemp;
88 [ # # ]: 0 : aURL = sTemp;
89 : : }
90 : : }
91 : :
92 [ # # ]: 0 : RtfReader aReader;
93 [ # # ]: 0 : sal_Bool bRet = aReader.Read(pStream, *pDoc, aURL, *pCurPam) == 0;
94 [ # # ][ # # ]: 0 : delete pStream;
95 [ # # ][ # # ]: 0 : return bRet;
[ # # ][ # # ]
96 : : }
97 : :
98 : :
99 : 0 : void RtfImportFilter::cancel( ) throw (uno::RuntimeException)
100 : : {
101 : 0 : }
102 : :
103 : 0 : void RtfImportFilter::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
104 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
105 : : {
106 : 0 : m_xDstDoc = xDoc;
107 : 0 : }
108 : :
109 : : //////////////////////////////////////////////////////////////////////////
110 : : // UNO helpers
111 : : //////////////////////////////////////////////////////////////////////////
112 : :
113 : 6 : OUString RtfImport_getImplementationName()
114 : : {
115 : 6 : return OUString( IMPL_NAME_RTFIMPORT );
116 : : }
117 : :
118 : 0 : uno::Sequence< OUString > SAL_CALL RtfImport_getSupportedServiceNames() throw()
119 : : {
120 : 0 : const OUString aServiceName( "com.sun.star.document.ImportFilter" );
121 [ # # ]: 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
122 : 0 : return aSeq;
123 : : }
124 : :
125 : 0 : uno::Reference< uno::XInterface > SAL_CALL RtfImport_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
126 : : {
127 [ # # ]: 0 : return (cppu::OWeakObject*) new RtfImportFilter( xCtx );
128 : : }
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|