Kaydet (Commit) 63d13cb2 authored tarafından Michael Brauer's avatar Michael Brauer

#87246#: OLE object support through SAX interface

üst 09d29887
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: xmleohlp.hxx,v $ * $RCSfile: xmleohlp.hxx,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change: $Author: mh $ * last change: $Author: mib $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
#ifndef _XMLEOHLP_HXX #ifndef _XMLEOHLP_HXX
#define _XMLEOHLP_HXX #define _XMLEOHLP_HXX
#ifndef _CPPUHELPER_COMPBASE1_HXX_ #ifndef _CPPUHELPER_COMPBASE2_HXX_
#include <cppuhelper/compbase1.hxx> #include <cppuhelper/compbase2.hxx>
#endif #endif
#ifndef _OSL_MUTEX_HXX_ #ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
...@@ -71,13 +71,16 @@ ...@@ -71,13 +71,16 @@
#ifndef _SVSTOR_HXX #ifndef _SVSTOR_HXX
#include <so3/svstor.hxx> #include <so3/svstor.hxx>
#endif #endif
#ifndef __SGI_STL_VECTOR #ifndef __SGI_STL_MAP
#include <vector> #include <map>
#endif #endif
#ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDOBJECTRESOLVER_HPP_ #ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDOBJECTRESOLVER_HPP_
#include <com/sun/star/document/XEmbeddedObjectResolver.hpp> #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
// ----------------------------- // -----------------------------
// - SvXMLEmbeddedObjectHelper - // - SvXMLEmbeddedObjectHelper -
...@@ -95,39 +98,38 @@ enum SvXMLEmbeddedObjectHelperMode ...@@ -95,39 +98,38 @@ enum SvXMLEmbeddedObjectHelperMode
class SvPersist; class SvPersist;
class SvGlobalName; class SvGlobalName;
struct OUStringLess;
class OutputStorageWrapper_Impl;
class SvXMLEmbeddedObjectHelper : public ::cppu::WeakComponentImplHelper1< ::com::sun::star::document::XEmbeddedObjectResolver > class SvXMLEmbeddedObjectHelper : public ::cppu::WeakComponentImplHelper2<
::com::sun::star::document::XEmbeddedObjectResolver,
::com::sun::star::container::XNameAccess >
{ {
typedef ::_STL::map< ::rtl::OUString, OutputStorageWrapper_Impl*,
OUStringLess > SvXMLEmbeddedObjectHelper_Impl;
private: private:
typedef ::_STL::vector< ::rtl::OUString > URLVector;
::osl::Mutex maMutex; ::osl::Mutex maMutex;
const ::rtl::OUString maDefaultContainerStorageName; const ::rtl::OUString maDefaultContainerStorageName;
::rtl::OUString maCurContainerStorageName; ::rtl::OUString maCurContainerStorageName;
URLVector maEmbeddedObjectURLs;
SvStorage* mpRootStorage; // package SvStorage* mpRootStorage; // package
SvPersist* mpDocPersist; SvPersist* mpDocPersist;
SvStorageRef mxContainerStorage; // container sub package for SvStorageRef mxContainerStorage; // container sub package for
// objects // objects
SvGlobalName** mpGlobalNameMap;
SvXMLEmbeddedObjectHelperMode meCreateMode; SvXMLEmbeddedObjectHelperMode meCreateMode;
void* mpDummy1; SvXMLEmbeddedObjectHelper_Impl *mpStreamMap;
void* mpDummy2; void* mpDummy2;
BOOL mbDirect : 1;
sal_Bool ImplGetStorageNames( sal_Bool ImplGetStorageNames(
const ::rtl::OUString& rURLStr, const ::rtl::OUString& rURLStr,
::rtl::OUString& rContainerStorageName, ::rtl::OUString& rContainerStorageName,
::rtl::OUString& rObjectStorageName, ::rtl::OUString& rObjectStorageName,
sal_Bool bInternalToExternal ) const; sal_Bool bInternalToExternal ) const;
sal_uInt16 ImplGetFlags(
const SvGlobalName& rClassId ) const;
SvStorageRef ImplGetContainerStorage( SvStorageRef ImplGetContainerStorage(
const ::rtl::OUString& rStorageName ); const ::rtl::OUString& rStorageName );
SvStorageRef ImplGetObjectStorage( SvStorageRef ImplGetObjectStorage(
...@@ -138,11 +140,10 @@ private: ...@@ -138,11 +140,10 @@ private:
const sal_Char* p ) const; const sal_Char* p ) const;
sal_Bool ImplReadObject( sal_Bool ImplReadObject(
const ::rtl::OUString& rContainerStorageName, const ::rtl::OUString& rContainerStorageName,
const ::rtl::OUString& rObjName, ::rtl::OUString& rObjName,
const SvGlobalName *pClassId ); const SvGlobalName *pClassId,
sal_Bool ImplWriteObject( SvStorage *pTempStor );
const ::rtl::OUString& rContainerStorageName,
const ::rtl::OUString& rObjName );
::rtl::OUString ImplInsertEmbeddedObjectURL( ::rtl::OUString ImplInsertEmbeddedObjectURL(
const ::rtl::OUString& rURLStr ); const ::rtl::OUString& rURLStr );
...@@ -150,10 +151,9 @@ protected: ...@@ -150,10 +151,9 @@ protected:
SvXMLEmbeddedObjectHelper(); SvXMLEmbeddedObjectHelper();
~SvXMLEmbeddedObjectHelper(); ~SvXMLEmbeddedObjectHelper();
void Init( SvStorage& rRootStorage, void Init( SvStorage *pRootStorage,
SvPersist& rDocPersist, SvPersist& rDocPersist,
SvXMLEmbeddedObjectHelperMode eCreateMode, SvXMLEmbeddedObjectHelperMode eCreateMode );
sal_Bool bDirect );
public: public:
...@@ -162,12 +162,24 @@ public: ...@@ -162,12 +162,24 @@ public:
SvPersist& rDocPersist, SvPersist& rDocPersist,
SvXMLEmbeddedObjectHelperMode eCreateMode, SvXMLEmbeddedObjectHelperMode eCreateMode,
sal_Bool bDirect = sal_True ); sal_Bool bDirect = sal_True );
static SvXMLEmbeddedObjectHelper* Create(
SvPersist& rDocPersist,
SvXMLEmbeddedObjectHelperMode eCreateMode );
static void Destroy( SvXMLEmbeddedObjectHelper* pSvXMLEmbeddedObjectHelper ); static void Destroy( SvXMLEmbeddedObjectHelper* pSvXMLEmbeddedObjectHelper );
void Flush(); void Flush();
// XEmbeddedObjectResolver // XEmbeddedObjectResolver
virtual ::rtl::OUString SAL_CALL resolveEmbeddedObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL resolveEmbeddedObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException);
// XNameAccess
virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException);
// XNameAccess
virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException);
}; };
#endif #endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* *
* $RCSfile: xmleohlp.cxx,v $ * $RCSfile: xmleohlp.cxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: mib $ * last change: $Author: mib $
* *
...@@ -64,6 +64,12 @@ ...@@ -64,6 +64,12 @@
#ifndef _DEBUG_HXX #ifndef _DEBUG_HXX
#include <tools/debug.hxx> #include <tools/debug.hxx>
#endif #endif
#ifndef _UTL_STREAM_WRAPPER_HXX_
#include <unotools/streamwrap.hxx>
#endif
#ifndef _UNOTOOLS_TEMPFILE_HXX
#include <unotools/tempfile.hxx>
#endif
#ifndef _SO_CLSIDS_HXX #ifndef _SO_CLSIDS_HXX
#include <so3/clsids.hxx> #include <so3/clsids.hxx>
...@@ -78,6 +84,10 @@ ...@@ -78,6 +84,10 @@
#include <so3/embobj.hxx> #include <so3/embobj.hxx>
#endif #endif
#ifndef __SGI_STL_MAP
#include <map>
#endif
#ifndef _XMLEOHLP_HXX #ifndef _XMLEOHLP_HXX
#include "xmleohlp.hxx" #include "xmleohlp.hxx"
#endif #endif
...@@ -89,68 +99,209 @@ ...@@ -89,68 +99,209 @@
using namespace ::rtl; using namespace ::rtl;
using namespace ::osl; using namespace ::osl;
using namespace ::cppu; using namespace ::cppu;
using namespace ::utl;
using namespace ::com::sun::star::document; using namespace ::com::sun::star::document;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang;
#define XML_CONTAINERSTORAGE_NAME "Objects" #define XML_CONTAINERSTORAGE_NAME "Objects"
#define XML_EMBEDDEDOBJECT_URL_BASE "vnd.sun.star.EmbeddedObject:" #define XML_EMBEDDEDOBJECT_URL_BASE "vnd.sun.star.EmbeddedObject:"
#define EO_FLAG_STAR_OBJECT 0x0001 // -----------------------------------------------------------------------------
#define EO_FLAG_UCB_STORAGE 0x0002
#define EO_FLAG_NEEDS_CONVERSION 0x0004
struct ClassNameInfo class InputStorageWrapper_Impl : public ::cppu::WeakImplHelper1<stario::XInputStream>
{ {
struct GUIDDummy ::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 )
{ {
sal_uInt32 n1; pStream->Seek( 0 );
sal_uInt16 n2, n3; xIn = new OInputStreamWrapper( *pStream );
sal_uInt8 n4, n5, n6, n7, n8, n9, n10, n11; }
} aGUID; }
sal_uInt16 nFlags;
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();
}; };
typedef SvGlobalName *SvGlobalNamePtr; OutputStorageWrapper_Impl::OutputStorageWrapper_Impl() :
bStreamClosed( sal_False ),
static ClassNameInfo aFlagsMap[] = bCreateStorageFailed( sal_False )
{ {
{ SO3_SM_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, aTempFile.EnableKillingFile();
{ SO3_SCH_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, SvStream *pStream = aTempFile.GetStream( STREAM_READWRITE );
{ SO3_SIM_CLASSID_50 , EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, xOut = new OOutputStreamWrapper( *pStream );
{ SO3_SDRAW_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, }
{ SO3_SIMPRESS_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION },
{ SO3_SC_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, OutputStorageWrapper_Impl::~OutputStorageWrapper_Impl()
{ SO3_SW_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, {
{ SO3_SWWEB_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, xStor = 0;
{ SO3_SWGLOB_CLASSID_50, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, xOut = 0;
}
{ SO3_SM_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION },
{ SO3_SCH_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, SvStorage *OutputStorageWrapper_Impl::GetStorage()
{ SO3_SIM_CLASSID_40 , EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, {
{ SO3_SIMPRESS_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, if( !xStor )
{ SO3_SC_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, {
{ SO3_SW_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, if( bStreamClosed && !bCreateStorageFailed )
{ SO3_SWWEB_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, {
{ SO3_SWGLOB_CLASSID_40, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, xStor = new SvStorage( *aTempFile.GetStream( STREAM_READWRITE ) );
if( xStor->GetError() != 0 )
{ SO3_SM_CLASSID_30, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, {
{ SO3_SCH_CLASSID_30, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, xStor = 0;
{ SO3_SIM_CLASSID_30 , EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, bCreateStorageFailed = sal_True;
{ SO3_SIMPRESS_CLASSID_30, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, }
{ SO3_SC_CLASSID_30, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION }, }
{ SO3_SW_CLASSID_30, EO_FLAG_STAR_OBJECT|EO_FLAG_NEEDS_CONVERSION } }
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;
}
}; };
// -----------------------------------------------------------------------------
// ----------------------------- // -----------------------------
// - SvXMLEmbeddedObjectHelper - // - SvXMLEmbeddedObjectHelper -
// ----------------------------- // -----------------------------
SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() : SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() :
WeakComponentImplHelper1< XEmbeddedObjectResolver >( maMutex ), WeakComponentImplHelper2< XEmbeddedObjectResolver, XNameAccess >( maMutex ),
maDefaultContainerStorageName( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME) ), maDefaultContainerStorageName( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME) ),
mpRootStorage( 0 ), mpRootStorage( 0 ),
mpDocPersist( 0 ), mpDocPersist( 0 ),
mpGlobalNameMap( 0 ), mpStreamMap( 0 ),
meCreateMode( EMBEDDEDOBJECTHELPER_MODE_READ ) meCreateMode( EMBEDDEDOBJECTHELPER_MODE_READ )
{ {
} }
...@@ -159,14 +310,18 @@ SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() : ...@@ -159,14 +310,18 @@ SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() :
SvXMLEmbeddedObjectHelper::~SvXMLEmbeddedObjectHelper() SvXMLEmbeddedObjectHelper::~SvXMLEmbeddedObjectHelper()
{ {
if( mpGlobalNameMap ) if( mpStreamMap )
{ {
size_t nCount = sizeof(aFlagsMap)/sizeof(ClassNameInfo); SvXMLEmbeddedObjectHelper_Impl::iterator aIter = mpStreamMap->begin();
SvGlobalNamePtr *p = mpGlobalNameMap; SvXMLEmbeddedObjectHelper_Impl::iterator aEnd = mpStreamMap->end();
while( nCount-- ) for( aIter; aIter != aEnd; aIter++ )
delete *p++; {
if( aIter->second )
delete mpGlobalNameMap; {
aIter->second->release();
aIter->second = 0;
}
}
} }
} }
...@@ -245,45 +400,6 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplGetStorageNames( ...@@ -245,45 +400,6 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplGetStorageNames(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
sal_uInt16 SvXMLEmbeddedObjectHelper::ImplGetFlags(
const SvGlobalName& rClassId ) const
{
size_t nCount = sizeof(aFlagsMap)/sizeof(ClassNameInfo);
if( !mpGlobalNameMap )
{
((SvXMLEmbeddedObjectHelper *)this)->mpGlobalNameMap =
new SvGlobalNamePtr[nCount];
size_t i = nCount;
SvGlobalNamePtr *p = (SvGlobalNamePtr *)mpGlobalNameMap;
while( i-- )
*p++ = 0;
}
sal_uInt16 nFlags = 0;
SvGlobalNamePtr *pNames = (SvGlobalNamePtr *)mpGlobalNameMap;
const ClassNameInfo *pInfo = aFlagsMap;
while( nCount-- )
{
if( !*pNames )
*pNames = new SvGlobalName( pInfo->aGUID.n1, pInfo->aGUID.n2,
pInfo->aGUID.n3, pInfo->aGUID.n4,
pInfo->aGUID.n5, pInfo->aGUID.n6,
pInfo->aGUID.n7, pInfo->aGUID.n8,
pInfo->aGUID.n9, pInfo->aGUID.n10,
pInfo->aGUID.n11 );
if( **pNames == rClassId )
{
nFlags = pInfo->nFlags;
break;
}
pNames++;
pInfo++;
}
return nFlags;
}
SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetContainerStorage( SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetContainerStorage(
const OUString& rStorageName ) const OUString& rStorageName )
{ {
...@@ -298,7 +414,7 @@ SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetContainerStorage( ...@@ -298,7 +414,7 @@ SvStorageRef SvXMLEmbeddedObjectHelper::ImplGetContainerStorage(
EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode ) EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode )
mxContainerStorage->Commit(); mxContainerStorage->Commit();
if( rStorageName.getLength() > 0 ) if( rStorageName.getLength() > 0 && mpRootStorage )
{ {
StreamMode eMode = EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode StreamMode eMode = EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode
? STREAM_STD_READWRITE ? STREAM_STD_READWRITE
...@@ -360,18 +476,19 @@ String SvXMLEmbeddedObjectHelper::ImplGetUniqueName( SvStorage* pStg, ...@@ -360,18 +476,19 @@ String SvXMLEmbeddedObjectHelper::ImplGetUniqueName( SvStorage* pStg,
sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject( sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
const OUString& rContainerStorageName, const OUString& rContainerStorageName,
const OUString& rObjName, OUString& rObjName,
const SvGlobalName *pClassId ) const SvGlobalName *pClassId,
SvStorage *pTempStor )
{ {
SvStorageRef xDocStor( mpDocPersist->GetStorage() ); SvStorageRef xDocStor( mpDocPersist->GetStorage() );
SvStorageRef xCntnrStor( ImplGetContainerStorage( SvStorageRef xCntnrStor( ImplGetContainerStorage(
rContainerStorageName ) ); rContainerStorageName ) );
if( !xCntnrStor.Is() )
if( !xCntnrStor.Is() && !pTempStor )
return sal_False; return sal_False;
String aObjName( rObjName ); String aSrcObjName( rObjName );
String aSrcObjName( aObjName ); if( xDocStor != xCntnrStor || pTempStor )
if( xDocStor != xCntnrStor )
{ {
// Is the object name unique? // Is the object name unique?
...@@ -382,17 +499,27 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject( ...@@ -382,17 +499,27 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
{ {
SvInfoObject* pTst = mpDocPersist->GetObjectList()->GetObject(i); SvInfoObject* pTst = mpDocPersist->GetObjectList()->GetObject(i);
// TODO: unicode: is this correct? // TODO: unicode: is this correct?
if( aObjName.EqualsIgnoreCaseAscii( pTst->GetObjName() ) || if( rObjName.equalsIgnoreCase( pTst->GetObjName() ) ||
aObjName.EqualsIgnoreCaseAscii( pTst->GetStorageName() ) ) rObjName.equalsIgnoreCase( pTst->GetStorageName() ) )
{ {
aObjName = ImplGetUniqueName( xDocStor, "Obj" ); rObjName = ImplGetUniqueName( xDocStor, "Obj" );
break; break;
} }
} }
} }
if( !xCntnrStor->CopyTo( aSrcObjName, xDocStor, aObjName ) ) if( pTempStor )
return sal_False; {
SvStorageRef xDstStor = xDocStor->OpenStorage( rObjName );
if( !pTempStor->CopyTo( xDstStor ) )
return sal_False;
xDstStor->Commit();
}
else
{
if( !xCntnrStor->CopyTo( aSrcObjName, xDocStor, rObjName ) )
return sal_False;
}
} }
SvGlobalName aClassId; SvGlobalName aClassId;
...@@ -408,9 +535,15 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject( ...@@ -408,9 +535,15 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
// is stored in the packages manifest and the manifest is read when // is stored in the packages manifest and the manifest is read when
// the stoage is opened. Therfor, the class id is available without // the stoage is opened. Therfor, the class id is available without
// realy accessing the storage. // realy accessing the storage.
SvStorageRef xObjStor( ImplGetObjectStorage( rContainerStorageName, SvStorageRef xObjStor;
aSrcObjName, sal_False ) ); if( xDocStor == xCntnrStor )
aClassId = xObjStor->GetClassName(); 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();
} }
// For all unkown class id, the OLE object has to be wrapped by an // For all unkown class id, the OLE object has to be wrapped by an
...@@ -421,7 +554,7 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject( ...@@ -421,7 +554,7 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
!SvFactory::IsIntern( aClassId, 0 ) ) ) !SvFactory::IsIntern( aClassId, 0 ) ) )
aClassId = SvGlobalName( aOutClassId ); aClassId = SvGlobalName( aOutClassId );
SvInfoObjectRef xInfo = new SvEmbeddedInfoObject( aObjName, aClassId ); SvInfoObjectRef xInfo = new SvEmbeddedInfoObject( rObjName, aClassId );
mpDocPersist->Insert( xInfo ); mpDocPersist->Insert( xInfo );
return sal_True; return sal_True;
...@@ -429,63 +562,6 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject( ...@@ -429,63 +562,6 @@ sal_Bool SvXMLEmbeddedObjectHelper::ImplReadObject(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
sal_Bool SvXMLEmbeddedObjectHelper::ImplWriteObject(
const OUString& rContainerStorageName,
const OUString& rObjName )
{
SvInfoObject *pInfo = mpDocPersist->Find( rObjName );
DBG_ASSERT( pInfo, "OLE object not found" );
if( !pInfo )
return sal_False;
// Get object type
sal_uInt16 nFlags = ImplGetFlags( pInfo->GetClassName() );
// If the objects needs a conversion it has to be loaded and stored
// again later. The same would apply if the save into an old format.
if( (nFlags & EO_FLAG_NEEDS_CONVERSION) != 0 )
mpDocPersist->GetObject( rObjName );
if( pInfo->GetPersist() )
{
// The object is loaded either because it is stored within the
// wrong file format or it has been modified
// Create either an UCB or an OLE storage, based on object's type
SvStorageRef xObjStor( ImplGetObjectStorage(
rContainerStorageName,
rObjName,
(nFlags&EO_FLAG_UCB_STORAGE) != 0 ) );
if( !xObjStor.Is() )
return sal_False;
// Save file (again)
xObjStor->SetVersion( mpRootStorage->GetVersion() );
if( !pInfo->GetPersist()->DoSaveAs( xObjStor ) )
return sal_False;
// Commit changes
if( !xObjStor->Commit() )
return sal_False;
}
else
{
SvStorageRef xCntnrStor( ImplGetContainerStorage(
rContainerStorageName ) );
if( !xCntnrStor.Is() )
return sal_False;
if( !mpDocPersist->GetStorage()->CopyTo( pInfo->GetStorageName(),
xCntnrStor, rObjName ) )
return sal_False;
}
return sal_True;
}
// -----------------------------------------------------------------------------
OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL( OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
const OUString& rURLStr ) const OUString& rURLStr )
{ {
...@@ -499,6 +575,16 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL( ...@@ -499,6 +575,16 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode ) if( EMBEDDEDOBJECTHELPER_MODE_READ == meCreateMode )
{ {
OutputStorageWrapper_Impl *pOut = 0;
SvXMLEmbeddedObjectHelper_Impl::iterator aIter;
if( mpStreamMap )
{
aIter = mpStreamMap->find( rURLStr );
if( aIter != mpStreamMap->end() && aIter->second )
pOut = aIter->second;
}
SvGlobalName aClassId, *pClassId = 0; SvGlobalName aClassId, *pClassId = 0;
sal_Int32 nPos = aObjectStorageName.lastIndexOf( '!' ); sal_Int32 nPos = aObjectStorageName.lastIndexOf( '!' );
if( -1 != nPos && aClassId.MakeId( aObjectStorageName.copy( nPos+1 ) ) ) if( -1 != nPos && aClassId.MakeId( aObjectStorageName.copy( nPos+1 ) ) )
...@@ -506,17 +592,20 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL( ...@@ -506,17 +592,20 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
aObjectStorageName = aObjectStorageName.copy( 0, nPos ); aObjectStorageName = aObjectStorageName.copy( 0, nPos );
pClassId = &aClassId; pClassId = &aClassId;
} }
ImplReadObject( aContainerStorageName, aObjectStorageName, pClassId ); ImplReadObject( aContainerStorageName, aObjectStorageName, pClassId,
pOut ? pOut->GetStorage() : 0 );
sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_EMBEDDEDOBJECT_URL_BASE ) ); sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_EMBEDDEDOBJECT_URL_BASE ) );
sRetURL += aObjectStorageName; sRetURL += aObjectStorageName;
if( pOut )
{
mpStreamMap->erase( aIter );
pOut->release();
}
} }
else else
{ {
// Objects are written using SfxObjectShell::SaveAs // Objects are written using SfxObjectShell::SaveAs
// if( mbDirect )
// ImplWriteObject( aContainerStorageName, aObjectStorageName );
// else
// maEmbeddedObjectURLs.push_back( rURLStr );
sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM("#./") ); sRetURL = OUString( RTL_CONSTASCII_USTRINGPARAM("#./") );
if( aContainerStorageName.getLength() ) if( aContainerStorageName.getLength() )
{ {
...@@ -532,15 +621,13 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL( ...@@ -532,15 +621,13 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SvXMLEmbeddedObjectHelper::Init( void SvXMLEmbeddedObjectHelper::Init(
SvStorage& rRootStorage, SvStorage *pRootStorage,
SvPersist& rPersist, SvPersist& rPersist,
SvXMLEmbeddedObjectHelperMode eCreateMode, SvXMLEmbeddedObjectHelperMode eCreateMode )
sal_Bool bDirect )
{ {
mpRootStorage = &rRootStorage; mpRootStorage = pRootStorage;
mpDocPersist = &rPersist; mpDocPersist = &rPersist;
meCreateMode = eCreateMode; meCreateMode = eCreateMode;
mbDirect = bDirect;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -554,7 +641,19 @@ SvXMLEmbeddedObjectHelper* SvXMLEmbeddedObjectHelper::Create( ...@@ -554,7 +641,19 @@ SvXMLEmbeddedObjectHelper* SvXMLEmbeddedObjectHelper::Create(
SvXMLEmbeddedObjectHelper* pThis = new SvXMLEmbeddedObjectHelper; SvXMLEmbeddedObjectHelper* pThis = new SvXMLEmbeddedObjectHelper;
pThis->acquire(); pThis->acquire();
pThis->Init( rRootStorage, rDocPersist, eCreateMode, bDirect ); 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 );
return pThis; return pThis;
} }
...@@ -575,31 +674,114 @@ void SvXMLEmbeddedObjectHelper::Destroy( ...@@ -575,31 +674,114 @@ void SvXMLEmbeddedObjectHelper::Destroy(
void SvXMLEmbeddedObjectHelper::Flush() void SvXMLEmbeddedObjectHelper::Flush()
{ {
if( ( EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode ) && !mbDirect ) }
// 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 )
{ {
OUString aContainerStorageName, aObjectStorageName; Reference < XOutputStream > xStrm;
URLVector::iterator aIter( maEmbeddedObjectURLs.begin() ); if( mpStreamMap )
URLVector::iterator aEnd( maEmbeddedObjectURLs.end() ); {
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;
}
while( aIter != aEnd ) aRet <<= xStrm;
}
else
{
Reference < XInputStream > xStrm;
OUString aContainerStorageName, aObjectStorageName;
if( ImplGetStorageNames( rURLStr, aContainerStorageName,
aObjectStorageName,
sal_True ) )
{ {
if( ImplGetStorageNames( *aIter, aContainerStorageName, SvPersistRef xObj = mpDocPersist->GetObject( aObjectStorageName );
aObjectStorageName, sal_True ) ) if( xObj.Is() )
ImplWriteObject( aContainerStorageName, aObjectStorageName ); xStrm = new InputStorageWrapper_Impl( xObj );
aIter++;
} }
aRet <<= xStrm;
} }
if( EMBEDDEDOBJECTHELPER_MODE_WRITE == meCreateMode && return aRet;
mxContainerStorage.Is() )
mxContainerStorage->Commit();
} }
// XGraphicObjectResolver Sequence< OUString > SAL_CALL SvXMLEmbeddedObjectHelper::getElementNames()
OUString SAL_CALL SvXMLEmbeddedObjectHelper::resolveEmbeddedObjectURL( const OUString& aURL ) throw (RuntimeException)
throw(RuntimeException)
{ {
MutexGuard aGuard( maMutex ); MutexGuard aGuard( maMutex );
return Sequence< OUString >(0);
}
return ImplInsertEmbeddedObjectURL( aURL ); 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;
}
} }
/*************************************************************************
*
* $RCSfile: XMLBase64Export.hxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: mib $ $Date: 2001-05-18 13:13: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): _______________________________________
*
*
************************************************************************/
#ifndef _XMLOFF_XMLBASE64EXPORT_HXX
#define _XMLOFF_XMLBASE64EXPORT_HXX
namespace com { namespace sun { namespace star { namespace io {
class XInputStream; } } } }
class SvXMLExport;
class XMLBase64Export
{
SvXMLExport& rExport;
protected:
SvXMLExport& GetExport() { return rExport; }
public:
XMLBase64Export( SvXMLExport& rExport );
sal_Bool exportXML( const ::com::sun::star::uno::Reference <
::com::sun::star::io::XInputStream > & rIn );
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment