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

Generated by: LCOV version 1.10