Branch data 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 "oox/core/filterbase.hxx"
21 : :
22 : : #include <set>
23 : : #include <com/sun/star/container/XNameAccess.hpp>
24 : : #include <com/sun/star/frame/XModel.hpp>
25 : : #include <com/sun/star/task/XStatusIndicator.hpp>
26 : : #include <com/sun/star/task/XInteractionHandler.hpp>
27 : : #include <com/sun/star/drawing/XShape.hpp>
28 : : #include <comphelper/docpasswordhelper.hxx>
29 : : #include <comphelper/mediadescriptor.hxx>
30 : : #include <osl/mutex.hxx>
31 : : #include <rtl/instance.hxx>
32 : : #include <rtl/uri.hxx>
33 : : #include "oox/helper/binaryinputstream.hxx"
34 : : #include "oox/helper/binaryoutputstream.hxx"
35 : : #include "oox/helper/graphichelper.hxx"
36 : : #include "oox/helper/modelobjecthelper.hxx"
37 : : #include "oox/ole/oleobjecthelper.hxx"
38 : : #include "oox/ole/vbaproject.hxx"
39 : :
40 : : namespace oox {
41 : : namespace core {
42 : :
43 : : // ============================================================================
44 : :
45 : : using namespace ::com::sun::star::beans;
46 : : using namespace ::com::sun::star::frame;
47 : : using namespace ::com::sun::star::graphic;
48 : : using namespace ::com::sun::star::drawing;
49 : : using namespace ::com::sun::star::io;
50 : : using namespace ::com::sun::star::lang;
51 : : using namespace ::com::sun::star::task;
52 : : using namespace ::com::sun::star::uno;
53 : :
54 : : using ::com::sun::star::container::XNameAccess;
55 : : using ::comphelper::MediaDescriptor;
56 : : using ::comphelper::SequenceAsHashMap;
57 : : using ::oox::ole::OleObjectHelper;
58 : : using ::oox::ole::VbaProject;
59 : : using ::rtl::OUString;
60 : :
61 : : // ============================================================================
62 : :
63 : : namespace {
64 : :
65 [ + - ]: 36 : struct UrlPool
66 : : {
67 : : ::osl::Mutex maMutex;
68 : : ::std::set< OUString > maUrls;
69 : : };
70 : :
71 : : struct StaticUrlPool : public ::rtl::Static< UrlPool, StaticUrlPool > {};
72 : :
73 : : // ----------------------------------------------------------------------------
74 : :
75 : : /** This guard prevents recursive loading/saving of the same document. */
76 : : class DocumentOpenedGuard
77 : : {
78 : : public:
79 : : explicit DocumentOpenedGuard( const OUString& rUrl );
80 : : ~DocumentOpenedGuard();
81 : :
82 : 147 : inline bool isValid() const { return mbValid; }
83 : :
84 : : private:
85 : : DocumentOpenedGuard( const DocumentOpenedGuard& );
86 : : DocumentOpenedGuard& operator=( const DocumentOpenedGuard& );
87 : :
88 : : OUString maUrl;
89 : : bool mbValid;
90 : : };
91 : :
92 : 147 : DocumentOpenedGuard::DocumentOpenedGuard( const OUString& rUrl )
93 : : {
94 [ + - ]: 147 : UrlPool& rUrlPool = StaticUrlPool::get();
95 [ + - ]: 147 : ::osl::MutexGuard aGuard( rUrlPool.maMutex );
96 [ + + ][ + - ]: 147 : mbValid = rUrl.isEmpty() || (rUrlPool.maUrls.count( rUrl ) == 0);
[ + - ]
97 [ + - ][ + + ]: 147 : if( mbValid && !rUrl.isEmpty() )
[ + + ]
98 : : {
99 [ + - ]: 90 : rUrlPool.maUrls.insert( rUrl );
100 : 90 : maUrl = rUrl;
101 [ + - ]: 147 : }
102 : 147 : }
103 : :
104 : 147 : DocumentOpenedGuard::~DocumentOpenedGuard()
105 : : {
106 [ + - ]: 147 : UrlPool& rUrlPool = StaticUrlPool::get();
107 [ + - ]: 147 : ::osl::MutexGuard aGuard( rUrlPool.maMutex );
108 [ + + ]: 147 : if( !maUrl.isEmpty() )
109 [ + - ][ + - ]: 147 : rUrlPool.maUrls.erase( maUrl );
110 : 147 : }
111 : :
112 : : } // namespace
113 : :
114 : : // ============================================================================
115 : :
116 : : /** Specifies whether this filter is an import or export filter. */
117 : : enum FilterDirection
118 : : {
119 : : FILTERDIRECTION_UNKNOWN,
120 : : FILTERDIRECTION_IMPORT,
121 : : FILTERDIRECTION_EXPORT
122 : : };
123 : :
124 : : // ----------------------------------------------------------------------------
125 : :
126 [ + - ][ + - ]: 123 : struct FilterBaseImpl
[ + - ][ + - ]
[ + - ][ + - ]
127 : : {
128 : : typedef ::boost::shared_ptr< GraphicHelper > GraphicHelperRef;
129 : : typedef ::boost::shared_ptr< ModelObjectHelper > ModelObjHelperRef;
130 : : typedef ::boost::shared_ptr< OleObjectHelper > OleObjHelperRef;
131 : : typedef ::boost::shared_ptr< VbaProject > VbaProjectRef;
132 : :
133 : : FilterDirection meDirection;
134 : : SequenceAsHashMap maArguments;
135 : : MediaDescriptor maMediaDesc;
136 : : OUString maFileUrl;
137 : : StorageRef mxStorage;
138 : : OoxmlVersion meVersion;
139 : :
140 : : GraphicHelperRef mxGraphicHelper; /// Graphic and graphic object handling.
141 : : ModelObjHelperRef mxModelObjHelper; /// Tables to create new named drawing objects.
142 : : OleObjHelperRef mxOleObjHelper; /// OLE object handling.
143 : : VbaProjectRef mxVbaProject; /// VBA project manager.
144 : :
145 : : Reference< XComponentContext > mxComponentContext;
146 : : Reference< XMultiComponentFactory > mxComponentFactory;
147 : : Reference< XMultiServiceFactory > mxServiceFactory;
148 : : Reference< XModel > mxModel;
149 : : Reference< XMultiServiceFactory > mxModelFactory;
150 : : Reference< XFrame > mxTargetFrame;
151 : : Reference< XInputStream > mxInStream;
152 : : Reference< XStream > mxOutStream;
153 : : Reference< XStatusIndicator > mxStatusIndicator;
154 : : Reference< XInteractionHandler > mxInteractionHandler;
155 : : Reference< XShape > mxParentShape;
156 : :
157 : : explicit FilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException );
158 : :
159 : : void setDocumentModel( const Reference< XComponent >& rxComponent ) throw( IllegalArgumentException );
160 : :
161 : : void initializeFilter();
162 : : void finalizeFilter();
163 : : };
164 : :
165 : : // ----------------------------------------------------------------------------
166 : :
167 : 123 : FilterBaseImpl::FilterBaseImpl( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
168 : : meDirection( FILTERDIRECTION_UNKNOWN ),
169 : : mxComponentContext( rxContext, UNO_SET_THROW ),
170 [ + - ]: 123 : mxComponentFactory( rxContext->getServiceManager(), UNO_SET_THROW ),
171 [ + - ][ + - ]: 246 : mxServiceFactory( rxContext->getServiceManager(), UNO_QUERY_THROW )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
172 : : {
173 : 123 : }
174 : :
175 : 147 : void FilterBaseImpl::setDocumentModel( const Reference< XComponent >& rxComponent ) throw( IllegalArgumentException )
176 : : {
177 : : try
178 : : {
179 [ + - ]: 147 : mxModel.set( rxComponent, UNO_QUERY_THROW );
180 [ + - ]: 147 : mxModelFactory.set( rxComponent, UNO_QUERY_THROW );
181 : : }
182 [ # # ]: 0 : catch( Exception& )
183 : : {
184 [ # # ]: 0 : throw IllegalArgumentException();
185 : : }
186 : 147 : }
187 : :
188 : 147 : void FilterBaseImpl::initializeFilter()
189 : : {
190 : : try
191 : : {
192 : : // lock the model controllers
193 [ + - ][ + - ]: 147 : mxModel->lockControllers();
194 : : }
195 : 0 : catch( Exception& )
196 : : {
197 : : }
198 [ # # ]: 147 : }
199 : :
200 : 147 : void FilterBaseImpl::finalizeFilter()
201 : : {
202 : : try
203 : : {
204 : : // write the descriptor back to the document model (adds the passwords)
205 [ + - ][ + - ]: 147 : mxModel->attachResource( maFileUrl, maMediaDesc.getAsConstPropertyValueList() );
[ + - ]
[ + - # # ]
206 : : // unlock the model controllers
207 [ + - ][ + - ]: 147 : mxModel->unlockControllers();
208 : : }
209 : 0 : catch( Exception& )
210 : : {
211 : : }
212 : 147 : }
213 : :
214 : : // ============================================================================
215 : :
216 : 123 : FilterBase::FilterBase( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
217 [ + - ][ + - ]: 123 : mxImpl( new FilterBaseImpl( rxContext ) )
[ + - ]
218 : : {
219 : 123 : }
220 : :
221 [ + - ][ + - ]: 123 : FilterBase::~FilterBase()
222 : : {
223 [ - + ]: 123 : }
224 : :
225 : 96 : bool FilterBase::isImportFilter() const
226 : : {
227 : 96 : return mxImpl->meDirection == FILTERDIRECTION_IMPORT;
228 : : }
229 : :
230 : 0 : bool FilterBase::isExportFilter() const
231 : : {
232 : 0 : return mxImpl->meDirection == FILTERDIRECTION_EXPORT;
233 : : }
234 : :
235 : 573 : OoxmlVersion FilterBase::getVersion() const
236 : : {
237 : 573 : return mxImpl->meVersion;
238 : : }
239 : :
240 : 357 : const Reference< XComponentContext >& FilterBase::getComponentContext() const
241 : : {
242 : 357 : return mxImpl->mxComponentContext;
243 : : }
244 : :
245 : 210 : const Reference< XMultiServiceFactory >& FilterBase::getServiceFactory() const
246 : : {
247 : 210 : return mxImpl->mxServiceFactory;
248 : : }
249 : :
250 : 345 : const Reference< XModel >& FilterBase::getModel() const
251 : : {
252 : 345 : return mxImpl->mxModel;
253 : : }
254 : :
255 : 264 : const Reference< XMultiServiceFactory >& FilterBase::getModelFactory() const
256 : : {
257 : 264 : return mxImpl->mxModelFactory;
258 : : }
259 : :
260 : 66 : const Reference< XFrame >& FilterBase::getTargetFrame() const
261 : : {
262 : 66 : return mxImpl->mxTargetFrame;
263 : : }
264 : :
265 : 0 : const Reference< XShape >& FilterBase::getParentShape() const
266 : : {
267 : 0 : return mxImpl->mxParentShape;
268 : : }
269 : :
270 : 33 : const Reference< XStatusIndicator >& FilterBase::getStatusIndicator() const
271 : : {
272 : 33 : return mxImpl->mxStatusIndicator;
273 : : }
274 : :
275 : 48 : MediaDescriptor& FilterBase::getMediaDescriptor() const
276 : : {
277 : 48 : return mxImpl->maMediaDesc;
278 : : }
279 : :
280 : 0 : const OUString& FilterBase::getFileUrl() const
281 : : {
282 : 0 : return mxImpl->maFileUrl;
283 : : }
284 : :
285 : : namespace {
286 : :
287 : 0 : inline bool lclIsDosDrive( const OUString& rUrl, sal_Int32 nPos = 0 )
288 : : {
289 : : return
290 : 0 : (rUrl.getLength() >= nPos + 3) &&
291 : 0 : ((('A' <= rUrl[ nPos ]) && (rUrl[ nPos ] <= 'Z')) || (('a' <= rUrl[ nPos ]) && (rUrl[ nPos ] <= 'z'))) &&
292 : 0 : (rUrl[ nPos + 1 ] == ':') &&
293 [ # # ][ # # : 0 : (rUrl[ nPos + 2 ] == '/');
# # # # #
# # # #
# ]
294 : : }
295 : :
296 : : } // namespace
297 : :
298 : 0 : OUString FilterBase::getAbsoluteUrl( const OUString& rUrl ) const
299 : : {
300 : : // handle some special cases before calling ::rtl::Uri::convertRelToAbs()
301 : :
302 [ # # ]: 0 : const OUString aFileSchema = CREATE_OUSTRING( "file:" );
303 [ # # ]: 0 : const OUString aFilePrefix = CREATE_OUSTRING( "file:///" );
304 : 0 : const sal_Int32 nFilePrefixLen = aFilePrefix.getLength();
305 [ # # ]: 0 : const OUString aUncPrefix = CREATE_OUSTRING( "//" );
306 : :
307 : : /* (1) convert all backslashes to slashes, and check that passed URL is
308 : : not empty. */
309 : 0 : OUString aUrl = rUrl.replace( '\\', '/' );
310 [ # # ]: 0 : if( aUrl.isEmpty() )
311 : 0 : return aUrl;
312 : :
313 : : /* (2) add 'file:///' to absolute Windows paths, e.g. convert
314 : : 'C:/path/file' to 'file:///c:/path/file'. */
315 [ # # ]: 0 : if( lclIsDosDrive( aUrl ) )
316 : 0 : return aFilePrefix + aUrl;
317 : :
318 : : /* (3) add 'file:' to UNC paths, e.g. convert '//server/path/file' to
319 : : 'file://server/path/file'. */
320 [ # # ]: 0 : if( aUrl.match( aUncPrefix ) )
321 : 0 : return aFileSchema + aUrl;
322 : :
323 : : /* (4) remove additional slashes from UNC paths, e.g. convert
324 : : 'file://///server/path/file' to 'file://server/path/file'. */
325 [ # # # # : 0 : if( (aUrl.getLength() >= nFilePrefixLen + 2) &&
# # ][ # # ]
326 : 0 : aUrl.match( aFilePrefix ) &&
327 : 0 : aUrl.match( aUncPrefix, nFilePrefixLen ) )
328 : : {
329 : 0 : return aFileSchema + aUrl.copy( nFilePrefixLen );
330 : : }
331 : :
332 : : /* (5) handle URLs relative to current drive, e.g. the URL '/path1/file1'
333 : : relative to the base URL 'file:///C:/path2/file2' does not result in
334 : : the expected 'file:///C:/path1/file1', but in 'file:///path1/file1'. */
335 [ # # ][ # # : 0 : if( !aUrl.isEmpty() && (aUrl[ 0 ] == '/') &&
# # # # ]
[ # # ]
336 : 0 : mxImpl->maFileUrl.match( aFilePrefix ) &&
337 : 0 : lclIsDosDrive( mxImpl->maFileUrl, nFilePrefixLen ) )
338 : : {
339 : 0 : return mxImpl->maFileUrl.copy( 0, nFilePrefixLen + 3 ) + aUrl.copy( 1 );
340 : : }
341 : :
342 : : try
343 : : {
344 [ # # ]: 0 : return ::rtl::Uri::convertRelToAbs( mxImpl->maFileUrl, aUrl );
345 : : }
346 : 0 : catch( ::rtl::MalformedUriException& )
347 : : {
348 : : }
349 [ # # ]: 0 : return aUrl;
350 : : }
351 : :
352 : 237 : StorageRef FilterBase::getStorage() const
353 : : {
354 : 237 : return mxImpl->mxStorage;
355 : : }
356 : :
357 : 480 : Reference< XInputStream > FilterBase::openInputStream( const OUString& rStreamName ) const
358 : : {
359 : 480 : return mxImpl->mxStorage->openInputStream( rStreamName );
360 : : }
361 : :
362 : 345 : Reference< XOutputStream > FilterBase::openOutputStream( const OUString& rStreamName ) const
363 : : {
364 : 345 : return mxImpl->mxStorage->openOutputStream( rStreamName );
365 : : }
366 : :
367 : 57 : void FilterBase::commitStorage() const
368 : : {
369 : 57 : mxImpl->mxStorage->commit();
370 : 57 : }
371 : :
372 : : // helpers --------------------------------------------------------------------
373 : :
374 : 1227 : GraphicHelper& FilterBase::getGraphicHelper() const
375 : : {
376 [ + + ]: 1227 : if( !mxImpl->mxGraphicHelper )
377 : 66 : mxImpl->mxGraphicHelper.reset( implCreateGraphicHelper() );
378 : 1227 : return *mxImpl->mxGraphicHelper;
379 : : }
380 : :
381 : 129 : ModelObjectHelper& FilterBase::getModelObjectHelper() const
382 : : {
383 [ + + ]: 129 : if( !mxImpl->mxModelObjHelper )
384 [ + - ]: 36 : mxImpl->mxModelObjHelper.reset( new ModelObjectHelper( mxImpl->mxModelFactory ) );
385 : 129 : return *mxImpl->mxModelObjHelper;
386 : : }
387 : :
388 : 0 : OleObjectHelper& FilterBase::getOleObjectHelper() const
389 : : {
390 [ # # ]: 0 : if( !mxImpl->mxOleObjHelper )
391 [ # # ]: 0 : mxImpl->mxOleObjHelper.reset( new OleObjectHelper( mxImpl->mxModelFactory ) );
392 : 0 : return *mxImpl->mxOleObjHelper;
393 : : }
394 : :
395 : 0 : VbaProject& FilterBase::getVbaProject() const
396 : : {
397 [ # # ]: 0 : if( !mxImpl->mxVbaProject )
398 : 0 : mxImpl->mxVbaProject.reset( implCreateVbaProject() );
399 : 0 : return *mxImpl->mxVbaProject;
400 : : }
401 : :
402 : 0 : bool FilterBase::importBinaryData( StreamDataSequence& orDataSeq, const OUString& rStreamName )
403 : : {
404 : : OSL_ENSURE( !rStreamName.isEmpty(), "FilterBase::importBinaryData - empty stream name" );
405 [ # # ]: 0 : if( rStreamName.isEmpty() )
406 : 0 : return false;
407 : :
408 : : // try to open the stream (this may fail - do not assert)
409 [ # # ][ # # ]: 0 : BinaryXInputStream aInStrm( openInputStream( rStreamName ), true );
410 [ # # ]: 0 : if( aInStrm.isEof() )
411 : 0 : return false;
412 : :
413 : : // copy the entire stream to the passed sequence
414 [ # # ]: 0 : SequenceOutputStream aOutStrm( orDataSeq );
415 [ # # ]: 0 : aInStrm.copyToStream( aOutStrm );
416 [ # # ][ # # ]: 0 : return true;
417 : : }
418 : :
419 : : // com.sun.star.lang.XServiceInfo interface -----------------------------------
420 : :
421 : 0 : OUString SAL_CALL FilterBase::getImplementationName() throw( RuntimeException )
422 : : {
423 : 0 : return implGetImplementationName();
424 : : }
425 : :
426 : 0 : sal_Bool SAL_CALL FilterBase::supportsService( const OUString& rServiceName ) throw( RuntimeException )
427 : : {
428 : : return
429 [ # # ][ # # ]: 0 : (rServiceName == CREATE_OUSTRING( "com.sun.star.document.ImportFilter" )) ||
[ # # ]
430 [ # # ][ # # ]: 0 : (rServiceName == CREATE_OUSTRING( "com.sun.star.document.ExportFilter" ));
[ # # ][ # # ]
[ # # ]
431 : : }
432 : :
433 : 0 : Sequence< OUString > SAL_CALL FilterBase::getSupportedServiceNames() throw( RuntimeException )
434 : : {
435 : 0 : Sequence< OUString > aServiceNames( 2 );
436 [ # # ][ # # ]: 0 : aServiceNames[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.ImportFilter" );
437 [ # # ][ # # ]: 0 : aServiceNames[ 1 ] = CREATE_OUSTRING( "com.sun.star.document.ExportFilter" );
438 : 0 : return aServiceNames;
439 : : }
440 : :
441 : : // com.sun.star.lang.XInitialization interface --------------------------------
442 : :
443 : 33 : void SAL_CALL FilterBase::initialize( const Sequence< Any >& rArgs ) throw( Exception, RuntimeException )
444 : : {
445 [ - + ]: 33 : if( rArgs.getLength() >= 2 ) try
446 : : {
447 [ # # ]: 0 : mxImpl->maArguments << rArgs[ 1 ];
448 : : }
449 : 0 : catch( Exception& )
450 : : {
451 : : }
452 [ # # ]: 33 : }
453 : :
454 : : // com.sun.star.document.XImporter interface ----------------------------------
455 : :
456 : 90 : void SAL_CALL FilterBase::setTargetDocument( const Reference< XComponent >& rxDocument ) throw( IllegalArgumentException, RuntimeException )
457 : : {
458 : 90 : mxImpl->setDocumentModel( rxDocument );
459 : 90 : mxImpl->meDirection = FILTERDIRECTION_IMPORT;
460 : 90 : }
461 : :
462 : : // com.sun.star.document.XExporter interface ----------------------------------
463 : :
464 : 57 : void SAL_CALL FilterBase::setSourceDocument( const Reference< XComponent >& rxDocument ) throw( IllegalArgumentException, RuntimeException )
465 : : {
466 : 57 : mxImpl->setDocumentModel( rxDocument );
467 : 57 : mxImpl->meDirection = FILTERDIRECTION_EXPORT;
468 : 57 : }
469 : :
470 : : // com.sun.star.document.XFilter interface ------------------------------------
471 : :
472 : 147 : sal_Bool SAL_CALL FilterBase::filter( const Sequence< PropertyValue >& rMediaDescSeq ) throw( RuntimeException )
473 : : {
474 [ + - ][ + - ]: 147 : if( !mxImpl->mxModel.is() || !mxImpl->mxModelFactory.is() || (mxImpl->meDirection == FILTERDIRECTION_UNKNOWN) )
[ - + ][ - + ]
475 [ # # ]: 0 : throw RuntimeException();
476 : :
477 : 147 : sal_Bool bRet = sal_False;
478 [ + - ]: 147 : setMediaDescriptor( rMediaDescSeq );
479 [ + - ]: 147 : DocumentOpenedGuard aOpenedGuard( mxImpl->maFileUrl );
480 [ - + ][ # # ]: 147 : if( aOpenedGuard.isValid() || mxImpl->maFileUrl.isEmpty() )
[ + - ]
481 : : {
482 [ + - ]: 147 : mxImpl->initializeFilter();
483 [ - + + - ]: 147 : switch( mxImpl->meDirection )
484 : : {
485 : : case FILTERDIRECTION_UNKNOWN:
486 : 0 : break;
487 : : case FILTERDIRECTION_IMPORT:
488 [ + - ]: 90 : if( mxImpl->mxInStream.is() )
489 : : {
490 [ + - ][ + - ]: 90 : mxImpl->mxStorage = implCreateStorage( mxImpl->mxInStream );
[ + - ]
491 [ + - ][ + - ]: 90 : bRet = mxImpl->mxStorage.get() && importDocument();
[ + - ]
492 : : }
493 : 90 : break;
494 : : case FILTERDIRECTION_EXPORT:
495 [ + - ]: 57 : if( mxImpl->mxOutStream.is() )
496 : : {
497 [ + - ][ + - ]: 57 : mxImpl->mxStorage = implCreateStorage( mxImpl->mxOutStream );
[ + - ]
498 [ + - ][ + - ]: 57 : bRet = mxImpl->mxStorage.get() && exportDocument();
[ + - ]
499 : : }
500 : 57 : break;
501 : : }
502 [ + - ]: 147 : mxImpl->finalizeFilter();
503 : : }
504 [ + - ]: 147 : return bRet;
505 : : }
506 : :
507 : 0 : void SAL_CALL FilterBase::cancel() throw( RuntimeException )
508 : : {
509 : 0 : }
510 : :
511 : : // protected ------------------------------------------------------------------
512 : :
513 : 0 : Reference< XInputStream > FilterBase::implGetInputStream( MediaDescriptor& rMediaDesc ) const
514 : : {
515 [ # # ][ # # ]: 0 : return rMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INPUTSTREAM(), Reference< XInputStream >() );
516 : : }
517 : :
518 : 57 : Reference< XStream > FilterBase::implGetOutputStream( MediaDescriptor& rMediaDesc ) const
519 : : {
520 [ + - ][ + - ]: 57 : return rMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STREAMFOROUTPUT(), Reference< XStream >() );
521 : : }
522 : :
523 : : // private --------------------------------------------------------------------
524 : :
525 : 147 : void FilterBase::setMediaDescriptor( const Sequence< PropertyValue >& rMediaDescSeq )
526 : : {
527 [ + - ]: 147 : mxImpl->maMediaDesc << rMediaDescSeq;
528 : :
529 [ - + + - ]: 147 : switch( mxImpl->meDirection )
530 : : {
531 : : case FILTERDIRECTION_UNKNOWN:
532 : : OSL_FAIL( "FilterBase::setMediaDescriptor - invalid filter direction" );
533 : 0 : break;
534 : : case FILTERDIRECTION_IMPORT:
535 [ + - ]: 90 : mxImpl->maMediaDesc.addInputStream();
536 [ + - ][ + - ]: 90 : mxImpl->mxInStream = implGetInputStream( mxImpl->maMediaDesc );
537 : : OSL_ENSURE( mxImpl->mxInStream.is(), "FilterBase::setMediaDescriptor - missing input stream" );
538 : 90 : break;
539 : : case FILTERDIRECTION_EXPORT:
540 [ + - ][ + - ]: 57 : mxImpl->mxOutStream = implGetOutputStream( mxImpl->maMediaDesc );
541 : : OSL_ENSURE( mxImpl->mxOutStream.is(), "FilterBase::setMediaDescriptor - missing output stream" );
542 : 57 : break;
543 : : }
544 : :
545 [ + - ][ + - ]: 147 : mxImpl->maFileUrl = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() );
546 [ + - ][ + - ]: 147 : mxImpl->mxTargetFrame = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_FRAME(), Reference< XFrame >() );
[ + - ]
547 [ + - ][ + - ]: 147 : mxImpl->mxStatusIndicator = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STATUSINDICATOR(), Reference< XStatusIndicator >() );
[ + - ]
548 [ + - ][ + - ]: 147 : mxImpl->mxInteractionHandler = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() );
[ + - ]
549 [ + - ][ + - ]: 147 : mxImpl->mxParentShape = mxImpl->maMediaDesc.getUnpackedValueOrDefault( CREATE_OUSTRING( "ParentShape" ), mxImpl->mxParentShape );
[ + - ]
550 : :
551 : : // Check for ISO OOXML
552 [ + - ][ + - ]: 147 : OUString sFilterName = mxImpl->maMediaDesc.getUnpackedValueOrDefault( CREATE_OUSTRING( "FilterName" ), OUString() );
553 : : try
554 : : {
555 [ + - ][ + - ]: 147 : Reference< XNameAccess > xFilters( getServiceFactory()->createInstance(
556 [ + - ][ + - ]: 147 : CREATE_OUSTRING( "com.sun.star.document.FilterFactory" ) ), UNO_QUERY_THROW );
[ + - ]
557 [ + + ][ + - ]: 147 : Any aValues = xFilters->getByName( sFilterName );
558 [ + - ]: 90 : Sequence<PropertyValue > aPropSeq;
559 [ + - ]: 90 : aValues >>= aPropSeq;
560 [ + - ]: 90 : SequenceAsHashMap aProps( aPropSeq );
561 : :
562 [ + - ][ + - ]: 90 : sal_Int32 nVersion = aProps.getUnpackedValueOrDefault( CREATE_OUSTRING( "FileFormatVersion" ), sal_Int32( 0 ) );
563 [ + - ][ - + ]: 147 : mxImpl->meVersion = OoxmlVersion( nVersion );
[ + - ]
564 : : }
565 [ + - ]: 57 : catch ( Exception& )
566 : : {
567 : : // Not ISO OOXML
568 : 147 : }
569 : 147 : }
570 : :
571 : 0 : GraphicHelper* FilterBase::implCreateGraphicHelper() const
572 : : {
573 : : // default: return base implementation without any special behaviour
574 [ # # ]: 0 : return new GraphicHelper( mxImpl->mxComponentContext, mxImpl->mxTargetFrame, mxImpl->mxStorage );
575 : : }
576 : :
577 : : // ============================================================================
578 : :
579 : : } // namespace core
580 [ + - ][ + - ]: 285 : } // namespace oox
581 : :
582 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|