LCOV - code coverage report
Current view: top level - libreoffice/oox/source/core - filterbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 132 206 64.1 %
Date: 2012-12-17 Functions: 36 50 72.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10