2001-01-26 10:22:09 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: xmleohlp.cxx,v $
|
|
|
|
*
|
2001-06-20 07:42:01 +00:00
|
|
|
* $Revision: 1.7 $
|
2001-01-26 10:22:09 +00:00
|
|
|
*
|
|
|
|
* last change: $Author: mib $
|
|
|
|
*
|
|
|
|
* 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): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifndef _DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
2001-05-18 12:13:00 +00:00
|
|
|
#ifndef _UTL_STREAM_WRAPPER_HXX_
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _UNOTOOLS_TEMPFILE_HXX
|
|
|
|
#include <unotools/tempfile.hxx>
|
|
|
|
#endif
|
2001-01-26 10:22:09 +00:00
|
|
|
|
|
|
|
#ifndef _SO_CLSIDS_HXX
|
|
|
|
#include <so3/clsids.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PERSIST_HXX
|
|
|
|
#include <so3/persist.hxx>
|
|
|
|
#endif
|
2001-03-16 11:46:48 +00:00
|
|
|
#ifndef _FACTORY_HXX
|
|
|
|
#include <so3/factory.hxx>
|
|
|
|
#endif
|
2001-01-26 10:22:09 +00:00
|
|
|
#ifndef _EMBOBJ_HXX
|
|
|
|
#include <so3/embobj.hxx>
|
|
|
|
#endif
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
#ifndef __SGI_STL_MAP
|
|
|
|
#include <map>
|
|
|
|
#endif
|
|
|
|
|
2001-01-26 10:22:09 +00:00
|
|
|
#ifndef _XMLEOHLP_HXX
|
|
|
|
#include "xmleohlp.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -----------
|
|
|
|
// - Defines -
|
|
|
|
// -----------
|
|
|
|
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::cppu;
|
2001-05-18 12:13:00 +00:00
|
|
|
using namespace ::utl;
|
2001-01-26 10:22:09 +00:00
|
|
|
using namespace ::com::sun::star::document;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2001-05-18 12:13:00 +00:00
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::io;
|
|
|
|
using namespace ::com::sun::star::lang;
|
2001-01-26 10:22:09 +00:00
|
|
|
|
|
|
|
#define XML_CONTAINERSTORAGE_NAME "Objects"
|
|
|
|
#define XML_EMBEDDEDOBJECT_URL_BASE "vnd.sun.star.EmbeddedObject:"
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-01-26 10:22:09 +00:00
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
class InputStorageWrapper_Impl : public ::cppu::WeakImplHelper1<stario::XInputStream>
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
::osl::Mutex maMutex;
|
|
|
|
SvStorageRef xStor;
|
|
|
|
Reference < XInputStream > xIn;
|
|
|
|
TempFile aTempFile;
|
|
|
|
|
|
|
|
public:
|
|
|
|
InputStorageWrapper_Impl( SvPersist *pPersist );
|
|
|
|
virtual ~InputStorageWrapper_Impl();
|
|
|
|
|
|
|
|
virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
|
|
|
|
virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
|
|
|
|
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
|
|
|
|
virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException);
|
|
|
|
virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InputStorageWrapper_Impl::InputStorageWrapper_Impl(
|
|
|
|
SvPersist *pPersist )
|
|
|
|
{
|
|
|
|
SvStream *pStream = 0;
|
|
|
|
aTempFile.EnableKillingFile();
|
|
|
|
pStream = aTempFile.GetStream( STREAM_READWRITE );
|
|
|
|
SvStorageRef aTempStor = new SvStorage( sal_False, *pStream );
|
|
|
|
if( pPersist->DoSaveAs( aTempStor ) )
|
|
|
|
{
|
|
|
|
aTempStor->Commit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aTempStor.Clear();
|
|
|
|
pStream = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pStream )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
pStream->Seek( 0 );
|
|
|
|
xIn = new OInputStreamWrapper( *pStream );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputStorageWrapper_Impl::~InputStorageWrapper_Impl()
|
|
|
|
{
|
|
|
|
xIn = 0;
|
|
|
|
xStor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL InputStorageWrapper_Impl::readBytes(
|
|
|
|
Sequence< sal_Int8 >& aData,
|
|
|
|
sal_Int32 nBytesToRead)
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
return xIn->readBytes( aData, nBytesToRead );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL InputStorageWrapper_Impl::readSomeBytes(
|
|
|
|
Sequence< sal_Int8 >& aData,
|
|
|
|
sal_Int32 nMaxBytesToRead)
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
return xIn->readSomeBytes( aData, nMaxBytesToRead );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL InputStorageWrapper_Impl::skipBytes( sal_Int32 nBytesToSkip )
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
xIn->skipBytes( nBytesToSkip );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL InputStorageWrapper_Impl::available()
|
|
|
|
throw(NotConnectedException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
return xIn->available();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL InputStorageWrapper_Impl::closeInput()
|
|
|
|
throw(NotConnectedException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
xIn->closeInput();
|
|
|
|
xIn = 0;
|
|
|
|
xStor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class OutputStorageWrapper_Impl : public ::cppu::WeakImplHelper1<XOutputStream>
|
|
|
|
{
|
|
|
|
::osl::Mutex maMutex;
|
|
|
|
SvStorageRef xStor;
|
|
|
|
Reference < XOutputStream > xOut;
|
|
|
|
TempFile aTempFile;
|
|
|
|
sal_Bool bStreamClosed : 1;
|
|
|
|
sal_Bool bCreateStorageFailed : 1;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OutputStorageWrapper_Impl();
|
|
|
|
virtual ~OutputStorageWrapper_Impl();
|
|
|
|
|
|
|
|
// stario::XOutputStream
|
|
|
|
virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData) throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
virtual void SAL_CALL flush() throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
virtual void SAL_CALL closeOutput() throw(NotConnectedException, BufferSizeExceededException, RuntimeException);
|
|
|
|
|
|
|
|
SvStorage *GetStorage();
|
2001-01-26 10:22:09 +00:00
|
|
|
};
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
OutputStorageWrapper_Impl::OutputStorageWrapper_Impl() :
|
|
|
|
bStreamClosed( sal_False ),
|
|
|
|
bCreateStorageFailed( sal_False )
|
|
|
|
{
|
|
|
|
aTempFile.EnableKillingFile();
|
|
|
|
SvStream *pStream = aTempFile.GetStream( STREAM_READWRITE );
|
|
|
|
xOut = new OOutputStreamWrapper( *pStream );
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputStorageWrapper_Impl::~OutputStorageWrapper_Impl()
|
|
|
|
{
|
|
|
|
xStor = 0;
|
|
|
|
xOut = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvStorage *OutputStorageWrapper_Impl::GetStorage()
|
|
|
|
{
|
|
|
|
if( !xStor )
|
|
|
|
{
|
|
|
|
if( bStreamClosed && !bCreateStorageFailed )
|
|
|
|
{
|
|
|
|
xStor = new SvStorage( *aTempFile.GetStream( STREAM_READWRITE ) );
|
|
|
|
if( xStor->GetError() != 0 )
|
|
|
|
{
|
|
|
|
xStor = 0;
|
|
|
|
bCreateStorageFailed = sal_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return xStor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OutputStorageWrapper_Impl::writeBytes(
|
|
|
|
const Sequence< sal_Int8 >& aData)
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
xOut->writeBytes( aData );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OutputStorageWrapper_Impl::flush()
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
xOut->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OutputStorageWrapper_Impl::closeOutput()
|
|
|
|
throw(NotConnectedException, BufferSizeExceededException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
xOut->closeOutput();
|
|
|
|
bStreamClosed = sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct OUStringLess
|
|
|
|
{
|
|
|
|
bool operator() ( const ::rtl::OUString& r1, const ::rtl::OUString& r2 ) const
|
|
|
|
{
|
|
|
|
return (r1 < r2) != sal_False;
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
};
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2001-01-26 10:22:09 +00:00
|
|
|
// -----------------------------
|
|
|
|
// - SvXMLEmbeddedObjectHelper -
|
|
|
|
// -----------------------------
|
|
|
|
|
|
|
|
SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() :
|
2001-05-18 12:13:00 +00:00
|
|
|
WeakComponentImplHelper2< XEmbeddedObjectResolver, XNameAccess >( maMutex ),
|
2001-01-26 10:22:09 +00:00
|
|
|
maDefaultContainerStorageName( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME) ),
|
|
|
|
mpRootStorage( 0 ),
|
|
|
|
mpDocPersist( 0 ),
|
2001-05-18 12:13:00 +00:00
|
|
|
mpStreamMap( 0 ),
|
2001-01-26 10:22:09 +00:00
|
|
|
meCreateMode( EMBEDDEDOBJECTHELPER_MODE_READ )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLEmbeddedObjectHelper::~SvXMLEmbeddedObjectHelper()
|
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
if( mpStreamMap )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
SvXMLEmbeddedObjectHelper_Impl::iterator aIter = mpStreamMap->begin();
|
|
|
|
SvXMLEmbeddedObjectHelper_Impl::iterator aEnd = mpStreamMap->end();
|
|
|
|
for( aIter; aIter != aEnd; aIter++ )
|
|
|
|
{
|
|
|
|
if( aIter->second )
|
|
|
|
{
|
|
|
|
aIter->second->release();
|
|
|
|
aIter->second = 0;
|
|
|
|
}
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SvXMLEmbeddedObjectHelper::ImplGetStorageNames(
|
|
|
|
const OUString& rURLStr,
|
|
|
|
OUString& rContainerStorageName,
|
|
|
|
OUString& rObjectStorageName,
|
|
|
|
sal_Bool bInternalToExternal ) const
|
|
|
|
{
|
|
|
|
// internal URL: vnd.sun.star.EmbeddedObject:<object-name>
|
|
|
|
// or: vnd.sun.star.EmbeddedObject:<path>/<object-name>
|
|
|
|
// external URL: #./<path>/<object-name>
|
|
|
|
// or: #<path>/<object-name>
|
|
|
|
// or: #<object-name>
|
|
|
|
// currently, path may only consist of a single directory name
|
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
|
|
|
|
if( !rURLStr.getLength() )
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
if( bInternalToExternal )
|
|
|
|
{
|
|
|
|
sal_Int32 nPos = rURLStr.indexOf( ':' );
|
|
|
|
if( -1 == nPos ||
|
|
|
|
0 != rURLStr.compareToAscii( XML_EMBEDDEDOBJECT_URL_BASE,
|
|
|
|
sizeof( XML_EMBEDDEDOBJECT_URL_BASE ) -1 ) )
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
sal_Int32 nPathStart = nPos + 1;
|
|
|
|
nPos = rURLStr.lastIndexOf( '/' );
|
|
|
|
if( -1 == nPos )
|
|
|
|
{
|
2001-02-01 13:29:01 +00:00
|
|
|
rContainerStorageName = OUString();
|
2001-01-26 10:22:09 +00:00
|
|
|
rObjectStorageName = rURLStr.copy( nPathStart );
|
|
|
|
}
|
|
|
|
else if( nPos > nPathStart )
|
|
|
|
{
|
|
|
|
rContainerStorageName = rURLStr.copy( nPathStart, nPos-nPathStart);
|
|
|
|
rObjectStorageName = rURLStr.copy( nPos+1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( '#' != rURLStr[0 ] )
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
sal_Int32 nPos = rURLStr.lastIndexOf( '/' );
|
|
|
|
if( -1 == nPos )
|
|
|
|
{
|
|
|
|
rContainerStorageName = OUString();
|
|
|
|
rObjectStorageName = rURLStr.copy( 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nPathStart = 1;
|
|
|
|
if( 0 == rURLStr.compareToAscii( "#./", 3 ) )
|
|
|
|
nPathStart = 3;
|
|
|
|
rContainerStorageName = rURLStr.copy( nPathStart, nPos-nPathStart);
|
|
|
|
rObjectStorageName = rURLStr.copy( nPos+1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( -1 != rContainerStorageName.indexOf( '/' ) )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "SvXMLEmbeddedObjectHelper: invalid path name" );
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetContainerStorage(
|
|
|
|
const OUString& rStorageName )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( -1 == rStorageName.indexOf( '/' ) &&
|
|
|
|
-1 == rStorageName.indexOf( '\\' ),
|
|
|
|
"nested embedded storages aren't supported" );
|
|
|
|
if( !mxContainerStorage.Is() ||
|
|
|
|
( rStorageName != maCurContainerStorageName ) )
|
|
|
|
{
|
|
|
|
if( mxContainerStorage.Is() &&
|
2001-02-01 13:29:01 +00:00
|
|
|
maCurContainerStorageName.getLength() > 0 &&
|
2001-01-26 10:22:09 +00:00
|
|
|
EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode )
|
|
|
|
mxContainerStorage->Commit();
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
if( rStorageName.getLength() > 0 && mpRootStorage )
|
2001-02-01 13:29:01 +00:00
|
|
|
{
|
|
|
|
StreamMode eMode = EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode
|
|
|
|
? STREAM_STD_READWRITE
|
|
|
|
: STREAM_STD_READ;
|
2001-02-14 13:09:49 +00:00
|
|
|
mxContainerStorage = mpRootStorage->OpenStorage( rStorageName,
|
|
|
|
eMode );
|
2001-02-01 13:29:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mxContainerStorage = mpRootStorage;
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
maCurContainerStorageName = rStorageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mxContainerStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetObjectStorage(
|
|
|
|
const OUString& rContainerStorageName,
|
|
|
|
const OUString& rObjectStorageName,
|
|
|
|
sal_Bool bUCBStorage )
|
|
|
|
{
|
|
|
|
SvStorageRef xObjStor;
|
|
|
|
SvStorageRef xCntnrStor( ImplGetContainerStorage( rContainerStorageName ) );
|
|
|
|
if( xCntnrStor.Is() )
|
|
|
|
{
|
|
|
|
StreamMode eMode = EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode
|
|
|
|
? STREAM_STD_READWRITE
|
|
|
|
: STREAM_STD_READ;
|
2001-02-14 13:09:49 +00:00
|
|
|
xObjStor = xCntnrStor->OpenStorage( rObjectStorageName, eMode );
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xObjStor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
String SvXMLEmbeddedObjectHelper::ImplGetUniqueName( SvStorage* pStg,
|
|
|
|
const sal_Char* p ) const
|
|
|
|
{
|
|
|
|
String aName;
|
|
|
|
sal_Char cBuf[ 32 ];
|
|
|
|
|
|
|
|
static ULONG nId = (ULONG) cBuf;
|
|
|
|
|
|
|
|
nId++;
|
|
|
|
for( ;; )
|
|
|
|
{
|
|
|
|
sprintf( cBuf, "%s%08lX", p, nId );
|
|
|
|
aName.AssignAscii( cBuf );
|
|
|
|
if( !pStg->IsContained( aName ) )
|
|
|
|
break;
|
|
|
|
nId++;
|
|
|
|
}
|
|
|
|
return aName;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
|
|
|
|
const OUString& rContainerStorageName,
|
2001-05-18 12:13:00 +00:00
|
|
|
OUString& rObjName,
|
|
|
|
const SvGlobalName *pClassId,
|
|
|
|
SvStorage *pTempStor )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
|
|
|
SvStorageRef xDocStor( mpDocPersist->GetStorage() );
|
2001-02-01 13:29:01 +00:00
|
|
|
SvStorageRef xCntnrStor( ImplGetContainerStorage(
|
|
|
|
rContainerStorageName ) );
|
2001-05-18 12:13:00 +00:00
|
|
|
|
|
|
|
if( !xCntnrStor.Is() && !pTempStor )
|
2001-02-01 13:29:01 +00:00
|
|
|
return sal_False;
|
2001-01-26 10:22:09 +00:00
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
String aSrcObjName( rObjName );
|
|
|
|
if( xDocStor != xCntnrStor || pTempStor )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-02-01 13:29:01 +00:00
|
|
|
|
|
|
|
// Is the object name unique?
|
|
|
|
if( mpDocPersist->GetObjectList() )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-02-01 13:29:01 +00:00
|
|
|
sal_uInt32 nCount = mpDocPersist->GetObjectList()->Count();
|
|
|
|
for( sal_uInt32 i = 0; i < nCount; i++ )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-02-01 13:29:01 +00:00
|
|
|
SvInfoObject* pTst = mpDocPersist->GetObjectList()->GetObject(i);
|
|
|
|
// TODO: unicode: is this correct?
|
2001-05-18 12:58:34 +00:00
|
|
|
if( rObjName.equalsIgnoreAsciiCase( pTst->GetObjName() ) ||
|
|
|
|
rObjName.equalsIgnoreAsciiCase( pTst->GetStorageName() ) )
|
2001-02-01 13:29:01 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
rObjName = ImplGetUniqueName( xDocStor, "Obj" );
|
2001-02-01 13:29:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
if( pTempStor )
|
|
|
|
{
|
2001-06-20 07:42:01 +00:00
|
|
|
SvStorageRef xDstStor = xDocStor->OpenOLEStorage( rObjName );
|
2001-05-18 12:13:00 +00:00
|
|
|
if( !pTempStor->CopyTo( xDstStor ) )
|
|
|
|
return sal_False;
|
|
|
|
xDstStor->Commit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !xCntnrStor->CopyTo( aSrcObjName, xDocStor, rObjName ) )
|
|
|
|
return sal_False;
|
|
|
|
}
|
2001-02-01 13:29:01 +00:00
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
|
|
|
|
SvGlobalName aClassId;
|
|
|
|
if( pClassId )
|
|
|
|
{
|
2001-03-16 11:46:48 +00:00
|
|
|
// If a class id is specifies, use it.
|
2001-01-26 10:22:09 +00:00
|
|
|
aClassId = *pClassId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-16 11:46:48 +00:00
|
|
|
// Otherwise try to get one from the storage. For packages, the
|
|
|
|
// class id is derived from the package's mime type. The mime type
|
|
|
|
// is stored in the packages manifest and the manifest is read when
|
|
|
|
// the stoage is opened. Therfor, the class id is available without
|
|
|
|
// realy accessing the storage.
|
2001-05-18 12:13:00 +00:00
|
|
|
SvStorageRef xObjStor;
|
|
|
|
if( xDocStor == xCntnrStor )
|
|
|
|
xObjStor = ImplGetObjectStorage( rContainerStorageName,
|
|
|
|
rObjName, sal_False );
|
|
|
|
else
|
|
|
|
xObjStor = xDocStor->OpenStorage( rObjName, STREAM_STD_READ );
|
|
|
|
DBG_ASSERT( xObjStor.Is(), "Couldn't open object storage" );
|
|
|
|
if( xObjStor.Is() )
|
|
|
|
aClassId = xObjStor->GetClassName();
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
|
2001-03-16 11:46:48 +00:00
|
|
|
// For all unkown class id, the OLE object has to be wrapped by an
|
|
|
|
// outplace object.
|
|
|
|
SvGlobalName aOutClassId( SO3_OUT_CLASSID );
|
|
|
|
if( SvGlobalName() == aClassId ||
|
|
|
|
( aOutClassId != aClassId &&
|
|
|
|
!SvFactory::IsIntern( aClassId, 0 ) ) )
|
|
|
|
aClassId = SvGlobalName( aOutClassId );
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
SvInfoObjectRef xInfo = new SvEmbeddedInfoObject( rObjName, aClassId );
|
2001-01-26 10:22:09 +00:00
|
|
|
mpDocPersist->Insert( xInfo );
|
|
|
|
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
|
|
|
|
const OUString& rURLStr )
|
|
|
|
{
|
|
|
|
OUString sRetURL;
|
|
|
|
|
|
|
|
OUString aContainerStorageName, aObjectStorageName;
|
|
|
|
if( !ImplGetStorageNames( rURLStr, aContainerStorageName,
|
|
|
|
aObjectStorageName,
|
|
|
|
EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode ) )
|
|
|
|
return sRetURL;
|
|
|
|
|
|
|
|
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
|
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
OutputStorageWrapper_Impl *pOut = 0;
|
|
|
|
SvXMLEmbeddedObjectHelper_Impl::iterator aIter;
|
|
|
|
|
|
|
|
if( mpStreamMap )
|
|
|
|
{
|
|
|
|
aIter = mpStreamMap->find( rURLStr );
|
|
|
|
if( aIter != mpStreamMap->end() && aIter->second )
|
|
|
|
pOut = aIter->second;
|
|
|
|
}
|
|
|
|
|
2001-01-26 10:22:09 +00:00
|
|
|
SvGlobalName aClassId, *pClassId = 0;
|
|
|
|
sal_Int32 nPos = aObjectStorageName.lastIndexOf( '!' );
|
|
|
|
if( -1 != nPos && aClassId.MakeId( aObjectStorageName.copy( nPos+1 ) ) )
|
|
|
|
{
|
|
|
|
aObjectStorageName = aObjectStorageName.copy( 0, nPos );
|
|
|
|
pClassId = &aClassId;
|
|
|
|
}
|
2001-05-18 12:13:00 +00:00
|
|
|
ImplReadObject( aContainerStorageName, aObjectStorageName, pClassId,
|
|
|
|
pOut ? pOut->GetStorage() : 0 );
|
2001-01-26 10:22:09 +00:00
|
|
|
sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_EMBEDDEDOBJECT_URL_BASE ) );
|
|
|
|
sRetURL += aObjectStorageName;
|
2001-05-18 12:13:00 +00:00
|
|
|
|
|
|
|
if( pOut )
|
|
|
|
{
|
|
|
|
mpStreamMap->erase( aIter );
|
|
|
|
pOut->release();
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-01 13:29:01 +00:00
|
|
|
// Objects are written using SfxObjectShell::SaveAs
|
2001-01-26 10:22:09 +00:00
|
|
|
sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM("#./") );
|
2001-02-01 13:29:01 +00:00
|
|
|
if( aContainerStorageName.getLength() )
|
|
|
|
{
|
|
|
|
sRetURL += aContainerStorageName;
|
|
|
|
sRetURL += OUString( '/' );
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
sRetURL += aObjectStorageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sRetURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvXMLEmbeddedObjectHelper::Init(
|
2001-05-18 12:13:00 +00:00
|
|
|
SvStorage *pRootStorage,
|
2001-01-26 10:22:09 +00:00
|
|
|
SvPersist& rPersist,
|
2001-05-18 12:13:00 +00:00
|
|
|
SvXMLEmbeddedObjectHelperMode eCreateMode )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
mpRootStorage = pRootStorage;
|
2001-01-26 10:22:09 +00:00
|
|
|
mpDocPersist = &rPersist;
|
|
|
|
meCreateMode = eCreateMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SvXMLEmbeddedObjectHelper* SvXMLEmbeddedObjectHelper::Create(
|
|
|
|
SvStorage& rRootStorage,
|
|
|
|
SvPersist& rDocPersist,
|
|
|
|
SvXMLEmbeddedObjectHelperMode eCreateMode,
|
|
|
|
sal_Bool bDirect )
|
|
|
|
{
|
|
|
|
SvXMLEmbeddedObjectHelper* pThis = new SvXMLEmbeddedObjectHelper;
|
|
|
|
|
|
|
|
pThis->acquire();
|
2001-05-18 12:13:00 +00:00
|
|
|
pThis->Init( &rRootStorage, rDocPersist, eCreateMode );
|
|
|
|
|
|
|
|
return pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLEmbeddedObjectHelper* SvXMLEmbeddedObjectHelper::Create(
|
|
|
|
SvPersist& rDocPersist,
|
|
|
|
SvXMLEmbeddedObjectHelperMode eCreateMode )
|
|
|
|
{
|
|
|
|
SvXMLEmbeddedObjectHelper* pThis = new SvXMLEmbeddedObjectHelper;
|
|
|
|
|
|
|
|
pThis->acquire();
|
|
|
|
pThis->Init( 0, rDocPersist, eCreateMode );
|
2001-01-26 10:22:09 +00:00
|
|
|
|
|
|
|
return pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvXMLEmbeddedObjectHelper::Destroy(
|
|
|
|
SvXMLEmbeddedObjectHelper* pSvXMLEmbeddedObjectHelper )
|
|
|
|
{
|
|
|
|
if( pSvXMLEmbeddedObjectHelper )
|
|
|
|
{
|
|
|
|
pSvXMLEmbeddedObjectHelper->Flush();
|
|
|
|
pSvXMLEmbeddedObjectHelper->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvXMLEmbeddedObjectHelper::Flush()
|
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XGraphicObjectResolver
|
|
|
|
OUString SAL_CALL SvXMLEmbeddedObjectHelper::resolveEmbeddedObjectURL( const OUString& aURL )
|
|
|
|
throw(RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
|
|
|
|
return ImplInsertEmbeddedObjectURL( aURL );
|
|
|
|
}
|
|
|
|
|
|
|
|
// XNameAccess
|
|
|
|
Any SAL_CALL SvXMLEmbeddedObjectHelper::getByName(
|
|
|
|
const OUString& rURLStr )
|
|
|
|
throw (NoSuchElementException, WrappedTargetException, RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
Any aRet;
|
|
|
|
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
Reference < XOutputStream > xStrm;
|
|
|
|
if( mpStreamMap )
|
|
|
|
{
|
|
|
|
SvXMLEmbeddedObjectHelper_Impl::iterator aIter =
|
|
|
|
mpStreamMap->find( rURLStr );
|
|
|
|
if( aIter != mpStreamMap->end() && aIter->second )
|
|
|
|
xStrm = aIter->second;
|
|
|
|
}
|
|
|
|
if( !xStrm.is() )
|
|
|
|
{
|
|
|
|
OutputStorageWrapper_Impl *pOut = new OutputStorageWrapper_Impl;
|
|
|
|
pOut->acquire();
|
|
|
|
if( !mpStreamMap )
|
|
|
|
mpStreamMap = new SvXMLEmbeddedObjectHelper_Impl;
|
|
|
|
(*mpStreamMap)[rURLStr] = pOut;
|
|
|
|
xStrm = pOut;
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
aRet <<= xStrm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Reference < XInputStream > xStrm;
|
|
|
|
OUString aContainerStorageName, aObjectStorageName;
|
|
|
|
if( ImplGetStorageNames( rURLStr, aContainerStorageName,
|
|
|
|
aObjectStorageName,
|
|
|
|
sal_True ) )
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
2001-05-18 12:13:00 +00:00
|
|
|
SvPersistRef xObj = mpDocPersist->GetObject( aObjectStorageName );
|
|
|
|
if( xObj.Is() )
|
|
|
|
xStrm = new InputStorageWrapper_Impl( xObj );
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
2001-05-18 12:13:00 +00:00
|
|
|
aRet <<= xStrm;
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
return aRet;
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
Sequence< OUString > SAL_CALL SvXMLEmbeddedObjectHelper::getElementNames()
|
|
|
|
throw (RuntimeException)
|
2001-01-26 10:22:09 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
2001-05-18 12:13:00 +00:00
|
|
|
return Sequence< OUString >(0);
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
|
2001-05-18 12:13:00 +00:00
|
|
|
sal_Bool SAL_CALL SvXMLEmbeddedObjectHelper::hasByName( const OUString& rURLStr )
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
|
|
|
|
{
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OUString aContainerStorageName, aObjectStorageName;
|
|
|
|
if( !ImplGetStorageNames( rURLStr, aContainerStorageName,
|
|
|
|
aObjectStorageName,
|
|
|
|
sal_True ) )
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
return aObjectStorageName.getLength() > 0 &&
|
|
|
|
mpDocPersist->Find( aObjectStorageName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XNameAccess
|
|
|
|
Type SAL_CALL SvXMLEmbeddedObjectHelper::getElementType()
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
|
|
|
|
return ::getCppuType((const Reference<XOutputStream>*)0);
|
|
|
|
else
|
|
|
|
return ::getCppuType((const Reference<XInputStream>*)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SvXMLEmbeddedObjectHelper::hasElements()
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard( maMutex );
|
|
|
|
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
|
|
|
|
{
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return mpDocPersist->GetObjectList() != 0 &&
|
|
|
|
mpDocPersist->GetObjectList()->Count() > 0;
|
|
|
|
}
|
2001-01-26 10:22:09 +00:00
|
|
|
}
|