LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/xml - xmlgrhlp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 138 462 29.9 %
Date: 2013-07-09 Functions: 31 61 50.8 %
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 <comphelper/string.hxx>
      21             : #include <sal/macros.h>
      22             : #include <rtl/strbuf.hxx>
      23             : #include <com/sun/star/embed/XTransactedObject.hpp>
      24             : #include <com/sun/star/embed/ElementModes.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/lang/XInitialization.hpp>
      29             : #include <cppuhelper/compbase4.hxx>
      30             : 
      31             : #include <unotools/ucbstreamhelper.hxx>
      32             : #include <unotools/streamwrap.hxx>
      33             : #include <unotools/tempfile.hxx>
      34             : #include <unotools/saveopt.hxx>
      35             : #include <tools/debug.hxx>
      36             : #include <vcl/cvtgrf.hxx>
      37             : #include <vcl/gfxlink.hxx>
      38             : #include <vcl/metaact.hxx>
      39             : #include <tools/zcodec.hxx>
      40             : 
      41             : #include <vcl/graphicfilter.hxx>
      42             : #include "svx/xmlgrhlp.hxx"
      43             : #include "svx/xmleohlp.hxx"
      44             : 
      45             : #include <algorithm>
      46             : 
      47             : using namespace com::sun::star;
      48             : using namespace com::sun::star::uno;
      49             : using namespace com::sun::star::io;
      50             : 
      51             : using ::com::sun::star::lang::XMultiServiceFactory;
      52             : 
      53             : #define XML_GRAPHICSTORAGE_NAME     "Pictures"
      54             : #define XML_GRAPHICOBJECT_URL_BASE  "vnd.sun.star.GraphicObject:"
      55             : 
      56           0 : const MetaCommentAction* ImplCheckForEPS( GDIMetaFile& rMtf )
      57             : {
      58           0 :     const MetaCommentAction* pComment = NULL;
      59             : 
      60           0 :     if ( ( rMtf.GetActionSize() >= 2 )
      61           0 :             && ( rMtf.FirstAction()->GetType() == META_EPS_ACTION )
      62           0 :             && ( ((const MetaAction*)rMtf.GetAction( 1 ))->GetType() == META_COMMENT_ACTION )
      63           0 :             && ( ((const MetaCommentAction*)rMtf.GetAction( 1 ))->GetComment().equalsL(RTL_CONSTASCII_STRINGPARAM("EPSReplacementGraphic")) ) )
      64           0 :         pComment = (const MetaCommentAction*)rMtf.GetAction( 1 );
      65             : 
      66           0 :     return pComment;
      67             : }
      68             : 
      69             : class SvXMLGraphicInputStream : public::cppu::WeakImplHelper1< XInputStream >
      70             : {
      71             : private:
      72             : 
      73             :     virtual sal_Int32   SAL_CALL    readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
      74             :     virtual sal_Int32   SAL_CALL    readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
      75             :     virtual void        SAL_CALL    skipBytes(sal_Int32 nBytesToSkip) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
      76             :     virtual sal_Int32   SAL_CALL    available() throw(NotConnectedException, RuntimeException);
      77             :     virtual void        SAL_CALL    closeInput() throw(NotConnectedException, RuntimeException);
      78             : 
      79             : private:
      80             : 
      81             :     ::utl::TempFile                 maTmp;
      82             :     Reference< XInputStream >       mxStmWrapper;
      83             : 
      84             :                                     // not available
      85             :                                     SvXMLGraphicInputStream();
      86             :                                     SvXMLGraphicInputStream( const SvXMLGraphicInputStream& );
      87             :     SvXMLGraphicInputStream&        operator==( SvXMLGraphicInputStream& );
      88             : 
      89             : public:
      90             : 
      91             :                                     SvXMLGraphicInputStream( const OUString& rGraphicId );
      92             :     virtual                         ~SvXMLGraphicInputStream();
      93             : 
      94           0 :     bool                            Exists() const { return mxStmWrapper.is(); }
      95             : };
      96             : 
      97           0 : SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId )
      98             : {
      99           0 :     GraphicObject   aGrfObject( OUStringToOString(rGraphicId, RTL_TEXTENCODING_ASCII_US) );
     100             : 
     101           0 :     maTmp.EnableKillingFile();
     102             : 
     103           0 :     if( aGrfObject.GetType() != GRAPHIC_NONE )
     104             :     {
     105           0 :         SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( maTmp.GetURL(), STREAM_WRITE | STREAM_TRUNC );
     106             : 
     107           0 :         if( pStm )
     108             :         {
     109           0 :             Graphic         aGraphic( (Graphic&) aGrfObject.GetGraphic() );
     110           0 :             const GfxLink   aGfxLink( aGraphic.GetLink() );
     111           0 :             sal_Bool        bRet = sal_False;
     112             : 
     113           0 :             if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
     114             :             {
     115           0 :                 pStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
     116           0 :                 bRet = ( pStm->GetError() == 0 );
     117             :             }
     118             :             else
     119             :             {
     120           0 :                 if( aGraphic.GetType() == GRAPHIC_BITMAP )
     121             :                 {
     122           0 :                     GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
     123           0 :                     String          aFormat;
     124             : 
     125           0 :                     if( aGraphic.IsAnimated() )
     126           0 :                         aFormat = String(  "gif"  );
     127             :                     else
     128           0 :                         aFormat = String(  "png"  );
     129             : 
     130           0 :                     bRet = ( rFilter.ExportGraphic( aGraphic, String(), *pStm, rFilter.GetExportFormatNumberForShortName( aFormat ) ) == 0 );
     131             :                 }
     132           0 :                 else if( aGraphic.GetType() == GRAPHIC_GDIMETAFILE )
     133             :                 {
     134           0 :                     pStm->SetVersion( SOFFICE_FILEFORMAT_8 );
     135           0 :                     pStm->SetCompressMode( COMPRESSMODE_ZBITMAP );
     136           0 :                     ( (GDIMetaFile&) aGraphic.GetGDIMetaFile() ).Write( *pStm );
     137           0 :                     bRet = ( pStm->GetError() == 0 );
     138             :                 }
     139             :             }
     140             : 
     141           0 :             if( bRet )
     142             :             {
     143           0 :                 pStm->Seek( 0 );
     144           0 :                 mxStmWrapper = new ::utl::OInputStreamWrapper( pStm, sal_True );
     145             :             }
     146             :             else
     147           0 :                 delete pStm;
     148             :         }
     149           0 :     }
     150           0 : }
     151             : 
     152           0 : SvXMLGraphicInputStream::~SvXMLGraphicInputStream()
     153             : {
     154           0 : }
     155             : 
     156           0 : sal_Int32 SAL_CALL SvXMLGraphicInputStream::readBytes( Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead )
     157             :     throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
     158             : {
     159           0 :     if( !mxStmWrapper.is() )
     160           0 :         throw NotConnectedException();
     161             : 
     162           0 :     return mxStmWrapper->readBytes( rData, nBytesToRead );
     163             : }
     164             : 
     165           0 : sal_Int32 SAL_CALL SvXMLGraphicInputStream::readSomeBytes( Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead )
     166             :     throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
     167             : {
     168           0 :     if( !mxStmWrapper.is() )
     169           0 :         throw NotConnectedException() ;
     170             : 
     171           0 :     return mxStmWrapper->readSomeBytes( rData, nMaxBytesToRead );
     172             : }
     173             : 
     174           0 : void SAL_CALL SvXMLGraphicInputStream::skipBytes( sal_Int32 nBytesToSkip )
     175             :     throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
     176             : {
     177           0 :     if( !mxStmWrapper.is() )
     178           0 :         throw NotConnectedException() ;
     179             : 
     180           0 :     mxStmWrapper->skipBytes( nBytesToSkip );
     181           0 : }
     182             : 
     183           0 : sal_Int32 SAL_CALL SvXMLGraphicInputStream::available() throw( NotConnectedException, RuntimeException )
     184             : {
     185           0 :     if( !mxStmWrapper.is() )
     186           0 :         throw NotConnectedException() ;
     187             : 
     188           0 :     return mxStmWrapper->available();
     189             : }
     190             : 
     191           0 : void SAL_CALL SvXMLGraphicInputStream::closeInput() throw( NotConnectedException, RuntimeException )
     192             : {
     193           0 :     if( !mxStmWrapper.is() )
     194           0 :         throw NotConnectedException() ;
     195             : 
     196           0 :     mxStmWrapper->closeInput();
     197           0 : }
     198             : 
     199             : class SvXMLGraphicOutputStream : public::cppu::WeakImplHelper1< XOutputStream >
     200             : {
     201             : private:
     202             : 
     203             :     // XOutputStream
     204             :     virtual void SAL_CALL           writeBytes( const Sequence< sal_Int8 >& rData ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
     205             :     virtual void SAL_CALL           flush() throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
     206             :     virtual void SAL_CALL           closeOutput() throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
     207             : 
     208             : private:
     209             : 
     210             :     ::utl::TempFile*                mpTmp;
     211             :     SvStream*                       mpOStm;
     212             :     Reference< XOutputStream >      mxStmWrapper;
     213             :     GraphicObject                   maGrfObj;
     214             :     sal_Bool                        mbClosed;
     215             : 
     216             :                                     // not available
     217             :                                     SvXMLGraphicOutputStream( const SvXMLGraphicOutputStream& );
     218             :     SvXMLGraphicOutputStream&       operator==( SvXMLGraphicOutputStream& );
     219             : 
     220             : public:
     221             : 
     222             :                                     SvXMLGraphicOutputStream();
     223             :     virtual                         ~SvXMLGraphicOutputStream();
     224             : 
     225           0 :     bool                            Exists() const { return mxStmWrapper.is(); }
     226             :     const GraphicObject&            GetGraphicObject();
     227             : };
     228             : 
     229           0 : SvXMLGraphicOutputStream::SvXMLGraphicOutputStream() :
     230           0 :     mpTmp( new ::utl::TempFile ),
     231           0 :     mbClosed( sal_False )
     232             : {
     233           0 :     mpTmp->EnableKillingFile();
     234             : 
     235           0 :     mpOStm = ::utl::UcbStreamHelper::CreateStream( mpTmp->GetURL(), STREAM_WRITE | STREAM_TRUNC );
     236             : 
     237           0 :     if( mpOStm )
     238           0 :         mxStmWrapper = new ::utl::OOutputStreamWrapper( *mpOStm );
     239           0 : }
     240             : 
     241           0 : SvXMLGraphicOutputStream::~SvXMLGraphicOutputStream()
     242             : {
     243           0 :     delete mpTmp;
     244           0 :     delete mpOStm;
     245           0 : }
     246             : 
     247           0 : void SAL_CALL SvXMLGraphicOutputStream::writeBytes( const Sequence< sal_Int8 >& rData )
     248             :     throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
     249             : {
     250           0 :     if( !mxStmWrapper.is() )
     251           0 :         throw NotConnectedException() ;
     252             : 
     253           0 :     mxStmWrapper->writeBytes( rData );
     254           0 : }
     255             : 
     256           0 : void SAL_CALL SvXMLGraphicOutputStream::flush()
     257             :     throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
     258             : {
     259           0 :     if( !mxStmWrapper.is() )
     260           0 :         throw NotConnectedException() ;
     261             : 
     262           0 :     mxStmWrapper->flush();
     263           0 : }
     264             : 
     265           0 : void SAL_CALL SvXMLGraphicOutputStream::closeOutput()
     266             :     throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
     267             : {
     268           0 :     if( !mxStmWrapper.is() )
     269           0 :         throw NotConnectedException() ;
     270             : 
     271           0 :     mxStmWrapper->closeOutput();
     272           0 :     mxStmWrapper.clear();
     273             : 
     274           0 :     mbClosed = sal_True;
     275           0 : }
     276             : 
     277           0 : const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject()
     278             : {
     279           0 :     if( mbClosed && ( maGrfObj.GetType() == GRAPHIC_NONE ) && mpOStm )
     280             :     {
     281           0 :         Graphic aGraphic;
     282             : 
     283           0 :         mpOStm->Seek( 0 );
     284           0 :         sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
     285           0 :         sal_uInt16 pDeterminedFormat = GRFILTER_FORMAT_DONTKNOW;
     286           0 :         GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, String(), *mpOStm ,nFormat,&pDeterminedFormat );
     287             : 
     288           0 :         if (pDeterminedFormat == GRFILTER_FORMAT_DONTKNOW)
     289             :         {
     290             :             //Read the first two byte to check whether it is a gzipped stream, is so it may be in wmz or emz format
     291             :             //unzip them and try again
     292             : 
     293             :             sal_uInt8    sFirstBytes[ 2 ];
     294             : 
     295           0 :             mpOStm->Seek( STREAM_SEEK_TO_END );
     296           0 :             sal_uIntPtr nStreamLen = mpOStm->Tell();
     297           0 :             mpOStm->Seek( 0 );
     298             : 
     299           0 :             if ( !nStreamLen )
     300             :             {
     301           0 :                 SvLockBytes* pLockBytes = mpOStm->GetLockBytes();
     302           0 :                 if ( pLockBytes  )
     303           0 :                     pLockBytes->SetSynchronMode( sal_True );
     304             : 
     305           0 :                 mpOStm->Seek( STREAM_SEEK_TO_END );
     306           0 :                 nStreamLen = mpOStm->Tell();
     307           0 :                 mpOStm->Seek( 0 );
     308             :             }
     309           0 :             if( nStreamLen >= 2 )
     310             :             {
     311             :                 //read two byte
     312           0 :                 mpOStm->Read( sFirstBytes, 2 );
     313             : 
     314           0 :                 if( sFirstBytes[0] == 0x1f && sFirstBytes[1] == 0x8b )
     315             :                 {
     316           0 :                     SvMemoryStream* pDest = new SvMemoryStream;
     317           0 :                     ZCodec aZCodec( 0x8000, 0x8000 );
     318           0 :                     aZCodec.BeginCompression(ZCODEC_GZ_LIB);
     319           0 :                     mpOStm->Seek( 0 );
     320           0 :                     aZCodec.Decompress( *mpOStm, *pDest );
     321             : 
     322           0 :                     if (aZCodec.EndCompression() && pDest )
     323             :                     {
     324           0 :                         pDest->Seek( STREAM_SEEK_TO_END );
     325           0 :                         sal_uIntPtr nStreamLen_ = pDest->Tell();
     326           0 :                         if (nStreamLen_)
     327             :                         {
     328           0 :                             pDest->Seek(0L);
     329           0 :                             GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, String(), *pDest ,nFormat,&pDeterminedFormat );
     330             :                         }
     331             :                     }
     332           0 :                     delete pDest;
     333             :                 }
     334             :             }
     335             :         }
     336             : 
     337           0 :         maGrfObj = aGraphic;
     338           0 :         if( maGrfObj.GetType() != GRAPHIC_NONE )
     339             :         {
     340           0 :             delete mpOStm, mpOStm = NULL;
     341           0 :             delete mpTmp, mpTmp = NULL;
     342           0 :         }
     343             :     }
     344             : 
     345           0 :     return maGrfObj;
     346             : }
     347             : 
     348         169 : SvXMLGraphicHelper::SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode ) :
     349             :     ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
     350         169 :                                       ::com::sun::star::document::XBinaryStreamResolver >( maMutex )
     351             : {
     352         169 :     Init( NULL, eCreateMode, sal_False );
     353         169 : }
     354             : 
     355         275 : SvXMLGraphicHelper::SvXMLGraphicHelper() :
     356             :     ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
     357         275 :                                       ::com::sun::star::document::XBinaryStreamResolver >( maMutex )
     358             : {
     359         275 : }
     360             : 
     361         888 : SvXMLGraphicHelper::~SvXMLGraphicHelper()
     362             : {
     363         888 : }
     364             : 
     365         444 : void SAL_CALL SvXMLGraphicHelper::disposing()
     366             : {
     367         444 : }
     368             : 
     369          91 : sal_Bool SvXMLGraphicHelper::ImplGetStreamNames( const OUString& rURLStr,
     370             :                                                  OUString& rPictureStorageName,
     371             :                                                  OUString& rPictureStreamName )
     372             : {
     373          91 :     String      aURLStr( rURLStr );
     374          91 :     sal_Bool    bRet = sal_False;
     375             : 
     376          91 :     if( aURLStr.Len() )
     377             :     {
     378          91 :         aURLStr = aURLStr.GetToken( comphelper::string::getTokenCount(aURLStr, ':') - 1, ':' );
     379             : 
     380          91 :         const sal_uInt32 nTokenCount = comphelper::string::getTokenCount(aURLStr, '/');
     381             : 
     382          91 :         if( 1 == nTokenCount )
     383             :         {
     384           0 :             rPictureStorageName = String(  XML_GRAPHICSTORAGE_NAME  );
     385           0 :             rPictureStreamName = aURLStr;
     386             :         }
     387             :         else
     388          91 :             SvXMLEmbeddedObjectHelper::splitObjectURL(aURLStr, rPictureStorageName, rPictureStreamName);
     389             : 
     390          91 :         bRet = !rPictureStreamName.isEmpty();
     391             :         SAL_WARN_IF(!bRet, "svx", "SvXMLGraphicHelper::ImplInsertGraphicURL: invalid scheme: " << rURLStr);
     392             :     }
     393             : 
     394          91 :     return bRet;
     395             : }
     396             : 
     397          91 : uno::Reference < embed::XStorage > SvXMLGraphicHelper::ImplGetGraphicStorage( const OUString& rStorageName )
     398             : {
     399          91 :     uno::Reference < embed::XStorage > xRetStorage;
     400          91 :     if( mxRootStorage.is() )
     401             :     {
     402             :         try
     403             :         {
     404         364 :             xRetStorage = mxRootStorage->openStorageElement(
     405          91 :                 maCurStorageName = rStorageName,
     406          91 :                 ( GRAPHICHELPER_MODE_WRITE == meCreateMode )
     407             :                     ? embed::ElementModes::READWRITE
     408         182 :                     : embed::ElementModes::READ );
     409             :         }
     410           0 :         catch ( uno::Exception& )
     411             :         {
     412             :         }
     413             :         //#i43196# try again to open the storage element - this time readonly
     414          91 :         if(!xRetStorage.is())
     415             :         {
     416             :             try
     417             :             {
     418           0 :                 xRetStorage = mxRootStorage->openStorageElement( maCurStorageName = rStorageName, embed::ElementModes::READ );
     419             :             }
     420           0 :             catch ( uno::Exception& )
     421             :             {
     422             :             }
     423             :         }
     424             :     }
     425             : 
     426          91 :     return xRetStorage;
     427             : }
     428             : 
     429          91 : SvxGraphicHelperStream_Impl SvXMLGraphicHelper::ImplGetGraphicStream( const OUString& rPictureStorageName,
     430             :                                                               const OUString& rPictureStreamName,
     431             :                                                               sal_Bool bTruncate )
     432             : {
     433          91 :     SvxGraphicHelperStream_Impl aRet;
     434          91 :     aRet.xStorage = ImplGetGraphicStorage( rPictureStorageName );
     435             : 
     436          91 :     if( aRet.xStorage.is() )
     437             :     {
     438          91 :         sal_Int32 nMode = embed::ElementModes::READ;
     439          91 :         if ( GRAPHICHELPER_MODE_WRITE == meCreateMode )
     440             :         {
     441           0 :             nMode = embed::ElementModes::READWRITE;
     442           0 :             if ( bTruncate )
     443           0 :                 nMode |= embed::ElementModes::TRUNCATE;
     444             :         }
     445             : 
     446          91 :         aRet.xStream = aRet.xStorage->openStreamElement( rPictureStreamName, nMode );
     447          91 :         if( aRet.xStream.is() && ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) )
     448             :         {
     449           0 :             OUString aPropName( "UseCommonStoragePasswordEncryption" );
     450           0 :             uno::Reference < beans::XPropertySet > xProps( aRet.xStream, uno::UNO_QUERY );
     451           0 :             xProps->setPropertyValue( aPropName, uno::makeAny( sal_True) );
     452             :         }
     453             :     }
     454             : 
     455          91 :     return aRet;
     456             : }
     457             : 
     458           0 : String SvXMLGraphicHelper::ImplGetGraphicMimeType( const String& rFileName ) const
     459             : {
     460             :     struct XMLGraphicMimeTypeMapper
     461             :     {
     462             :         const char* pExt;
     463             :         const char* pMimeType;
     464             :     };
     465             : 
     466             :     static const XMLGraphicMimeTypeMapper aMapper[] =
     467             :     {
     468             :         { "gif", "image/gif" },
     469             :         { "png", "image/png" },
     470             :         { "jpg", "image/jpeg" },
     471             :         { "tif", "image/tiff" },
     472             :         { "svg", "image/svg+xml" }
     473             :     };
     474             : 
     475           0 :     String aMimeType;
     476             : 
     477           0 :     if( ( rFileName.Len() >= 4 ) && ( rFileName.GetChar( rFileName.Len() - 4 ) == '.' ) )
     478             :     {
     479           0 :         const OString aExt(OUStringToOString(rFileName.Copy(rFileName.Len() - 3),
     480           0 :             RTL_TEXTENCODING_ASCII_US));
     481             : 
     482           0 :         for( long i = 0, nCount = sizeof (aMapper) / sizeof (aMapper[0]); ( i < nCount ) && !aMimeType.Len(); i++ )
     483           0 :             if( aExt.getStr() == aMapper[ i ].pExt )
     484           0 :                 aMimeType = String( aMapper[ i ].pMimeType, RTL_TEXTENCODING_ASCII_US );
     485             :     }
     486             : 
     487           0 :     return aMimeType;
     488             : }
     489             : 
     490          91 : Graphic SvXMLGraphicHelper::ImplReadGraphic( const OUString& rPictureStorageName,
     491             :                                              const OUString& rPictureStreamName )
     492             : {
     493          91 :     Graphic             aGraphic;
     494         182 :     SvxGraphicHelperStream_Impl aStream( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName, sal_False ) );
     495          91 :     if( aStream.xStream.is() )
     496             :     {
     497          91 :         SvStream* pStream = utl::UcbStreamHelper::CreateStream( aStream.xStream );
     498          91 :         GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, String(), *pStream );
     499          91 :         delete pStream;
     500             :     }
     501             : 
     502         182 :     return aGraphic;
     503             : }
     504             : 
     505           0 : sal_Bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName,
     506             :                                                const OUString& rPictureStreamName,
     507             :                                                const OUString& rGraphicId,
     508             :                                                bool bUseGfxLink )
     509             : {
     510           0 :     GraphicObject   aGrfObject( OUStringToOString(rGraphicId, RTL_TEXTENCODING_ASCII_US) );
     511           0 :     sal_Bool        bRet = sal_False;
     512             : 
     513           0 :     if( aGrfObject.GetType() != GRAPHIC_NONE )
     514             :     {
     515           0 :         SvxGraphicHelperStream_Impl aStream( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName, sal_False ) );
     516           0 :         if( aStream.xStream.is() )
     517             :         {
     518           0 :             Graphic         aGraphic( (Graphic&) aGrfObject.GetGraphic() );
     519           0 :             const GfxLink   aGfxLink( aGraphic.GetLink() );
     520           0 :             const OUString  aMimeType( ImplGetGraphicMimeType( rPictureStreamName ) );
     521           0 :             uno::Any        aAny;
     522           0 :             uno::Reference < beans::XPropertySet > xProps( aStream.xStream, uno::UNO_QUERY );
     523             : 
     524             :             // set stream properties (MediaType/Compression)
     525           0 :             if( !aMimeType.isEmpty() )
     526             :             {
     527           0 :                 aAny <<= aMimeType;
     528           0 :                 xProps->setPropertyValue( String(  "MediaType"  ), aAny );
     529             :             }
     530             : 
     531           0 :             const sal_Bool bCompressed = aMimeType.isEmpty() || aMimeType == "image/tiff";
     532           0 :             aAny <<= bCompressed;
     533           0 :             xProps->setPropertyValue( String(  "Compressed"  ), aAny );
     534             : 
     535           0 :             SvStream* pStream = utl::UcbStreamHelper::CreateStream( aStream.xStream );
     536           0 :             if( bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData() )
     537           0 :                 pStream->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
     538             :             else
     539             :             {
     540           0 :                 if( aGraphic.GetType() == GRAPHIC_BITMAP )
     541             :                 {
     542           0 :                     GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
     543           0 :                     String          aFormat;
     544             : 
     545           0 :                     if( aGraphic.IsAnimated() )
     546           0 :                         aFormat = String(  "gif"  );
     547             :                     else
     548           0 :                         aFormat = String(  "png"  );
     549             : 
     550             :                     bRet = ( rFilter.ExportGraphic( aGraphic, String(), *pStream,
     551           0 :                                                      rFilter.GetExportFormatNumberForShortName( aFormat ) ) == 0 );
     552             :                 }
     553           0 :                 else if( aGraphic.GetType() == GRAPHIC_GDIMETAFILE )
     554             :                 {
     555           0 :                     pStream->SetVersion( SOFFICE_FILEFORMAT_8 );
     556           0 :                     pStream->SetCompressMode( COMPRESSMODE_ZBITMAP );
     557             : 
     558             :                     // SJ: first check if this metafile is just a eps file, then we will store the eps instead of svm
     559           0 :                     GDIMetaFile& rMtf( (GDIMetaFile&)aGraphic.GetGDIMetaFile() );
     560           0 :                     const MetaCommentAction* pComment = ImplCheckForEPS( rMtf );
     561           0 :                     if ( pComment )
     562             :                     {
     563           0 :                         sal_uInt32  nSize = pComment->GetDataSize();
     564           0 :                         const sal_uInt8* pData = pComment->GetData();
     565           0 :                         if ( nSize && pData )
     566           0 :                             pStream->Write( pData, nSize );
     567             : 
     568           0 :                         const MetaEPSAction* pAct = ( (const MetaEPSAction*)rMtf.FirstAction() );
     569           0 :                         const GfxLink&       rLink = pAct->GetLink();
     570             : 
     571           0 :                         pStream->Write( rLink.GetData(), rLink.GetDataSize() );
     572             :                     }
     573             :                     else
     574           0 :                         rMtf.Write( *pStream );
     575             : 
     576           0 :                     bRet = ( pStream->GetError() == 0 );
     577             :                 }
     578             :             }
     579             :             uno::Reference < embed::XTransactedObject > xStorage(
     580           0 :                                     aStream.xStorage, uno::UNO_QUERY);
     581           0 :             delete pStream;
     582           0 :             aStream.xStream->getOutputStream()->closeOutput();
     583           0 :             if( xStorage.is() )
     584           0 :                 xStorage->commit();
     585           0 :         }
     586             :     }
     587             : 
     588           0 :     return bRet;
     589             : }
     590             : 
     591          91 : void SvXMLGraphicHelper::ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt32 nInsertPos, OUString& rRequestedFileName )
     592             : {
     593          91 :     OUString aURLString( rURLStr );
     594         182 :     OUString aPictureStorageName, aPictureStreamName;
     595          91 :     if( ( maURLSet.find( aURLString ) != maURLSet.end() ) )
     596             :     {
     597           0 :         for (URLPairVector::const_iterator aIter( maGrfURLs.begin() ), aEnd( maGrfURLs.end() ); aIter != aEnd ; ++aIter)
     598             :         {
     599           0 :             if( aURLString == (*aIter).first )
     600             :             {
     601           0 :                 maGrfURLs[ nInsertPos ].second = (*aIter).second;
     602           0 :                 break;
     603             :             }
     604             :         }
     605             :     }
     606          91 :     else if( ImplGetStreamNames( aURLString, aPictureStorageName, aPictureStreamName ) )
     607             :     {
     608          91 :         URLPair& rURLPair = maGrfURLs[ nInsertPos ];
     609             : 
     610          91 :         if( GRAPHICHELPER_MODE_READ == meCreateMode )
     611             :         {
     612          91 :             const GraphicObject aObj( ImplReadGraphic( aPictureStorageName, aPictureStreamName ) );
     613             : 
     614          91 :             if( aObj.GetType() != GRAPHIC_NONE )
     615             :             {
     616          91 :                 maGrfObjs.push_back( aObj );
     617          91 :                 OUString aBaseURL(  XML_GRAPHICOBJECT_URL_BASE  );
     618             : 
     619          91 :                 rURLPair.second = aBaseURL;
     620         182 :                 rURLPair.second += OStringToOUString(aObj.GetUniqueID(),
     621         182 :                     RTL_TEXTENCODING_ASCII_US);
     622             :             }
     623             :             else
     624           0 :                 rURLPair.second = String();
     625             :         }
     626             :         else
     627             :         {
     628           0 :             const String        aGraphicObjectId( aPictureStreamName );
     629           0 :             const OString aAsciiObjectID(OUStringToOString(aGraphicObjectId, RTL_TEXTENCODING_ASCII_US));
     630           0 :             const GraphicObject aGrfObject( aAsciiObjectID );
     631           0 :             if( aGrfObject.GetType() != GRAPHIC_NONE )
     632             :             {
     633           0 :                 String          aStreamName( aGraphicObjectId );
     634           0 :                 Graphic         aGraphic( (Graphic&) aGrfObject.GetGraphic() );
     635           0 :                 const GfxLink   aGfxLink( aGraphic.GetLink() );
     636           0 :                 String          aExtension;
     637           0 :                 bool            bUseGfxLink( true );
     638             : 
     639           0 :                 if( aGfxLink.GetDataSize() )
     640             :                 {
     641           0 :                     switch( aGfxLink.GetType() )
     642             :                     {
     643           0 :                         case( GFX_LINK_TYPE_EPS_BUFFER ): aExtension = String(  ".eps"  ); break;
     644           0 :                         case( GFX_LINK_TYPE_NATIVE_GIF ): aExtension = String(  ".gif"  ); break;
     645           0 :                         case( GFX_LINK_TYPE_NATIVE_JPG ): aExtension = String(  ".jpg"  ); break;
     646           0 :                         case( GFX_LINK_TYPE_NATIVE_PNG ): aExtension = String(  ".png"  ); break;
     647           0 :                         case( GFX_LINK_TYPE_NATIVE_TIF ): aExtension = String(  ".tif"  ); break;
     648           0 :                         case( GFX_LINK_TYPE_NATIVE_WMF ): aExtension = String(  ".wmf"  ); break;
     649           0 :                         case( GFX_LINK_TYPE_NATIVE_MET ): aExtension = String(  ".met"  ); break;
     650           0 :                         case( GFX_LINK_TYPE_NATIVE_PCT ): aExtension = String(  ".pct"  ); break;
     651             :                         case( GFX_LINK_TYPE_NATIVE_SVG ):
     652             :                             // backward-compat kludge: since no released OOo
     653             :                             // version to date can handle svg properly, wrap it up
     654             :                             // into an svm. slight catch22 here, since strict ODF
     655             :                             // conformance _recommends_ svg - then again, most old
     656             :                             // ODF consumers are believed to be OOo
     657           0 :                             if( SvtSaveOptions().GetODFDefaultVersion() <= SvtSaveOptions::ODFVER_012 )
     658             :                             {
     659           0 :                                 bUseGfxLink = false;
     660           0 :                                 aExtension = String(  ".svm"  );
     661             :                             }
     662             :                             else
     663           0 :                                 aExtension = String(  ".svg"  );
     664           0 :                             break;
     665             : 
     666             :                         default:
     667           0 :                             aExtension = String(  ".grf"  );
     668           0 :                         break;
     669             :                     }
     670             :                 }
     671             :                 else
     672             :                 {
     673           0 :                     if( aGrfObject.GetType() == GRAPHIC_BITMAP )
     674             :                     {
     675           0 :                         if( aGrfObject.IsAnimated() )
     676           0 :                             aExtension = String(  ".gif"  );
     677             :                         else
     678           0 :                             aExtension = String(  ".png"  );
     679             :                     }
     680           0 :                     else if( aGrfObject.GetType() == GRAPHIC_GDIMETAFILE )
     681             :                     {
     682             :                         // SJ: first check if this metafile is just a eps file, then we will store the eps instead of svm
     683           0 :                         GDIMetaFile& rMtf( (GDIMetaFile&)aGraphic.GetGDIMetaFile() );
     684           0 :                         if ( ImplCheckForEPS( rMtf ) )
     685           0 :                             aExtension = String(  ".eps"  );
     686             :                         else
     687           0 :                             aExtension = String(  ".svm"  );
     688             :                     }
     689             :                 }
     690             : 
     691           0 :                 OUString aURLEntry;
     692           0 :                 const String sPictures(  "Pictures/"  );
     693             : 
     694           0 :                 if ( !rRequestedFileName.isEmpty() )
     695             :                 {
     696           0 :                     aURLEntry = sPictures;
     697           0 :                     aURLEntry += rRequestedFileName;
     698           0 :                     aURLEntry += aExtension;
     699             : 
     700           0 :                     URLPairVector::const_iterator aIter( maGrfURLs.begin() ), aEnd( maGrfURLs.end() );
     701           0 :                     for ( ; aIter != aEnd; ++aIter )
     702             :                     {
     703           0 :                         if( aURLEntry == (*aIter).second )
     704           0 :                             break;
     705             :                     }
     706           0 :                     if ( aIter == aEnd )
     707           0 :                         aStreamName = rRequestedFileName;
     708             :                 }
     709             : 
     710           0 :                 aStreamName += aExtension;
     711             : 
     712           0 :                 if( mbDirect && aStreamName.Len() )
     713           0 :                     ImplWriteGraphic( aPictureStorageName, aStreamName, aGraphicObjectId, bUseGfxLink );
     714             : 
     715           0 :                 rURLPair.second = sPictures;
     716           0 :                 rURLPair.second += aStreamName;
     717           0 :             }
     718             : #if OSL_DEBUG_LEVEL > 0
     719             :             else
     720             :             {
     721             :                 OStringBuffer sMessage(
     722             :                     RTL_CONSTASCII_STRINGPARAM("graphic object with ID '"));
     723             :                 sMessage.append(aAsciiObjectID).
     724             :                     append(RTL_CONSTASCII_STRINGPARAM("' has an unknown type"));
     725             :                 OSL_ENSURE( false, sMessage.getStr() );
     726             :             }
     727             : #endif
     728             :         }
     729             : 
     730          91 :         maURLSet.insert( aURLString );
     731          91 :     }
     732          91 : }
     733             : 
     734         444 : void SvXMLGraphicHelper::Init( const uno::Reference < embed::XStorage >& rXMLStorage,
     735             :                                SvXMLGraphicHelperMode eCreateMode,
     736             :                                sal_Bool bDirect )
     737             : {
     738         444 :     mxRootStorage = rXMLStorage;
     739         444 :     meCreateMode = eCreateMode;
     740         444 :     mbDirect = ( ( GRAPHICHELPER_MODE_READ == meCreateMode ) ? bDirect : sal_True );
     741         444 : }
     742             : 
     743         192 : SvXMLGraphicHelper* SvXMLGraphicHelper::Create( const uno::Reference < embed::XStorage >& rXMLStorage,
     744             :                                                 SvXMLGraphicHelperMode eCreateMode,
     745             :                                                 sal_Bool bDirect )
     746             : {
     747         192 :     SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper;
     748             : 
     749         192 :     pThis->acquire();
     750         192 :     pThis->Init( rXMLStorage, eCreateMode, bDirect );
     751             : 
     752         192 :     return pThis;
     753             : }
     754             : 
     755          83 : SvXMLGraphicHelper* SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode )
     756             : {
     757          83 :     SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper;
     758             : 
     759          83 :     pThis->acquire();
     760          83 :     pThis->Init( NULL, eCreateMode, sal_False );
     761             : 
     762          83 :     return pThis;
     763             : }
     764             : 
     765         196 : void SvXMLGraphicHelper::Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper )
     766             : {
     767         196 :     if( pSvXMLGraphicHelper )
     768             :     {
     769         196 :         pSvXMLGraphicHelper->dispose();
     770         196 :         pSvXMLGraphicHelper->release();
     771             :     }
     772         196 : }
     773             : 
     774             : // XGraphicObjectResolver
     775          91 : OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& rURL )
     776             :     throw(uno::RuntimeException)
     777             : {
     778          91 :     ::osl::MutexGuard   aGuard( maMutex );
     779          91 :     const sal_Int32     nIndex = maGrfURLs.size();
     780             : 
     781         182 :     OUString aURL( rURL );
     782         182 :     OUString aUserData;
     783         182 :     OUString aRequestedFileName;
     784             : 
     785          91 :     sal_Int32 nUser = rURL.indexOf( '?', 0 );
     786          91 :     if ( nUser >= 0 )
     787             :     {
     788           0 :         aURL = OUString( rURL.copy( 0, nUser ) );
     789           0 :         nUser++;
     790           0 :         aUserData = rURL.copy( nUser, rURL.getLength() - nUser );
     791             :     }
     792          91 :     if ( !aUserData.isEmpty() )
     793             :     {
     794           0 :         sal_Int32 nIndex2 = 0;
     795           0 :         do
     796             :         {
     797           0 :             OUString aToken = aUserData.getToken( 0, ';', nIndex2 );
     798           0 :             sal_Int32 n = aToken.indexOf( '=' );
     799           0 :             if ( ( n > 0 ) && ( ( n + 1 ) < aToken.getLength() ) )
     800             :             {
     801           0 :                 OUString aParam( aToken.copy( 0, n ) );
     802           0 :                 OUString aValue( aToken.copy( n + 1, aToken.getLength() - ( n + 1 ) ) );
     803             : 
     804           0 :                 const OUString sRequestedName( "requestedName" );
     805           0 :                 if ( aParam.match( sRequestedName ) )
     806           0 :                     aRequestedFileName = aValue;
     807           0 :             }
     808             :         }
     809           0 :         while ( nIndex2 >= 0 );
     810             :     }
     811             : 
     812          91 :     maGrfURLs.push_back( ::std::make_pair( aURL, OUString() ) );
     813          91 :     ImplInsertGraphicURL( aURL, nIndex, aRequestedFileName );
     814             : 
     815         182 :     return maGrfURLs[ nIndex ].second;
     816             : }
     817             : 
     818             : // XBinaryStreamResolver
     819           0 : Reference< XInputStream > SAL_CALL SvXMLGraphicHelper::getInputStream( const OUString& rURL )
     820             :     throw( RuntimeException )
     821             : {
     822           0 :     Reference< XInputStream >   xRet;
     823           0 :     OUString                    aPictureStorageName, aGraphicId;
     824             : 
     825             : 
     826           0 :     if( ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) &&
     827           0 :         ImplGetStreamNames( rURL, aPictureStorageName, aGraphicId ) )
     828             :     {
     829           0 :         SvXMLGraphicInputStream* pInputStream = new SvXMLGraphicInputStream( aGraphicId );
     830             : 
     831           0 :         if( pInputStream->Exists() )
     832           0 :             xRet = pInputStream;
     833             :         else
     834           0 :             delete pInputStream;
     835             :     }
     836             : 
     837           0 :     return xRet;
     838             : }
     839             : 
     840           0 : Reference< XOutputStream > SAL_CALL SvXMLGraphicHelper::createOutputStream()
     841             :     throw( RuntimeException )
     842             : {
     843           0 :     Reference< XOutputStream > xRet;
     844             : 
     845           0 :     if( GRAPHICHELPER_MODE_READ == meCreateMode )
     846             :     {
     847           0 :         SvXMLGraphicOutputStream* pOutputStream = new SvXMLGraphicOutputStream;
     848             : 
     849           0 :         if( pOutputStream->Exists() )
     850           0 :             maGrfStms.push_back( xRet = pOutputStream );
     851             :         else
     852           0 :             delete pOutputStream;
     853             :     }
     854             : 
     855           0 :     return xRet;
     856             : }
     857             : 
     858           0 : OUString SAL_CALL SvXMLGraphicHelper::resolveOutputStream( const Reference< XOutputStream >& rxBinaryStream )
     859             :     throw( RuntimeException )
     860             : {
     861           0 :     OUString aRet;
     862             : 
     863           0 :     if( ( GRAPHICHELPER_MODE_READ == meCreateMode ) && rxBinaryStream.is() )
     864             :     {
     865           0 :         if( ::std::find( maGrfStms.begin(), maGrfStms.end(), rxBinaryStream ) != maGrfStms.end() )
     866             :         {
     867           0 :             SvXMLGraphicOutputStream* pOStm = static_cast< SvXMLGraphicOutputStream* >( rxBinaryStream.get() );
     868             : 
     869           0 :             if( pOStm )
     870             :             {
     871           0 :                 const GraphicObject& rGrfObj = pOStm->GetGraphicObject();
     872             :                 const OUString aId(OStringToOUString(
     873           0 :                     rGrfObj.GetUniqueID(), RTL_TEXTENCODING_ASCII_US));
     874             : 
     875           0 :                 if( !aId.isEmpty() )
     876             :                 {
     877           0 :                     aRet = OUString( XML_GRAPHICOBJECT_URL_BASE );
     878           0 :                     aRet += aId;
     879           0 :                 }
     880             :             }
     881             :         }
     882             :     }
     883             : 
     884           0 :     return aRet;
     885             : }
     886             : 
     887             : // for instantiation via service manager
     888             : namespace svx
     889             : {
     890             : 
     891             : namespace impl
     892             : {
     893             : typedef ::cppu::WeakComponentImplHelper4<
     894             :         lang::XInitialization,
     895             :         document::XGraphicObjectResolver,
     896             :         document::XBinaryStreamResolver,
     897             :         lang::XServiceInfo >
     898             :     SvXMLGraphicImportExportHelper_Base;
     899          26 : class MutexContainer
     900             : {
     901             : public:
     902             :     virtual ~MutexContainer();
     903             : 
     904             : protected:
     905             :     mutable ::osl::Mutex m_aMutex;
     906             : };
     907          26 : MutexContainer::~MutexContainer()
     908          26 : {}
     909             : } // namespace impl
     910             : 
     911          52 : class SvXMLGraphicImportExportHelper :
     912             :     public impl::MutexContainer,
     913             :     public impl::SvXMLGraphicImportExportHelper_Base
     914             : {
     915             : public:
     916             :     SvXMLGraphicImportExportHelper( SvXMLGraphicHelperMode eMode );
     917             : 
     918             : protected:
     919             :     // is called from WeakComponentImplHelper when XComponent::dispose() was
     920             :     // called from outside
     921             :     virtual void SAL_CALL disposing();
     922             : 
     923             :     // ____ XInitialization ____
     924             :     // one argument is allowed, which is the XStorage
     925             :     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
     926             :         throw (Exception,
     927             :                RuntimeException);
     928             : 
     929             :     // ____ XGraphicObjectResolver ____
     930             :     virtual OUString SAL_CALL resolveGraphicObjectURL( const OUString& aURL )
     931             :         throw (RuntimeException);
     932             : 
     933             :     // ____ XBinaryStreamResolver ____
     934             :     virtual Reference< io::XInputStream > SAL_CALL getInputStream( const OUString& aURL )
     935             :         throw (RuntimeException);
     936             :     virtual Reference< io::XOutputStream > SAL_CALL createOutputStream()
     937             :         throw (RuntimeException);
     938             :     virtual OUString SAL_CALL resolveOutputStream( const Reference< io::XOutputStream >& aBinaryStream )
     939             :         throw (RuntimeException);
     940             : 
     941             :     // ____ XServiceInfo ____
     942             :     virtual OUString SAL_CALL getImplementationName()
     943             :         throw (RuntimeException);
     944             :     virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
     945             :         throw (RuntimeException);
     946             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
     947             :         throw (RuntimeException);
     948             : 
     949             : private:
     950             :     SvXMLGraphicHelperMode              m_eGraphicHelperMode;
     951             :     Reference< XGraphicObjectResolver > m_xGraphicObjectResolver;
     952             :     Reference< XBinaryStreamResolver >  m_xBinaryStreamResolver;
     953             : };
     954             : 
     955          26 : SvXMLGraphicImportExportHelper::SvXMLGraphicImportExportHelper( SvXMLGraphicHelperMode eMode ) :
     956             :         impl::SvXMLGraphicImportExportHelper_Base( m_aMutex ),
     957          26 :         m_eGraphicHelperMode( eMode )
     958          26 : {}
     959             : 
     960          26 : void SAL_CALL SvXMLGraphicImportExportHelper::disposing()
     961             : {
     962          26 :     Reference< XComponent > xComp( m_xGraphicObjectResolver, UNO_QUERY );
     963             :     OSL_ASSERT( xComp.is());
     964          26 :     if( xComp.is())
     965          26 :         xComp->dispose();
     966             :     // m_xBinaryStreamResolver is a reference to the same object => don't call
     967             :     // dispose() again
     968          26 : }
     969             : 
     970             : // ____ XInitialization ____
     971          26 : void SAL_CALL SvXMLGraphicImportExportHelper::initialize(
     972             :     const Sequence< Any >& aArguments )
     973             :     throw (Exception, RuntimeException)
     974             : {
     975          26 :     Reference< embed::XStorage > xStorage;
     976          26 :     if( aArguments.getLength() > 0 )
     977          26 :         aArguments[0] >>= xStorage;
     978             : 
     979          26 :     SvXMLGraphicHelper * pHelper( SvXMLGraphicHelper::Create( xStorage, m_eGraphicHelperMode ));
     980          26 :     m_xGraphicObjectResolver.set( pHelper );
     981          26 :     m_xBinaryStreamResolver.set( pHelper );
     982             :     // SvXMLGraphicHelper::Create calls acquire.  Since we have two references
     983             :     // now it is safe (and necessary) to undo this acquire
     984          26 :     pHelper->release();
     985          26 : }
     986             : 
     987             : // ____ XGraphicObjectResolver ____
     988           6 : OUString SAL_CALL SvXMLGraphicImportExportHelper::resolveGraphicObjectURL( const OUString& aURL )
     989             :     throw (uno::RuntimeException)
     990             : {
     991           6 :     return m_xGraphicObjectResolver->resolveGraphicObjectURL( aURL );
     992             : }
     993             : 
     994             : 
     995             : // ____ XBinaryStreamResolver ____
     996           0 : Reference< io::XInputStream > SAL_CALL SvXMLGraphicImportExportHelper::getInputStream( const OUString& aURL )
     997             :     throw (uno::RuntimeException)
     998             : {
     999           0 :     return m_xBinaryStreamResolver->getInputStream( aURL );
    1000             : }
    1001           0 : Reference< io::XOutputStream > SAL_CALL SvXMLGraphicImportExportHelper::createOutputStream()
    1002             :     throw (uno::RuntimeException)
    1003             : {
    1004           0 :     return m_xBinaryStreamResolver->createOutputStream();
    1005             : }
    1006           0 : OUString SAL_CALL SvXMLGraphicImportExportHelper::resolveOutputStream( const Reference< io::XOutputStream >& aBinaryStream )
    1007             :     throw (uno::RuntimeException)
    1008             : {
    1009           0 :     return m_xBinaryStreamResolver->resolveOutputStream( aBinaryStream );
    1010             : }
    1011             : 
    1012             : // ____ XServiceInfo ____
    1013           0 : OUString SAL_CALL SvXMLGraphicImportExportHelper::getImplementationName()
    1014             :     throw (uno::RuntimeException)
    1015             : {
    1016           0 :     if( m_eGraphicHelperMode == GRAPHICHELPER_MODE_READ )
    1017           0 :         return SvXMLGraphicImportHelper_getImplementationName();
    1018           0 :     return SvXMLGraphicExportHelper_getImplementationName();
    1019             : }
    1020           0 : ::sal_Bool SAL_CALL SvXMLGraphicImportExportHelper::supportsService( const OUString& ServiceName )
    1021             :     throw (uno::RuntimeException)
    1022             : {
    1023           0 :     Sequence< OUString > aServiceNames( getSupportedServiceNames());
    1024           0 :     const OUString * pBegin = aServiceNames.getConstArray();
    1025           0 :     const OUString * pEnd = pBegin + aServiceNames.getLength();
    1026           0 :     return (::std::find( pBegin, pEnd, ServiceName ) != pEnd);
    1027             : }
    1028           0 : Sequence< OUString > SAL_CALL SvXMLGraphicImportExportHelper::getSupportedServiceNames()
    1029             :     throw (uno::RuntimeException)
    1030             : {
    1031           0 :     if( m_eGraphicHelperMode == GRAPHICHELPER_MODE_READ )
    1032           0 :         return SvXMLGraphicImportHelper_getSupportedServiceNames();
    1033           0 :     return SvXMLGraphicExportHelper_getSupportedServiceNames();
    1034             : }
    1035             : 
    1036             : // import
    1037          21 : Reference< XInterface > SAL_CALL SvXMLGraphicImportHelper_createInstance(const Reference< XMultiServiceFactory > & /* rSMgr */ )
    1038             :     throw( Exception )
    1039             : {
    1040          21 :     return static_cast< XWeak* >( new SvXMLGraphicImportExportHelper( GRAPHICHELPER_MODE_READ ));
    1041             : }
    1042           9 : OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName()
    1043             :     throw()
    1044             : {
    1045           9 :     return OUString(  "com.sun.star.comp.Svx.GraphicImportHelper" );
    1046             : }
    1047           3 : Sequence< OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames()
    1048             :     throw()
    1049             : {
    1050             :     // XGraphicObjectResolver and XBinaryStreamResolver are not part of any service
    1051           3 :     Sequence< OUString > aSupportedServiceNames( 2 );
    1052           3 :     aSupportedServiceNames[0] = OUString(  "com.sun.star.document.GraphicObjectResolver"  );
    1053           3 :     aSupportedServiceNames[1] = OUString(  "com.sun.star.document.BinaryStreamResolver"  );
    1054           3 :     return aSupportedServiceNames;
    1055             : }
    1056             : 
    1057             : // export
    1058           5 : Reference< XInterface > SAL_CALL SvXMLGraphicExportHelper_createInstance(const Reference< XMultiServiceFactory > & /* rSMgr */ )
    1059             :     throw( Exception )
    1060             : {
    1061           5 :     return static_cast< XWeak* >( new SvXMLGraphicImportExportHelper( GRAPHICHELPER_MODE_WRITE ));
    1062             : }
    1063           6 : OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName()
    1064             :     throw()
    1065             : {
    1066           6 :     return OUString(  "com.sun.star.comp.Svx.GraphicExportHelper" );
    1067             : }
    1068           3 : Sequence< OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames()
    1069             :     throw()
    1070             : {
    1071             :     // XGraphicObjectResolver and XBinaryStreamResolver are not part of any service
    1072           3 :     Sequence< OUString > aSupportedServiceNames( 2 );
    1073           3 :     aSupportedServiceNames[0] = OUString(  "com.sun.star.document.GraphicObjectResolver"  );
    1074           3 :     aSupportedServiceNames[1] = OUString(  "com.sun.star.document.BinaryStreamResolver"  );
    1075           3 :     return aSupportedServiceNames;
    1076             : }
    1077             : 
    1078         258 : } // namespace svx
    1079             : 
    1080             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10