1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmleohlp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include <com/sun/star/io/XStream.hpp>
36 #include <com/sun/star/embed/XTransactedObject.hpp>
37 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
38 #include <com/sun/star/embed/XEmbedObjectFactory.hpp>
39 #include <com/sun/star/embed/ElementModes.hpp>
40 #include <com/sun/star/embed/XEmbeddedObject.hpp>
41 #ifndef _COM_SUN_STAR_EMBED_XEMBED_PERSIST_HPP_
42 #include <com/sun/star/embed/XEmbedPersist.hpp>
44 #include <com/sun/star/embed/EntryInitModes.hpp>
45 #include <com/sun/star/embed/EmbedStates.hpp>
46 #include <com/sun/star/embed/Aspects.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <tools/debug.hxx>
49 #include <unotools/streamwrap.hxx>
50 #include <unotools/tempfile.hxx>
52 #include <svtools/embedhlp.hxx>
53 #include <unotools/ucbstreamhelper.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <comphelper/storagehelper.hxx>
56 #include <comphelper/embeddedobjectcontainer.hxx>
58 #ifndef _SO_CLSIDS_HXX
59 #include <sot/clsids.hxx>
62 #include "xmleohlp.hxx"
68 using namespace ::osl
;
69 using namespace ::cppu
;
70 using namespace ::utl
;
71 using namespace ::com::sun::star
;
72 using namespace ::com::sun::star::document
;
73 using namespace ::com::sun::star::uno
;
74 using namespace ::com::sun::star::container
;
75 using namespace ::com::sun::star::io
;
76 using namespace ::com::sun::star::lang
;
78 #define XML_CONTAINERSTORAGE_NAME_60 "Pictures"
79 #define XML_CONTAINERSTORAGE_NAME "ObjectReplacements"
80 #define XML_EMBEDDEDOBJECT_URL_BASE "vnd.sun.star.EmbeddedObject:"
81 #define XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE "vnd.sun.star.GraphicObject:"
83 // -----------------------------------------------------------------------------
85 // -----------------------------------------------------------------------------
87 class OutputStorageWrapper_Impl
: public ::cppu::WeakImplHelper1
<XOutputStream
>
90 Reference
< XOutputStream
> xOut
;
92 sal_Bool bStreamClosed
: 1;
96 OutputStorageWrapper_Impl();
97 virtual ~OutputStorageWrapper_Impl();
99 // stario::XOutputStream
100 virtual void SAL_CALL
writeBytes(const Sequence
< sal_Int8
>& aData
) throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
);
101 virtual void SAL_CALL
flush() throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
);
102 virtual void SAL_CALL
closeOutput() throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
);
104 SvStream
* GetStream();
107 OutputStorageWrapper_Impl::OutputStorageWrapper_Impl()
108 : bStreamClosed( sal_False
)
111 aTempFile
.EnableKillingFile();
112 pStream
= aTempFile
.GetStream( STREAM_READWRITE
);
113 xOut
= new OOutputStreamWrapper( *pStream
);
116 OutputStorageWrapper_Impl::~OutputStorageWrapper_Impl()
120 SvStream
*OutputStorageWrapper_Impl::GetStream()
127 void SAL_CALL
OutputStorageWrapper_Impl::writeBytes(
128 const Sequence
< sal_Int8
>& aData
)
129 throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
)
131 MutexGuard
aGuard( maMutex
);
132 xOut
->writeBytes( aData
);
135 void SAL_CALL
OutputStorageWrapper_Impl::flush()
136 throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
)
138 MutexGuard
aGuard( maMutex
);
142 void SAL_CALL
OutputStorageWrapper_Impl::closeOutput()
143 throw(NotConnectedException
, BufferSizeExceededException
, RuntimeException
)
145 MutexGuard
aGuard( maMutex
);
147 bStreamClosed
= sal_True
;
150 // -----------------------------------------------------------------------------
154 bool operator() ( const ::rtl::OUString
& r1
, const ::rtl::OUString
& r2
) const
156 return (r1
< r2
) != sal_False
;
160 // -----------------------------------------------------------------------------
162 // -----------------------------
163 // - SvXMLEmbeddedObjectHelper -
164 // -----------------------------
165 DBG_NAME(SvXMLEmbeddedObjectHelper
)
166 SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper() :
167 WeakComponentImplHelper2
< XEmbeddedObjectResolver
, XNameAccess
>( maMutex
),
168 maReplacementGraphicsContainerStorageName( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME
) ),
169 maReplacementGraphicsContainerStorageName60( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME_60
) ),
171 meCreateMode( EMBEDDEDOBJECTHELPER_MODE_READ
),
174 DBG_CTOR(SvXMLEmbeddedObjectHelper
,NULL
);
177 SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper( ::comphelper::IEmbeddedHelper
& rDocPersist
, SvXMLEmbeddedObjectHelperMode eCreateMode
) :
178 WeakComponentImplHelper2
< XEmbeddedObjectResolver
, XNameAccess
>( maMutex
),
179 maReplacementGraphicsContainerStorageName( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME
) ),
180 maReplacementGraphicsContainerStorageName60( RTL_CONSTASCII_USTRINGPARAM(XML_CONTAINERSTORAGE_NAME_60
) ),
182 meCreateMode( EMBEDDEDOBJECTHELPER_MODE_READ
),
185 DBG_CTOR(SvXMLEmbeddedObjectHelper
,NULL
);
186 Init( 0, rDocPersist
, eCreateMode
);
190 // -----------------------------------------------------------------------------
192 SvXMLEmbeddedObjectHelper::~SvXMLEmbeddedObjectHelper()
194 DBG_DTOR(SvXMLEmbeddedObjectHelper
,NULL
);
197 SvXMLEmbeddedObjectHelper_Impl::iterator aIter
= mpStreamMap
->begin();
198 SvXMLEmbeddedObjectHelper_Impl::iterator aEnd
= mpStreamMap
->end();
199 for( ; aIter
!= aEnd
; aIter
++ )
203 aIter
->second
->release();
210 // -----------------------------------------------------------------------------
212 void SAL_CALL
SvXMLEmbeddedObjectHelper::disposing()
217 // -----------------------------------------------------------------------------
219 sal_Bool
SvXMLEmbeddedObjectHelper::ImplGetStorageNames(
220 const ::rtl::OUString
& rURLStr
,
221 ::rtl::OUString
& rContainerStorageName
,
222 ::rtl::OUString
& rObjectStorageName
,
223 sal_Bool bInternalToExternal
,
224 sal_Bool
*pGraphicRepl
,
225 sal_Bool
*pOasisFormat
) const
227 // internal URL: vnd.sun.star.EmbeddedObject:<object-name>
228 // or: vnd.sun.star.EmbeddedObject:<path>/<object-name>
229 // internal replacement images:
230 // vnd.sun.star.EmbeddedObjectGraphic:<object-name>
231 // or: vnd.sun.star.EmbeddedObjectGraphic:<path>/<object-name>
232 // external URL: ./<path>/<object-name>
233 // or: <path>/<object-name>
235 // currently, path may only consist of a single directory name
236 // it is also possible to have additional arguments at the end of URL: <main URL>[?<name>=<value>[,<name>=<value>]*]
239 *pGraphicRepl
= sal_False
;
242 *pOasisFormat
= sal_True
; // the default value
244 if( !rURLStr
.getLength() )
247 // get rid of arguments
248 sal_Int32 nPos
= rURLStr
.indexOf( '?' );
249 ::rtl::OUString aURLNoPar
;
254 aURLNoPar
= rURLStr
.copy( 0, nPos
);
256 // check the arguments
258 while( nPos
>= 0 && nPos
< rURLStr
.getLength() )
260 ::rtl::OUString aToken
= rURLStr
.getToken( 0, ',', nPos
);
261 if ( aToken
.equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "oasis=false" ) ) ) )
264 *pOasisFormat
= sal_False
;
269 DBG_ASSERT( sal_False
, "invalid arguments was found in URL!" );
274 if( bInternalToExternal
)
276 nPos
= aURLNoPar
.indexOf( ':' );
280 0 == aURLNoPar
.compareToAscii( XML_EMBEDDEDOBJECT_URL_BASE
,
281 sizeof( XML_EMBEDDEDOBJECT_URL_BASE
) -1 );
282 sal_Bool bGrUrl
= !bObjUrl
&&
283 0 == aURLNoPar
.compareToAscii( XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE
,
284 sizeof( XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE
) -1 );
285 if( !(bObjUrl
|| bGrUrl
) )
288 sal_Int32 nPathStart
= nPos
+ 1;
289 nPos
= aURLNoPar
.lastIndexOf( '/' );
292 rContainerStorageName
= ::rtl::OUString();
293 rObjectStorageName
= aURLNoPar
.copy( nPathStart
);
295 else if( nPos
> nPathStart
)
297 rContainerStorageName
= aURLNoPar
.copy( nPathStart
, nPos
-nPathStart
);
298 rObjectStorageName
= aURLNoPar
.copy( nPos
+1 );
305 sal_Bool bOASIS
= mxRootStorage
.is() &&
306 ( SotStorage::GetVersion( mxRootStorage
) > SOFFICE_FILEFORMAT_60
);
307 rContainerStorageName
= bOASIS
308 ? maReplacementGraphicsContainerStorageName
309 : maReplacementGraphicsContainerStorageName60
;
312 *pGraphicRepl
= sal_True
;
319 DBG_ASSERT( '#' != aURLNoPar
[0], "invalid object URL" );
321 sal_Int32 _nPos
= aURLNoPar
.lastIndexOf( '/' );
324 rContainerStorageName
= ::rtl::OUString();
325 rObjectStorageName
= aURLNoPar
;
329 //eliminate 'superfluous' slashes at start and end
330 //#i103076# load objects with all allowed xlink:href syntaxes
332 //eliminate './' at start
333 sal_Int32 nStart
= 0;
334 sal_Int32 nCount
= aURLNoPar
.getLength();
335 if( 0 == aURLNoPar
.compareToAscii( "./", 2 ) )
341 //eliminate '/' at end
342 sal_Int32 nEnd
= aURLNoPar
.lastIndexOf( '/' );
343 if( nEnd
== aURLNoPar
.getLength()-1 && nEnd
!= (nStart
-1) )
346 aURLNoPar
= aURLNoPar
.copy( nStart
, nCount
);
349 _nPos
= aURLNoPar
.lastIndexOf( '/' );
351 rContainerStorageName
= aURLNoPar
.copy( 0, _nPos
);
352 rObjectStorageName
= aURLNoPar
.copy( _nPos
+1 );
356 if( -1 != rContainerStorageName
.indexOf( '/' ) )
358 DBG_ERROR( "SvXMLEmbeddedObjectHelper: invalid path name" );
366 // -----------------------------------------------------------------------------
368 uno::Reference
< embed::XStorage
> SvXMLEmbeddedObjectHelper::ImplGetContainerStorage(
369 const ::rtl::OUString
& rStorageName
)
371 DBG_ASSERT( -1 == rStorageName
.indexOf( '/' ) &&
372 -1 == rStorageName
.indexOf( '\\' ),
373 "nested embedded storages aren't supported" );
374 if( !mxContainerStorage
.is() ||
375 ( rStorageName
!= maCurContainerStorageName
) )
377 if( mxContainerStorage
.is() &&
378 maCurContainerStorageName
.getLength() > 0 &&
379 EMBEDDEDOBJECTHELPER_MODE_WRITE
== meCreateMode
)
381 uno::Reference
< embed::XTransactedObject
> xTrans( mxContainerStorage
, uno::UNO_QUERY
);
386 if( rStorageName
.getLength() > 0 && mxRootStorage
.is() )
388 sal_Int32 nMode
= EMBEDDEDOBJECTHELPER_MODE_WRITE
== meCreateMode
389 ? ::embed::ElementModes::READWRITE
390 : ::embed::ElementModes::READ
;
391 mxContainerStorage
= mxRootStorage
->openStorageElement( rStorageName
,
396 mxContainerStorage
= mxRootStorage
;
398 maCurContainerStorageName
= rStorageName
;
401 return mxContainerStorage
;
404 // -----------------------------------------------------------------------------
406 sal_Bool
SvXMLEmbeddedObjectHelper::ImplReadObject(
407 const ::rtl::OUString
& rContainerStorageName
,
408 ::rtl::OUString
& rObjName
,
409 const SvGlobalName
*pClassId
,
414 uno::Reference
< embed::XStorage
> xDocStor( mpDocPersist
->getStorage() );
415 uno::Reference
< embed::XStorage
> xCntnrStor( ImplGetContainerStorage( rContainerStorageName
) );
417 if( !xCntnrStor
.is() && !pTemp
)
420 String
aSrcObjName( rObjName
);
421 comphelper::EmbeddedObjectContainer
& rContainer
= mpDocPersist
->getEmbeddedObjectContainer();
423 // Is the object name unique?
424 // if the object is already instantiated by GetEmbeddedObject
425 // that means that the duplication is being loaded
426 sal_Bool bDuplicate
= rContainer
.HasInstantiatedEmbeddedObject( rObjName
);
427 DBG_ASSERT( !bDuplicate
, "An object in the document is referenced twice!" );
429 if( xDocStor
!= xCntnrStor
|| pTemp
|| bDuplicate
)
431 // TODO/LATER: make this alltogether a method in the EmbeddedObjectContainer
433 // create a unique name for the duplicate object
435 rObjName
= rContainer
.CreateUniqueObjectName();
442 uno::Reference
< io::XStream
> xStm
= xDocStor
->openStreamElement( rObjName
,
443 embed::ElementModes::READWRITE
| embed::ElementModes::TRUNCATE
);
444 SvStream
* pStream
= ::utl::UcbStreamHelper::CreateStream( xStm
);
448 // TODO/LATER: what to do when other types of objects are based on substream persistence?
449 // This is an ole object
450 uno::Reference
< beans::XPropertySet
> xProps( xStm
, uno::UNO_QUERY_THROW
);
451 xProps
->setPropertyValue(
452 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
453 uno::makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.oleobject" ) ) ) );
455 xStm
->getOutputStream()->closeOutput();
457 catch ( uno::Exception
& )
466 xCntnrStor
->copyElementTo( aSrcObjName
, xDocStor
, rObjName
);
468 catch ( uno::Exception
& )
475 // make object known to the container
476 // TODO/LATER: could be done a little bit more efficient!
477 ::rtl::OUString
aName( rObjName
);
479 // TODO/LATER: The provided pClassId is ignored for now.
480 // The stream contains OLE storage internally and this storage already has a class id specifying the
481 // server that was used to create the object. pClassId could be used to specify the server that should
482 // be used for the next opening, but this information seems to be out of the file format responsibility
484 rContainer
.GetEmbeddedObject( aName
);
489 // -----------------------------------------------------------------------------
491 ::rtl::OUString
SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
492 const ::rtl::OUString
& rURLStr
)
494 ::rtl::OUString sRetURL
;
496 ::rtl::OUString aContainerStorageName
, aObjectStorageName
;
497 if( !ImplGetStorageNames( rURLStr
, aContainerStorageName
,
499 EMBEDDEDOBJECTHELPER_MODE_WRITE
== meCreateMode
) )
502 if( EMBEDDEDOBJECTHELPER_MODE_READ
== meCreateMode
)
504 OutputStorageWrapper_Impl
*pOut
= 0;
505 SvXMLEmbeddedObjectHelper_Impl::iterator aIter
;
509 aIter
= mpStreamMap
->find( rURLStr
);
510 if( aIter
!= mpStreamMap
->end() && aIter
->second
)
511 pOut
= aIter
->second
;
514 SvGlobalName aClassId
, *pClassId
= 0;
515 sal_Int32 nPos
= aObjectStorageName
.lastIndexOf( '!' );
516 if( -1 != nPos
&& aClassId
.MakeId( aObjectStorageName
.copy( nPos
+1 ) ) )
518 aObjectStorageName
= aObjectStorageName
.copy( 0, nPos
);
519 pClassId
= &aClassId
;
522 ImplReadObject( aContainerStorageName
, aObjectStorageName
, pClassId
, pOut
? pOut
->GetStream() : 0 );
523 sRetURL
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(XML_EMBEDDEDOBJECT_URL_BASE
) );
524 sRetURL
+= aObjectStorageName
;
528 mpStreamMap
->erase( aIter
);
534 // Objects are written using ::comphelper::IEmbeddedHelper::SaveAs
535 sRetURL
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("./") );
536 if( aContainerStorageName
.getLength() )
538 sRetURL
+= aContainerStorageName
;
539 sRetURL
+= ::rtl::OUString( '/' );
541 sRetURL
+= aObjectStorageName
;
547 // -----------------------------------------------------------------------------
549 uno::Reference
< io::XInputStream
> SvXMLEmbeddedObjectHelper::ImplGetReplacementImage(
550 const uno::Reference
< embed::XEmbeddedObject
>& xObj
)
552 uno::Reference
< io::XInputStream
> xStream
;
558 sal_Bool bSwitchBackToLoaded
= sal_False
;
559 sal_Int32 nCurState
= xObj
->getCurrentState();
560 if ( nCurState
== embed::EmbedStates::LOADED
|| nCurState
== embed::EmbedStates::RUNNING
)
562 // means that the object is not active
563 // copy replacement image from old to new container
564 ::rtl::OUString aMediaType
;
565 xStream
= mpDocPersist
->getEmbeddedObjectContainer().GetGraphicStream( xObj
, &aMediaType
);
570 // the image must be regenerated
571 // TODO/LATER: another aspect could be used
572 if ( nCurState
== embed::EmbedStates::LOADED
)
573 bSwitchBackToLoaded
= sal_True
;
575 ::rtl::OUString aMediaType
;
576 xStream
= svt::EmbeddedObjectRef::GetGraphicReplacementStream(
577 embed::Aspects::MSOLE_CONTENT
,
582 if ( bSwitchBackToLoaded
)
583 // switch back to loaded state; that way we have a minimum cache confusion
584 xObj
->changeState( embed::EmbedStates::LOADED
);
586 catch( uno::Exception
& )
593 // -----------------------------------------------------------------------------
595 void SvXMLEmbeddedObjectHelper::Init(
596 const uno::Reference
< embed::XStorage
>& rRootStorage
,
597 ::comphelper::IEmbeddedHelper
& rPersist
,
598 SvXMLEmbeddedObjectHelperMode eCreateMode
)
600 mxRootStorage
= rRootStorage
;
601 mpDocPersist
= &rPersist
;
602 meCreateMode
= eCreateMode
;
605 // -----------------------------------------------------------------------------
607 SvXMLEmbeddedObjectHelper
* SvXMLEmbeddedObjectHelper::Create(
608 const uno::Reference
< embed::XStorage
>& rRootStorage
,
609 ::comphelper::IEmbeddedHelper
& rDocPersist
,
610 SvXMLEmbeddedObjectHelperMode eCreateMode
,
615 SvXMLEmbeddedObjectHelper
* pThis
= new SvXMLEmbeddedObjectHelper
;
618 pThis
->Init( rRootStorage
, rDocPersist
, eCreateMode
);
623 SvXMLEmbeddedObjectHelper
* SvXMLEmbeddedObjectHelper::Create(
624 ::comphelper::IEmbeddedHelper
& rDocPersist
,
625 SvXMLEmbeddedObjectHelperMode eCreateMode
)
627 SvXMLEmbeddedObjectHelper
* pThis
= new SvXMLEmbeddedObjectHelper
;
630 pThis
->Init( 0, rDocPersist
, eCreateMode
);
635 // -----------------------------------------------------------------------------
637 void SvXMLEmbeddedObjectHelper::Destroy(
638 SvXMLEmbeddedObjectHelper
* pSvXMLEmbeddedObjectHelper
)
640 if( pSvXMLEmbeddedObjectHelper
)
642 pSvXMLEmbeddedObjectHelper
->dispose();
643 pSvXMLEmbeddedObjectHelper
->release();
647 // -----------------------------------------------------------------------------
649 void SvXMLEmbeddedObjectHelper::Flush()
651 if( mxTempStorage
.is() )
653 Reference
< XComponent
> xComp( mxTempStorage
, UNO_QUERY
);
658 // XGraphicObjectResolver: alien objects!
659 ::rtl::OUString SAL_CALL
SvXMLEmbeddedObjectHelper::resolveEmbeddedObjectURL( const ::rtl::OUString
& aURL
)
660 throw(RuntimeException
)
662 MutexGuard
aGuard( maMutex
);
664 return ImplInsertEmbeddedObjectURL( aURL
);
667 // XNameAccess: alien objects!
668 Any SAL_CALL
SvXMLEmbeddedObjectHelper::getByName(
669 const ::rtl::OUString
& rURLStr
)
670 throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
672 MutexGuard
aGuard( maMutex
);
674 if( EMBEDDEDOBJECTHELPER_MODE_READ
== meCreateMode
)
676 Reference
< XOutputStream
> xStrm
;
679 SvXMLEmbeddedObjectHelper_Impl::iterator aIter
=
680 mpStreamMap
->find( rURLStr
);
681 if( aIter
!= mpStreamMap
->end() && aIter
->second
)
682 xStrm
= aIter
->second
;
686 OutputStorageWrapper_Impl
*pOut
= new OutputStorageWrapper_Impl
;
689 mpStreamMap
= new SvXMLEmbeddedObjectHelper_Impl
;
690 (*mpStreamMap
)[rURLStr
] = pOut
;
698 sal_Bool bGraphicRepl
= sal_False
;
699 sal_Bool bOasisFormat
= sal_True
;
700 Reference
< XInputStream
> xStrm
;
701 ::rtl::OUString aContainerStorageName
, aObjectStorageName
;
702 if( ImplGetStorageNames( rURLStr
, aContainerStorageName
,
710 comphelper::EmbeddedObjectContainer
& rContainer
=
711 mpDocPersist
->getEmbeddedObjectContainer();
713 Reference
< embed::XEmbeddedObject
> xObj
= rContainer
.GetEmbeddedObject( aObjectStorageName
);
714 DBG_ASSERT( xObj
.is(), "Didn't get object" );
720 xStrm
= ImplGetReplacementImage( xObj
);
724 Reference
< embed::XEmbedPersist
> xPersist( xObj
, UNO_QUERY
);
727 if( !mxTempStorage
.is() )
729 comphelper::OStorageHelper::GetTemporaryStorage();
730 Sequence
< beans::PropertyValue
> aDummy( 0 ), aEmbDescr( 1 );
731 aEmbDescr
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StoreVisualReplacement" ) );
732 aEmbDescr
[0].Value
<<= (sal_Bool
)(!bOasisFormat
);
735 ::rtl::OUString aMimeType
;
736 uno::Reference
< io::XInputStream
> xGrInStream
= ImplGetReplacementImage( xObj
);
737 if ( xGrInStream
.is() )
739 aEmbDescr
.realloc( 2 );
740 aEmbDescr
[1].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualReplacement" ) );
741 aEmbDescr
[1].Value
<<= xGrInStream
;
745 xPersist
->storeToEntry( mxTempStorage
, aObjectStorageName
,
747 Reference
< io::XStream
> xStream
=
748 mxTempStorage
->openStreamElement(
750 embed::ElementModes::READ
);
752 xStrm
= xStream
->getInputStream();
757 catch ( uno::Exception
& )
768 Sequence
< ::rtl::OUString
> SAL_CALL
SvXMLEmbeddedObjectHelper::getElementNames()
769 throw (RuntimeException
)
771 MutexGuard
aGuard( maMutex
);
772 return Sequence
< ::rtl::OUString
>(0);
775 sal_Bool SAL_CALL
SvXMLEmbeddedObjectHelper::hasByName( const ::rtl::OUString
& rURLStr
)
776 throw (RuntimeException
)
778 MutexGuard
aGuard( maMutex
);
779 if( EMBEDDEDOBJECTHELPER_MODE_READ
== meCreateMode
)
785 ::rtl::OUString aContainerStorageName
, aObjectStorageName
;
786 if( !ImplGetStorageNames( rURLStr
, aContainerStorageName
,
791 comphelper::EmbeddedObjectContainer
& rContainer
= mpDocPersist
->getEmbeddedObjectContainer();
792 return aObjectStorageName
.getLength() > 0 &&
793 rContainer
.HasEmbeddedObject( aObjectStorageName
);
798 Type SAL_CALL
SvXMLEmbeddedObjectHelper::getElementType()
799 throw (RuntimeException
)
801 MutexGuard
aGuard( maMutex
);
802 if( EMBEDDEDOBJECTHELPER_MODE_READ
== meCreateMode
)
803 return ::getCppuType((const Reference
<XOutputStream
>*)0);
805 return ::getCppuType((const Reference
<XInputStream
>*)0);
808 sal_Bool SAL_CALL
SvXMLEmbeddedObjectHelper::hasElements()
809 throw (RuntimeException
)
811 MutexGuard
aGuard( maMutex
);
812 if( EMBEDDEDOBJECTHELPER_MODE_READ
== meCreateMode
)
818 comphelper::EmbeddedObjectContainer
& rContainer
= mpDocPersist
->getEmbeddedObjectContainer();
819 return rContainer
.HasEmbeddedObjects();