Update ooo320-m1
[ooovba.git] / package / source / xstor / xstorage.cxx
blob989d439b3010fc18e87663593655f84709d018f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xstorage.cxx,v $
10 * $Revision: 1.33 $
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_package.hxx"
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/embed/ElementModes.hpp>
35 #include <com/sun/star/embed/UseBackupException.hpp>
36 #include <com/sun/star/ucb/XProgressHandler.hpp>
37 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38 #include <com/sun/star/container/XEnumerationAccess.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/util/XChangesBatch.hpp>
41 #include <com/sun/star/util/XCloneable.hpp>
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
45 #include <com/sun/star/lang/XComponent.hpp>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
48 #include <com/sun/star/beans/NamedValue.hpp>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <cppuhelper/exc_hlp.hxx>
53 #include <rtl/logfile.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <comphelper/componentcontext.hxx>
57 #include <comphelper/storagehelper.hxx>
58 #include <comphelper/ofopxmlhelper.hxx>
60 #include "xstorage.hxx"
61 #include "owriteablestream.hxx"
62 #include "disposelistener.hxx"
63 #include "switchpersistencestream.hxx"
64 #include "ohierarchyholder.hxx"
66 using namespace ::com::sun::star;
68 //=========================================================
70 typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList;
72 struct StorInternalData_Impl
74 SotMutexHolderRef m_rSharedMutexRef;
75 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners
76 ::cppu::OTypeCollection* m_pTypeCollection;
77 sal_Bool m_bIsRoot;
78 sal_Int16 m_nStorageType; // the mode in wich the storage is used
79 sal_Bool m_bReadOnlyWrap;
81 OChildDispListener_Impl* m_pSubElDispListener;
83 WeakComponentList m_aOpenSubComponentsList;
85 ::rtl::Reference< OHierarchyHolder_Impl > m_rHierarchyHolder;
87 // the mutex reference MUST NOT be empty
88 StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Int16 nStorType, sal_Bool bReadOnlyWrap )
89 : m_rSharedMutexRef( rMutexRef )
90 , m_aListenersContainer( rMutexRef->GetMutex() )
91 , m_pTypeCollection( NULL )
92 , m_bIsRoot( bRoot )
93 , m_nStorageType( nStorType )
94 , m_bReadOnlyWrap( bReadOnlyWrap )
95 , m_pSubElDispListener( NULL )
98 ~StorInternalData_Impl();
101 //=========================================================
102 ::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory );
104 // static
105 void OStorage_Impl::completeStorageStreamCopy_Impl(
106 const uno::Reference< io::XStream >& xSource,
107 const uno::Reference< io::XStream >& xDest,
108 sal_Int16 nStorageType,
109 const uno::Sequence< uno::Sequence< beans::StringPair > >& aRelInfo )
111 uno::Reference< beans::XPropertySet > xSourceProps( xSource, uno::UNO_QUERY );
112 uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY );
113 if ( !xSourceProps.is() || !xDestProps.is() )
114 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
116 uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream();
117 if ( !xDestOutStream.is() )
118 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
120 uno::Reference< io::XInputStream > xSourceInStream = xSource->getInputStream();
121 if ( !xSourceInStream.is() )
122 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
124 // TODO: headers of encripted streams should be copied also
125 ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInStream, xDestOutStream );
127 uno::Sequence< ::rtl::OUString > aPropNames( 1 );
128 aPropNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) );
130 if ( nStorageType == PACKAGE_STORAGE )
132 aPropNames.realloc( 3 );
133 aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
134 aPropNames[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
136 else if ( nStorageType == OFOPXML_STORAGE )
138 // TODO/LATER: in future it might make sence to provide the stream if there is one
139 uno::Reference< embed::XRelationshipAccess > xRelAccess( xDest, uno::UNO_QUERY_THROW );
140 xRelAccess->clearRelationships();
141 xRelAccess->insertRelationships( aRelInfo, sal_False );
143 aPropNames.realloc( 2 );
144 aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
147 for ( int ind = 0; ind < aPropNames.getLength(); ind++ )
148 xDestProps->setPropertyValue( aPropNames[ind], xSourceProps->getPropertyValue( aPropNames[ind] ) );
151 uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInputStream > xInStream,
152 uno::Reference< lang::XMultiServiceFactory > xFactory )
154 uno::Reference < io::XOutputStream > xTempOut(
155 xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
156 uno::UNO_QUERY );
157 uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY );
159 if ( !xTempOut.is() || !xTempIn.is() )
160 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
162 ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
163 xTempOut->closeOutput();
165 return xTempIn;
168 StorInternalData_Impl::~StorInternalData_Impl()
170 if ( m_pTypeCollection )
171 delete m_pTypeCollection;
175 SotElement_Impl::SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew )
176 : m_aName( rName )
177 , m_aOriginalName( rName )
178 , m_bIsRemoved( sal_False )
179 , m_bIsInserted( bNew )
180 , m_bIsStorage( bStor )
181 , m_pStorage( NULL )
182 , m_pStream( NULL )
186 SotElement_Impl::~SotElement_Impl()
188 if ( m_pStorage )
189 delete m_pStorage;
191 if ( m_pStream )
192 delete m_pStream;
195 //-----------------------------------------------
196 // most of properties are holt by the storage but are not used
197 OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream,
198 sal_Int32 nMode,
199 uno::Sequence< beans::PropertyValue > xProperties,
200 uno::Reference< lang::XMultiServiceFactory > xFactory,
201 sal_Int16 nStorageType )
202 : m_rMutexRef( new SotMutexHolder )
203 , m_pAntiImpl( NULL )
204 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
205 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
206 , m_bBroadcastModified( sal_False )
207 , m_bCommited( sal_False )
208 , m_bIsRoot( sal_True )
209 , m_bListCreated( sal_False )
210 , m_xFactory( xFactory )
211 , m_xProperties( xProperties )
212 , m_bHasCommonPassword( sal_False )
213 , m_pParent( NULL )
214 , m_bControlMediaType( sal_False )
215 , m_bMTFallbackUsed( sal_False )
216 , m_bControlVersion( sal_False )
217 , m_pSwitchStream( NULL )
218 , m_nStorageType( nStorageType )
219 , m_pRelStorElement( NULL )
220 , m_nRelInfoStatus( RELINFO_NO_INIT )
222 // all the checks done below by assertion statements must be done by factory
223 OSL_ENSURE( xInputStream.is(), "No input stream is provided!\n" );
225 m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xInputStream );
226 m_xInputStream = m_pSwitchStream->getInputStream();
228 if ( m_nStorageMode & embed::ElementModes::WRITE )
230 // check that the stream allows to write
231 OSL_ENSURE( sal_False, "No stream for writing is provided!\n" );
235 //-----------------------------------------------
236 // most of properties are holt by the storage but are not used
237 OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream,
238 sal_Int32 nMode,
239 uno::Sequence< beans::PropertyValue > xProperties,
240 uno::Reference< lang::XMultiServiceFactory > xFactory,
241 sal_Int16 nStorageType )
242 : m_rMutexRef( new SotMutexHolder )
243 , m_pAntiImpl( NULL )
244 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
245 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
246 , m_bBroadcastModified( sal_False )
247 , m_bCommited( sal_False )
248 , m_bIsRoot( sal_True )
249 , m_bListCreated( sal_False )
250 , m_xFactory( xFactory )
251 , m_xProperties( xProperties )
252 , m_bHasCommonPassword( sal_False )
253 , m_pParent( NULL )
254 , m_bControlMediaType( sal_False )
255 , m_bMTFallbackUsed( sal_False )
256 , m_bControlVersion( sal_False )
257 , m_pSwitchStream( NULL )
258 , m_nStorageType( nStorageType )
259 , m_pRelStorElement( NULL )
260 , m_nRelInfoStatus( RELINFO_NO_INIT )
262 // all the checks done below by assertion statements must be done by factory
263 OSL_ENSURE( xStream.is(), "No stream is provided!\n" );
265 if ( m_nStorageMode & embed::ElementModes::WRITE )
267 m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xStream );
268 m_xStream = static_cast< io::XStream* >( m_pSwitchStream );
270 else
272 m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory,
273 xStream->getInputStream() );
274 m_xInputStream = m_pSwitchStream->getInputStream();
278 //-----------------------------------------------
279 OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent,
280 sal_Int32 nMode,
281 uno::Reference< container::XNameContainer > xPackageFolder,
282 uno::Reference< lang::XSingleServiceFactory > xPackage,
283 uno::Reference< lang::XMultiServiceFactory > xFactory,
284 sal_Int16 nStorageType )
285 : m_rMutexRef( new SotMutexHolder )
286 , m_pAntiImpl( NULL )
287 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
288 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
289 , m_bBroadcastModified( sal_False )
290 , m_bCommited( sal_False )
291 , m_bIsRoot( sal_False )
292 , m_bListCreated( sal_False )
293 , m_xPackageFolder( xPackageFolder )
294 , m_xPackage( xPackage )
295 , m_xFactory( xFactory )
296 , m_bHasCommonPassword( sal_False )
297 , m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage
298 , m_bControlMediaType( sal_False )
299 , m_bMTFallbackUsed( sal_False )
300 , m_bControlVersion( sal_False )
301 , m_pSwitchStream( NULL )
302 , m_nStorageType( nStorageType )
303 , m_pRelStorElement( NULL )
304 , m_nRelInfoStatus( RELINFO_NO_INIT )
306 OSL_ENSURE( xPackageFolder.is(), "No package folder!\n" );
309 //-----------------------------------------------
310 OStorage_Impl::~OStorage_Impl()
313 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
314 if ( m_pAntiImpl ) // root storage wrapper must set this member to NULL before destruction of object
316 OSL_ENSURE( !m_bIsRoot, "The root storage wrapper must be disposed already" );
318 try {
319 m_pAntiImpl->InternalDispose( sal_False );
321 catch ( uno::Exception& aException )
323 AddLog( aException.Message );
324 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
326 m_pAntiImpl = NULL;
328 else if ( !m_aReadOnlyWrapList.empty() )
330 for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
331 pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ )
333 uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
334 if ( xTmp.is() )
335 try {
336 pStorageIter->m_pPointer->InternalDispose( sal_False );
337 } catch( uno::Exception& aException )
339 AddLog( aException.Message );
340 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
344 m_aReadOnlyWrapList.clear();
347 m_pParent = NULL;
350 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
351 pElementIter != m_aChildrenList.end(); pElementIter++ )
352 delete *pElementIter;
354 m_aChildrenList.clear();
356 for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
357 pDeletedIter != m_aDeletedList.end(); pDeletedIter++ )
358 delete *pDeletedIter;
360 m_aDeletedList.clear();
362 if ( m_nStorageType == OFOPXML_STORAGE && m_pRelStorElement )
364 delete m_pRelStorElement;
365 m_pRelStorElement = NULL;
368 m_xPackageFolder = uno::Reference< container::XNameContainer >();
369 m_xPackage = uno::Reference< lang::XSingleServiceFactory >();
371 ::rtl::OUString aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
372 for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ )
374 if ( m_xProperties[aInd].Name.equals( aPropertyName ) )
376 // the storage is URL based so all the streams are opened by factory and should be closed
379 if ( m_xInputStream.is() )
381 m_xInputStream->closeInput();
382 m_xInputStream = uno::Reference< io::XInputStream >();
385 if ( m_xStream.is() )
387 uno::Reference< io::XInputStream > xInStr = m_xStream->getInputStream();
388 if ( xInStr.is() )
389 xInStr->closeInput();
391 uno::Reference< io::XOutputStream > xOutStr = m_xStream->getOutputStream();
392 if ( xOutStr.is() )
393 xOutStr->closeOutput();
395 m_xStream = uno::Reference< io::XStream >();
398 catch( uno::Exception& aException )
400 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
401 AddLog( aException.Message );
407 //-----------------------------------------------
408 void OStorage_Impl::AddLog( const ::rtl::OUString& aMessage )
410 if ( !m_xLogRing.is() )
414 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
415 if ( aContext.is() )
416 m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW );
418 catch( uno::Exception& )
420 // No log
424 if ( m_xLogRing.is() )
425 m_xLogRing->logString( aMessage );
428 //-----------------------------------------------
429 void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage )
431 // Weak reference is used inside the holder so the refcount must not be zero at this point
432 OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" );
433 m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) );
436 //-----------------------------------------------
437 void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage )
439 for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
440 pStorageIter != m_aReadOnlyWrapList.end();)
442 uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
443 if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage )
445 try {
446 pStorageIter->m_pPointer->InternalDispose( sal_False );
447 } catch( uno::Exception& aException )
449 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
450 AddLog( aException.Message );
453 OStorageList_Impl::iterator pIterToDelete( pStorageIter );
454 pStorageIter++;
455 m_aReadOnlyWrapList.erase( pIterToDelete );
457 else
458 pStorageIter++;
462 //-----------------------------------------------
463 void OStorage_Impl::OpenOwnPackage()
465 OSL_ENSURE( m_bIsRoot, "Opening of the package has no sence!\n" );
467 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
469 if ( !m_xPackageFolder.is() )
471 if ( !m_xPackage.is() )
473 uno::Sequence< uno::Any > aArguments( 2 );
474 if ( m_nStorageMode & embed::ElementModes::WRITE )
475 aArguments[ 0 ] <<= m_xStream;
476 else
478 OSL_ENSURE( m_xInputStream.is(), "Input stream must be set for readonly access!\n" );
479 aArguments[ 0 ] <<= m_xInputStream;
480 // TODO: if input stream is not seekable or XSeekable interface is supported
481 // on XStream object a wrapper must be used
484 // do not allow elements to remove themself from the old container in case of insertion to another container
485 aArguments[ 1 ] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowRemoveOnInsert" ) ),
486 uno::makeAny( (sal_Bool)sal_False ) );
488 sal_Int32 nArgNum = 2;
489 for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ )
491 if ( m_xProperties[aInd].Name.equalsAscii( "RepairPackage" )
492 || m_xProperties[aInd].Name.equalsAscii( "ProgressHandler" ) )
494 beans::NamedValue aNamedValue( m_xProperties[aInd].Name,
495 m_xProperties[aInd].Value );
496 aArguments.realloc( ++nArgNum );
497 aArguments[nArgNum-1] <<= aNamedValue;
499 else if ( m_xProperties[aInd].Name.equalsAscii( "Password" ) )
501 // TODO: implement password setting for documents
502 // the password entry must be removed after setting
506 if ( m_nStorageType == ZIP_STORAGE )
508 // let the package support only plain zip format
509 beans::NamedValue aNamedValue;
510 aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
511 aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) );
512 aArguments.realloc( ++nArgNum );
513 aArguments[nArgNum-1] <<= aNamedValue;
515 else if ( m_nStorageType == OFOPXML_STORAGE )
517 // let the package support OFOPXML media type handling
518 beans::NamedValue aNamedValue;
519 aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
520 aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) );
521 aArguments.realloc( ++nArgNum );
522 aArguments[nArgNum-1] <<= aNamedValue;
525 m_xPackage = uno::Reference< lang::XSingleServiceFactory > (
526 GetServiceFactory()->createInstanceWithArguments(
527 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.packages.comp.ZipPackage" ) ),
528 aArguments ),
529 uno::UNO_QUERY );
532 uno::Reference< container::XHierarchicalNameAccess > xHNameAccess( m_xPackage, uno::UNO_QUERY );
533 OSL_ENSURE( xHNameAccess.is(), "The package could not be created!\n" );
535 if ( xHNameAccess.is() )
537 uno::Any aFolder = xHNameAccess->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
538 aFolder >>= m_xPackageFolder;
542 OSL_ENSURE( m_xPackageFolder.is(), "The package root folder can not be opened!\n" );
543 if ( !m_xPackageFolder.is() )
544 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
547 //-----------------------------------------------
548 uno::Reference< lang::XMultiServiceFactory > OStorage_Impl::GetServiceFactory()
550 if ( m_xFactory.is() )
551 return m_xFactory;
553 return ::comphelper::getProcessServiceFactory();
556 //-----------------------------------------------
557 SotElementList_Impl& OStorage_Impl::GetChildrenList()
559 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
561 ReadContents();
562 return m_aChildrenList;
565 //-----------------------------------------------
566 void OStorage_Impl::GetStorageProperties()
568 if ( m_nStorageType == PACKAGE_STORAGE )
570 uno::Reference< beans::XPropertySet > xProps( m_xPackageFolder, uno::UNO_QUERY_THROW );
572 if ( !m_bControlMediaType )
574 uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW );
575 xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) ) >>= m_bMTFallbackUsed;
577 xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType;
578 m_bControlMediaType = sal_True;
581 if ( !m_bControlVersion )
583 xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= m_aVersion;
584 m_bControlVersion = sal_True;
588 // the properties of OFOPXML will be handled directly
591 //-----------------------------------------------
592 void OStorage_Impl::ReadRelInfoIfNecessary()
594 if ( m_nStorageType != OFOPXML_STORAGE )
595 return;
597 if ( m_nRelInfoStatus == RELINFO_NO_INIT )
599 // Init from original stream
600 uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() );
601 if ( xRelInfoStream.is() )
602 m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
603 xRelInfoStream,
604 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ),
605 m_xFactory );
607 m_nRelInfoStatus = RELINFO_READ;
609 else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
611 // Init from the new stream
614 if ( m_xNewRelInfoStream.is() )
615 m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
616 m_xNewRelInfoStream,
617 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ),
618 m_xFactory );
620 m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ;
622 catch( uno::Exception )
624 m_nRelInfoStatus = RELINFO_CHANGED_BROKEN;
629 //-----------------------------------------------
630 void OStorage_Impl::ReadContents()
632 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
634 if ( m_bListCreated )
635 return;
637 if ( m_bIsRoot )
638 OpenOwnPackage();
640 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xPackageFolder, uno::UNO_QUERY );
641 if ( !xEnumAccess.is() )
642 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
644 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
645 if ( !xEnum.is() )
646 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
648 m_bListCreated = sal_True;
650 while( xEnum->hasMoreElements() )
652 try {
653 uno::Reference< container::XNamed > xNamed;
654 xEnum->nextElement() >>= xNamed;
656 if ( !xNamed.is() )
658 OSL_ENSURE( sal_False, "XNamed is not supported!\n" );
659 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
662 ::rtl::OUString aName = xNamed->getName();
663 OSL_ENSURE( aName.getLength(), "Empty name!\n" );
665 uno::Reference< container::XNameContainer > xNameContainer( xNamed, uno::UNO_QUERY );
667 SotElement_Impl* pNewElement = new SotElement_Impl( aName, xNameContainer.is(), sal_False );
668 if ( m_nStorageType == OFOPXML_STORAGE && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
670 if ( !pNewElement->m_bIsStorage )
671 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Unexpected format
673 m_pRelStorElement = pNewElement;
674 CreateRelStorage();
676 else
678 if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
680 // if a storage is truncated all of it elements are marked as deleted
681 pNewElement->m_bIsRemoved = sal_True;
684 m_aChildrenList.push_back( pNewElement );
687 catch( container::NoSuchElementException& aNoSuchElementException )
689 AddLog( aNoSuchElementException.Message );
690 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "NoSuchElement" ) ) );
692 OSL_ENSURE( sal_False, "hasMoreElements() implementation has problems!\n" );
693 break;
696 if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
698 // if a storage is truncated the relations information should be cleaned
699 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
700 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
701 m_nRelInfoStatus = RELINFO_CHANGED;
704 // cache changeable folder properties
705 GetStorageProperties();
708 //-----------------------------------------------
709 void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDest, sal_Bool bDirect )
711 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
713 uno::Reference< beans::XPropertySet > xPropSet( xDest, uno::UNO_QUERY );
714 if ( !xPropSet.is() )
715 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
717 sal_Int32 nDestMode = embed::ElementModes::READ;
718 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nDestMode;
720 if ( !( nDestMode & embed::ElementModes::WRITE ) )
721 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
723 ReadContents();
725 if ( !m_xPackageFolder.is() )
726 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
728 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
729 pElementIter != m_aChildrenList.end(); pElementIter++ )
731 if ( !(*pElementIter)->m_bIsRemoved )
732 CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect );
735 // move storage properties to the destination one ( means changeable properties )
736 if ( m_nStorageType == PACKAGE_STORAGE )
738 ::rtl::OUString aMediaTypeString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
739 ::rtl::OUString aVersionString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) );
740 xPropSet->setPropertyValue( aMediaTypeString, uno::makeAny( m_aMediaType ) );
741 xPropSet->setPropertyValue( aVersionString, uno::makeAny( m_aVersion ) );
744 if ( m_nStorageType == PACKAGE_STORAGE )
746 // if this is a root storage, the common key from current one should be moved there
747 sal_Bool bIsRoot = sal_False;
748 ::rtl::OUString aRootString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsRoot" ) );
749 if ( ( xPropSet->getPropertyValue( aRootString ) >>= bIsRoot ) && bIsRoot )
753 ::rtl::OUString aCommonPass = GetCommonRootPass();
754 uno::Reference< embed::XEncryptionProtectedSource > xEncr( xDest, uno::UNO_QUERY );
755 if ( xEncr.is() )
756 xEncr->setEncryptionPassword( aCommonPass );
758 catch( packages::NoEncryptionException& aNoEncryptionException )
760 AddLog( aNoEncryptionException.Message );
761 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) );
765 else if ( m_nStorageType == OFOPXML_STORAGE )
768 // TODO/LATER: currently the optimization is not active
769 // uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own stream
770 // if ( xRelInfoStream.is() )
771 // {
772 // // Relations info stream is a writeonly property, introduced only to optimyze copying
773 // // Should be used carefuly since no check for stream consistency is done, and the stream must not stay locked
775 // ::rtl::OUString aRelInfoString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) );
776 // xPropSet->setPropertyValue( aRelInfoString, uno::makeAny( GetSeekableTempCopy( xRelInfoStream, m_xFactory ) ) );
777 // }
779 uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
780 if ( !xRels.is() )
781 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
783 xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
786 // if possible the destination storage should be commited after successful copying
787 uno::Reference< embed::XTransactedObject > xObjToCommit( xDest, uno::UNO_QUERY );
788 if ( xObjToCommit.is() )
789 xObjToCommit->commit();
792 //-----------------------------------------------
793 void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
794 uno::Reference< embed::XStorage > xDest,
795 ::rtl::OUString aName,
796 sal_Bool bDirect )
798 OSL_ENSURE( xDest.is(), "No destination storage!\n" );
799 OSL_ENSURE( aName.getLength(), "Empty element name!\n" );
801 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
803 uno::Reference< container::XNameAccess > xDestAccess( xDest, uno::UNO_QUERY );
804 if ( !xDestAccess.is() )
805 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
807 if ( xDestAccess->hasByName( aName )
808 && !( pElement->m_bIsStorage && xDest->isStorageElement( aName ) ) )
809 xDest->removeElement( aName );
811 if ( pElement->m_bIsStorage )
813 uno::Reference< embed::XStorage > xSubDest =
814 xDest->openStorageElement( aName,
815 embed::ElementModes::WRITE );
817 OSL_ENSURE( xSubDest.is(), "No destination substorage!\n" );
819 if ( !pElement->m_pStorage )
821 OpenSubStorage( pElement, embed::ElementModes::READ );
822 if ( !pElement->m_pStorage )
823 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
826 pElement->m_pStorage->CopyToStorage( xSubDest, bDirect );
828 else
830 if ( !pElement->m_pStream )
832 OpenSubStream( pElement );
833 if ( !pElement->m_pStream )
834 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
837 if ( !pElement->m_pStream->IsEncrypted() )
839 if ( bDirect )
841 // fill in the properties for the stream
842 uno::Sequence< beans::PropertyValue > aStrProps(0);
843 uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties();
844 sal_Int32 nNum = 0;
845 for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ )
847 if ( aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) )
848 || aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "Compressed" ) ) ) )
850 aStrProps.realloc( ++nNum );
851 aStrProps[nNum-1].Name = aSrcPkgProps[ind].Name;
852 aStrProps[nNum-1].Value = aSrcPkgProps[ind].Value;
856 if ( m_nStorageType == PACKAGE_STORAGE )
858 aStrProps.realloc( ++nNum );
859 aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
860 aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonPass_Impl() );
862 else if ( m_nStorageType == OFOPXML_STORAGE )
864 // TODO/LATER: currently the optimization is not active
865 // uno::Reference< io::XInputStream > xInStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own rels stream
866 // if ( xInStream.is() )
867 // {
868 // aStrProps.realloc( ++nNum );
869 // aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) );
870 // aStrProps[nNum-1].Value <<= GetSeekableTempCopy( xInStream, m_xFactory );
871 // }
873 uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
874 if ( !xRels.is() )
875 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
877 xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
880 uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW );
881 uno::Reference < io::XInputStream > xInputToInsert;
883 if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() )
885 OSL_ENSURE( pElement->m_pStream->m_xPackageStream.is(), "No package stream!" );
887 // if the stream is modified - the temporary file must be used for insertion
888 xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream();
890 else
892 // for now get just nonseekable access to the stream
893 // TODO/LATER: the raw stream can be used
895 xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream();
898 if ( !xInputToInsert.is() )
899 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
901 xOptDest->insertStreamElementDirect( aName, xInputToInsert, aStrProps );
903 else
905 uno::Reference< io::XStream > xSubStr =
906 xDest->openStreamElement( aName,
907 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
908 OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
910 pElement->m_pStream->CopyInternallyTo_Impl( xSubStr );
913 else if ( m_nStorageType != PACKAGE_STORAGE )
915 OSL_ENSURE( sal_False, "Encryption is only supported in package storage!\n" );
916 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
918 else if ( pElement->m_pStream->HasCachedPassword()
919 && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) )
921 ::rtl::OUString aCommonPass;
922 sal_Bool bHasCommonPass = sal_False;
925 aCommonPass = GetCommonRootPass();
926 bHasCommonPass = sal_True;
928 catch( packages::NoEncryptionException& aNoEncryptionException )
930 AddLog( aNoEncryptionException.Message );
931 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) );
934 if ( bHasCommonPass && pElement->m_pStream->GetCachedPassword().equals( aCommonPass ) )
936 // If the stream can be opened with the common storage password
937 // it must be stored with the common storage password as well
938 uno::Reference< io::XStream > xDestStream =
939 xDest->openStreamElement( aName,
940 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
942 pElement->m_pStream->CopyInternallyTo_Impl( xDestStream );
944 uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
945 xProps->setPropertyValue(
946 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ),
947 uno::Any( (sal_Bool) sal_True ) );
949 else
951 // the stream is already opened for writing or was changed
952 uno::Reference< io::XStream > xSubStr =
953 xDest->openEncryptedStreamElement( aName,
954 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
955 pElement->m_pStream->GetCachedPassword() );
956 OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
958 pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedPassword() );
961 else
963 // the stream is not opened at all, so it can be just opened for reading
966 // If the stream can be opened with the common storage password
967 // it must be stored with the common storage password as well
969 uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ,
970 sal_False );
971 uno::Reference< io::XStream > xDestStream =
972 xDest->openStreamElement( aName,
973 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
974 OSL_ENSURE( xDestStream.is(), "No destination substream!\n" );
975 completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
977 uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
978 xProps->setPropertyValue(
979 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ),
980 uno::Any( (sal_Bool) sal_True ) );
982 catch( packages::WrongPasswordException& aWrongPasswordException )
984 AddLog( aWrongPasswordException.Message );
985 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) );
987 // If the common storage password does not allow to open the stream
988 // it must be copyed in raw way
989 uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW );
990 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
991 xRawDest->insertRawEncrStreamElement( aName, xRawInStream );
997 //-----------------------------------------------
998 uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelationshipsIfAny()
1000 if ( m_nStorageType != OFOPXML_STORAGE )
1001 return uno::Sequence< uno::Sequence< beans::StringPair > >();
1003 ReadRelInfoIfNecessary();
1005 if ( m_nRelInfoStatus == RELINFO_READ
1006 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
1007 return m_aRelInfo;
1008 else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1009 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong relinfo stream!" ) ),
1010 uno::Reference< uno::XInterface >() );
1013 //-----------------------------------------------
1014 void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor )
1016 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1018 OSL_ENSURE( m_xPackageFolder.is(), "A commited storage is incomplete!\n" );
1019 if ( !m_xPackageFolder.is() )
1020 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1022 OStorage_Impl aTempRepresent( NULL,
1023 embed::ElementModes::READ,
1024 m_xPackageFolder,
1025 m_xPackage,
1026 m_xFactory,
1027 m_nStorageType);
1029 // TODO/LATER: could use direct copying
1030 aTempRepresent.CopyToStorage( xNewStor, sal_False );
1033 //-----------------------------------------------
1034 void OStorage_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName,
1035 const uno::Reference< container::XNameContainer >& xParentPackageFolder )
1037 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1039 OSL_ENSURE( m_xPackageFolder.is(), "An inserted storage is incomplete!\n" );
1040 uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageFolder, uno::UNO_QUERY );
1041 if ( !xTunnel.is() )
1042 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1044 xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) );
1046 m_bCommited = sal_False;
1049 //-----------------------------------------------
1050 void OStorage_Impl::Commit()
1052 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1054 if ( !m_bIsModified )
1055 return;
1057 // in case of a new empty storage it is possible that the contents are still not read
1058 // ( the storage of course has no contents, but the initialization is postponed till the first use,
1059 // thus if a new storage was created and commited immediatelly it must be initialized here )
1060 ReadContents();
1062 // if storage is commited it should have a valid Package representation
1063 OSL_ENSURE( m_xPackageFolder.is(), "The package representation should exist!\n" );
1064 if ( !m_xPackageFolder.is() )
1065 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1067 OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE,
1068 "Commit of readonly storage, should be detected before!\n" );
1070 uno::Reference< container::XNameContainer > xNewPackageFolder;
1072 // here the storage will switch to the temporary package folder
1073 // if the storage was already commited and the parent was not commited after that
1074 // the switch should not be done since the package folder in use is a temporary one;
1075 // it can be detected by m_bCommited flag ( root storage doesn't need temporary representation )
1076 if ( !m_bCommited && !m_bIsRoot )
1078 uno::Sequence< uno::Any > aSeq( 1 );
1079 aSeq[0] <<= sal_True;
1081 xNewPackageFolder = uno::Reference< container::XNameContainer >(
1082 m_xPackage->createInstanceWithArguments( aSeq ),
1083 uno::UNO_QUERY );
1085 else
1086 xNewPackageFolder = m_xPackageFolder;
1088 // remove replaced removed elements
1089 for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1090 pDeletedIter != m_aDeletedList.end();
1091 pDeletedIter++ )
1094 if ( m_nStorageType == OFOPXML_STORAGE && !(*pDeletedIter)->m_bIsStorage )
1095 RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName );
1097 // the removed elements are not in new temporary storage
1098 if ( m_bCommited || m_bIsRoot )
1099 xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName );
1100 delete *pDeletedIter;
1101 *pDeletedIter = NULL;
1103 m_aDeletedList.clear();
1105 // remove removed elements
1106 SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1107 while ( pElementIter != m_aChildrenList.end() )
1109 // renamed and inserted elements must be really inserted to package later
1110 // since thay can conflict with removed elements
1112 if ( (*pElementIter)->m_bIsRemoved )
1114 if ( m_nStorageType == OFOPXML_STORAGE && !(*pElementIter)->m_bIsStorage )
1115 RemoveStreamRelInfo( (*pElementIter)->m_aOriginalName );
1117 // the removed elements are not in new temporary storage
1118 if ( m_bCommited || m_bIsRoot )
1119 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1121 SotElement_Impl* pToDelete = *pElementIter;
1123 pElementIter++; // to let the iterator be valid it should be increased before removing
1125 m_aChildrenList.remove( pToDelete );
1126 delete pToDelete;
1128 else
1129 pElementIter++;
1132 // there should be no more deleted elements
1133 for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ )
1135 // if it is a 'duplicate commit' inserted elements must be really inserted to package later
1136 // since thay can conflict with renamed elements
1138 if ( !(*pElementIter)->m_bIsInserted )
1140 // for now stream is opened in direct mode that means that in case
1141 // storage is commited all the streams from it are commited in current state.
1142 // following two steps are separated to allow easily implement transacted mode
1143 // for streams if we need it in future.
1144 // Only hierarchical access uses transacted streams currently
1145 if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream
1146 && !(*pElementIter)->m_pStream->IsTransacted() )
1147 (*pElementIter)->m_pStream->Commit();
1149 // if the storage was not open, there is no need to commit it ???
1150 // the storage should be checked that it is commited
1151 if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited )
1153 // it's temporary PackageFolder should be inserted instead of current one
1154 // also the new copy of PackageFolder should be used by the children storages
1156 // the renamed elements are not in new temporary storage
1157 if ( m_bCommited || m_bIsRoot )
1158 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1160 (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1162 else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed )
1164 if ( m_nStorageType == OFOPXML_STORAGE )
1165 CommitStreamRelInfo( *pElementIter );
1167 // the renamed elements are not in new temporary storage
1168 if ( m_bCommited || m_bIsRoot )
1169 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1171 (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1173 else if ( !m_bCommited && !m_bIsRoot )
1175 // the element must be just copied to the new temporary package folder
1176 // the connection with the original package should not be lost just because
1177 // the element is still refered by the folder in the original hierarchy
1178 uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1179 xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1181 else if ( (*pElementIter)->m_aName.compareTo( (*pElementIter)->m_aOriginalName ) )
1183 // this is the case when xNewPackageFolder refers to m_xPackageFolder
1184 // in case the name was changed and it is not a changed storage - rename the element
1185 uno::Reference< container::XNamed > xNamed;
1186 uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1187 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1188 xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1190 if ( m_nStorageType == OFOPXML_STORAGE && !(*pElementIter)->m_bIsStorage )
1192 if ( !(*pElementIter)->m_pStream )
1194 OpenSubStream( *pElementIter );
1195 if ( !(*pElementIter)->m_pStream )
1196 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1199 CommitStreamRelInfo( *pElementIter );
1203 (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1207 for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ )
1209 // now inserted elements can be inserted to the package
1210 if ( (*pElementIter)->m_bIsInserted )
1212 (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1213 uno::Reference< lang::XUnoTunnel > xNewElement;
1215 if ( (*pElementIter)->m_bIsStorage )
1217 if ( (*pElementIter)->m_pStorage->m_bCommited )
1219 OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" );
1220 if ( !(*pElementIter)->m_pStorage )
1221 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1223 (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1225 (*pElementIter)->m_bIsInserted = sal_False;
1228 else
1230 OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" );
1231 if ( !(*pElementIter)->m_pStream )
1232 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1234 if ( !(*pElementIter)->m_pStream->IsTransacted() )
1235 (*pElementIter)->m_pStream->Commit();
1237 if ( (*pElementIter)->m_pStream->m_bFlushed )
1239 if ( m_nStorageType == OFOPXML_STORAGE )
1240 CommitStreamRelInfo( *pElementIter );
1242 (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1244 (*pElementIter)->m_bIsInserted = sal_False;
1250 if ( m_nStorageType == PACKAGE_STORAGE )
1252 // move properties to the destination package folder
1253 uno::Reference< beans::XPropertySet > xProps( xNewPackageFolder, uno::UNO_QUERY );
1254 if ( !xProps.is() )
1255 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1257 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), uno::makeAny( m_aMediaType ) );
1258 xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), uno::makeAny( m_aVersion ) );
1261 if ( m_nStorageType == OFOPXML_STORAGE )
1262 CommitRelInfo( xNewPackageFolder ); // store own relations and commit complete relations storage
1264 if ( m_bIsRoot )
1266 uno::Reference< util::XChangesBatch > xChangesBatch( m_xPackage, uno::UNO_QUERY );
1268 OSL_ENSURE( xChangesBatch.is(), "Impossible to commit package!\n" );
1269 if ( !xChangesBatch.is() )
1270 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1274 xChangesBatch->commitChanges();
1276 catch( lang::WrappedTargetException& r )
1278 // the wrapped UseBackupException means that the target medium can be corrupted
1279 embed::UseBackupException aException;
1280 if ( r.TargetException >>= aException )
1282 m_xStream = uno::Reference< io::XStream >();
1283 m_xInputStream = uno::Reference< io::XInputStream >();
1284 throw aException;
1287 AddLog( aException.Message );
1288 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
1289 throw;
1292 else if ( !m_bCommited )
1294 m_xPackageFolder = xNewPackageFolder;
1295 m_bCommited = sal_True;
1298 // after commit the mediatype treated as the correct one
1299 m_bMTFallbackUsed = sal_False;
1302 //-----------------------------------------------
1303 void OStorage_Impl::Revert()
1305 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1307 if ( !( m_nStorageMode & embed::ElementModes::WRITE ) )
1308 return; // nothing to do
1310 // all the children must be removed
1311 // they will be created later on demand
1313 SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1314 while ( pElementIter != m_aChildrenList.end() )
1316 if ( (*pElementIter)->m_bIsInserted )
1318 SotElement_Impl* pToDelete = *pElementIter;
1320 pElementIter++; // to let the iterator be valid it should be increased before removing
1322 m_aChildrenList.remove( pToDelete );
1323 delete pToDelete;
1325 else
1327 ClearElement( *pElementIter );
1329 (*pElementIter)->m_aName = (*pElementIter)->m_aOriginalName;
1330 (*pElementIter)->m_bIsRemoved = sal_False;
1332 pElementIter++;
1336 // return replaced removed elements
1337 for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1338 pDeletedIter != m_aDeletedList.end();
1339 pDeletedIter++ )
1341 m_aChildrenList.push_back( (*pDeletedIter) );
1343 ClearElement( *pDeletedIter );
1345 (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName;
1346 (*pDeletedIter)->m_bIsRemoved = sal_False;
1348 m_aDeletedList.clear();
1350 m_bControlMediaType = sal_False;
1351 m_bControlVersion = sal_False;
1353 GetStorageProperties();
1355 if ( m_nStorageType == OFOPXML_STORAGE )
1357 // currently the relations storage is changed only on commit
1358 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1359 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1360 m_nRelInfoStatus = RELINFO_NO_INIT;
1364 //-----------------------------------------------
1365 ::rtl::OUString OStorage_Impl::GetCommonRootPass()
1366 throw ( packages::NoEncryptionException )
1368 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1370 if ( m_nStorageType != PACKAGE_STORAGE )
1371 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1373 if ( m_bIsRoot )
1375 if ( !m_bHasCommonPassword )
1376 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1378 return m_aCommonPassword;
1380 else
1382 if ( !m_pParent )
1383 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1385 return m_pParent->GetCommonRootPass();
1389 //-----------------------------------------------
1390 SotElement_Impl* OStorage_Impl::FindElement( const ::rtl::OUString& rName )
1392 OSL_ENSURE( rName.getLength(), "Name is empty!" );
1394 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1396 ReadContents();
1398 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1399 pElementIter != m_aChildrenList.end(); pElementIter++ )
1401 if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved )
1402 return *pElementIter;
1405 return NULL;
1408 //-----------------------------------------------
1409 SotElement_Impl* OStorage_Impl::InsertStream( ::rtl::OUString aName, sal_Bool bEncr )
1411 OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1412 if ( !m_xPackage.is() )
1413 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1415 uno::Sequence< uno::Any > aSeq( 1 );
1416 aSeq[0] <<= sal_False;
1417 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1418 uno::UNO_QUERY );
1420 OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" );
1421 if ( !xNewElement.is() )
1422 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1424 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1425 if ( !xPackageSubStream.is() )
1426 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1428 OSL_ENSURE( m_nStorageType == PACKAGE_STORAGE || !bEncr, "Only package storage supports encryption!\n" );
1429 if ( m_nStorageType != PACKAGE_STORAGE && bEncr )
1430 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1432 // the mode is not needed for storage stream internal implementation
1433 SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
1434 pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType, sal_True );
1436 m_aChildrenList.push_back( pNewElement );
1437 m_bIsModified = sal_True;
1438 m_bBroadcastModified = sal_True;
1440 return pNewElement;
1443 //-----------------------------------------------
1444 SotElement_Impl* OStorage_Impl::InsertRawStream( ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInStream )
1446 // insert of raw stream means insert and commit
1447 OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1448 if ( !m_xPackage.is() )
1449 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1451 if ( m_nStorageType != PACKAGE_STORAGE )
1452 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1454 uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
1455 uno::Reference< io::XInputStream > xInStrToInsert = xSeek.is() ? xInStream :
1456 GetSeekableTempCopy( xInStream, GetServiceFactory() );
1458 uno::Sequence< uno::Any > aSeq( 1 );
1459 aSeq[0] <<= sal_False;
1460 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1461 uno::UNO_QUERY );
1463 OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" );
1464 if ( !xNewElement.is() )
1465 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1467 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1468 if ( !xPackageSubStream.is() )
1469 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1471 xPackageSubStream->setRawStream( xInStrToInsert );
1473 // the mode is not needed for storage stream internal implementation
1474 SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
1475 pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType, sal_False );
1476 // the stream is inserted and must be treated as a commited one
1477 pNewElement->m_pStream->SetToBeCommited();
1479 m_aChildrenList.push_back( pNewElement );
1480 m_bIsModified = sal_True;
1481 m_bBroadcastModified = sal_True;
1483 return pNewElement;
1486 //-----------------------------------------------
1487 OStorage_Impl* OStorage_Impl::CreateNewStorageImpl( sal_Int32 nStorageMode )
1489 OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1490 if ( !m_xPackage.is() )
1491 throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1493 uno::Sequence< uno::Any > aSeq( 1 );
1494 aSeq[0] <<= sal_True;
1495 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1496 uno::UNO_QUERY );
1498 OSL_ENSURE( xNewElement.is(), "Not possible to create a new storage!\n" );
1499 if ( !xNewElement.is() )
1500 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1502 uno::Reference< container::XNameContainer > xPackageSubFolder( xNewElement, uno::UNO_QUERY );
1503 if ( !xPackageSubFolder.is() )
1504 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1506 OStorage_Impl* pResult =
1507 new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType );
1508 pResult->m_bIsModified = sal_True;
1510 return pResult;
1513 //-----------------------------------------------
1514 SotElement_Impl* OStorage_Impl::InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode )
1516 SotElement_Impl* pNewElement = InsertElement( aName, sal_True );
1518 pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode );
1520 m_aChildrenList.push_back( pNewElement );
1522 return pNewElement;
1525 //-----------------------------------------------
1526 SotElement_Impl* OStorage_Impl::InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage )
1528 OSL_ENSURE( FindElement( aName ) == NULL, "Should not try to insert existing element" );
1530 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1532 SotElement_Impl* pDeletedElm = NULL;
1534 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1535 pElementIter != m_aChildrenList.end(); pElementIter++ )
1537 if ( (*pElementIter)->m_aName == aName )
1539 OSL_ENSURE( (*pElementIter)->m_bIsRemoved, "Try to insert an element instead of existing one!\n" );
1540 if ( (*pElementIter)->m_bIsRemoved )
1542 OSL_ENSURE( !(*pElementIter)->m_bIsInserted, "Inserted elements must be deleted immediatelly!\n" );
1543 pDeletedElm = *pElementIter;
1544 break;
1549 if ( pDeletedElm )
1551 if ( pDeletedElm->m_bIsStorage )
1552 OpenSubStorage( pDeletedElm, embed::ElementModes::READWRITE );
1553 else
1554 OpenSubStream( pDeletedElm );
1556 m_aChildrenList.remove( pDeletedElm ); // correct usage of list ???
1557 m_aDeletedList.push_back( pDeletedElm );
1560 // create new element
1561 return new SotElement_Impl( aName, bIsStorage, sal_True );
1564 //-----------------------------------------------
1565 void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode )
1567 OSL_ENSURE( pElement, "pElement is not set!\n" );
1568 OSL_ENSURE( pElement->m_bIsStorage, "Storage flag is not set!\n" );
1570 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1572 if ( !pElement->m_pStorage )
1574 OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" );
1576 uno::Reference< lang::XUnoTunnel > xTunnel;
1577 m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1578 if ( !xTunnel.is() )
1579 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1581 uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY );
1583 OSL_ENSURE( xPackageSubFolder.is(), "Can not get XNameContainer interface from folder!\n" );
1585 if ( !xPackageSubFolder.is() )
1586 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1588 pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType );
1592 //-----------------------------------------------
1593 void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
1595 OSL_ENSURE( pElement, "pElement is not set!\n" );
1596 OSL_ENSURE( !pElement->m_bIsStorage, "Storage flag is set!\n" );
1598 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1600 if ( !pElement->m_pStream )
1602 OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" );
1604 uno::Reference< lang::XUnoTunnel > xTunnel;
1605 m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1606 if ( !xTunnel.is() )
1607 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1609 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY );
1610 if ( !xPackageSubStream.is() )
1611 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1613 // the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction
1614 pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, sal_False, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
1618 //-----------------------------------------------
1619 uno::Sequence< ::rtl::OUString > OStorage_Impl::GetElementNames()
1621 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1623 ReadContents();
1625 sal_uInt32 nSize = m_aChildrenList.size();
1626 uno::Sequence< ::rtl::OUString > aElementNames( nSize );
1628 sal_uInt32 nInd = 0;
1629 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1630 pElementIter != m_aChildrenList.end(); pElementIter++ )
1632 if ( !(*pElementIter)->m_bIsRemoved )
1633 aElementNames[nInd++] = (*pElementIter)->m_aName;
1636 aElementNames.realloc( nInd );
1637 return aElementNames;
1640 //-----------------------------------------------
1641 void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
1643 OSL_ENSURE( pElement, "Element must be provided!" );
1645 if ( !pElement )
1646 return;
1648 if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() ))
1649 || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) )
1650 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied
1652 if ( pElement->m_bIsInserted )
1654 m_aChildrenList.remove( pElement );
1655 delete pElement; // ???
1657 else
1659 pElement->m_bIsRemoved = sal_True;
1660 ClearElement( pElement );
1663 // TODO/OFOPXML: the rel stream should be removed as well
1666 //-----------------------------------------------
1667 void OStorage_Impl::ClearElement( SotElement_Impl* pElement )
1669 if ( pElement->m_pStorage )
1671 delete pElement->m_pStorage;
1672 pElement->m_pStorage = NULL;
1675 if ( pElement->m_pStream )
1677 delete pElement->m_pStream;
1678 pElement->m_pStream = NULL;
1682 //-----------------------------------------------
1683 void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName,
1684 sal_Bool bPassProvided,
1685 const ::rtl::OUString& aPass,
1686 uno::Reference< io::XStream >& xTargetStream )
1687 throw ( embed::InvalidStorageException,
1688 lang::IllegalArgumentException,
1689 packages::WrongPasswordException,
1690 io::IOException,
1691 embed::StorageWrappedTargetException,
1692 uno::RuntimeException )
1694 SotElement_Impl *pElement = FindElement( aStreamName );
1695 if ( !pElement )
1697 // element does not exist, throw exception
1698 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
1700 else if ( pElement->m_bIsStorage )
1701 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1703 if ( !pElement->m_pStream )
1704 OpenSubStream( pElement );
1706 if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() )
1708 // the existence of m_pAntiImpl of the child is not interesting,
1709 // the copy will be created internally
1711 // usual copying is not applicable here, only last flushed version of the
1712 // child stream should be used for copiing. Probably the childs m_xPackageStream
1713 // can be used as a base of a new stream, that would be copied to result
1714 // storage. The only problem is that some package streams can be accessed from outside
1715 // at the same time ( now solwed by wrappers that remember own position ).
1717 if ( bPassProvided )
1718 pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aPass );
1719 else
1720 pElement->m_pStream->GetCopyOfLastCommit( xTargetStream );
1722 else
1723 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
1726 //-----------------------------------------------
1727 void OStorage_Impl::RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName )
1729 // this method should be used only in OStorage_Impl::Commit() method
1730 // the aOriginalName can be empty, in this case the storage relation info should be removed
1732 if ( m_nStorageType == OFOPXML_STORAGE && m_xRelStorage.is() )
1734 ::rtl::OUString aRelStreamName = aOriginalName;
1735 aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1737 if ( m_xRelStorage->hasByName( aRelStreamName ) )
1738 m_xRelStorage->removeElement( aRelStreamName );
1742 //-----------------------------------------------
1743 void OStorage_Impl::CreateRelStorage()
1745 if ( m_nStorageType != OFOPXML_STORAGE )
1746 return;
1748 if ( !m_xRelStorage.is() )
1750 if ( !m_pRelStorElement )
1752 m_pRelStorElement = new SotElement_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ), sal_True, sal_True );
1753 m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE );
1754 if ( m_pRelStorElement->m_pStorage )
1755 m_pRelStorElement->m_pStorage->m_pParent = NULL; // the relation storage is completely controlled by parent
1758 if ( !m_pRelStorElement->m_pStorage )
1759 OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE );
1761 if ( !m_pRelStorElement->m_pStorage )
1762 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1764 OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, sal_False );
1765 m_xRelStorage = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
1769 //-----------------------------------------------
1770 void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement )
1772 // this method should be used only in OStorage_Impl::Commit() method
1774 // the stream element must be provided
1775 if ( !pStreamElement )
1776 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1778 if ( m_nStorageType == OFOPXML_STORAGE && pStreamElement->m_pStream )
1780 OSL_ENSURE( pStreamElement->m_aName.getLength(), "The name must not be empty!\n" );
1782 if ( !m_xRelStorage.is() )
1784 // Create new rels storage, this is commit scenario so it must be possible
1785 CreateRelStorage();
1788 pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName );
1792 //-----------------------------------------------
1793 uno::Reference< io::XInputStream > OStorage_Impl::GetRelInfoStreamForName( const ::rtl::OUString& aName )
1795 if ( m_nStorageType == OFOPXML_STORAGE )
1797 ReadContents();
1798 if ( m_xRelStorage.is() )
1800 ::rtl::OUString aRelStreamName = aName;
1801 aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1802 if ( m_xRelStorage->hasByName( aRelStreamName ) )
1804 uno::Reference< io::XStream > xStream = m_xRelStorage->openStreamElement( aRelStreamName, embed::ElementModes::READ );
1805 if ( xStream.is() )
1806 return xStream->getInputStream();
1811 return uno::Reference< io::XInputStream >();
1814 //-----------------------------------------------
1815 void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContainer >& xNewPackageFolder )
1817 // this method should be used only in OStorage_Impl::Commit() method
1818 ::rtl::OUString aRelsStorName( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) );
1820 if ( !xNewPackageFolder.is() )
1821 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1823 if ( m_nStorageType == OFOPXML_STORAGE )
1825 if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN )
1826 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1828 if ( m_nRelInfoStatus == RELINFO_CHANGED
1829 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1830 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1832 if ( m_nRelInfoStatus == RELINFO_CHANGED )
1834 if ( m_aRelInfo.getLength() )
1836 CreateRelStorage();
1838 uno::Reference< io::XStream > xRelsStream =
1839 m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ),
1840 embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1842 uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream();
1843 if ( !xOutStream.is() )
1844 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1846 ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aRelInfo, m_xFactory );
1848 // set the mediatype
1849 uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1850 xPropSet->setPropertyValue(
1851 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1852 uno::makeAny( ::rtl::OUString(
1853 RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
1855 m_nRelInfoStatus = RELINFO_READ;
1857 else if ( m_xRelStorage.is() )
1858 RemoveStreamRelInfo( ::rtl::OUString() ); // remove own rel info
1860 else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1861 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1863 CreateRelStorage();
1865 uno::Reference< io::XStream > xRelsStream =
1866 m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ),
1867 embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1869 uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream();
1870 if ( !xOutputStream.is() )
1871 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1873 uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW );
1874 xSeek->seek( 0 );
1875 ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream );
1877 // set the mediatype
1878 uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1879 xPropSet->setPropertyValue(
1880 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1881 uno::makeAny( ::rtl::OUString(
1882 RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
1884 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1885 if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1887 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1888 m_nRelInfoStatus = RELINFO_NO_INIT;
1890 else
1891 m_nRelInfoStatus = RELINFO_READ;
1895 if ( m_xRelStorage.is() )
1897 if ( m_xRelStorage->hasElements() )
1899 uno::Reference< embed::XTransactedObject > xTrans( m_xRelStorage, uno::UNO_QUERY_THROW );
1900 if ( xTrans.is() )
1901 xTrans->commit();
1904 if ( xNewPackageFolder.is() && xNewPackageFolder->hasByName( aRelsStorName ) )
1905 xNewPackageFolder->removeByName( aRelsStorName );
1907 if ( !m_xRelStorage->hasElements() )
1909 // the empty relations storage should not be created
1910 delete m_pRelStorElement;
1911 m_pRelStorElement = NULL;
1912 m_xRelStorage = uno::Reference< embed::XStorage >();
1914 else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() )
1915 m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder );
1920 //=====================================================
1921 // OStorage implementation
1922 //=====================================================
1924 //-----------------------------------------------
1925 OStorage::OStorage( uno::Reference< io::XInputStream > xInputStream,
1926 sal_Int32 nMode,
1927 uno::Sequence< beans::PropertyValue > xProperties,
1928 uno::Reference< lang::XMultiServiceFactory > xFactory,
1929 sal_Int16 nStorageType )
1930 : m_pImpl( new OStorage_Impl( xInputStream, nMode, xProperties, xFactory, nStorageType ) )
1932 m_pImpl->m_pAntiImpl = this;
1933 m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False );
1936 //-----------------------------------------------
1937 OStorage::OStorage( uno::Reference< io::XStream > xStream,
1938 sal_Int32 nMode,
1939 uno::Sequence< beans::PropertyValue > xProperties,
1940 uno::Reference< lang::XMultiServiceFactory > xFactory,
1941 sal_Int16 nStorageType )
1942 : m_pImpl( new OStorage_Impl( xStream, nMode, xProperties, xFactory, nStorageType ) )
1944 m_pImpl->m_pAntiImpl = this;
1945 m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False );
1948 //-----------------------------------------------
1949 OStorage::OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap )
1950 : m_pImpl( pImpl )
1952 // this call can be done only from OStorage_Impl implementation to create child storage
1953 OSL_ENSURE( m_pImpl && m_pImpl->m_rMutexRef.Is(), "The provided pointer & mutex MUST NOT be empty!\n" );
1955 m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, bReadOnlyWrap );
1957 OSL_ENSURE( ( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ||
1958 m_pData->m_bReadOnlyWrap,
1959 "The wrapper can not allow writing in case implementation does not!\n" );
1961 if ( !bReadOnlyWrap )
1962 m_pImpl->m_pAntiImpl = this;
1965 //-----------------------------------------------
1966 OStorage::~OStorage()
1969 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
1970 if ( m_pImpl )
1972 m_refCount++; // to call dispose
1973 try {
1974 dispose();
1976 catch( uno::RuntimeException& aRuntimeException )
1978 m_pImpl->AddLog( aRuntimeException.Message );
1979 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) );
1984 if ( m_pData )
1986 if ( m_pData->m_pSubElDispListener )
1988 m_pData->m_pSubElDispListener->release();
1989 m_pData->m_pSubElDispListener = NULL;
1992 if ( m_pData->m_pTypeCollection )
1994 delete m_pData->m_pTypeCollection;
1995 m_pData->m_pTypeCollection = NULL;
1998 delete m_pData;
2002 //-----------------------------------------------
2003 void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl )
2005 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::InternalDispose" );
2007 if ( !m_pImpl )
2009 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2010 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2013 // the source object is also a kind of locker for the current object
2014 // since the listeners could dispose the object while being notified
2015 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2016 m_pData->m_aListenersContainer.disposeAndClear( aSource );
2018 if ( m_pData->m_bReadOnlyWrap )
2020 OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener,
2021 "If any subelements are open the listener must exist!\n" );
2023 if ( m_pData->m_pSubElDispListener )
2025 m_pData->m_pSubElDispListener->OwnerIsDisposed();
2027 // iterate through m_pData->m_aOpenSubComponentsList
2028 // deregister m_pData->m_pSubElDispListener and dispose all of them
2029 if ( !m_pData->m_aOpenSubComponentsList.empty() )
2031 for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
2032 pCompIter != m_pData->m_aOpenSubComponentsList.end(); pCompIter++ )
2034 uno::Reference< lang::XComponent > xTmp = (*pCompIter);
2035 if ( xTmp.is() )
2037 xTmp->removeEventListener( uno::Reference< lang::XEventListener >(
2038 static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) );
2040 try {
2041 xTmp->dispose();
2042 } catch( uno::Exception& aException )
2044 m_pImpl->AddLog( aException.Message );
2045 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
2050 m_pData->m_aOpenSubComponentsList.clear();
2054 if ( bNotifyImpl )
2055 m_pImpl->RemoveReadOnlyWrap( *this );
2057 else
2059 m_pImpl->m_pAntiImpl = NULL;
2061 if ( bNotifyImpl )
2063 if ( m_pData->m_bIsRoot )
2064 delete m_pImpl;
2065 else
2067 // the noncommited changes for the storage must be removed
2068 m_pImpl->Revert();
2073 m_pImpl = NULL;
2076 //-----------------------------------------------
2077 void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild )
2079 // this method can only be called by child disposing listener
2081 // this method must not contain any locking
2082 // the locking is done in the listener
2084 if ( !m_pData->m_aOpenSubComponentsList.empty() )
2086 for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
2087 pCompIter != m_pData->m_aOpenSubComponentsList.end(); )
2089 uno::Reference< lang::XComponent > xTmp = (*pCompIter);
2090 if ( !xTmp.is() || xTmp == xChild )
2092 WeakComponentList::iterator pIterToRemove = pCompIter;
2093 pCompIter++;
2094 m_pData->m_aOpenSubComponentsList.erase( pIterToRemove );
2096 else
2097 pCompIter++;
2102 //-----------------------------------------------
2103 void OStorage::BroadcastModifiedIfNecessary()
2105 // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2106 if ( !m_pImpl )
2108 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2109 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2112 if ( !m_pImpl->m_bBroadcastModified )
2113 return;
2115 m_pImpl->m_bBroadcastModified = sal_False;
2117 OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" );
2119 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2121 ::cppu::OInterfaceContainerHelper* pContainer =
2122 m_pData->m_aListenersContainer.getContainer(
2123 ::getCppuType( ( const uno::Reference< util::XModifyListener >*) NULL ) );
2124 if ( pContainer )
2126 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2127 while ( pIterator.hasMoreElements( ) )
2129 ( ( util::XModifyListener* )pIterator.next( ) )->modified( aSource );
2134 //-----------------------------------------------
2135 void OStorage::BroadcastTransaction( sal_Int8 nMessage )
2137 1 - preCommit
2138 2 - commited
2139 3 - preRevert
2140 4 - reverted
2143 // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2144 if ( !m_pImpl )
2146 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2147 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2150 OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" );
2152 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2154 ::cppu::OInterfaceContainerHelper* pContainer =
2155 m_pData->m_aListenersContainer.getContainer(
2156 ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) );
2157 if ( pContainer )
2159 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2160 while ( pIterator.hasMoreElements( ) )
2162 OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" );
2164 switch( nMessage )
2166 case STOR_MESS_PRECOMMIT:
2167 ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource );
2168 break;
2169 case STOR_MESS_COMMITED:
2170 ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource );
2171 break;
2172 case STOR_MESS_PREREVERT:
2173 ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource );
2174 break;
2175 case STOR_MESS_REVERTED:
2176 ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource );
2177 break;
2183 //-----------------------------------------------
2184 SotElement_Impl* OStorage::OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr )
2186 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2188 OSL_ENSURE( !m_pData->m_bReadOnlyWrap || ( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE,
2189 "An element can not be opened for writing in readonly storage!\n" );
2191 SotElement_Impl *pElement = m_pImpl->FindElement( aStreamName );
2192 if ( !pElement )
2194 // element does not exist, check if creation is allowed
2195 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2196 || (( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2197 || ( nOpenMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2198 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2200 // create a new StreamElement and insert it into the list
2201 pElement = m_pImpl->InsertStream( aStreamName, bEncr );
2203 else if ( pElement->m_bIsStorage )
2205 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2208 OSL_ENSURE( pElement, "In case element can not be created an exception must be thrown!" );
2210 if ( !pElement->m_pStream )
2211 m_pImpl->OpenSubStream( pElement );
2213 if ( !pElement->m_pStream )
2214 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2216 return pElement;
2219 //-----------------------------------------------
2220 void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XComponent >& xComponent )
2222 if ( !xComponent.is() )
2223 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2225 if ( !m_pData->m_pSubElDispListener )
2227 m_pData->m_pSubElDispListener = new OChildDispListener_Impl( *this );
2228 m_pData->m_pSubElDispListener->acquire();
2231 xComponent->addEventListener( uno::Reference< lang::XEventListener >(
2232 static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) );
2234 m_pData->m_aOpenSubComponentsList.push_back( xComponent );
2237 //____________________________________________________________________________________________________
2238 // XInterface
2239 //____________________________________________________________________________________________________
2241 //-----------------------------------------------
2242 uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
2243 throw( uno::RuntimeException )
2245 uno::Any aReturn;
2247 // common interfaces
2248 aReturn <<= ::cppu::queryInterface
2249 ( rType
2250 , static_cast<lang::XTypeProvider*> ( this )
2251 , static_cast<embed::XStorage*> ( this )
2252 , static_cast<embed::XTransactedObject*> ( this )
2253 , static_cast<embed::XTransactionBroadcaster*> ( this )
2254 , static_cast<util::XModifiable*> ( this )
2255 , static_cast<container::XNameAccess*> ( this )
2256 , static_cast<container::XElementAccess*> ( this )
2257 , static_cast<lang::XComponent*> ( this )
2258 , static_cast<beans::XPropertySet*> ( this )
2259 , static_cast<embed::XOptimizedStorage*> ( this )
2260 , static_cast<embed::XHierarchicalStorageAccess*> ( this ) );
2262 if ( aReturn.hasValue() == sal_True )
2263 return aReturn ;
2265 if ( m_pData->m_nStorageType == PACKAGE_STORAGE )
2267 if ( m_pData->m_bIsRoot )
2269 aReturn <<= ::cppu::queryInterface
2270 ( rType
2271 , static_cast<embed::XStorageRawAccess*> ( this )
2272 , static_cast<embed::XEncryptionProtectedSource*> ( this ) );
2274 else
2276 aReturn <<= ::cppu::queryInterface
2277 ( rType
2278 , static_cast<embed::XStorageRawAccess*> ( this ) );
2281 else if ( m_pData->m_nStorageType == OFOPXML_STORAGE )
2283 aReturn <<= ::cppu::queryInterface
2284 ( rType
2285 , static_cast<embed::XRelationshipAccess*> ( this ) );
2288 if ( aReturn.hasValue() == sal_True )
2289 return aReturn ;
2291 return OWeakObject::queryInterface( rType );
2294 //-----------------------------------------------
2295 void SAL_CALL OStorage::acquire() throw()
2297 OWeakObject::acquire();
2300 //-----------------------------------------------
2301 void SAL_CALL OStorage::release() throw()
2303 OWeakObject::release();
2306 //____________________________________________________________________________________________________
2307 // XTypeProvider
2308 //____________________________________________________________________________________________________
2310 //-----------------------------------------------
2311 uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
2312 throw( uno::RuntimeException )
2314 if ( m_pData->m_pTypeCollection == NULL )
2316 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2318 if ( m_pData->m_pTypeCollection == NULL )
2320 if ( m_pData->m_nStorageType == PACKAGE_STORAGE )
2322 if ( m_pData->m_bIsRoot )
2324 m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2325 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2326 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2327 , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
2328 , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2329 , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2330 , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2331 , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
2332 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2334 else
2336 m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2337 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2338 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2339 , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
2340 , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2341 , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2342 , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2343 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2346 else if ( m_pData->m_nStorageType == OFOPXML_STORAGE )
2348 m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2349 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2350 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2351 , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2352 , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2353 , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2354 , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL )
2355 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2357 else
2359 m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2360 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2361 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2362 , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2363 , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2364 , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2365 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2370 return m_pData->m_pTypeCollection->getTypes() ;
2373 //-----------------------------------------------
2374 uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId()
2375 throw( uno::RuntimeException )
2377 static ::cppu::OImplementationId* pID = NULL ;
2379 if ( pID == NULL )
2381 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
2383 if ( pID == NULL )
2385 static ::cppu::OImplementationId aID( sal_False ) ;
2386 pID = &aID ;
2390 return pID->getImplementationId() ;
2394 //____________________________________________________________________________________________________
2395 // XStorage
2396 //____________________________________________________________________________________________________
2399 //-----------------------------------------------
2400 void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
2401 throw ( embed::InvalidStorageException,
2402 io::IOException,
2403 lang::IllegalArgumentException,
2404 embed::StorageWrappedTargetException,
2405 uno::RuntimeException )
2407 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyToStorage" );
2409 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2411 if ( !m_pImpl )
2413 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2414 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2417 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
2418 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
2420 try {
2421 m_pImpl->CopyToStorage( xDest, sal_False );
2423 catch( embed::InvalidStorageException& aInvalidStorageException )
2425 m_pImpl->AddLog( aInvalidStorageException.Message );
2426 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2427 throw;
2429 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2431 m_pImpl->AddLog( aIllegalArgumentException.Message );
2432 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2433 throw;
2435 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2437 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2438 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2439 throw;
2441 catch( io::IOException& aIOException )
2443 m_pImpl->AddLog( aIOException.Message );
2444 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2445 throw;
2447 catch( uno::RuntimeException& aRuntimeException )
2449 m_pImpl->AddLog( aRuntimeException.Message );
2450 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2451 throw;
2453 catch( uno::Exception& aException )
2455 m_pImpl->AddLog( aException.Message );
2456 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2458 uno::Any aCaught( ::cppu::getCaughtException() );
2459 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy storage!" ) ),
2460 uno::Reference< io::XInputStream >(),
2461 aCaught );
2465 //-----------------------------------------------
2466 uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement(
2467 const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode )
2468 throw ( embed::InvalidStorageException,
2469 lang::IllegalArgumentException,
2470 packages::WrongPasswordException,
2471 io::IOException,
2472 embed::StorageWrappedTargetException,
2473 uno::RuntimeException )
2475 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStreamElement" );
2477 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2479 if ( !m_pImpl )
2481 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2482 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2485 if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
2486 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2488 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
2489 && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2490 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
2492 if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2493 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2495 uno::Reference< io::XStream > xResult;
2498 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_False );
2499 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
2501 xResult = pElement->m_pStream->GetStream( nOpenMode, sal_False );
2502 OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
2504 if ( m_pData->m_bReadOnlyWrap )
2506 // before the storage disposes the stream it must deregister itself as listener
2507 uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
2508 if ( !xStreamComponent.is() )
2509 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2511 MakeLinkToSubComponent_Impl( xStreamComponent );
2514 catch( embed::InvalidStorageException& aInvalidStorageException )
2516 m_pImpl->AddLog( aInvalidStorageException.Message );
2517 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2518 throw;
2520 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2522 m_pImpl->AddLog( aIllegalArgumentException.Message );
2523 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2524 throw;
2526 catch( packages::WrongPasswordException& aWrongPasswordException )
2528 m_pImpl->AddLog( aWrongPasswordException.Message );
2529 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2530 throw;
2532 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2534 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2535 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2536 throw;
2538 catch( io::IOException& aIOException )
2540 m_pImpl->AddLog( aIOException.Message );
2541 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2542 throw;
2544 catch( uno::RuntimeException& aRuntimeException )
2546 m_pImpl->AddLog( aRuntimeException.Message );
2547 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2548 throw;
2550 catch( uno::Exception& aException )
2552 m_pImpl->AddLog( aException.Message );
2553 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2555 uno::Any aCaught( ::cppu::getCaughtException() );
2556 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open stream element!" ) ),
2557 uno::Reference< io::XInputStream >(),
2558 aCaught );
2561 aGuard.clear();
2563 BroadcastModifiedIfNecessary();
2565 return xResult;
2568 //-----------------------------------------------
2569 uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement(
2570 const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass )
2571 throw ( embed::InvalidStorageException,
2572 lang::IllegalArgumentException,
2573 packages::NoEncryptionException,
2574 packages::WrongPasswordException,
2575 io::IOException,
2576 embed::StorageWrappedTargetException,
2577 uno::RuntimeException )
2579 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" );
2581 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2583 if ( !m_pImpl )
2585 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2586 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2589 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
2590 packages::NoEncryptionException();
2592 if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2593 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2595 if ( !aPass.getLength() )
2596 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
2598 uno::Reference< io::XStream > xResult;
2601 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True );
2602 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
2604 xResult = pElement->m_pStream->GetStream( nOpenMode, aPass, sal_False );
2605 OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
2607 if ( m_pData->m_bReadOnlyWrap )
2609 // before the storage disposes the stream it must deregister itself as listener
2610 uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
2611 if ( !xStreamComponent.is() )
2612 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2614 MakeLinkToSubComponent_Impl( xStreamComponent );
2617 catch( embed::InvalidStorageException& aInvalidStorageException )
2619 m_pImpl->AddLog( aInvalidStorageException.Message );
2620 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2621 throw;
2623 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2625 m_pImpl->AddLog( aIllegalArgumentException.Message );
2626 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2627 throw;
2629 catch( packages::NoEncryptionException& aNoEncryptionException )
2631 m_pImpl->AddLog( aNoEncryptionException.Message );
2632 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2633 throw;
2635 catch( packages::WrongPasswordException& aWrongPasswordException )
2637 m_pImpl->AddLog( aWrongPasswordException.Message );
2638 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2639 throw;
2641 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2643 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2644 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2645 throw;
2647 catch( io::IOException& aIOException )
2649 m_pImpl->AddLog( aIOException.Message );
2650 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2651 throw;
2653 catch( uno::RuntimeException& aRuntimeException )
2655 m_pImpl->AddLog( aRuntimeException.Message );
2656 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2657 throw;
2659 catch( uno::Exception& aException )
2661 m_pImpl->AddLog( aException.Message );
2662 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2664 uno::Any aCaught( ::cppu::getCaughtException() );
2665 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ),
2666 uno::Reference< io::XInputStream >(),
2667 aCaught );
2670 aGuard.clear();
2672 BroadcastModifiedIfNecessary();
2674 return xResult;
2677 //-----------------------------------------------
2678 uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
2679 const ::rtl::OUString& aStorName, sal_Int32 nStorageMode )
2680 throw ( embed::InvalidStorageException,
2681 lang::IllegalArgumentException,
2682 io::IOException,
2683 embed::StorageWrappedTargetException,
2684 uno::RuntimeException )
2686 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStorageElement" );
2688 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2690 if ( !m_pImpl )
2692 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2693 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2696 if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) )
2697 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2699 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
2700 && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2701 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2703 if ( ( nStorageMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2704 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2706 if ( ( nStorageMode & embed::ElementModes::TRUNCATE )
2707 && !( nStorageMode & embed::ElementModes::WRITE ) )
2708 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2710 // it's allways possible to read written storage in this implementation
2711 nStorageMode |= embed::ElementModes::READ;
2713 uno::Reference< embed::XStorage > xResult;
2716 SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
2717 if ( !pElement )
2719 // element does not exist, check if creation is allowed
2720 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2721 || (( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2722 || ( nStorageMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2723 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2725 // create a new StorageElement and insert it into the list
2726 pElement = m_pImpl->InsertStorage( aStorName, nStorageMode );
2728 else if ( !pElement->m_bIsStorage )
2730 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2732 else if ( pElement->m_pStorage )
2734 // storage has already been opened; it may be opened another time, if it the mode allows to do so
2735 if ( pElement->m_pStorage->m_pAntiImpl )
2737 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2739 else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty()
2740 && ( nStorageMode & embed::ElementModes::WRITE ) )
2742 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2744 else
2746 // in case parent storage allows writing the readonly mode of the child storage is
2747 // virtual, that means that it is just enough to change the flag to let it be writable
2748 // and since there is no AntiImpl nobody should be notified about it
2749 pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ;
2751 if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
2753 for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin();
2754 pElementIter != pElement->m_pStorage->m_aChildrenList.end(); )
2756 SotElement_Impl* pElementToDel = (*pElementIter);
2757 pElementIter++;
2759 m_pImpl->RemoveElement( pElementToDel );
2765 if ( !pElement->m_pStorage )
2766 m_pImpl->OpenSubStorage( pElement, nStorageMode );
2768 if ( !pElement->m_pStorage )
2769 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
2771 sal_Bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE );
2772 OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap );
2773 xResult = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
2775 if ( bReadOnlyWrap )
2777 // Before this call is done the object must be refcounted already
2778 pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage );
2780 // before the storage disposes the stream it must deregister itself as listener
2781 uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY );
2782 if ( !xStorageComponent.is() )
2783 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2785 MakeLinkToSubComponent_Impl( xStorageComponent );
2788 catch( embed::InvalidStorageException& aInvalidStorageException )
2790 m_pImpl->AddLog( aInvalidStorageException.Message );
2791 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2792 throw;
2794 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2796 m_pImpl->AddLog( aIllegalArgumentException.Message );
2797 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2798 throw;
2800 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2802 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2803 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2804 throw;
2806 catch( io::IOException& aIOException )
2808 m_pImpl->AddLog( aIOException.Message );
2809 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2810 throw;
2812 catch( uno::RuntimeException& aRuntimeException )
2814 m_pImpl->AddLog( aRuntimeException.Message );
2815 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2816 throw;
2818 catch( uno::Exception& aException )
2820 m_pImpl->AddLog( aException.Message );
2821 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2823 uno::Any aCaught( ::cppu::getCaughtException() );
2824 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open storage!" ) ),
2825 uno::Reference< io::XInputStream >(),
2826 aCaught );
2829 return xResult;
2832 //-----------------------------------------------
2833 uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl::OUString& aStreamName )
2834 throw ( embed::InvalidStorageException,
2835 lang::IllegalArgumentException,
2836 packages::WrongPasswordException,
2837 io::IOException,
2838 embed::StorageWrappedTargetException,
2839 uno::RuntimeException )
2841 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneStreamElement" );
2843 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2845 if ( !m_pImpl )
2847 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2848 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2851 if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
2852 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2854 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
2855 && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2856 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2860 uno::Reference< io::XStream > xResult;
2861 m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xResult );
2862 if ( !xResult.is() )
2863 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2864 return xResult;
2866 catch( embed::InvalidStorageException& aInvalidStorageException )
2868 m_pImpl->AddLog( aInvalidStorageException.Message );
2869 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2870 throw;
2872 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2874 m_pImpl->AddLog( aIllegalArgumentException.Message );
2875 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2876 throw;
2878 catch( packages::WrongPasswordException& aWrongPasswordException )
2880 m_pImpl->AddLog( aWrongPasswordException.Message );
2881 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2882 throw;
2884 catch( io::IOException& aIOException )
2886 m_pImpl->AddLog( aIOException.Message );
2887 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2888 throw;
2890 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2892 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2893 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2894 throw;
2896 catch( uno::RuntimeException& aRuntimeException )
2898 m_pImpl->AddLog( aRuntimeException.Message );
2899 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2900 throw;
2902 catch( uno::Exception& aException )
2904 m_pImpl->AddLog( aException.Message );
2905 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2907 uno::Any aCaught( ::cppu::getCaughtException() );
2908 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone stream!" ) ),
2909 uno::Reference< io::XInputStream >(),
2910 aCaught );
2914 //-----------------------------------------------
2915 uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement(
2916 const ::rtl::OUString& aStreamName,
2917 const ::rtl::OUString& aPass )
2918 throw ( embed::InvalidStorageException,
2919 lang::IllegalArgumentException,
2920 packages::NoEncryptionException,
2921 packages::WrongPasswordException,
2922 io::IOException,
2923 embed::StorageWrappedTargetException,
2924 uno::RuntimeException )
2926 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" );
2928 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2930 if ( !m_pImpl )
2932 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2933 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2936 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
2937 packages::NoEncryptionException();
2939 if ( !aPass.getLength() )
2940 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
2944 uno::Reference< io::XStream > xResult;
2945 m_pImpl->CloneStreamElement( aStreamName, sal_True, aPass, xResult );
2946 if ( !xResult.is() )
2947 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2948 return xResult;
2950 catch( embed::InvalidStorageException& aInvalidStorageException )
2952 m_pImpl->AddLog( aInvalidStorageException.Message );
2953 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2954 throw;
2956 catch( lang::IllegalArgumentException& aIllegalArgumentException )
2958 m_pImpl->AddLog( aIllegalArgumentException.Message );
2959 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2960 throw;
2962 catch( packages::NoEncryptionException& aNoEncryptionException )
2964 m_pImpl->AddLog( aNoEncryptionException.Message );
2965 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2966 throw;
2968 catch( packages::WrongPasswordException& aWrongPasswordException )
2970 m_pImpl->AddLog( aWrongPasswordException.Message );
2971 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2972 throw;
2974 catch( io::IOException& aIOException )
2976 m_pImpl->AddLog( aIOException.Message );
2977 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2978 throw;
2980 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2982 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2983 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2984 throw;
2986 catch( uno::RuntimeException& aRuntimeException )
2988 m_pImpl->AddLog( aRuntimeException.Message );
2989 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2990 throw;
2992 catch( uno::Exception& aException )
2994 m_pImpl->AddLog( aException.Message );
2995 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2997 uno::Any aCaught( ::cppu::getCaughtException() );
2998 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ),
2999 uno::Reference< io::XInputStream >(),
3000 aCaught );
3004 //-----------------------------------------------
3005 void SAL_CALL OStorage::copyLastCommitTo(
3006 const uno::Reference< embed::XStorage >& xTargetStorage )
3007 throw ( embed::InvalidStorageException,
3008 lang::IllegalArgumentException,
3009 io::IOException,
3010 embed::StorageWrappedTargetException,
3011 uno::RuntimeException )
3013 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyLastCommitTo" );
3015 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3017 if ( !m_pImpl )
3019 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3020 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3025 m_pImpl->CopyLastCommitTo( xTargetStorage );
3027 catch( embed::InvalidStorageException& aInvalidStorageException )
3029 m_pImpl->AddLog( aInvalidStorageException.Message );
3030 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3031 throw;
3033 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3035 m_pImpl->AddLog( aIllegalArgumentException.Message );
3036 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3037 throw;
3039 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3041 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3042 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3043 throw;
3045 catch( io::IOException& aIOException )
3047 m_pImpl->AddLog( aIOException.Message );
3048 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3049 throw;
3051 catch( uno::RuntimeException& aRuntimeException )
3053 m_pImpl->AddLog( aRuntimeException.Message );
3054 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3055 throw;
3057 catch( uno::Exception& aException )
3059 m_pImpl->AddLog( aException.Message );
3060 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3062 uno::Any aCaught( ::cppu::getCaughtException() );
3063 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit version!" ) ),
3064 uno::Reference< io::XInputStream >(),
3065 aCaught );
3070 //-----------------------------------------------
3071 void SAL_CALL OStorage::copyStorageElementLastCommitTo(
3072 const ::rtl::OUString& aStorName,
3073 const uno::Reference< embed::XStorage >& xTargetStorage )
3074 throw ( embed::InvalidStorageException,
3075 lang::IllegalArgumentException,
3076 io::IOException,
3077 embed::StorageWrappedTargetException,
3078 uno::RuntimeException )
3080 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyStorageElementLastCommitTo" );
3082 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3084 if ( !m_pImpl )
3086 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3087 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3090 if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) )
3091 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3093 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3094 && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3095 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
3097 // it's allways possible to read written storage in this implementation
3098 sal_Int32 nStorageMode = embed::ElementModes::READ;
3102 SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
3103 if ( !pElement )
3105 // element does not exist, throw exception
3106 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
3108 else if ( !pElement->m_bIsStorage )
3110 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3113 if ( !pElement->m_pStorage )
3114 m_pImpl->OpenSubStorage( pElement, nStorageMode );
3116 uno::Reference< embed::XStorage > xResult;
3117 if ( pElement->m_pStorage )
3119 // the existence of m_pAntiImpl of the child is not interesting,
3120 // the copy will be created internally
3122 pElement->m_pStorage->CopyLastCommitTo( xTargetStorage );
3124 else
3125 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
3127 catch( embed::InvalidStorageException& aInvalidStorageException )
3129 m_pImpl->AddLog( aInvalidStorageException.Message );
3130 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3131 throw;
3133 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3135 m_pImpl->AddLog( aIllegalArgumentException.Message );
3136 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3137 throw;
3139 catch( io::IOException& aIOException )
3141 m_pImpl->AddLog( aIOException.Message );
3142 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3143 throw;
3145 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3147 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3148 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3149 throw;
3151 catch( uno::RuntimeException& aRuntimeException )
3153 m_pImpl->AddLog( aRuntimeException.Message );
3154 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3155 throw;
3157 catch( uno::Exception& aException )
3159 m_pImpl->AddLog( aException.Message );
3160 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3162 uno::Any aCaught( ::cppu::getCaughtException() );
3163 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit element version!" ) ),
3164 uno::Reference< io::XInputStream >(),
3165 aCaught );
3169 //-----------------------------------------------
3170 sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName )
3171 throw ( embed::InvalidStorageException,
3172 lang::IllegalArgumentException,
3173 container::NoSuchElementException,
3174 uno::RuntimeException )
3176 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3178 if ( !m_pImpl )
3180 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3181 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3184 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3185 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3187 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3188 && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3189 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
3191 SotElement_Impl* pElement = NULL;
3195 pElement = m_pImpl->FindElement( aElementName );
3197 catch( embed::InvalidStorageException& aInvalidStorageException )
3199 m_pImpl->AddLog( aInvalidStorageException.Message );
3200 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3201 throw;
3203 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3205 m_pImpl->AddLog( aIllegalArgumentException.Message );
3206 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3207 throw;
3209 catch( container::NoSuchElementException& aNoSuchElementException )
3211 m_pImpl->AddLog( aNoSuchElementException.Message );
3212 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3213 throw;
3215 catch( uno::RuntimeException& aRuntimeException )
3217 m_pImpl->AddLog( aRuntimeException.Message );
3218 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3219 throw;
3221 catch( uno::Exception& aException )
3223 m_pImpl->AddLog( aException.Message );
3224 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3226 uno::Any aCaught( ::cppu::getCaughtException() );
3227 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ),
3228 uno::Reference< io::XInputStream >(),
3229 aCaught );
3232 if ( !pElement )
3233 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3235 return !pElement->m_bIsStorage;
3238 //-----------------------------------------------
3239 sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementName )
3240 throw ( embed::InvalidStorageException,
3241 lang::IllegalArgumentException,
3242 container::NoSuchElementException,
3243 uno::RuntimeException )
3245 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3247 if ( !m_pImpl )
3249 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3250 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3253 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3254 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3256 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3257 && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3258 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
3260 SotElement_Impl* pElement = NULL;
3264 pElement = m_pImpl->FindElement( aElementName );
3266 catch( embed::InvalidStorageException& aInvalidStorageException )
3268 m_pImpl->AddLog( aInvalidStorageException.Message );
3269 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3270 throw;
3272 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3274 m_pImpl->AddLog( aIllegalArgumentException.Message );
3275 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3276 throw;
3278 catch( container::NoSuchElementException& aNoSuchElementException )
3280 m_pImpl->AddLog( aNoSuchElementException.Message );
3281 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3282 throw;
3284 catch( uno::RuntimeException& aRuntimeException )
3286 m_pImpl->AddLog( aRuntimeException.Message );
3287 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3288 throw;
3290 catch( uno::Exception& aException )
3292 m_pImpl->AddLog( aException.Message );
3293 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3295 uno::Any aCaught( ::cppu::getCaughtException() );
3296 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "can't detect whether it is a storage" ) ),
3297 uno::Reference< io::XInputStream >(),
3298 aCaught );
3301 if ( !pElement )
3302 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3304 return pElement->m_bIsStorage;
3307 //-----------------------------------------------
3308 void SAL_CALL OStorage::removeElement( const ::rtl::OUString& aElementName )
3309 throw ( embed::InvalidStorageException,
3310 lang::IllegalArgumentException,
3311 container::NoSuchElementException,
3312 io::IOException,
3313 embed::StorageWrappedTargetException,
3314 uno::RuntimeException )
3316 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeElement" );
3318 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3320 if ( !m_pImpl )
3322 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3323 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3326 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3327 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3329 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3330 && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3331 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
3333 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3334 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3338 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3340 if ( !pElement )
3341 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3343 m_pImpl->RemoveElement( pElement );
3345 m_pImpl->m_bIsModified = sal_True;
3346 m_pImpl->m_bBroadcastModified = sal_True;
3348 catch( embed::InvalidStorageException& aInvalidStorageException )
3350 m_pImpl->AddLog( aInvalidStorageException.Message );
3351 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3352 throw;
3354 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3356 m_pImpl->AddLog( aIllegalArgumentException.Message );
3357 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3358 throw;
3360 catch( container::NoSuchElementException& aNoSuchElementException )
3362 m_pImpl->AddLog( aNoSuchElementException.Message );
3363 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3364 throw;
3366 catch( io::IOException& aIOException )
3368 m_pImpl->AddLog( aIOException.Message );
3369 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3370 throw;
3372 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3374 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3375 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3376 throw;
3378 catch( uno::RuntimeException& aRuntimeException )
3380 m_pImpl->AddLog( aRuntimeException.Message );
3381 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3382 throw;
3384 catch( uno::Exception& aException )
3386 m_pImpl->AddLog( aException.Message );
3387 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3389 uno::Any aCaught( ::cppu::getCaughtException() );
3390 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't remove element!" ) ),
3391 uno::Reference< io::XInputStream >(),
3392 aCaught );
3395 aGuard.clear();
3397 BroadcastModifiedIfNecessary();
3400 //-----------------------------------------------
3401 void SAL_CALL OStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName )
3402 throw ( embed::InvalidStorageException,
3403 lang::IllegalArgumentException,
3404 container::NoSuchElementException,
3405 container::ElementExistException,
3406 io::IOException,
3407 embed::StorageWrappedTargetException,
3408 uno::RuntimeException )
3410 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::renameElement" );
3412 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3414 if ( !m_pImpl )
3416 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3417 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3420 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3421 || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3422 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3424 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3425 && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3426 || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3427 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name
3429 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3430 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3434 SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName );
3435 if ( pRefElement )
3436 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3438 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3439 if ( !pElement )
3440 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3442 pElement->m_aName = aNewName;
3444 m_pImpl->m_bIsModified = sal_True;
3445 m_pImpl->m_bBroadcastModified = sal_True;
3447 catch( embed::InvalidStorageException& aInvalidStorageException )
3449 m_pImpl->AddLog( aInvalidStorageException.Message );
3450 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3451 throw;
3453 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3455 m_pImpl->AddLog( aIllegalArgumentException.Message );
3456 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3457 throw;
3459 catch( container::NoSuchElementException& aNoSuchElementException )
3461 m_pImpl->AddLog( aNoSuchElementException.Message );
3462 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3463 throw;
3465 catch( container::ElementExistException& aElementExistException )
3467 m_pImpl->AddLog( aElementExistException.Message );
3468 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3469 throw;
3471 catch( io::IOException& aIOException )
3473 m_pImpl->AddLog( aIOException.Message );
3474 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3475 throw;
3477 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3479 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3480 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3481 throw;
3483 catch( uno::RuntimeException& aRuntimeException )
3485 m_pImpl->AddLog( aRuntimeException.Message );
3486 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3487 throw;
3489 catch( uno::Exception& aException )
3491 m_pImpl->AddLog( aException.Message );
3492 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3494 uno::Any aCaught( ::cppu::getCaughtException() );
3495 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't rename element!" ) ),
3496 uno::Reference< io::XInputStream >(),
3497 aCaught );
3500 aGuard.clear();
3502 BroadcastModifiedIfNecessary();
3505 //-----------------------------------------------
3506 void SAL_CALL OStorage::copyElementTo( const ::rtl::OUString& aElementName,
3507 const uno::Reference< embed::XStorage >& xDest,
3508 const ::rtl::OUString& aNewName )
3509 throw ( embed::InvalidStorageException,
3510 lang::IllegalArgumentException,
3511 container::NoSuchElementException,
3512 container::ElementExistException,
3513 io::IOException,
3514 embed::StorageWrappedTargetException,
3515 uno::RuntimeException )
3517 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementTo" );
3519 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3521 if ( !m_pImpl )
3523 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3524 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3527 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3528 || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3529 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3531 if ( !xDest.is() )
3532 // || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3533 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3535 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3536 && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3537 || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3538 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3542 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3543 if ( !pElement )
3544 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3546 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3547 if ( !xNameAccess.is() )
3548 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3550 if ( xNameAccess->hasByName( aNewName ) )
3551 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3553 m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False );
3555 catch( embed::InvalidStorageException& aInvalidStorageException )
3557 m_pImpl->AddLog( aInvalidStorageException.Message );
3558 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3559 throw;
3561 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3563 m_pImpl->AddLog( aIllegalArgumentException.Message );
3564 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3565 throw;
3567 catch( container::NoSuchElementException& aNoSuchElementException )
3569 m_pImpl->AddLog( aNoSuchElementException.Message );
3570 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3571 throw;
3573 catch( container::ElementExistException& aElementExistException )
3575 m_pImpl->AddLog( aElementExistException.Message );
3576 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3577 throw;
3579 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3581 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3582 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3583 throw;
3585 catch( io::IOException& aIOException )
3587 m_pImpl->AddLog( aIOException.Message );
3588 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3589 throw;
3591 catch( uno::RuntimeException& aRuntimeException )
3593 m_pImpl->AddLog( aRuntimeException.Message );
3594 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3595 throw;
3597 catch( uno::Exception& aException )
3599 m_pImpl->AddLog( aException.Message );
3600 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3602 uno::Any aCaught( ::cppu::getCaughtException() );
3603 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element!" ) ),
3604 uno::Reference< io::XInputStream >(),
3605 aCaught );
3610 //-----------------------------------------------
3611 void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName,
3612 const uno::Reference< embed::XStorage >& xDest,
3613 const ::rtl::OUString& aNewName )
3614 throw ( embed::InvalidStorageException,
3615 lang::IllegalArgumentException,
3616 container::NoSuchElementException,
3617 container::ElementExistException,
3618 io::IOException,
3619 embed::StorageWrappedTargetException,
3620 uno::RuntimeException )
3622 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::moveElementTo" );
3624 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3626 if ( !m_pImpl )
3628 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3629 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3632 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3633 || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3634 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3636 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3637 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3639 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
3640 && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3641 || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3642 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3644 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3645 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3649 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3650 if ( !pElement )
3651 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3653 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3654 if ( !xNameAccess.is() )
3655 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3657 if ( xNameAccess->hasByName( aNewName ) )
3658 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3660 m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False );
3662 m_pImpl->RemoveElement( pElement );
3664 m_pImpl->m_bIsModified = sal_True;
3665 m_pImpl->m_bBroadcastModified = sal_True;
3667 catch( embed::InvalidStorageException& aInvalidStorageException )
3669 m_pImpl->AddLog( aInvalidStorageException.Message );
3670 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3671 throw;
3673 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3675 m_pImpl->AddLog( aIllegalArgumentException.Message );
3676 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3677 throw;
3679 catch( container::NoSuchElementException& aNoSuchElementException )
3681 m_pImpl->AddLog( aNoSuchElementException.Message );
3682 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3683 throw;
3685 catch( container::ElementExistException& aElementExistException )
3687 m_pImpl->AddLog( aElementExistException.Message );
3688 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3689 throw;
3691 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3693 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3694 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3695 throw;
3697 catch( io::IOException& aIOException )
3699 m_pImpl->AddLog( aIOException.Message );
3700 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3701 throw;
3703 catch( uno::RuntimeException& aRuntimeException )
3705 m_pImpl->AddLog( aRuntimeException.Message );
3706 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3707 throw;
3709 catch( uno::Exception& aException )
3711 m_pImpl->AddLog( aException.Message );
3712 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3714 uno::Any aCaught( ::cppu::getCaughtException() );
3715 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't move element!" ) ),
3716 uno::Reference< io::XInputStream >(),
3717 aCaught );
3720 aGuard.clear();
3722 BroadcastModifiedIfNecessary();
3725 //____________________________________________________________________________________________________
3726 // XStorageRawAccess
3727 //____________________________________________________________________________________________________
3729 //-----------------------------------------------
3730 uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement(
3731 const ::rtl::OUString& sStreamName )
3732 throw ( embed::InvalidStorageException,
3733 lang::IllegalArgumentException,
3734 container::NoSuchElementException,
3735 io::IOException,
3736 embed::StorageWrappedTargetException,
3737 uno::RuntimeException )
3739 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPlainRawStreamElement" );
3741 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3743 if ( !m_pImpl )
3745 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3746 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3749 if ( m_pData->m_nStorageType == OFOPXML_STORAGE )
3750 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface is not supported and must not be accessible
3752 if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) )
3753 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3755 uno::Reference < io::XInputStream > xTempIn;
3758 SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3759 if ( !pElement )
3760 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3762 if ( !pElement->m_pStream )
3764 m_pImpl->OpenSubStream( pElement );
3765 if ( !pElement->m_pStream )
3766 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3769 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream();
3770 if ( !xRawInStream.is() )
3771 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3773 uno::Reference < io::XOutputStream > xTempOut(
3774 m_pImpl->GetServiceFactory()->createInstance (
3775 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
3776 uno::UNO_QUERY );
3777 xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY );
3778 uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3780 if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3781 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3783 // Copy temporary file to a new one
3784 ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3785 xTempOut->closeOutput();
3786 xSeek->seek( 0 );
3788 catch( embed::InvalidStorageException& aInvalidStorageException )
3790 m_pImpl->AddLog( aInvalidStorageException.Message );
3791 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3792 throw;
3794 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3796 m_pImpl->AddLog( aIllegalArgumentException.Message );
3797 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3798 throw;
3800 catch( container::NoSuchElementException& aNoSuchElementException )
3802 m_pImpl->AddLog( aNoSuchElementException.Message );
3803 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3804 throw;
3806 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3808 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3809 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3810 throw;
3812 catch( io::IOException& aIOException )
3814 m_pImpl->AddLog( aIOException.Message );
3815 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3816 throw;
3818 catch( uno::RuntimeException& aRuntimeException )
3820 m_pImpl->AddLog( aRuntimeException.Message );
3821 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3822 throw;
3824 catch( uno::Exception& aException )
3826 m_pImpl->AddLog( aException.Message );
3827 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3829 uno::Any aCaught( ::cppu::getCaughtException() );
3830 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get plain raw stream!" ) ),
3831 uno::Reference< io::XInputStream >(),
3832 aCaught );
3835 return xTempIn;
3838 //-----------------------------------------------
3839 uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement(
3840 const ::rtl::OUString& sStreamName )
3841 throw ( embed::InvalidStorageException,
3842 lang::IllegalArgumentException,
3843 packages::NoEncryptionException,
3844 container::NoSuchElementException,
3845 io::IOException,
3846 embed::StorageWrappedTargetException,
3847 uno::RuntimeException )
3849 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getRawEncrStreamElement" );
3851 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3853 if ( !m_pImpl )
3855 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3856 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3859 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
3860 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3862 if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) )
3863 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3865 uno::Reference < io::XInputStream > xTempIn;
3868 SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3869 if ( !pElement )
3870 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3872 if ( !pElement->m_pStream )
3874 m_pImpl->OpenSubStream( pElement );
3875 if ( !pElement->m_pStream )
3876 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3879 if ( !pElement->m_pStream->IsEncrypted() )
3880 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3882 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
3883 if ( !xRawInStream.is() )
3884 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3886 uno::Reference < io::XOutputStream > xTempOut(
3887 m_pImpl->GetServiceFactory()->createInstance (
3888 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
3889 uno::UNO_QUERY );
3890 xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY );
3891 uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3893 if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3894 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3896 // Copy temporary file to a new one
3897 ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3898 xTempOut->closeOutput();
3899 xSeek->seek( 0 );
3902 catch( embed::InvalidStorageException& aInvalidStorageException )
3904 m_pImpl->AddLog( aInvalidStorageException.Message );
3905 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3906 throw;
3908 catch( lang::IllegalArgumentException& aIllegalArgumentException )
3910 m_pImpl->AddLog( aIllegalArgumentException.Message );
3911 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3912 throw;
3914 catch( packages::NoEncryptionException& aNoEncryptionException )
3916 m_pImpl->AddLog( aNoEncryptionException.Message );
3917 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3918 throw;
3920 catch( container::NoSuchElementException& aNoSuchElementException )
3922 m_pImpl->AddLog( aNoSuchElementException.Message );
3923 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3924 throw;
3926 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3928 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3929 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3930 throw;
3932 catch( io::IOException& aIOException )
3934 m_pImpl->AddLog( aIOException.Message );
3935 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3936 throw;
3938 catch( uno::RuntimeException& aRuntimeException )
3940 m_pImpl->AddLog( aRuntimeException.Message );
3941 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3942 throw;
3944 catch( uno::Exception& aException )
3946 m_pImpl->AddLog( aException.Message );
3947 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3949 uno::Any aCaught( ::cppu::getCaughtException() );
3950 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get raw stream!" ) ),
3951 uno::Reference< io::XInputStream >(),
3952 aCaught );
3955 return xTempIn;
3958 //-----------------------------------------------
3959 void SAL_CALL OStorage::insertRawEncrStreamElement( const ::rtl::OUString& aStreamName,
3960 const uno::Reference< io::XInputStream >& xInStream )
3961 throw ( embed::InvalidStorageException,
3962 lang::IllegalArgumentException,
3963 packages::NoRawFormatException,
3964 container::ElementExistException,
3965 io::IOException,
3966 embed::StorageWrappedTargetException,
3967 uno::RuntimeException)
3969 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertRawEncrStreamElement" );
3971 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3973 if ( !m_pImpl )
3975 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3976 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3979 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
3980 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3982 if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
3983 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3985 if ( !xInStream.is() )
3986 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3988 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3989 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3993 SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
3994 if ( pElement )
3995 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3997 m_pImpl->InsertRawStream( aStreamName, xInStream );
3999 catch( embed::InvalidStorageException& aInvalidStorageException )
4001 m_pImpl->AddLog( aInvalidStorageException.Message );
4002 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4003 throw;
4005 catch( lang::IllegalArgumentException& aIllegalArgumentException )
4007 m_pImpl->AddLog( aIllegalArgumentException.Message );
4008 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4009 throw;
4011 catch( packages::NoRawFormatException& aNoRawFormatException )
4013 m_pImpl->AddLog( aNoRawFormatException.Message );
4014 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4015 throw;
4017 catch( container::ElementExistException& aElementExistException )
4019 m_pImpl->AddLog( aElementExistException.Message );
4020 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4021 throw;
4023 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4025 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4026 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4027 throw;
4029 catch( io::IOException& aIOException )
4031 m_pImpl->AddLog( aIOException.Message );
4032 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4033 throw;
4035 catch( uno::RuntimeException& aRuntimeException )
4037 m_pImpl->AddLog( aRuntimeException.Message );
4038 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4039 throw;
4041 catch( uno::Exception& aException )
4043 m_pImpl->AddLog( aException.Message );
4044 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4046 uno::Any aCaught( ::cppu::getCaughtException() );
4047 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert raw stream!" ) ),
4048 uno::Reference< io::XInputStream >(),
4049 aCaught );
4053 //____________________________________________________________________________________________________
4054 // XTransactedObject
4055 //____________________________________________________________________________________________________
4057 //-----------------------------------------------
4058 void SAL_CALL OStorage::commit()
4059 throw ( io::IOException,
4060 embed::StorageWrappedTargetException,
4061 uno::RuntimeException )
4063 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::commit" );
4065 uno::Reference< util::XModifiable > xParentModif;
4067 try {
4068 BroadcastTransaction( STOR_MESS_PRECOMMIT );
4070 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4072 if ( !m_pImpl )
4074 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4075 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4078 if ( m_pData->m_bReadOnlyWrap )
4079 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
4081 m_pImpl->Commit(); // the root storage initiates the storing to source
4083 // when the storage is commited the parent is modified
4084 if ( m_pImpl->m_pParent && m_pImpl->m_pParent->m_pAntiImpl )
4085 xParentModif = (util::XModifiable*)m_pImpl->m_pParent->m_pAntiImpl;
4087 catch( io::IOException& aIOException )
4089 m_pImpl->AddLog( aIOException.Message );
4090 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4091 throw;
4093 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4095 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4096 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4097 throw;
4099 catch( uno::RuntimeException& aRuntimeException )
4101 m_pImpl->AddLog( aRuntimeException.Message );
4102 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4103 throw;
4105 catch( uno::Exception& aException )
4107 m_pImpl->AddLog( aException.Message );
4108 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4110 uno::Any aCaught( ::cppu::getCaughtException() );
4111 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on commit!" ) ),
4112 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
4113 aCaught );
4116 setModified( sal_False );
4117 if ( xParentModif.is() )
4118 xParentModif->setModified( sal_True );
4120 BroadcastTransaction( STOR_MESS_COMMITED );
4123 //-----------------------------------------------
4124 void SAL_CALL OStorage::revert()
4125 throw ( io::IOException,
4126 embed::StorageWrappedTargetException,
4127 uno::RuntimeException )
4129 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::revert" );
4131 // the method removes all the changes done after last commit
4133 BroadcastTransaction( STOR_MESS_PREREVERT );
4135 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4137 if ( !m_pImpl )
4139 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4140 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4143 for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin();
4144 pElementIter != m_pImpl->m_aChildrenList.end(); pElementIter++ )
4146 if ( ((*pElementIter)->m_pStorage
4147 && ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() ))
4148 || ((*pElementIter)->m_pStream
4149 && ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) )
4150 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
4153 if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated )
4154 return; // nothing to do
4156 try {
4157 m_pImpl->Revert();
4158 m_pImpl->m_bIsModified = sal_False;
4159 m_pImpl->m_bBroadcastModified = sal_True;
4161 catch( io::IOException& aIOException )
4163 m_pImpl->AddLog( aIOException.Message );
4164 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4165 throw;
4167 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4169 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4170 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4171 throw;
4173 catch( uno::RuntimeException& aRuntimeException )
4175 m_pImpl->AddLog( aRuntimeException.Message );
4176 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4177 throw;
4179 catch( uno::Exception& aException )
4181 m_pImpl->AddLog( aException.Message );
4182 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4184 uno::Any aCaught( ::cppu::getCaughtException() );
4185 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on revert!" ) ),
4186 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
4187 aCaught );
4190 aGuard.clear();
4192 setModified( sal_False );
4193 BroadcastTransaction( STOR_MESS_REVERTED );
4196 //____________________________________________________________________________________________________
4197 // XTransactionBroadcaster
4198 //____________________________________________________________________________________________________
4200 //-----------------------------------------------
4201 void SAL_CALL OStorage::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4202 throw ( uno::RuntimeException )
4204 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4206 if ( !m_pImpl )
4208 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4209 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4212 m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
4213 aListener );
4216 //-----------------------------------------------
4217 void SAL_CALL OStorage::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4218 throw ( uno::RuntimeException )
4220 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4222 if ( !m_pImpl )
4224 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4225 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4228 m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
4229 aListener );
4232 //____________________________________________________________________________________________________
4233 // XModifiable
4234 // TODO: if there will be no demand on this interface it will be removed from implementation,
4235 // I do not want to remove it now since it is still possible that it will be inserted
4236 // to the service back.
4237 //____________________________________________________________________________________________________
4239 //-----------------------------------------------
4240 sal_Bool SAL_CALL OStorage::isModified()
4241 throw ( uno::RuntimeException )
4243 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4245 if ( !m_pImpl )
4247 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4248 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4251 return m_pImpl->m_bIsModified;
4255 //-----------------------------------------------
4256 void SAL_CALL OStorage::setModified( sal_Bool bModified )
4257 throw ( beans::PropertyVetoException,
4258 uno::RuntimeException )
4260 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4262 if ( !m_pImpl )
4264 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4265 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4268 if ( m_pData->m_bReadOnlyWrap )
4269 throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
4271 if ( m_pImpl->m_bIsModified != bModified )
4272 m_pImpl->m_bIsModified = bModified;
4274 aGuard.clear();
4275 if ( bModified )
4277 m_pImpl->m_bBroadcastModified = sal_True;
4278 BroadcastModifiedIfNecessary();
4282 //-----------------------------------------------
4283 void SAL_CALL OStorage::addModifyListener(
4284 const uno::Reference< util::XModifyListener >& aListener )
4285 throw ( uno::RuntimeException )
4287 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4289 if ( !m_pImpl )
4291 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4292 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4295 m_pData->m_aListenersContainer.addInterface(
4296 ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener );
4300 //-----------------------------------------------
4301 void SAL_CALL OStorage::removeModifyListener(
4302 const uno::Reference< util::XModifyListener >& aListener )
4303 throw ( uno::RuntimeException )
4305 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4307 if ( !m_pImpl )
4309 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4310 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4313 m_pData->m_aListenersContainer.removeInterface(
4314 ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener );
4317 //____________________________________________________________________________________________________
4318 // XNameAccess
4319 //____________________________________________________________________________________________________
4321 //-----------------------------------------------
4322 uno::Any SAL_CALL OStorage::getByName( const ::rtl::OUString& aName )
4323 throw ( container::NoSuchElementException,
4324 lang::WrappedTargetException,
4325 uno::RuntimeException )
4327 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getByName" );
4329 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4331 if ( !m_pImpl )
4333 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4334 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4337 if ( !aName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_False ) )
4338 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
4340 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
4341 && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
4342 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
4344 uno::Any aResult;
4347 SotElement_Impl* pElement = m_pImpl->FindElement( aName );
4348 if ( !pElement )
4349 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4351 if ( pElement->m_bIsStorage )
4352 aResult <<= openStorageElement( aName, embed::ElementModes::READ );
4353 else
4354 aResult <<= openStreamElement( aName, embed::ElementModes::READ );
4356 catch( container::NoSuchElementException& aNoSuchElementException )
4358 m_pImpl->AddLog( aNoSuchElementException.Message );
4359 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4360 throw;
4362 catch( lang::WrappedTargetException& aWrappedTargetException )
4364 m_pImpl->AddLog( aWrappedTargetException.Message );
4365 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4366 throw;
4368 catch( uno::RuntimeException& aRuntimeException )
4370 m_pImpl->AddLog( aRuntimeException.Message );
4371 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4372 throw;
4374 catch ( uno::Exception& aException )
4376 m_pImpl->AddLog( aException.Message );
4377 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4379 uno::Any aCaught( ::cppu::getCaughtException() );
4380 throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4381 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4382 uno::UNO_QUERY ),
4383 aCaught );
4386 return aResult;
4390 //-----------------------------------------------
4391 uno::Sequence< ::rtl::OUString > SAL_CALL OStorage::getElementNames()
4392 throw ( uno::RuntimeException )
4394 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementNames" );
4396 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4398 if ( !m_pImpl )
4400 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4401 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4406 return m_pImpl->GetElementNames();
4408 catch( uno::RuntimeException& aRuntimeException )
4410 m_pImpl->AddLog( aRuntimeException.Message );
4411 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4412 throw;
4414 catch ( uno::Exception& aException )
4416 m_pImpl->AddLog( aException.Message );
4417 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4419 uno::Any aCaught( ::cppu::getCaughtException() );
4420 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4421 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4422 uno::UNO_QUERY ),
4423 aCaught );
4428 //-----------------------------------------------
4429 sal_Bool SAL_CALL OStorage::hasByName( const ::rtl::OUString& aName )
4430 throw ( uno::RuntimeException )
4432 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasByName" );
4434 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4436 if ( !m_pImpl )
4438 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4439 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4442 if ( !aName.getLength() )
4443 return sal_False;
4445 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
4446 && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
4447 return sal_False;
4449 SotElement_Impl* pElement = NULL;
4452 pElement = m_pImpl->FindElement( aName );
4454 catch( uno::RuntimeException& aRuntimeException )
4456 m_pImpl->AddLog( aRuntimeException.Message );
4457 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4458 throw;
4460 catch ( uno::Exception& aException )
4462 m_pImpl->AddLog( aException.Message );
4463 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4465 uno::Any aCaught( ::cppu::getCaughtException() );
4466 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4467 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4468 uno::UNO_QUERY ),
4469 aCaught );
4472 return ( pElement != NULL );
4476 //-----------------------------------------------
4477 uno::Type SAL_CALL OStorage::getElementType()
4478 throw ( uno::RuntimeException )
4480 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4482 if ( !m_pImpl )
4484 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4485 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4488 // it is a multitype container
4489 return uno::Type();
4493 //-----------------------------------------------
4494 sal_Bool SAL_CALL OStorage::hasElements()
4495 throw ( uno::RuntimeException )
4497 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasElements" );
4499 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4501 if ( !m_pImpl )
4503 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4504 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4509 return ( m_pImpl->GetChildrenList().size() != 0 );
4511 catch( uno::RuntimeException& aRuntimeException )
4513 m_pImpl->AddLog( aRuntimeException.Message );
4514 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4515 throw;
4517 catch ( uno::Exception& aException )
4519 m_pImpl->AddLog( aException.Message );
4520 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4522 uno::Any aCaught( ::cppu::getCaughtException() );
4523 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4524 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4525 uno::UNO_QUERY ),
4526 aCaught );
4531 //____________________________________________________________________________________________________
4532 // XComponent
4533 //____________________________________________________________________________________________________
4535 //-----------------------------------------------
4536 void SAL_CALL OStorage::dispose()
4537 throw ( uno::RuntimeException )
4539 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4541 if ( !m_pImpl )
4543 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4544 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4549 InternalDispose( sal_True );
4551 catch( uno::RuntimeException& aRuntimeException )
4553 m_pImpl->AddLog( aRuntimeException.Message );
4554 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4555 throw;
4557 catch ( uno::Exception& aException )
4559 m_pImpl->AddLog( aException.Message );
4560 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4562 uno::Any aCaught( ::cppu::getCaughtException() );
4563 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4564 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4565 uno::UNO_QUERY ),
4566 aCaught );
4570 //-----------------------------------------------
4571 void SAL_CALL OStorage::addEventListener(
4572 const uno::Reference< lang::XEventListener >& xListener )
4573 throw ( uno::RuntimeException )
4575 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4577 if ( !m_pImpl )
4579 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4580 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4583 m_pData->m_aListenersContainer.addInterface(
4584 ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener );
4587 //-----------------------------------------------
4588 void SAL_CALL OStorage::removeEventListener(
4589 const uno::Reference< lang::XEventListener >& xListener )
4590 throw ( uno::RuntimeException )
4592 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4594 if ( !m_pImpl )
4596 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4597 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4600 m_pData->m_aListenersContainer.removeInterface(
4601 ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener );
4604 //____________________________________________________________________________________________________
4605 // XEncryptionProtectedSource
4606 //____________________________________________________________________________________________________
4608 void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
4609 throw ( uno::RuntimeException,
4610 io::IOException )
4612 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" );
4614 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4616 if ( !m_pImpl )
4618 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4619 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4622 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
4623 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4625 OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionPassword() method is not available for nonroot storages!\n" );
4627 if ( m_pData->m_bIsRoot )
4629 try {
4630 m_pImpl->ReadContents();
4632 catch ( uno::RuntimeException& aRuntimeException )
4634 m_pImpl->AddLog( aRuntimeException.Message );
4635 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4636 throw;
4638 catch ( uno::Exception& aException )
4640 m_pImpl->AddLog( aException.Message );
4641 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4643 uno::Any aCaught( ::cppu::getCaughtException() );
4644 throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4645 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4646 uno::UNO_QUERY ),
4647 aCaught );
4650 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
4651 if ( !xPackPropSet.is() )
4652 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4656 xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
4657 uno::makeAny( ::package::MakeKeyFromPass( aPass, sal_True ) ) );
4659 m_pImpl->m_bHasCommonPassword = sal_True;
4660 m_pImpl->m_aCommonPassword = aPass;
4662 catch( uno::Exception& aException )
4664 m_pImpl->AddLog( aException.Message );
4665 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4667 OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" );
4668 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4673 //-----------------------------------------------
4674 void SAL_CALL OStorage::removeEncryption()
4675 throw ( uno::RuntimeException,
4676 io::IOException )
4678 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" );
4680 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4682 if ( !m_pImpl )
4684 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4685 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4688 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
4689 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4691 OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" );
4693 if ( m_pData->m_bIsRoot )
4695 try {
4696 m_pImpl->ReadContents();
4698 catch ( uno::RuntimeException& aRuntimeException )
4700 m_pImpl->AddLog( aRuntimeException.Message );
4701 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4702 throw;
4704 catch ( uno::Exception& aException )
4706 m_pImpl->AddLog( aException.Message );
4707 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4709 uno::Any aCaught( ::cppu::getCaughtException() );
4710 throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4711 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4712 uno::UNO_QUERY ),
4713 aCaught );
4716 // TODO: check if the password is valid
4717 // update all streams that was encrypted with old password
4719 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
4720 if ( !xPackPropSet.is() )
4721 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4725 xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ),
4726 uno::makeAny( uno::Sequence< sal_Int8 >() ) );
4728 m_pImpl->m_bHasCommonPassword = sal_False;
4729 m_pImpl->m_aCommonPassword = ::rtl::OUString();
4731 catch( uno::Exception& aException )
4733 m_pImpl->AddLog( aException.Message );
4734 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4736 OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" );
4737 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4742 //____________________________________________________________________________________________________
4743 // XPropertySet
4744 //____________________________________________________________________________________________________
4746 //-----------------------------------------------
4747 uno::Reference< beans::XPropertySetInfo > SAL_CALL OStorage::getPropertySetInfo()
4748 throw ( uno::RuntimeException )
4750 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4752 if ( !m_pImpl )
4754 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4755 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4758 //TODO:
4759 return uno::Reference< beans::XPropertySetInfo >();
4763 //-----------------------------------------------
4764 void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue )
4765 throw ( beans::UnknownPropertyException,
4766 beans::PropertyVetoException,
4767 lang::IllegalArgumentException,
4768 lang::WrappedTargetException,
4769 uno::RuntimeException )
4771 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setPropertyValue" );
4773 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4775 if ( !m_pImpl )
4777 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4778 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4781 //TODO: think about interaction handler
4783 if ( m_pData->m_bReadOnlyWrap )
4784 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied
4786 if ( m_pData->m_nStorageType == ZIP_STORAGE )
4787 throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4788 else if ( m_pData->m_nStorageType == PACKAGE_STORAGE )
4790 if ( aPropertyName.equalsAscii( "MediaType" ) )
4792 aValue >>= m_pImpl->m_aMediaType;
4793 m_pImpl->m_bControlMediaType = sal_True;
4795 m_pImpl->m_bBroadcastModified = sal_True;
4796 m_pImpl->m_bIsModified = sal_True;
4798 else if ( aPropertyName.equalsAscii( "Version" ) )
4800 aValue >>= m_pImpl->m_aVersion;
4801 m_pImpl->m_bControlVersion = sal_True;
4803 m_pImpl->m_bBroadcastModified = sal_True;
4804 m_pImpl->m_bIsModified = sal_True;
4806 else if ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "HasEncryptedEntries" )
4807 || aPropertyName.equalsAscii( "HasNonEncryptedEntries" )
4808 || aPropertyName.equalsAscii( "URL" )
4809 || aPropertyName.equalsAscii( "RepairPackage" ) )
4810 || aPropertyName.equalsAscii( "IsRoot" )
4811 || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" ) )
4812 throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4813 else
4814 throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4816 else if ( m_pData->m_nStorageType == OFOPXML_STORAGE )
4818 if ( aPropertyName.equalsAscii( "RelationsInfoStream" ) )
4820 uno::Reference< io::XInputStream > xInRelStream;
4821 if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
4823 uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
4824 if ( !xSeek.is() )
4826 // currently this is an internal property that is used for optimization
4827 // and the stream must support XSeekable interface
4828 // TODO/LATER: in future it can be changed if property is used from outside
4829 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
4832 m_pImpl->m_xNewRelInfoStream = xInRelStream;
4833 m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
4834 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
4835 m_pImpl->m_bBroadcastModified = sal_True;
4836 m_pImpl->m_bIsModified = sal_True;
4838 else
4839 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
4841 else if ( aPropertyName.equalsAscii( "RelationsInfo" ) )
4843 if ( aValue >>= m_pImpl->m_aRelInfo )
4845 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
4846 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
4847 m_pImpl->m_bBroadcastModified = sal_True;
4848 m_pImpl->m_bIsModified = sal_True;
4850 else
4851 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
4853 else if ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "URL" )
4854 || aPropertyName.equalsAscii( "RepairPackage" ) )
4855 || aPropertyName.equalsAscii( "IsRoot" ) )
4856 throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4857 else
4858 throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4860 else
4861 throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4863 BroadcastModifiedIfNecessary();
4867 //-----------------------------------------------
4868 uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyName )
4869 throw ( beans::UnknownPropertyException,
4870 lang::WrappedTargetException,
4871 uno::RuntimeException )
4873 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPropertyValue" );
4875 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4877 if ( !m_pImpl )
4879 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4880 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4883 if ( m_pData->m_nStorageType == PACKAGE_STORAGE
4884 && ( aPropertyName.equalsAscii( "MediaType" )
4885 || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" )
4886 || aPropertyName.equalsAscii( "Version" ) ) )
4890 m_pImpl->ReadContents();
4892 catch ( uno::RuntimeException& aRuntimeException )
4894 m_pImpl->AddLog( aRuntimeException.Message );
4895 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4896 throw;
4898 catch ( uno::Exception& aException )
4900 m_pImpl->AddLog( aException.Message );
4901 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4903 uno::Any aCaught( ::cppu::getCaughtException() );
4904 throw lang::WrappedTargetException(
4905 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't read contents!" ) ),
4906 uno::Reference< XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ),
4907 aCaught );
4910 if ( aPropertyName.equalsAscii( "MediaType" ) )
4911 return uno::makeAny( m_pImpl->m_aMediaType );
4912 else if ( aPropertyName.equalsAscii( "Version" ) )
4913 return uno::makeAny( m_pImpl->m_aVersion );
4914 else
4915 return uno::makeAny( m_pImpl->m_bMTFallbackUsed );
4917 else if ( aPropertyName.equalsAscii( "IsRoot" ) )
4919 return uno::makeAny( m_pData->m_bIsRoot );
4921 else if ( aPropertyName.equalsAscii( "OpenMode" ) )
4923 return uno::makeAny( m_pImpl->m_nStorageMode );
4925 else if ( m_pData->m_bIsRoot )
4927 if ( aPropertyName.equalsAscii( "URL" )
4928 || aPropertyName.equalsAscii( "RepairPackage" ) )
4930 for ( sal_Int32 aInd = 0; aInd < m_pImpl->m_xProperties.getLength(); aInd++ )
4932 if ( m_pImpl->m_xProperties[aInd].Name.equals( aPropertyName ) )
4933 return m_pImpl->m_xProperties[aInd].Value;
4936 if ( aPropertyName.equalsAscii( "URL" ) )
4937 return uno::makeAny( ::rtl::OUString() );
4939 return uno::makeAny( sal_False ); // RepairPackage
4941 else if ( m_pData->m_nStorageType == PACKAGE_STORAGE
4942 && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) ) )
4944 try {
4945 m_pImpl->ReadContents();
4946 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
4947 if ( !xPackPropSet.is() )
4948 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4950 return xPackPropSet->getPropertyValue( aPropertyName );
4952 catch ( uno::RuntimeException& aRuntimeException )
4954 m_pImpl->AddLog( aRuntimeException.Message );
4955 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4956 throw;
4958 catch ( uno::Exception& aException )
4960 m_pImpl->AddLog( aException.Message );
4961 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4963 uno::Any aCaught( ::cppu::getCaughtException() );
4964 throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4965 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
4966 uno::UNO_QUERY ),
4967 aCaught );
4972 throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4976 //-----------------------------------------------
4977 void SAL_CALL OStorage::addPropertyChangeListener(
4978 const ::rtl::OUString& /*aPropertyName*/,
4979 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
4980 throw ( beans::UnknownPropertyException,
4981 lang::WrappedTargetException,
4982 uno::RuntimeException )
4984 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4986 if ( !m_pImpl )
4988 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4989 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4992 //TODO:
4996 //-----------------------------------------------
4997 void SAL_CALL OStorage::removePropertyChangeListener(
4998 const ::rtl::OUString& /*aPropertyName*/,
4999 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
5000 throw ( beans::UnknownPropertyException,
5001 lang::WrappedTargetException,
5002 uno::RuntimeException )
5004 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5006 if ( !m_pImpl )
5008 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5009 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5012 //TODO:
5016 //-----------------------------------------------
5017 void SAL_CALL OStorage::addVetoableChangeListener(
5018 const ::rtl::OUString& /*PropertyName*/,
5019 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
5020 throw ( beans::UnknownPropertyException,
5021 lang::WrappedTargetException,
5022 uno::RuntimeException )
5024 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5026 if ( !m_pImpl )
5028 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5029 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5032 //TODO:
5036 //-----------------------------------------------
5037 void SAL_CALL OStorage::removeVetoableChangeListener(
5038 const ::rtl::OUString& /*PropertyName*/,
5039 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
5040 throw ( beans::UnknownPropertyException,
5041 lang::WrappedTargetException,
5042 uno::RuntimeException )
5044 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5046 if ( !m_pImpl )
5048 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5049 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5052 //TODO:
5055 //____________________________________________________________________________________________________
5056 // XRelationshipAccess
5057 //____________________________________________________________________________________________________
5059 // TODO/LATER: the storage and stream implementations of this interface are very similar, they could use a helper class
5061 //-----------------------------------------------
5062 sal_Bool SAL_CALL OStorage::hasByID( const ::rtl::OUString& sID )
5063 throw ( io::IOException,
5064 uno::RuntimeException )
5066 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5068 if ( !m_pImpl )
5070 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5071 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5074 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5075 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5079 getRelationshipByID( sID );
5080 return sal_True;
5082 catch( container::NoSuchElementException& aNoSuchElementException )
5084 m_pImpl->AddLog( aNoSuchElementException.Message );
5085 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
5088 return sal_False;
5091 //-----------------------------------------------
5092 ::rtl::OUString SAL_CALL OStorage::getTargetByID( const ::rtl::OUString& sID )
5093 throw ( container::NoSuchElementException,
5094 io::IOException,
5095 uno::RuntimeException )
5097 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5099 if ( !m_pImpl )
5101 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5102 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5105 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5106 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5108 uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5109 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5110 if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) )
5111 return aSeq[nInd].Second;
5113 return ::rtl::OUString();
5116 //-----------------------------------------------
5117 ::rtl::OUString SAL_CALL OStorage::getTypeByID( const ::rtl::OUString& sID )
5118 throw ( container::NoSuchElementException,
5119 io::IOException,
5120 uno::RuntimeException )
5122 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5124 if ( !m_pImpl )
5126 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5127 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5130 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5131 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5133 uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5134 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5135 if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) )
5136 return aSeq[nInd].Second;
5138 return ::rtl::OUString();
5141 //-----------------------------------------------
5142 uno::Sequence< beans::StringPair > SAL_CALL OStorage::getRelationshipByID( const ::rtl::OUString& sID )
5143 throw ( container::NoSuchElementException,
5144 io::IOException,
5145 uno::RuntimeException )
5147 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5149 if ( !m_pImpl )
5151 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5152 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5155 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5156 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5158 // TODO/LATER: in future the unification of the ID could be checked
5159 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5160 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5161 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5162 if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) )
5164 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5165 return aSeq[nInd1];
5166 break;
5169 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5172 //-----------------------------------------------
5173 uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getRelationshipsByType( const ::rtl::OUString& sType )
5174 throw ( io::IOException,
5175 uno::RuntimeException )
5177 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5179 if ( !m_pImpl )
5181 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5182 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5185 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5186 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5188 uno::Sequence< uno::Sequence< beans::StringPair > > aResult;
5189 sal_Int32 nEntriesNum = 0;
5191 // TODO/LATER: in future the unification of the ID could be checked
5192 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5193 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5194 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5195 if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) )
5197 // the type is usually an URL, so the check should be case insensitive
5198 if ( aSeq[nInd1][nInd2].Second.equalsIgnoreAsciiCase( sType ) )
5200 aResult.realloc( ++nEntriesNum );
5201 aResult[nEntriesNum-1] = aSeq[nInd1];
5203 break;
5206 return aResult;
5209 //-----------------------------------------------
5210 uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getAllRelationships()
5211 throw (io::IOException, uno::RuntimeException)
5213 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5215 if ( !m_pImpl )
5217 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5218 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5221 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5222 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5224 return m_pImpl->GetAllRelationshipsIfAny();
5227 //-----------------------------------------------
5228 void SAL_CALL OStorage::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace )
5229 throw ( container::ElementExistException,
5230 io::IOException,
5231 uno::RuntimeException )
5233 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5235 if ( !m_pImpl )
5237 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5238 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5241 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5242 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5244 ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
5246 sal_Int32 nIDInd = -1;
5248 // TODO/LATER: in future the unification of the ID could be checked
5249 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5250 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5251 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5252 if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) )
5254 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5255 nIDInd = nInd1;
5257 break;
5260 if ( nIDInd == -1 || bReplace )
5262 if ( nIDInd == -1 )
5264 nIDInd = aSeq.getLength();
5265 aSeq.realloc( nIDInd + 1 );
5268 aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
5270 aSeq[nIDInd][0].First = aIDTag;
5271 aSeq[nIDInd][0].Second = sID;
5272 sal_Int32 nIndTarget = 1;
5273 for ( sal_Int32 nIndOrig = 0;
5274 nIndOrig < aEntry.getLength();
5275 nIndOrig++ )
5277 if ( !aEntry[nIndOrig].First.equals( aIDTag ) )
5278 aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
5281 aSeq[nIDInd].realloc( nIndTarget );
5283 else
5284 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5287 m_pImpl->m_aRelInfo = aSeq;
5288 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5289 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5292 //-----------------------------------------------
5293 void SAL_CALL OStorage::removeRelationshipByID( const ::rtl::OUString& sID )
5294 throw ( container::NoSuchElementException,
5295 io::IOException,
5296 uno::RuntimeException )
5298 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5300 if ( !m_pImpl )
5302 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5303 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5306 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5307 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5309 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5310 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5311 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5312 if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) )
5314 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5316 sal_Int32 nLength = aSeq.getLength();
5317 aSeq[nInd1] = aSeq[nLength-1];
5318 aSeq.realloc( nLength - 1 );
5320 m_pImpl->m_aRelInfo = aSeq;
5321 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5322 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5324 // TODO/LATER: in future the unification of the ID could be checked
5325 return;
5328 break;
5331 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5334 //-----------------------------------------------
5335 void SAL_CALL OStorage::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace )
5336 throw ( container::ElementExistException,
5337 io::IOException,
5338 uno::RuntimeException )
5340 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5342 if ( !m_pImpl )
5344 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5345 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5348 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5349 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5351 ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
5352 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5353 uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() );
5354 sal_Int32 nResultInd = 0;
5356 for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ )
5357 for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ )
5358 if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) )
5360 sal_Int32 nIndSourceSame = -1;
5362 for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5363 for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5365 if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5367 if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) )
5369 if ( !bReplace )
5370 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5372 nIndSourceSame = nIndSource1;
5375 break;
5379 if ( nIndSourceSame == -1 )
5381 // no such element in the provided sequence
5382 aResultSeq[nResultInd++] = aSeq[nIndTarget1];
5385 break;
5388 for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5390 aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() );
5391 sal_Bool bHasID = sal_False;
5392 sal_Int32 nResInd2 = 1;
5394 for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5395 if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5397 aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2];
5398 bHasID = sal_True;
5400 else if ( nResInd2 < aResultSeq[nResultInd].getLength() )
5401 aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2];
5402 else
5403 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relation ( no ID )
5405 if ( !bHasID )
5406 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relations
5408 nResultInd++;
5411 aResultSeq.realloc( nResultInd );
5412 m_pImpl->m_aRelInfo = aResultSeq;
5413 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5414 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5417 //-----------------------------------------------
5418 void SAL_CALL OStorage::clearRelationships()
5419 throw ( io::IOException,
5420 uno::RuntimeException )
5422 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5424 if ( !m_pImpl )
5426 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5427 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5430 if ( m_pData->m_nStorageType != OFOPXML_STORAGE )
5431 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5433 m_pImpl->m_aRelInfo.realloc( 0 );
5434 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5435 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5438 //____________________________________________________________________________________________________
5439 // XOptimizedStorage
5440 //____________________________________________________________________________________________________
5441 //-----------------------------------------------
5442 void SAL_CALL OStorage::insertRawNonEncrStreamElementDirect(
5443 const ::rtl::OUString& /*sStreamName*/,
5444 const uno::Reference< io::XInputStream >& /*xInStream*/ )
5445 throw ( embed::InvalidStorageException,
5446 lang::IllegalArgumentException,
5447 packages::NoRawFormatException,
5448 container::ElementExistException,
5449 io::IOException,
5450 embed::StorageWrappedTargetException,
5451 uno::RuntimeException )
5453 // not implemented currently because there is still no demand
5454 // might need to be implemented if direct copying of compressed streams is used
5455 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5458 //-----------------------------------------------
5459 void SAL_CALL OStorage::insertStreamElementDirect(
5460 const ::rtl::OUString& aStreamName,
5461 const uno::Reference< io::XInputStream >& xInStream,
5462 const uno::Sequence< beans::PropertyValue >& aProps )
5463 throw ( embed::InvalidStorageException,
5464 lang::IllegalArgumentException,
5465 container::ElementExistException,
5466 io::IOException,
5467 embed::StorageWrappedTargetException,
5468 uno::RuntimeException )
5470 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertStreamElementDirect" );
5472 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5474 if ( !m_pImpl )
5476 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5477 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5480 if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
5481 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5483 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
5484 && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
5485 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
5487 if ( m_pData->m_bReadOnlyWrap )
5488 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
5492 SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
5494 if ( pElement )
5495 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5497 pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, sal_False );
5498 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
5500 pElement->m_pStream->InsertStreamDirectly( xInStream, aProps );
5502 catch( embed::InvalidStorageException& aInvalidStorageException )
5504 m_pImpl->AddLog( aInvalidStorageException.Message );
5505 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5506 throw;
5508 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5510 m_pImpl->AddLog( aIllegalArgumentException.Message );
5511 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5512 throw;
5514 catch( container::ElementExistException& aElementExistException )
5516 m_pImpl->AddLog( aElementExistException.Message );
5517 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5518 throw;
5520 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5522 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5523 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5524 throw;
5526 catch( io::IOException& aIOException )
5528 m_pImpl->AddLog( aIOException.Message );
5529 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5530 throw;
5532 catch( uno::RuntimeException& aRuntimeException )
5534 m_pImpl->AddLog( aRuntimeException.Message );
5535 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5536 throw;
5538 catch( uno::Exception& aException )
5540 m_pImpl->AddLog( aException.Message );
5541 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5543 uno::Any aCaught( ::cppu::getCaughtException() );
5544 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert stream directly!" ) ),
5545 uno::Reference< io::XInputStream >(),
5546 aCaught );
5550 //-----------------------------------------------
5551 void SAL_CALL OStorage::copyElementDirectlyTo(
5552 const ::rtl::OUString& aElementName,
5553 const uno::Reference< embed::XOptimizedStorage >& xDest,
5554 const ::rtl::OUString& aNewName )
5555 throw ( embed::InvalidStorageException,
5556 lang::IllegalArgumentException,
5557 container::NoSuchElementException,
5558 container::ElementExistException,
5559 io::IOException,
5560 embed::StorageWrappedTargetException,
5561 uno::RuntimeException )
5563 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementDirectlyTo" );
5565 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5567 if ( !m_pImpl )
5569 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5570 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5573 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
5574 || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
5575 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5577 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
5578 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
5580 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
5581 && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
5582 || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
5583 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable name
5587 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
5588 if ( !pElement )
5589 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5591 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
5592 if ( !xNameAccess.is() )
5593 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5595 if ( xNameAccess->hasByName( aNewName ) )
5596 throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5598 // let the element be copied directly
5599 uno::Reference< embed::XStorage > xStorDest( xDest, uno::UNO_QUERY_THROW );
5600 m_pImpl->CopyStorageElement( pElement, xStorDest, aNewName, sal_True );
5602 catch( embed::InvalidStorageException& aInvalidStorageException )
5604 m_pImpl->AddLog( aInvalidStorageException.Message );
5605 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5606 throw;
5608 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5610 m_pImpl->AddLog( aIllegalArgumentException.Message );
5611 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5612 throw;
5614 catch( container::NoSuchElementException& aNoSuchElementException )
5616 m_pImpl->AddLog( aNoSuchElementException.Message );
5617 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5618 throw;
5620 catch( container::ElementExistException& aElementExistException )
5622 m_pImpl->AddLog( aElementExistException.Message );
5623 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5624 throw;
5626 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5628 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5629 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5630 throw;
5632 catch( io::IOException& aIOException )
5634 m_pImpl->AddLog( aIOException.Message );
5635 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5636 throw;
5638 catch( uno::RuntimeException& aRuntimeException )
5640 m_pImpl->AddLog( aRuntimeException.Message );
5641 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5642 throw;
5644 catch( uno::Exception& aException )
5646 m_pImpl->AddLog( aException.Message );
5647 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5649 uno::Any aCaught( ::cppu::getCaughtException() );
5650 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element direcly!" ) ),
5651 uno::Reference< io::XInputStream >(),
5652 aCaught );
5656 //-----------------------------------------------
5657 void SAL_CALL OStorage::writeAndAttachToStream( const uno::Reference< io::XStream >& xStream )
5658 throw ( embed::InvalidStorageException,
5659 lang::IllegalArgumentException,
5660 io::IOException,
5661 embed::StorageWrappedTargetException,
5662 uno::RuntimeException )
5664 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::writeAndAttachToStream" );
5666 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5668 if ( !m_pImpl )
5670 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5671 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5674 if ( !m_pData->m_bIsRoot )
5675 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5677 if ( !m_pImpl->m_pSwitchStream )
5678 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5682 m_pImpl->m_pSwitchStream->CopyAndSwitchPersistenceTo( xStream );
5684 catch( embed::InvalidStorageException& aInvalidStorageException )
5686 m_pImpl->AddLog( aInvalidStorageException.Message );
5687 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5688 throw;
5690 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5692 m_pImpl->AddLog( aIllegalArgumentException.Message );
5693 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5694 throw;
5696 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5698 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5699 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5700 throw;
5702 catch( io::IOException& aIOException )
5704 m_pImpl->AddLog( aIOException.Message );
5705 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5706 throw;
5708 catch( uno::RuntimeException& aRuntimeException )
5710 m_pImpl->AddLog( aRuntimeException.Message );
5711 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5712 throw;
5714 catch( uno::Exception& aException )
5716 m_pImpl->AddLog( aException.Message );
5717 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5719 uno::Any aCaught( ::cppu::getCaughtException() );
5720 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't write and attach to stream!" ) ),
5721 uno::Reference< io::XInputStream >(),
5722 aCaught );
5727 //-----------------------------------------------
5728 void SAL_CALL OStorage::attachToURL( const ::rtl::OUString& sURL,
5729 sal_Bool bReadOnly )
5730 throw ( embed::InvalidStorageException,
5731 lang::IllegalArgumentException,
5732 io::IOException,
5733 embed::StorageWrappedTargetException,
5734 uno::RuntimeException )
5736 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::attachToURL" );
5738 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5740 if ( !m_pImpl )
5742 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5743 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5746 if ( !m_pData->m_bIsRoot )
5747 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5749 if ( !m_pImpl->m_pSwitchStream )
5750 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5752 uno::Reference < ucb::XSimpleFileAccess > xAccess(
5753 m_pImpl->m_xFactory->createInstance (
5754 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
5755 uno::UNO_QUERY_THROW );
5759 if ( bReadOnly )
5761 uno::Reference< io::XInputStream > xInputStream = xAccess->openFileRead( sURL );
5762 m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xInputStream );
5764 else
5766 uno::Reference< io::XStream > xStream = xAccess->openFileReadWrite( sURL );
5767 m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xStream );
5770 catch( embed::InvalidStorageException& aInvalidStorageException )
5772 m_pImpl->AddLog( aInvalidStorageException.Message );
5773 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5774 throw;
5776 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5778 m_pImpl->AddLog( aIllegalArgumentException.Message );
5779 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5780 throw;
5782 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5784 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5785 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5786 throw;
5788 catch( io::IOException& aIOException )
5790 m_pImpl->AddLog( aIOException.Message );
5791 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5792 throw;
5794 catch( uno::RuntimeException& aRuntimeException )
5796 m_pImpl->AddLog( aRuntimeException.Message );
5797 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5798 throw;
5800 catch( uno::Exception& aException )
5802 m_pImpl->AddLog( aException.Message );
5803 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5805 uno::Any aCaught( ::cppu::getCaughtException() );
5806 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't attach to URL!" ) ),
5807 uno::Reference< io::XInputStream >(),
5808 aCaught );
5812 //-----------------------------------------------
5813 uno::Any SAL_CALL OStorage::getElementPropertyValue( const ::rtl::OUString& aElementName, const ::rtl::OUString& aPropertyName )
5814 throw ( embed::InvalidStorageException,
5815 lang::IllegalArgumentException,
5816 container::NoSuchElementException,
5817 io::IOException,
5818 beans::UnknownPropertyException,
5819 beans::PropertyVetoException,
5820 embed::StorageWrappedTargetException,
5821 uno::RuntimeException)
5823 RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementPropertyValue" );
5825 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5827 if ( !m_pImpl )
5829 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5830 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5833 if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
5834 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5836 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
5837 && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
5838 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
5842 SotElement_Impl *pElement = m_pImpl->FindElement( aElementName );
5843 if ( !pElement )
5844 throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5846 // TODO/LATER: Currently it is only implemented for MediaType property of substorages, might be changed in future
5847 if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != PACKAGE_STORAGE || !aPropertyName.equalsAscii( "MediaType" ) )
5848 throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5850 if ( !pElement->m_pStorage )
5851 m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ );
5853 if ( !pElement->m_pStorage )
5854 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
5856 pElement->m_pStorage->ReadContents();
5857 return uno::makeAny( pElement->m_pStorage->m_aMediaType );
5859 catch( embed::InvalidStorageException& aInvalidStorageException )
5861 m_pImpl->AddLog( aInvalidStorageException.Message );
5862 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5863 throw;
5865 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5867 m_pImpl->AddLog( aIllegalArgumentException.Message );
5868 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5869 throw;
5871 catch( container::NoSuchElementException& aNoSuchElementException )
5873 m_pImpl->AddLog( aNoSuchElementException.Message );
5874 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5875 throw;
5877 catch( beans::UnknownPropertyException& aUnknownPropertyException )
5879 m_pImpl->AddLog( aUnknownPropertyException.Message );
5880 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5881 throw;
5883 catch( beans::PropertyVetoException& aPropertyVetoException )
5885 m_pImpl->AddLog( aPropertyVetoException.Message );
5886 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5887 throw;
5889 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5891 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5892 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5893 throw;
5895 catch( io::IOException& aIOException )
5897 m_pImpl->AddLog( aIOException.Message );
5898 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5899 throw;
5901 catch( uno::RuntimeException& aRuntimeException )
5903 m_pImpl->AddLog( aRuntimeException.Message );
5904 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5905 throw;
5907 catch( uno::Exception& aException )
5909 m_pImpl->AddLog( aException.Message );
5910 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5912 uno::Any aCaught( ::cppu::getCaughtException() );
5913 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get element property!" ) ),
5914 uno::Reference< io::XInputStream >(),
5915 aCaught );
5919 //-----------------------------------------------
5920 void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamName, const uno::Reference< io::XStream >& xTargetStream )
5921 throw ( embed::InvalidStorageException,
5922 lang::IllegalArgumentException,
5923 packages::WrongPasswordException,
5924 io::IOException,
5925 embed::StorageWrappedTargetException,
5926 uno::RuntimeException )
5928 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5930 if ( !m_pImpl )
5932 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5933 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5936 if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
5937 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5939 if ( m_pData->m_nStorageType == OFOPXML_STORAGE
5940 && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
5941 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
5943 if ( !xTargetStream.is() )
5944 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
5948 uno::Reference< io::XStream > xNonconstRef = xTargetStream;
5949 m_pImpl->CloneStreamElement( aStreamName, sal_False, ::rtl::OUString(), xNonconstRef );
5951 OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" );
5952 if ( xNonconstRef != xTargetStream )
5953 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // if the stream reference is set it must not be changed!
5955 catch( embed::InvalidStorageException& aInvalidStorageException )
5957 m_pImpl->AddLog( aInvalidStorageException.Message );
5958 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5959 throw;
5961 catch( lang::IllegalArgumentException& aIllegalArgumentException )
5963 m_pImpl->AddLog( aIllegalArgumentException.Message );
5964 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5965 throw;
5967 catch( packages::WrongPasswordException& aWrongPasswordException )
5969 m_pImpl->AddLog( aWrongPasswordException.Message );
5970 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5971 throw;
5973 catch( io::IOException& aIOException )
5975 m_pImpl->AddLog( aIOException.Message );
5976 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5977 throw;
5979 catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5981 m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5982 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5983 throw;
5985 catch( uno::RuntimeException& aRuntimeException )
5987 m_pImpl->AddLog( aRuntimeException.Message );
5988 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5989 throw;
5991 catch( uno::Exception& aException )
5993 m_pImpl->AddLog( aException.Message );
5994 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5996 uno::Any aCaught( ::cppu::getCaughtException() );
5997 throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy stream data!" ) ),
5998 uno::Reference< io::XInputStream >(),
5999 aCaught );
6005 //____________________________________________________________________________________________________
6006 // XHierarchicalStorageAccess
6007 //____________________________________________________________________________________________________
6009 //-----------------------------------------------
6010 uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode )
6011 throw ( embed::InvalidStorageException,
6012 lang::IllegalArgumentException,
6013 packages::WrongPasswordException,
6014 io::IOException,
6015 embed::StorageWrappedTargetException,
6016 uno::RuntimeException )
6018 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6020 if ( !m_pImpl )
6022 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6023 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6026 if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6027 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6029 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
6030 && ( nOpenMode & embed::ElementModes::WRITE ) )
6031 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6033 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6034 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6036 uno::Reference< embed::XExtendedStorageStream > xResult;
6037 if ( aListPath.size() == 1 )
6039 // that must be a direct request for a stream
6040 // the transacted version of the stream should be opened
6042 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_False );
6043 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
6045 xResult = uno::Reference< embed::XExtendedStorageStream >(
6046 pElement->m_pStream->GetStream( nOpenMode, sal_True ),
6047 uno::UNO_QUERY_THROW );
6049 else
6051 // there are still storages in between
6052 if ( !m_pData->m_rHierarchyHolder.is() )
6053 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6054 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6056 xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
6057 ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
6058 aListPath,
6059 nOpenMode );
6062 if ( !xResult.is() )
6063 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6065 return xResult;
6068 //-----------------------------------------------
6069 uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword )
6070 throw ( embed::InvalidStorageException,
6071 lang::IllegalArgumentException,
6072 packages::NoEncryptionException,
6073 packages::WrongPasswordException,
6074 io::IOException,
6075 embed::StorageWrappedTargetException,
6076 uno::RuntimeException )
6078 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6080 if ( !m_pImpl )
6082 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6083 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6086 if ( m_pData->m_nStorageType != PACKAGE_STORAGE )
6087 throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6089 if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6090 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6092 if ( !sPassword.getLength() )
6093 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
6095 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
6096 && ( nOpenMode & embed::ElementModes::WRITE ) )
6097 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6099 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6100 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6102 uno::Reference< embed::XExtendedStorageStream > xResult;
6103 if ( aListPath.size() == 1 )
6105 // that must be a direct request for a stream
6106 // the transacted version of the stream should be opened
6108 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_True );
6109 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
6111 xResult = uno::Reference< embed::XExtendedStorageStream >(
6112 pElement->m_pStream->GetStream( nOpenMode, sPassword, sal_True ),
6113 uno::UNO_QUERY_THROW );
6115 else
6117 // there are still storages in between
6118 if ( !m_pData->m_rHierarchyHolder.is() )
6119 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6120 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6122 xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
6123 ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
6124 aListPath,
6125 nOpenMode,
6126 sPassword );
6129 if ( !xResult.is() )
6130 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6132 return xResult;
6135 //-----------------------------------------------
6136 void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath )
6137 throw ( embed::InvalidStorageException,
6138 lang::IllegalArgumentException,
6139 container::NoSuchElementException,
6140 io::IOException,
6141 embed::StorageWrappedTargetException,
6142 uno::RuntimeException )
6144 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6146 if ( !m_pImpl )
6148 ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6149 throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6152 if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6153 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6155 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
6156 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6158 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6159 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6161 if ( !m_pData->m_rHierarchyHolder.is() )
6162 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6163 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6165 m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );