2000-11-30 06:32:41 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: xmlgrhlp.cxx,v $
|
|
|
|
*
|
2004-07-13 06:51:42 +00:00
|
|
|
* $Revision: 1.20 $
|
2000-11-30 06:32:41 +00:00
|
|
|
*
|
2004-07-13 06:51:42 +00:00
|
|
|
* last change: $Author: rt $
|
2000-11-30 06:32:41 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2001-06-12 13:22:47 +00:00
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#include <unotools/tempfile.hxx>
|
2000-11-30 06:32:41 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <vcl/cvtgrf.hxx>
|
|
|
|
#include <vcl/gfxlink.hxx>
|
|
|
|
|
|
|
|
#include "impgrf.hxx"
|
|
|
|
#include "xmlgrhlp.hxx"
|
|
|
|
|
|
|
|
// -----------
|
|
|
|
// - Defines -
|
|
|
|
// -----------
|
|
|
|
|
2001-01-12 15:40:29 +00:00
|
|
|
using namespace rtl;
|
|
|
|
using namespace com::sun::star;
|
2001-06-12 13:22:47 +00:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::io;
|
2001-01-12 15:40:29 +00:00
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
#define XML_GRAPHICSTORAGE_NAME "Pictures"
|
|
|
|
#define XML_PACKAGE_URL_BASE "vnd.sun.star.Package:"
|
|
|
|
#define XML_GRAPHICOBJECT_URL_BASE "vnd.sun.star.GraphicObject:"
|
2000-11-30 06:32:41 +00:00
|
|
|
|
2001-06-12 13:22:47 +00:00
|
|
|
// ---------------------------
|
|
|
|
// - SvXMLGraphicInputStream -
|
|
|
|
// ---------------------------
|
|
|
|
|
|
|
|
class SvXMLGraphicInputStream : public::cppu::WeakImplHelper1< XInputStream >
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
virtual sal_Int32 SAL_CALL available() throw(NotConnectedException, RuntimeException);
|
|
|
|
virtual void SAL_CALL closeInput() throw(NotConnectedException, RuntimeException);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
::utl::TempFile maTmp;
|
|
|
|
Reference< XInputStream > mxStmWrapper;
|
|
|
|
|
|
|
|
// not available
|
|
|
|
SvXMLGraphicInputStream();
|
|
|
|
SvXMLGraphicInputStream( const SvXMLGraphicInputStream& );
|
|
|
|
SvXMLGraphicInputStream& operator==( SvXMLGraphicInputStream& );
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
SvXMLGraphicInputStream( const OUString& rGraphicId );
|
|
|
|
virtual ~SvXMLGraphicInputStream();
|
|
|
|
|
|
|
|
sal_Bool Exists() const { return mxStmWrapper.is(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId )
|
|
|
|
{
|
|
|
|
String aGraphicId( rGraphicId );
|
|
|
|
GraphicObject aGrfObject( ByteString( aGraphicId, RTL_TEXTENCODING_ASCII_US ) );
|
|
|
|
|
|
|
|
maTmp.EnableKillingFile();
|
|
|
|
|
|
|
|
if( aGrfObject.GetType() != GRAPHIC_NONE )
|
|
|
|
{
|
|
|
|
SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( maTmp.GetURL(), STREAM_WRITE | STREAM_TRUNC );
|
|
|
|
|
|
|
|
if( pStm )
|
|
|
|
{
|
|
|
|
Graphic aGraphic( (Graphic&) aGrfObject.GetGraphic() );
|
|
|
|
const GfxLink aGfxLink( aGraphic.GetLink() );
|
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
|
|
|
|
if( aGfxLink.GetDataSize() )
|
|
|
|
{
|
|
|
|
pStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
|
|
|
|
bRet = ( pStm->GetError() == 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aGraphic.GetType() == GRAPHIC_BITMAP )
|
|
|
|
{
|
|
|
|
GraphicFilter* pFilter = GetGrfFilter();
|
|
|
|
String aFormat;
|
|
|
|
|
|
|
|
if( aGraphic.IsAnimated() )
|
|
|
|
aFormat = String( RTL_CONSTASCII_USTRINGPARAM( "gif" ) );
|
|
|
|
else
|
|
|
|
aFormat = String( RTL_CONSTASCII_USTRINGPARAM( "png" ) );
|
|
|
|
|
|
|
|
bRet = ( pFilter->ExportGraphic( aGraphic, String(), *pStm, pFilter->GetExportFormatNumberForShortName( aFormat ) ) == 0 );
|
|
|
|
}
|
|
|
|
else if( aGraphic.GetType() == GRAPHIC_GDIMETAFILE )
|
|
|
|
{
|
|
|
|
( (GDIMetaFile&) aGraphic.GetGDIMetaFile() ).Write( *pStm );
|
|
|
|
bRet = ( pStm->GetError() == 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bRet )
|
|
|
|
{
|
|
|
|
pStm->Seek( 0 );
|
|
|
|
mxStmWrapper = new ::utl::OInputStreamWrapper( pStm, sal_True );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete pStm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicInputStream::~SvXMLGraphicInputStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL SvXMLGraphicInputStream::readBytes( Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead )
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException();
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
return mxStmWrapper->readBytes( rData, nBytesToRead );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL SvXMLGraphicInputStream::readSomeBytes( Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead )
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
return mxStmWrapper->readSomeBytes( rData, nMaxBytesToRead );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL SvXMLGraphicInputStream::skipBytes( sal_Int32 nBytesToSkip )
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
mxStmWrapper->skipBytes( nBytesToSkip );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL SvXMLGraphicInputStream::available() throw( NotConnectedException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
return mxStmWrapper->available();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL SvXMLGraphicInputStream::closeInput() throw( NotConnectedException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
mxStmWrapper->closeInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------
|
|
|
|
// - SvXMLGraphicOutputStream -
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
class SvXMLGraphicOutputStream : public::cppu::WeakImplHelper1< XOutputStream >
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
// XOutputStream
|
|
|
|
virtual void SAL_CALL writeBytes( const Sequence< sal_Int8 >& rData ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
|
|
|
|
virtual void SAL_CALL flush() throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
|
|
|
|
virtual void SAL_CALL closeOutput() throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException );
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
::utl::TempFile* mpTmp;
|
|
|
|
SvStream* mpOStm;
|
|
|
|
Reference< XOutputStream > mxStmWrapper;
|
|
|
|
GraphicObject maGrfObj;
|
|
|
|
sal_Bool mbClosed;
|
|
|
|
|
|
|
|
// not available
|
|
|
|
SvXMLGraphicOutputStream( const SvXMLGraphicOutputStream& );
|
|
|
|
SvXMLGraphicOutputStream& operator==( SvXMLGraphicOutputStream& );
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
SvXMLGraphicOutputStream();
|
|
|
|
virtual ~SvXMLGraphicOutputStream();
|
|
|
|
|
|
|
|
sal_Bool Exists() const { return mxStmWrapper.is(); }
|
|
|
|
const GraphicObject& GetGraphicObject();
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicOutputStream::SvXMLGraphicOutputStream() :
|
|
|
|
mpTmp( new ::utl::TempFile ),
|
|
|
|
mbClosed( sal_False )
|
|
|
|
{
|
|
|
|
mpTmp->EnableKillingFile();
|
|
|
|
|
|
|
|
mpOStm = ::utl::UcbStreamHelper::CreateStream( mpTmp->GetURL(), STREAM_WRITE | STREAM_TRUNC );
|
|
|
|
|
|
|
|
if( mpOStm )
|
|
|
|
mxStmWrapper = new ::utl::OOutputStreamWrapper( *mpOStm );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicOutputStream::~SvXMLGraphicOutputStream()
|
|
|
|
{
|
|
|
|
delete mpTmp;
|
|
|
|
delete mpOStm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL SvXMLGraphicOutputStream::writeBytes( const Sequence< sal_Int8 >& rData )
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
mxStmWrapper->writeBytes( rData );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL SvXMLGraphicOutputStream::flush()
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
mxStmWrapper->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL SvXMLGraphicOutputStream::closeOutput()
|
|
|
|
throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
|
|
|
|
{
|
|
|
|
if( !mxStmWrapper.is() )
|
2001-06-14 15:02:22 +00:00
|
|
|
throw NotConnectedException() ;
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
mxStmWrapper->closeOutput();
|
|
|
|
mxStmWrapper = Reference< XOutputStream >();
|
|
|
|
|
|
|
|
mbClosed = sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject()
|
|
|
|
{
|
|
|
|
if( mbClosed && ( maGrfObj.GetType() == GRAPHIC_NONE ) && mpOStm )
|
|
|
|
{
|
|
|
|
Graphic aGraphic;
|
|
|
|
|
|
|
|
mpOStm->Seek( 0 );
|
|
|
|
GetGrfFilter()->ImportGraphic( aGraphic, String(), *mpOStm );
|
|
|
|
|
|
|
|
maGrfObj = aGraphic;
|
|
|
|
|
|
|
|
if( maGrfObj.GetType() != GRAPHIC_NONE )
|
|
|
|
{
|
|
|
|
delete mpOStm, mpOStm = NULL;
|
|
|
|
delete mpTmp, mpTmp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maGrfObj;
|
|
|
|
}
|
|
|
|
|
2000-11-30 06:32:41 +00:00
|
|
|
// ----------------------
|
|
|
|
// - SvXMLGraphicHelper -
|
|
|
|
// ----------------------
|
|
|
|
|
2002-06-04 07:27:50 +00:00
|
|
|
SvXMLGraphicHelper::SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode ) :
|
|
|
|
::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
|
|
|
|
::com::sun::star::document::XBinaryStreamResolver >( maMutex )
|
|
|
|
{
|
|
|
|
Init( NULL, eCreateMode, sal_False );
|
|
|
|
}
|
|
|
|
|
2000-11-30 06:32:41 +00:00
|
|
|
SvXMLGraphicHelper::SvXMLGraphicHelper() :
|
2001-06-12 13:22:47 +00:00
|
|
|
::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver,
|
|
|
|
::com::sun::star::document::XBinaryStreamResolver >( maMutex )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicHelper::~SvXMLGraphicHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2002-06-04 07:27:50 +00:00
|
|
|
void SAL_CALL SvXMLGraphicHelper::disposing()
|
|
|
|
{
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
sal_Bool SvXMLGraphicHelper::ImplGetStreamNames( const ::rtl::OUString& rURLStr,
|
|
|
|
::rtl::OUString& rPictureStorageName,
|
|
|
|
::rtl::OUString& rPictureStreamName )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2000-12-01 09:54:16 +00:00
|
|
|
String aURLStr( rURLStr );
|
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
if( aURLStr.Len() )
|
2000-12-01 09:54:16 +00:00
|
|
|
{
|
|
|
|
aURLStr = aURLStr.GetToken( aURLStr.GetTokenCount( ':' ) - 1, ':' );
|
|
|
|
const sal_uInt32 nTokenCount = aURLStr.GetTokenCount( '/' );
|
|
|
|
|
|
|
|
if( 1 == nTokenCount )
|
|
|
|
{
|
|
|
|
rPictureStorageName = String( RTL_CONSTASCII_USTRINGPARAM( XML_GRAPHICSTORAGE_NAME ) );
|
|
|
|
rPictureStreamName = aURLStr;
|
|
|
|
bRet = sal_True;
|
|
|
|
}
|
|
|
|
else if( 2 == nTokenCount )
|
|
|
|
{
|
|
|
|
rPictureStorageName = aURLStr.GetToken( 0, '/' );
|
2000-12-06 19:14:52 +00:00
|
|
|
|
2004-07-13 06:51:42 +00:00
|
|
|
DBG_ASSERT( rPictureStorageName.getLength() &&
|
|
|
|
rPictureStorageName.getStr()[ 0 ] != '#',
|
|
|
|
"invalid relative URL" );
|
2000-12-06 19:14:52 +00:00
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
rPictureStreamName = aURLStr.GetToken( 1, '/' );
|
|
|
|
bRet = sal_True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ERROR( "SvXMLGraphicHelper::ImplInsertGraphicURL: invalid scheme" );
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 06:32:41 +00:00
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageRef SvXMLGraphicHelper::ImplGetGraphicStorage( const ::rtl::OUString& rStorageName )
|
2000-12-01 09:54:16 +00:00
|
|
|
{
|
2001-06-15 09:40:52 +00:00
|
|
|
if( mpRootStorage && ( !mxGraphicStorage.Is() || ( rStorageName != maCurStorageName ) ) )
|
2000-12-02 08:21:34 +00:00
|
|
|
{
|
|
|
|
if( mxGraphicStorage.Is() && GRAPHICHELPER_MODE_WRITE == meCreateMode )
|
|
|
|
mxGraphicStorage->Commit();
|
2001-05-31 14:24:57 +00:00
|
|
|
|
2000-12-02 08:21:34 +00:00
|
|
|
mxGraphicStorage = mpRootStorage->OpenUCBStorage( maCurStorageName = rStorageName, STREAM_READ | STREAM_WRITE );
|
|
|
|
}
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
return mxGraphicStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageStreamRef SvXMLGraphicHelper::ImplGetGraphicStream( const ::rtl::OUString& rPictureStorageName,
|
2001-05-31 14:24:57 +00:00
|
|
|
const ::rtl::OUString& rPictureStreamName,
|
|
|
|
BOOL bTruncate )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageStreamRef xStm;
|
|
|
|
SotStorageRef xStorage( ImplGetGraphicStorage( rPictureStorageName ) );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
if( xStorage.Is() )
|
|
|
|
{
|
2001-03-19 09:19:40 +00:00
|
|
|
xStm = xStorage->OpenSotStream( rPictureStreamName,
|
2001-05-31 14:24:57 +00:00
|
|
|
STREAM_READ | ( ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) ?
|
|
|
|
( STREAM_WRITE | ( bTruncate ? STREAM_TRUNC : 0 ) ) : 0 ) );
|
|
|
|
|
|
|
|
if( xStm.Is() && ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) )
|
2001-05-31 08:56:19 +00:00
|
|
|
{
|
|
|
|
OUString aPropName( RTL_CONSTASCII_USTRINGPARAM("Encrypted") );
|
|
|
|
sal_Bool bTrue = sal_True;
|
|
|
|
uno::Any aAny;
|
2001-05-31 14:24:57 +00:00
|
|
|
|
2001-05-31 08:56:19 +00:00
|
|
|
aAny.setValue( &bTrue, ::getBooleanCppuType() );
|
|
|
|
xStm->SetProperty( aPropName, aAny );
|
|
|
|
|
|
|
|
}
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xStm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-05-31 14:24:57 +00:00
|
|
|
String SvXMLGraphicHelper::ImplGetGraphicMimeType( const String& rFileName ) const
|
|
|
|
{
|
|
|
|
struct XMLGraphicMimeTypeMapper
|
|
|
|
{
|
|
|
|
const char* pExt;
|
|
|
|
const char* pMimeType;
|
|
|
|
};
|
|
|
|
|
|
|
|
static XMLGraphicMimeTypeMapper aMapper[] =
|
|
|
|
{
|
|
|
|
{ "gif", "image/gif" },
|
|
|
|
{ "png", "image/png" },
|
|
|
|
{ "jpg", "image/jpeg" },
|
|
|
|
{ "tif", "image/tiff" }
|
|
|
|
};
|
|
|
|
|
|
|
|
String aMimeType;
|
|
|
|
|
|
|
|
if( ( rFileName.Len() >= 4 ) && ( rFileName.GetChar( rFileName.Len() - 4 ) == '.' ) )
|
|
|
|
{
|
|
|
|
const ByteString aExt( rFileName.Copy( rFileName.Len() - 3 ), RTL_TEXTENCODING_ASCII_US );
|
|
|
|
|
|
|
|
for( long i = 0, nCount = sizeof( aMapper ) / sizeof( aMapper[ 0 ] ); ( i < nCount ) && !aMimeType.Len(); i++ )
|
|
|
|
if( aExt == aMapper[ i ].pExt )
|
|
|
|
aMimeType = String( aMapper[ i ].pMimeType, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aMimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
Graphic SvXMLGraphicHelper::ImplReadGraphic( const ::rtl::OUString& rPictureStorageName,
|
|
|
|
const ::rtl::OUString& rPictureStreamName )
|
|
|
|
{
|
|
|
|
Graphic aGraphic;
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageStreamRef xStm( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName, FALSE ) );
|
2000-12-01 09:54:16 +00:00
|
|
|
|
|
|
|
if( xStm.Is() )
|
|
|
|
GetGrfFilter()->ImportGraphic( aGraphic, String(), *xStm );
|
|
|
|
|
|
|
|
return aGraphic;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
sal_Bool SvXMLGraphicHelper::ImplWriteGraphic( const ::rtl::OUString& rPictureStorageName,
|
|
|
|
const ::rtl::OUString& rPictureStreamName,
|
|
|
|
const ::rtl::OUString& rGraphicId )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2000-12-07 17:15:08 +00:00
|
|
|
String aGraphicId( rGraphicId );
|
|
|
|
GraphicObject aGrfObject( ByteString( aGraphicId, RTL_TEXTENCODING_ASCII_US ) );
|
2000-12-06 19:14:52 +00:00
|
|
|
sal_Bool bRet = sal_False;
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
if( aGrfObject.GetType() != GRAPHIC_NONE )
|
|
|
|
{
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageStreamRef xStm( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName, TRUE ) );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
if( xStm.Is() )
|
|
|
|
{
|
|
|
|
Graphic aGraphic( (Graphic&) aGrfObject.GetGraphic() );
|
|
|
|
const GfxLink aGfxLink( aGraphic.GetLink() );
|
2001-05-31 14:24:57 +00:00
|
|
|
const OUString aMimeType( ImplGetGraphicMimeType( rPictureStreamName ) );
|
|
|
|
uno::Any aAny;
|
|
|
|
|
|
|
|
// set stream properties (MediaType/Compression)
|
|
|
|
if( aMimeType.getLength() )
|
|
|
|
{
|
|
|
|
aAny <<= aMimeType;
|
|
|
|
xStm->SetProperty( String( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), aAny );
|
|
|
|
}
|
2001-06-06 15:02:24 +00:00
|
|
|
|
|
|
|
const sal_Bool bCompressed = ( ( 0 == aMimeType.getLength() ) || ( aMimeType == OUString::createFromAscii( "image/tiff" ) ) );
|
|
|
|
aAny <<= bCompressed;
|
|
|
|
xStm->SetProperty( String( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), aAny );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
if( aGfxLink.GetDataSize() )
|
|
|
|
xStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aGraphic.GetType() == GRAPHIC_BITMAP )
|
|
|
|
{
|
2001-05-31 14:24:57 +00:00
|
|
|
GraphicFilter* pFilter = GetGrfFilter();
|
2000-11-30 06:32:41 +00:00
|
|
|
String aFormat;
|
|
|
|
|
|
|
|
if( aGraphic.IsAnimated() )
|
2000-12-06 19:14:52 +00:00
|
|
|
aFormat = String( RTL_CONSTASCII_USTRINGPARAM( "gif" ) );
|
2000-11-30 06:32:41 +00:00
|
|
|
else
|
2000-12-06 19:14:52 +00:00
|
|
|
aFormat = String( RTL_CONSTASCII_USTRINGPARAM( "png" ) );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
bRet = ( pFilter->ExportGraphic( aGraphic, String(), *xStm,
|
|
|
|
pFilter->GetExportFormatNumberForShortName( aFormat ) ) == 0 );
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
else if( aGraphic.GetType() == GRAPHIC_GDIMETAFILE )
|
2000-12-06 19:14:52 +00:00
|
|
|
{
|
2000-11-30 06:32:41 +00:00
|
|
|
( (GDIMetaFile&) aGraphic.GetGDIMetaFile() ).Write( *xStm );
|
2000-12-06 19:14:52 +00:00
|
|
|
bRet = ( xStm->GetError() == 0 );
|
|
|
|
}
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
2000-12-06 19:14:52 +00:00
|
|
|
|
2000-12-02 08:21:34 +00:00
|
|
|
xStm->Commit();
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-06 19:14:52 +00:00
|
|
|
|
|
|
|
return bRet;
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-12-01 09:54:16 +00:00
|
|
|
void SvXMLGraphicHelper::ImplInsertGraphicURL( const ::rtl::OUString& rURLStr, sal_uInt32 nInsertPos )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2000-12-01 09:54:16 +00:00
|
|
|
::rtl::OUString aPictureStorageName, aPictureStreamName;
|
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
if( ( maURLSet.find( rURLStr ) != maURLSet.end() ) )
|
2000-12-01 09:54:16 +00:00
|
|
|
{
|
2000-12-06 19:14:52 +00:00
|
|
|
URLPairVector::iterator aIter( maGrfURLs.begin() ), aEnd( maGrfURLs.end() );
|
|
|
|
|
|
|
|
while( aIter != aEnd )
|
|
|
|
{
|
|
|
|
if( rURLStr == (*aIter).first )
|
|
|
|
{
|
|
|
|
maGrfURLs[ nInsertPos ].second = (*aIter).second;
|
|
|
|
aIter = aEnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aIter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( ImplGetStreamNames( rURLStr, aPictureStorageName, aPictureStreamName ) )
|
|
|
|
{
|
|
|
|
URLPair& rURLPair = maGrfURLs[ nInsertPos ];
|
2000-12-01 09:54:16 +00:00
|
|
|
|
|
|
|
if( GRAPHICHELPER_MODE_READ == meCreateMode )
|
|
|
|
{
|
|
|
|
const GraphicObject aObj( ImplReadGraphic( aPictureStorageName, aPictureStreamName ) );
|
|
|
|
|
|
|
|
if( aObj.GetType() != GRAPHIC_NONE )
|
|
|
|
{
|
2000-12-06 19:14:52 +00:00
|
|
|
const static ::rtl::OUString aBaseURL( RTL_CONSTASCII_USTRINGPARAM( XML_GRAPHICOBJECT_URL_BASE ) );
|
|
|
|
|
|
|
|
maGrfObjs.push_back( aObj );
|
|
|
|
rURLPair.second = aBaseURL;
|
|
|
|
rURLPair.second += String( aObj.GetUniqueID().GetBuffer(), RTL_TEXTENCODING_ASCII_US );
|
2000-12-01 09:54:16 +00:00
|
|
|
}
|
|
|
|
else
|
2000-12-06 19:14:52 +00:00
|
|
|
rURLPair.second = String();
|
2000-12-01 09:54:16 +00:00
|
|
|
}
|
2000-12-06 19:14:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const String aGraphicObjectId( aPictureStreamName );
|
|
|
|
const GraphicObject aGrfObject( ByteString( aGraphicObjectId, RTL_TEXTENCODING_ASCII_US ) );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
if( aGrfObject.GetType() != GRAPHIC_NONE )
|
|
|
|
{
|
2000-12-12 15:24:50 +00:00
|
|
|
String aStreamName( aGraphicObjectId );
|
|
|
|
Graphic aGraphic( (Graphic&) aGrfObject.GetGraphic() );
|
|
|
|
const GfxLink aGfxLink( aGraphic.GetLink() );
|
2000-12-06 19:14:52 +00:00
|
|
|
|
2000-12-12 15:24:50 +00:00
|
|
|
if( aGfxLink.GetDataSize() )
|
2000-12-06 19:14:52 +00:00
|
|
|
{
|
2000-12-12 15:24:50 +00:00
|
|
|
switch( aGfxLink.GetType() )
|
|
|
|
{
|
|
|
|
case( GFX_LINK_TYPE_EPS_BUFFER ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".eps" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_GIF ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".gif" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_JPG ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".jpg" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_PNG ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".png" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_TIF ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".tif" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_WMF ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".wmf" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_MET ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".met" ) ); break;
|
|
|
|
case( GFX_LINK_TYPE_NATIVE_PCT ): aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".pct" ) ); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".grf" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aGrfObject.GetType() == GRAPHIC_BITMAP )
|
|
|
|
{
|
|
|
|
if( aGrfObject.IsAnimated() )
|
|
|
|
aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".gif" ) );
|
|
|
|
else
|
|
|
|
aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".png" ) );
|
|
|
|
}
|
|
|
|
else if( aGrfObject.GetType() == GRAPHIC_GDIMETAFILE )
|
|
|
|
aStreamName += String( RTL_CONSTASCII_USTRINGPARAM( ".svm" ) );
|
2000-12-06 19:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( mbDirect && aStreamName.Len() )
|
|
|
|
ImplWriteGraphic( aPictureStorageName, aStreamName, aGraphicObjectId );
|
|
|
|
|
2004-07-13 06:51:42 +00:00
|
|
|
rURLPair.second = String( RTL_CONSTASCII_USTRINGPARAM( "Pictures/" ) );
|
2000-12-06 19:14:52 +00:00
|
|
|
rURLPair.second += aStreamName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maURLSet.insert( rURLStr );
|
2000-12-01 09:54:16 +00:00
|
|
|
}
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-06-15 09:40:52 +00:00
|
|
|
void SvXMLGraphicHelper::Init( SotStorage* pXMLStorage,
|
2000-11-30 06:32:41 +00:00
|
|
|
SvXMLGraphicHelperMode eCreateMode,
|
|
|
|
BOOL bDirect )
|
|
|
|
{
|
2001-06-15 09:40:52 +00:00
|
|
|
mpRootStorage = pXMLStorage;
|
2000-11-30 06:32:41 +00:00
|
|
|
meCreateMode = eCreateMode;
|
2002-07-30 12:25:00 +00:00
|
|
|
mbDirect = ( ( GRAPHICHELPER_MODE_READ == meCreateMode ) ? bDirect : sal_True );
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-03-19 09:19:40 +00:00
|
|
|
SvXMLGraphicHelper* SvXMLGraphicHelper::Create( SotStorage& rXMLStorage,
|
2000-11-30 06:32:41 +00:00
|
|
|
SvXMLGraphicHelperMode eCreateMode,
|
|
|
|
BOOL bDirect )
|
|
|
|
{
|
|
|
|
SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper;
|
|
|
|
|
|
|
|
pThis->acquire();
|
2001-06-15 09:40:52 +00:00
|
|
|
pThis->Init( &rXMLStorage, eCreateMode, bDirect );
|
|
|
|
|
|
|
|
return pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLGraphicHelper* SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode )
|
|
|
|
{
|
|
|
|
SvXMLGraphicHelper* pThis = new SvXMLGraphicHelper;
|
|
|
|
|
|
|
|
pThis->acquire();
|
|
|
|
pThis->Init( NULL, eCreateMode, sal_False );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
|
|
|
return pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvXMLGraphicHelper::Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper )
|
|
|
|
{
|
|
|
|
if( pSvXMLGraphicHelper )
|
|
|
|
{
|
2002-06-04 07:27:50 +00:00
|
|
|
pSvXMLGraphicHelper->dispose();
|
2000-11-30 06:32:41 +00:00
|
|
|
pSvXMLGraphicHelper->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvXMLGraphicHelper::Flush()
|
|
|
|
{
|
2000-12-01 09:54:16 +00:00
|
|
|
if( ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) && !mbDirect )
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2000-12-06 19:14:52 +00:00
|
|
|
::rtl::OUString aPictureStorageName, aPictureStreamName;
|
|
|
|
URLSet::iterator aSetIter( maURLSet.begin() ), aSetEnd( maURLSet.end() );
|
2000-11-30 06:32:41 +00:00
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
while( aSetIter != aSetEnd )
|
2000-12-01 09:54:16 +00:00
|
|
|
{
|
2000-12-06 19:14:52 +00:00
|
|
|
URLPairVector::iterator aPairIter( maGrfURLs.begin() ), aPairEnd( maGrfURLs.end() );
|
|
|
|
|
|
|
|
while( aPairIter != aPairEnd )
|
|
|
|
{
|
|
|
|
if( *aSetIter == (*aPairIter).first )
|
|
|
|
{
|
|
|
|
if( ImplGetStreamNames( (*aPairIter).second, aPictureStorageName, aPictureStreamName ) )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( String( aPictureStreamName ).GetTokenCount( '.' ) == 2, "invalid URL" );
|
|
|
|
ImplWriteGraphic( aPictureStorageName, aPictureStreamName, String( aPictureStreamName ).GetToken( 0, '.' ) );
|
|
|
|
}
|
2000-12-01 09:54:16 +00:00
|
|
|
|
2000-12-06 19:14:52 +00:00
|
|
|
aPairIter = aPairEnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aPairIter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSetIter++;
|
2000-12-01 09:54:16 +00:00
|
|
|
}
|
2002-06-04 07:27:50 +00:00
|
|
|
|
|
|
|
mbDirect = sal_True;
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
2000-12-02 08:21:34 +00:00
|
|
|
if( GRAPHICHELPER_MODE_WRITE == meCreateMode )
|
|
|
|
{
|
2001-03-19 09:19:40 +00:00
|
|
|
SotStorageRef xStorage = ImplGetGraphicStorage( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(XML_GRAPHICSTORAGE_NAME) ) );
|
2000-12-06 19:14:52 +00:00
|
|
|
|
2000-12-02 08:21:34 +00:00
|
|
|
if( xStorage.Is() )
|
|
|
|
xStorage->Commit();
|
|
|
|
}
|
|
|
|
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
|
|
|
|
2001-06-12 13:22:47 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-01-12 15:40:29 +00:00
|
|
|
// XGraphicObjectResolver
|
|
|
|
OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& aURL )
|
|
|
|
throw(uno::RuntimeException)
|
2000-11-30 06:32:41 +00:00
|
|
|
{
|
2001-06-12 13:22:47 +00:00
|
|
|
::osl::MutexGuard aGuard( maMutex );
|
|
|
|
const sal_Int32 nIndex = maGrfURLs.size();
|
|
|
|
|
2002-07-03 07:12:03 +00:00
|
|
|
maGrfURLs.push_back( ::std::make_pair( aURL, ::rtl::OUString() ) );
|
2001-01-12 15:40:29 +00:00
|
|
|
ImplInsertGraphicURL( aURL, nIndex );
|
2001-06-12 13:22:47 +00:00
|
|
|
|
2001-01-12 15:40:29 +00:00
|
|
|
return maGrfURLs[ nIndex ].second;
|
2000-11-30 06:32:41 +00:00
|
|
|
}
|
2001-06-12 13:22:47 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// XBinaryStreamResolver
|
|
|
|
Reference< XInputStream > SAL_CALL SvXMLGraphicHelper::getInputStream( const OUString& rURL )
|
|
|
|
throw( RuntimeException )
|
|
|
|
{
|
|
|
|
Reference< XInputStream > xRet;
|
|
|
|
OUString aPictureStorageName, aGraphicId;
|
|
|
|
|
|
|
|
|
|
|
|
if( ( GRAPHICHELPER_MODE_WRITE == meCreateMode ) &&
|
|
|
|
ImplGetStreamNames( rURL, aPictureStorageName, aGraphicId ) )
|
|
|
|
{
|
|
|
|
SvXMLGraphicInputStream* pInputStream = new SvXMLGraphicInputStream( aGraphicId );
|
|
|
|
|
|
|
|
if( pInputStream->Exists() )
|
|
|
|
xRet = pInputStream;
|
|
|
|
else
|
|
|
|
delete pInputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Reference< XOutputStream > SAL_CALL SvXMLGraphicHelper::createOutputStream()
|
|
|
|
throw( RuntimeException )
|
|
|
|
{
|
|
|
|
Reference< XOutputStream > xRet;
|
|
|
|
|
|
|
|
if( GRAPHICHELPER_MODE_READ == meCreateMode )
|
|
|
|
{
|
|
|
|
SvXMLGraphicOutputStream* pOutputStream = new SvXMLGraphicOutputStream;
|
|
|
|
|
|
|
|
if( pOutputStream->Exists() )
|
|
|
|
maGrfStms.push_back( xRet = pOutputStream );
|
|
|
|
else
|
|
|
|
delete pOutputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OUString SAL_CALL SvXMLGraphicHelper::resolveOutputStream( const Reference< XOutputStream >& rxBinaryStream )
|
|
|
|
throw( RuntimeException )
|
|
|
|
{
|
|
|
|
OUString aRet;
|
|
|
|
|
|
|
|
if( ( GRAPHICHELPER_MODE_READ == meCreateMode ) && rxBinaryStream.is() )
|
|
|
|
{
|
|
|
|
if( ::std::find( maGrfStms.begin(), maGrfStms.end(), rxBinaryStream ) != maGrfStms.end() )
|
|
|
|
{
|
|
|
|
SvXMLGraphicOutputStream* pOStm = static_cast< SvXMLGraphicOutputStream* >( rxBinaryStream.get() );
|
|
|
|
|
|
|
|
if( pOStm )
|
|
|
|
{
|
|
|
|
const GraphicObject& rGrfObj = pOStm->GetGraphicObject();
|
|
|
|
const OUString aId( OUString::createFromAscii( rGrfObj.GetUniqueID().GetBuffer() ) );
|
|
|
|
|
|
|
|
if( aId.getLength() )
|
|
|
|
{
|
|
|
|
aRet = OUString::createFromAscii( XML_GRAPHICOBJECT_URL_BASE );
|
|
|
|
aRet += aId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRet;
|
|
|
|
}
|