Branch libreoffice-5-0-4
[LibreOffice.git] / package / source / xstor / xstorage.cxx
blob63158f6bd7f55c05e5e90ba13fd06d0a38a1d36b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/PropertyValue.hpp>
21 #include <com/sun/star/embed/ElementModes.hpp>
22 #include <com/sun/star/embed/UseBackupException.hpp>
23 #include <com/sun/star/embed/StorageFormats.hpp>
24 #include <com/sun/star/ucb/XProgressHandler.hpp>
25 #include <com/sun/star/io/TempFile.hpp>
26 #include <com/sun/star/logging/DocumentIOLogRing.hpp>
27 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
28 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
29 #include <com/sun/star/container/XEnumerationAccess.hpp>
30 #include <com/sun/star/container/XNamed.hpp>
31 #include <com/sun/star/util/XChangesBatch.hpp>
32 #include <com/sun/star/util/XCloneable.hpp>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
38 #include <com/sun/star/beans/NamedValue.hpp>
40 #include <PackageConstants.hxx>
42 #include <cppuhelper/queryinterface.hxx>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <cppuhelper/exc_hlp.hxx>
45 #include <rtl/instance.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/storagehelper.hxx>
49 #include <comphelper/ofopxmlhelper.hxx>
51 #include "xstorage.hxx"
52 #include "owriteablestream.hxx"
53 #include "disposelistener.hxx"
54 #include "switchpersistencestream.hxx"
55 #include "ohierarchyholder.hxx"
57 #include <boost/checked_delete.hpp>
59 using namespace ::com::sun::star;
61 #if OSL_DEBUG_LEVEL > 0
62 #define THROW_WHERE SAL_WHERE
63 #else
64 #define THROW_WHERE ""
65 #endif
67 typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList;
69 struct StorInternalData_Impl
71 SotMutexHolderRef m_rSharedMutexRef;
72 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners
73 ::std::unique_ptr< ::cppu::OTypeCollection> m_pTypeCollection;
74 bool m_bIsRoot;
75 sal_Int32 m_nStorageType; // the mode in which the storage is used
76 bool m_bReadOnlyWrap;
78 ::rtl::Reference<OChildDispListener_Impl> m_pSubElDispListener;
80 WeakComponentList m_aOpenSubComponentsList;
82 ::rtl::Reference< OHierarchyHolder_Impl > m_rHierarchyHolder;
84 // the mutex reference MUST NOT be empty
85 StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, bool bRoot, sal_Int32 nStorageType, bool bReadOnlyWrap )
86 : m_rSharedMutexRef( rMutexRef )
87 , m_aListenersContainer( rMutexRef->GetMutex() )
88 , m_pTypeCollection()
89 , m_bIsRoot( bRoot )
90 , m_nStorageType( nStorageType )
91 , m_bReadOnlyWrap( bReadOnlyWrap )
92 , m_pSubElDispListener()
95 ~StorInternalData_Impl();
98 // static
99 void OStorage_Impl::completeStorageStreamCopy_Impl(
100 const uno::Reference< io::XStream >& xSource,
101 const uno::Reference< io::XStream >& xDest,
102 sal_Int32 nStorageType,
103 const uno::Sequence< uno::Sequence< beans::StringPair > >& aRelInfo )
105 uno::Reference< beans::XPropertySet > xSourceProps( xSource, uno::UNO_QUERY );
106 uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY );
107 if ( !xSourceProps.is() || !xDestProps.is() )
108 throw uno::RuntimeException( THROW_WHERE );
110 uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream();
111 if ( !xDestOutStream.is() )
112 throw io::IOException( THROW_WHERE );
114 uno::Reference< io::XInputStream > xSourceInStream = xSource->getInputStream();
115 if ( !xSourceInStream.is() )
116 throw io::IOException( THROW_WHERE );
118 // TODO: headers of encripted streams should be copied also
119 ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInStream, xDestOutStream );
121 uno::Sequence< OUString > aPropNames( 1 );
122 aPropNames[0] = "Compressed";
124 if ( nStorageType == embed::StorageFormats::PACKAGE )
126 aPropNames.realloc( 3 );
127 aPropNames[1] = "MediaType";
128 aPropNames[2] = "UseCommonStoragePasswordEncryption";
130 else if ( nStorageType == embed::StorageFormats::OFOPXML )
132 // TODO/LATER: in future it might make sense to provide the stream if there is one
133 uno::Reference< embed::XRelationshipAccess > xRelAccess( xDest, uno::UNO_QUERY_THROW );
134 xRelAccess->clearRelationships();
135 xRelAccess->insertRelationships( aRelInfo, sal_False );
137 aPropNames.realloc( 2 );
138 aPropNames[1] = "MediaType";
141 for ( int ind = 0; ind < aPropNames.getLength(); ind++ )
142 xDestProps->setPropertyValue( aPropNames[ind], xSourceProps->getPropertyValue( aPropNames[ind] ) );
145 uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInputStream > xInStream,
146 uno::Reference< uno::XComponentContext > xContext )
148 uno::Reference < io::XTempFile > xTempFile = io::TempFile::create(xContext);
149 uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream();
150 uno::Reference < io::XInputStream > xTempIn = xTempFile->getInputStream();
152 if ( !xTempOut.is() || !xTempIn.is() )
153 throw io::IOException( THROW_WHERE );
155 ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
156 xTempOut->closeOutput();
158 return xTempIn;
161 StorInternalData_Impl::~StorInternalData_Impl()
165 SotElement_Impl::SotElement_Impl( const OUString& rName, bool bStor, bool bNew )
166 : m_aName( rName )
167 , m_aOriginalName( rName )
168 , m_bIsRemoved( false )
169 , m_bIsInserted( bNew )
170 , m_bIsStorage( bStor )
171 , m_pStorage( NULL )
172 , m_pStream( NULL )
176 SotElement_Impl::~SotElement_Impl()
178 delete m_pStorage;
179 delete m_pStream;
182 // most of properties are holt by the storage but are not used
183 OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream,
184 sal_Int32 nMode,
185 const uno::Sequence< beans::PropertyValue >& xProperties,
186 uno::Reference< uno::XComponentContext > xContext,
187 sal_Int32 nStorageType )
188 : m_rMutexRef( new SotMutexHolder )
189 , m_pAntiImpl( NULL )
190 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
191 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
192 , m_bBroadcastModified( false )
193 , m_bCommited( false )
194 , m_bIsRoot( true )
195 , m_bListCreated( false )
196 , m_nModifiedListenerCount( 0 )
197 , m_xContext( xContext )
198 , m_xProperties( xProperties )
199 , m_bHasCommonEncryptionData( false )
200 , m_pParent( NULL )
201 , m_bControlMediaType( false )
202 , m_bMTFallbackUsed( false )
203 , m_bControlVersion( false )
204 , m_pSwitchStream( NULL )
205 , m_nStorageType( nStorageType )
206 , m_pRelStorElement( NULL )
207 , m_nRelInfoStatus( RELINFO_NO_INIT )
209 // all the checks done below by assertion statements must be done by factory
210 SAL_WARN_IF( !xInputStream.is(), "package.xstor", "No input stream is provided!" );
212 m_pSwitchStream = new SwitchablePersistenceStream(xContext, xInputStream);
213 m_xInputStream = m_pSwitchStream->getInputStream();
215 if ( m_nStorageMode & embed::ElementModes::WRITE )
217 // check that the stream allows to write
218 SAL_WARN( "package.xstor", "No stream for writing is provided!" );
222 // most of properties are holt by the storage but are not used
223 OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream,
224 sal_Int32 nMode,
225 const uno::Sequence< beans::PropertyValue >& xProperties,
226 uno::Reference< uno::XComponentContext > xContext,
227 sal_Int32 nStorageType )
228 : m_rMutexRef( new SotMutexHolder )
229 , m_pAntiImpl( NULL )
230 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
231 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
232 , m_bBroadcastModified( false )
233 , m_bCommited( false )
234 , m_bIsRoot( true )
235 , m_bListCreated( false )
236 , m_nModifiedListenerCount( 0 )
237 , m_xContext( xContext )
238 , m_xProperties( xProperties )
239 , m_bHasCommonEncryptionData( false )
240 , m_pParent( NULL )
241 , m_bControlMediaType( false )
242 , m_bMTFallbackUsed( false )
243 , m_bControlVersion( false )
244 , m_pSwitchStream( NULL )
245 , m_nStorageType( nStorageType )
246 , m_pRelStorElement( NULL )
247 , m_nRelInfoStatus( RELINFO_NO_INIT )
249 // all the checks done below by assertion statements must be done by factory
250 SAL_WARN_IF( !xStream.is(), "package.xstor", "No stream is provided!" );
252 if ( m_nStorageMode & embed::ElementModes::WRITE )
254 m_pSwitchStream = new SwitchablePersistenceStream(xContext, xStream);
255 m_xStream = static_cast< io::XStream* >( m_pSwitchStream );
257 else
259 m_pSwitchStream = new SwitchablePersistenceStream(xContext, xStream->getInputStream());
260 m_xInputStream = m_pSwitchStream->getInputStream();
264 OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent,
265 sal_Int32 nMode,
266 uno::Reference< container::XNameContainer > xPackageFolder,
267 uno::Reference< lang::XSingleServiceFactory > xPackage,
268 uno::Reference< uno::XComponentContext > xContext,
269 sal_Int32 nStorageType )
270 : m_rMutexRef( new SotMutexHolder )
271 , m_pAntiImpl( NULL )
272 , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
273 , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
274 , m_bBroadcastModified( false )
275 , m_bCommited( false )
276 , m_bIsRoot( false )
277 , m_bListCreated( false )
278 , m_nModifiedListenerCount( 0 )
279 , m_xPackageFolder( xPackageFolder )
280 , m_xPackage( xPackage )
281 , m_xContext( xContext )
282 , m_bHasCommonEncryptionData( false )
283 , m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage
284 , m_bControlMediaType( false )
285 , m_bMTFallbackUsed( false )
286 , m_bControlVersion( false )
287 , m_pSwitchStream( NULL )
288 , m_nStorageType( nStorageType )
289 , m_pRelStorElement( NULL )
290 , m_nRelInfoStatus( RELINFO_NO_INIT )
292 SAL_WARN_IF( !xPackageFolder.is(), "package.xstor", "No package folder!" );
295 OStorage_Impl::~OStorage_Impl()
298 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
299 if ( m_pAntiImpl ) // root storage wrapper must set this member to NULL before destruction of object
301 SAL_WARN_IF( m_bIsRoot, "package.xstor", "The root storage wrapper must be disposed already" );
303 try {
304 m_pAntiImpl->InternalDispose( false );
306 catch ( const uno::Exception& rException )
308 AddLog( rException.Message );
309 AddLog( THROW_WHERE "Quiet exception" );
311 m_pAntiImpl = NULL;
313 else if ( !m_aReadOnlyWrapList.empty() )
315 for ( StorageHoldersType::iterator pStorageIter = m_aReadOnlyWrapList.begin();
316 pStorageIter != m_aReadOnlyWrapList.end(); ++pStorageIter )
318 uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
319 if ( xTmp.is() )
320 try {
321 pStorageIter->m_pPointer->InternalDispose( false );
322 } catch( const uno::Exception& rException )
324 AddLog( rException.Message );
325 AddLog( THROW_WHERE "Quiet exception" );
329 m_aReadOnlyWrapList.clear();
332 m_pParent = NULL;
335 std::for_each(m_aChildrenList.begin(), m_aChildrenList.end(), boost::checked_deleter<SotElement_Impl>());
336 m_aChildrenList.clear();
338 std::for_each(m_aDeletedList.begin(), m_aDeletedList.end(), boost::checked_deleter<SotElement_Impl>());
339 m_aDeletedList.clear();
341 if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement )
343 delete m_pRelStorElement;
344 m_pRelStorElement = NULL;
347 m_xPackageFolder = uno::Reference< container::XNameContainer >();
348 m_xPackage = uno::Reference< lang::XSingleServiceFactory >();
350 OUString aPropertyName = "URL";
351 for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); ++aInd )
353 if ( m_xProperties[aInd].Name.equals( aPropertyName ) )
355 // the storage is URL based so all the streams are opened by factory and should be closed
358 if ( m_xInputStream.is() )
360 m_xInputStream->closeInput();
361 m_xInputStream = uno::Reference< io::XInputStream >();
364 if ( m_xStream.is() )
366 uno::Reference< io::XInputStream > xInStr = m_xStream->getInputStream();
367 if ( xInStr.is() )
368 xInStr->closeInput();
370 uno::Reference< io::XOutputStream > xOutStr = m_xStream->getOutputStream();
371 if ( xOutStr.is() )
372 xOutStr->closeOutput();
374 m_xStream = uno::Reference< io::XStream >();
377 catch( const uno::Exception& rException )
379 AddLog( THROW_WHERE "Quiet exception" );
380 AddLog( rException.Message );
386 void OStorage_Impl::AddLog( const OUString& aMessage )
388 if ( !m_xLogRing.is() )
392 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
393 m_xLogRing = logging::DocumentIOLogRing::get(xContext);
395 catch( const uno::Exception& )
397 // No log
401 if ( m_xLogRing.is() )
402 m_xLogRing->logString( aMessage );
405 void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage )
407 // Weak reference is used inside the holder so the refcount must not be zero at this point
408 OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" );
409 m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) );
412 void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage )
414 for ( StorageHoldersType::iterator pStorageIter = m_aReadOnlyWrapList.begin();
415 pStorageIter != m_aReadOnlyWrapList.end();)
417 uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
418 if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage )
420 try {
421 pStorageIter->m_pPointer->InternalDispose( false );
422 } catch( const uno::Exception& rException )
424 AddLog( THROW_WHERE "Quiet exception" );
425 AddLog( rException.Message );
428 StorageHoldersType::iterator pIterToDelete( pStorageIter );
429 ++pStorageIter;
430 m_aReadOnlyWrapList.erase( pIterToDelete );
432 else
433 ++pStorageIter;
437 void OStorage_Impl::OpenOwnPackage()
439 SAL_WARN_IF( !m_bIsRoot, "package.xstor", "Opening of the package has no sense!" );
441 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
443 if ( !m_xPackageFolder.is() )
445 if ( !m_xPackage.is() )
447 uno::Sequence< uno::Any > aArguments( 2 );
448 if ( m_nStorageMode & embed::ElementModes::WRITE )
449 aArguments[ 0 ] <<= m_xStream;
450 else
452 SAL_WARN_IF( !m_xInputStream.is(), "package.xstor", "Input stream must be set for readonly access!" );
453 aArguments[ 0 ] <<= m_xInputStream;
454 // TODO: if input stream is not seekable or XSeekable interface is supported
455 // on XStream object a wrapper must be used
458 // do not allow elements to remove themself from the old container in case of insertion to another container
459 aArguments[ 1 ] <<= beans::NamedValue( "AllowRemoveOnInsert",
460 uno::makeAny( false ) );
462 sal_Int32 nArgNum = 2;
463 for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ )
465 if ( m_xProperties[aInd].Name == "RepairPackage"
466 || m_xProperties[aInd].Name == "ProgressHandler" )
468 beans::NamedValue aNamedValue( m_xProperties[aInd].Name,
469 m_xProperties[aInd].Value );
470 aArguments.realloc( ++nArgNum );
471 aArguments[nArgNum-1] <<= aNamedValue;
473 else if ( m_xProperties[aInd].Name == "Password" )
475 // TODO: implement password setting for documents
476 // the password entry must be removed after setting
480 if ( m_nStorageType == embed::StorageFormats::ZIP )
482 // let the package support only plain zip format
483 beans::NamedValue aNamedValue;
484 aNamedValue.Name = "StorageFormat";
485 aNamedValue.Value <<= OUString( "ZipFormat" );
486 aArguments.realloc( ++nArgNum );
487 aArguments[nArgNum-1] <<= aNamedValue;
489 else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
491 // let the package support OFOPXML media type handling
492 beans::NamedValue aNamedValue;
493 aNamedValue.Name = "StorageFormat";
494 aNamedValue.Value <<= OUString( "OFOPXMLFormat" );
495 aArguments.realloc( ++nArgNum );
496 aArguments[nArgNum-1] <<= aNamedValue;
499 m_xPackage = uno::Reference< lang::XSingleServiceFactory > (
500 GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(
501 "com.sun.star.packages.comp.ZipPackage", aArguments, GetComponentContext()),
502 uno::UNO_QUERY );
505 uno::Reference< container::XHierarchicalNameAccess > xHNameAccess( m_xPackage, uno::UNO_QUERY );
506 SAL_WARN_IF( !xHNameAccess.is(), "package.xstor", "The package could not be created!" );
508 if ( xHNameAccess.is() )
510 uno::Any aFolder = xHNameAccess->getByHierarchicalName("/");
511 aFolder >>= m_xPackageFolder;
515 SAL_WARN_IF( !m_xPackageFolder.is(), "package.xstor", "The package root folder can not be opened!" );
516 if ( !m_xPackageFolder.is() )
517 throw embed::InvalidStorageException( THROW_WHERE );
520 uno::Reference< uno::XComponentContext > OStorage_Impl::GetComponentContext()
522 if ( m_xContext.is() )
523 return m_xContext;
525 return ::comphelper::getProcessComponentContext();
528 SotElementList_Impl& OStorage_Impl::GetChildrenList()
530 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
532 ReadContents();
533 return m_aChildrenList;
536 void OStorage_Impl::GetStorageProperties()
538 if ( m_nStorageType == embed::StorageFormats::PACKAGE )
540 uno::Reference< beans::XPropertySet > xProps( m_xPackageFolder, uno::UNO_QUERY_THROW );
542 if ( !m_bControlMediaType )
544 uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW );
545 xPackageProps->getPropertyValue( MEDIATYPE_FALLBACK_USED_PROPERTY ) >>= m_bMTFallbackUsed;
547 xProps->getPropertyValue( "MediaType" ) >>= m_aMediaType;
548 m_bControlMediaType = true;
551 if ( !m_bControlVersion )
553 xProps->getPropertyValue( "Version" ) >>= m_aVersion;
554 m_bControlVersion = true;
558 // the properties of OFOPXML will be handled directly
561 void OStorage_Impl::ReadRelInfoIfNecessary()
563 if ( m_nStorageType != embed::StorageFormats::OFOPXML )
564 return;
566 if ( m_nRelInfoStatus == RELINFO_NO_INIT )
568 // Init from original stream
569 uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( OUString() );
572 if ( xRelInfoStream.is() )
573 m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
574 xRelInfoStream,
575 "_rels/.rels",
576 m_xContext );
577 m_nRelInfoStatus = RELINFO_READ;
579 catch (css::uno::Exception & e)
581 SAL_INFO("package.xstor", "caught Exception " << e.Message);
584 else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
586 // Init from the new stream
589 if ( m_xNewRelInfoStream.is() )
590 m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
591 m_xNewRelInfoStream,
592 "_rels/.rels",
593 m_xContext );
595 m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ;
597 catch( const uno::Exception& )
599 m_nRelInfoStatus = RELINFO_CHANGED_BROKEN;
604 void OStorage_Impl::ReadContents()
606 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
608 if ( m_bListCreated )
609 return;
611 if ( m_bIsRoot )
612 OpenOwnPackage();
614 uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xPackageFolder, uno::UNO_QUERY );
615 if ( !xEnumAccess.is() )
616 throw uno::RuntimeException( THROW_WHERE );
618 uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
619 if ( !xEnum.is() )
620 throw uno::RuntimeException( THROW_WHERE );
622 m_bListCreated = true;
624 while( xEnum->hasMoreElements() )
626 try {
627 uno::Reference< container::XNamed > xNamed;
628 xEnum->nextElement() >>= xNamed;
630 if ( !xNamed.is() )
632 SAL_WARN( "package.xstor", "XNamed is not supported!" );
633 throw uno::RuntimeException( THROW_WHERE );
636 OUString aName = xNamed->getName();
637 SAL_WARN_IF( aName.isEmpty(), "package.xstor", "Empty name!" );
639 uno::Reference< container::XNameContainer > xNameContainer( xNamed, uno::UNO_QUERY );
641 SotElement_Impl* pNewElement = new SotElement_Impl( aName, xNameContainer.is(), false );
642 if ( m_nStorageType == embed::StorageFormats::OFOPXML && aName == "_rels" )
644 if ( !pNewElement->m_bIsStorage )
645 throw io::IOException( THROW_WHERE ); // TODO: Unexpected format
647 m_pRelStorElement = pNewElement;
648 CreateRelStorage();
650 else
652 if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
654 // if a storage is truncated all of it elements are marked as deleted
655 pNewElement->m_bIsRemoved = true;
658 m_aChildrenList.push_back( pNewElement );
661 catch( const container::NoSuchElementException& rNoSuchElementException )
663 AddLog( rNoSuchElementException.Message );
664 AddLog( THROW_WHERE "NoSuchElement" );
666 SAL_WARN( "package.xstor", "hasMoreElements() implementation has problems!" );
667 break;
670 if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
672 // if a storage is truncated the relations information should be cleaned
673 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
674 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
675 m_nRelInfoStatus = RELINFO_CHANGED;
678 // cache changeable folder properties
679 GetStorageProperties();
682 void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDest, bool bDirect )
684 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
686 uno::Reference< beans::XPropertySet > xPropSet( xDest, uno::UNO_QUERY );
687 if ( !xPropSet.is() )
688 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
690 sal_Int32 nDestMode = embed::ElementModes::READ;
691 xPropSet->getPropertyValue( "OpenMode" ) >>= nDestMode;
693 if ( !( nDestMode & embed::ElementModes::WRITE ) )
694 throw io::IOException( THROW_WHERE ); // TODO: access_denied
696 ReadContents();
698 if ( !m_xPackageFolder.is() )
699 throw embed::InvalidStorageException( THROW_WHERE );
701 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
702 pElementIter != m_aChildrenList.end(); ++pElementIter )
704 if ( !(*pElementIter)->m_bIsRemoved )
705 CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect );
708 // move storage properties to the destination one ( means changeable properties )
709 if ( m_nStorageType == embed::StorageFormats::PACKAGE )
711 OUString aMediaTypeString = "MediaType";
712 OUString aVersionString = "Version";
713 xPropSet->setPropertyValue( aMediaTypeString, uno::makeAny( m_aMediaType ) );
714 xPropSet->setPropertyValue( aVersionString, uno::makeAny( m_aVersion ) );
717 if ( m_nStorageType == embed::StorageFormats::PACKAGE )
719 // if this is a root storage, the common key from current one should be moved there
720 bool bIsRoot = false;
721 OUString aRootString = "IsRoot";
722 if ( ( xPropSet->getPropertyValue( aRootString ) >>= bIsRoot ) && bIsRoot )
726 uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY );
727 if ( xEncr.is() )
729 xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() );
731 uno::Sequence< beans::NamedValue > aAlgorithms;
732 uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW );
733 xPackPropSet->getPropertyValue( ENCRYPTION_ALGORITHMS_PROPERTY )
734 >>= aAlgorithms;
735 xEncr->setEncryptionAlgorithms( aAlgorithms );
738 catch( const packages::NoEncryptionException& rNoEncryptionException )
740 AddLog( rNoEncryptionException.Message );
741 AddLog( THROW_WHERE "No Encryption" );
745 else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
748 // TODO/LATER: currently the optimization is not active
749 // uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( OUString() ); // own stream
750 // if ( xRelInfoStream.is() )
751 // {
752 // // Relations info stream is a writeonly property, introduced only to optimyze copying
753 // // Should be used carefuly since no check for stream consistency is done, and the stream must not stay locked
755 // OUString aRelInfoString = "RelationsInfoStream";
756 // xPropSet->setPropertyValue( aRelInfoString, uno::makeAny( GetSeekableTempCopy( xRelInfoStream, m_xFactory ) ) );
757 // }
759 uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
760 if ( !xRels.is() )
761 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
763 xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
766 // if possible the destination storage should be committed after successful copying
767 uno::Reference< embed::XTransactedObject > xObjToCommit( xDest, uno::UNO_QUERY );
768 if ( xObjToCommit.is() )
769 xObjToCommit->commit();
772 void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
773 uno::Reference< embed::XStorage > xDest,
774 const OUString& aName,
775 bool bDirect )
777 SAL_WARN_IF( !xDest.is(), "package.xstor", "No destination storage!" );
778 SAL_WARN_IF( aName.isEmpty(), "package.xstor", "Empty element name!" );
780 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
782 uno::Reference< container::XNameAccess > xDestAccess( xDest, uno::UNO_QUERY );
783 if ( !xDestAccess.is() )
784 throw uno::RuntimeException( THROW_WHERE );
786 if ( xDestAccess->hasByName( aName )
787 && !( pElement->m_bIsStorage && xDest->isStorageElement( aName ) ) )
788 xDest->removeElement( aName );
790 if ( pElement->m_bIsStorage )
792 uno::Reference< embed::XStorage > xSubDest =
793 xDest->openStorageElement( aName,
794 embed::ElementModes::WRITE );
796 SAL_WARN_IF( !xSubDest.is(), "package.xstor", "No destination substorage!" );
798 if ( !pElement->m_pStorage )
800 OpenSubStorage( pElement, embed::ElementModes::READ );
801 if ( !pElement->m_pStorage )
802 throw io::IOException( THROW_WHERE );
805 pElement->m_pStorage->CopyToStorage( xSubDest, bDirect );
807 else
809 if ( !pElement->m_pStream )
811 OpenSubStream( pElement );
812 if ( !pElement->m_pStream )
813 throw io::IOException( THROW_WHERE );
816 if ( !pElement->m_pStream->IsEncrypted() )
818 if ( bDirect )
820 // fill in the properties for the stream
821 uno::Sequence< beans::PropertyValue > aStrProps(0);
822 uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties();
823 sal_Int32 nNum = 0;
824 for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ )
826 if ( aSrcPkgProps[ind].Name == "MediaType" || aSrcPkgProps[ind].Name == "Compressed" )
828 aStrProps.realloc( ++nNum );
829 aStrProps[nNum-1].Name = aSrcPkgProps[ind].Name;
830 aStrProps[nNum-1].Value = aSrcPkgProps[ind].Value;
834 if ( m_nStorageType == embed::StorageFormats::PACKAGE )
836 aStrProps.realloc( ++nNum );
837 aStrProps[nNum-1].Name = "UseCommonStoragePasswordEncryption";
838 aStrProps[nNum-1].Value <<= pElement->m_pStream->UsesCommonEncryption_Impl();
840 else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
842 // TODO/LATER: currently the optimization is not active
843 // uno::Reference< io::XInputStream > xInStream = GetRelInfoStreamForName( OUString() ); // own rels stream
844 // if ( xInStream.is() )
845 // {
846 // aStrProps.realloc( ++nNum );
847 // aStrProps[nNum-1].Name = "RelationsInfoStream";
848 // aStrProps[nNum-1].Value <<= GetSeekableTempCopy( xInStream, m_xFactory );
849 // }
851 uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
852 if ( !xRels.is() )
853 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
855 xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
858 uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW );
859 uno::Reference < io::XInputStream > xInputToInsert;
861 if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() )
863 SAL_WARN_IF( !pElement->m_pStream->m_xPackageStream.is(), "package.xstor", "No package stream!" );
865 // if the stream is modified - the temporary file must be used for insertion
866 xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream();
868 else
870 // for now get just nonseekable access to the stream
871 // TODO/LATER: the raw stream can be used
873 xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream();
876 if ( !xInputToInsert.is() )
877 throw io::IOException( THROW_WHERE );
879 xOptDest->insertStreamElementDirect( aName, xInputToInsert, aStrProps );
881 else
883 uno::Reference< io::XStream > xSubStr =
884 xDest->openStreamElement( aName,
885 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
886 SAL_WARN_IF( !xSubStr.is(), "package.xstor", "No destination substream!" );
888 pElement->m_pStream->CopyInternallyTo_Impl( xSubStr );
891 else if ( m_nStorageType != embed::StorageFormats::PACKAGE )
893 SAL_WARN( "package.xstor", "Encryption is only supported in package storage!" );
894 throw io::IOException( THROW_WHERE );
896 else if ( pElement->m_pStream->HasCachedEncryptionData()
897 && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) )
899 ::comphelper::SequenceAsHashMap aCommonEncryptionData;
900 bool bHasCommonEncryptionData = false;
903 aCommonEncryptionData = GetCommonRootEncryptionData();
904 bHasCommonEncryptionData = true;
906 catch( const packages::NoEncryptionException& rNoEncryptionException )
908 AddLog( rNoEncryptionException.Message );
909 AddLog( THROW_WHERE "No Encryption" );
912 if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) )
914 // If the stream can be opened with the common storage password
915 // it must be stored with the common storage password as well
916 uno::Reference< io::XStream > xDestStream =
917 xDest->openStreamElement( aName,
918 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
920 pElement->m_pStream->CopyInternallyTo_Impl( xDestStream );
922 uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
923 xProps->setPropertyValue(
924 "UseCommonStoragePasswordEncryption",
925 uno::Any( true ) );
927 else
929 // the stream is already opened for writing or was changed
930 uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW );
931 uno::Reference< io::XStream > xSubStr =
932 xDest2->openEncryptedStream( aName,
933 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
934 pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() );
935 SAL_WARN_IF( !xSubStr.is(), "package.xstor", "No destination substream!" );
937 pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() );
940 else
942 // the stream is not opened at all, so it can be just opened for reading
945 // If the stream can be opened with the common storage password
946 // it must be stored with the common storage password as well
948 uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ,
949 false );
950 uno::Reference< io::XStream > xDestStream =
951 xDest->openStreamElement( aName,
952 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
953 SAL_WARN_IF( !xDestStream.is(), "package.xstor", "No destination substream!" );
954 completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
956 uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
957 xProps->setPropertyValue(
958 "UseCommonStoragePasswordEncryption",
959 uno::Any( true ) );
961 catch( const packages::WrongPasswordException& rWrongPasswordException )
963 AddLog( rWrongPasswordException.Message );
964 AddLog( THROW_WHERE "Handled exception" );
966 // If the common storage password does not allow to open the stream
967 // it could be copyed in raw way, the problem is that the StartKey should be the same
968 // in the ODF1.2 package, so an invalid package could be produced if the stream
969 // is copied from ODF1.1 package, where it is allowed to have different StartKeys
970 uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW );
971 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
972 xRawDest->insertRawEncrStreamElement( aName, xRawInStream );
978 uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelationshipsIfAny()
980 if ( m_nStorageType != embed::StorageFormats::OFOPXML )
981 return uno::Sequence< uno::Sequence< beans::StringPair > >();
983 ReadRelInfoIfNecessary();
985 if ( m_nRelInfoStatus == RELINFO_READ
986 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
987 return m_aRelInfo;
988 else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
989 throw io::IOException( THROW_WHERE "Wrong relinfo stream!" );
992 void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor )
994 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
996 SAL_WARN_IF( !m_xPackageFolder.is(), "package.xstor", "A committed storage is incomplete!" );
997 if ( !m_xPackageFolder.is() )
998 throw uno::RuntimeException( THROW_WHERE );
1000 OStorage_Impl aTempRepresent( NULL,
1001 embed::ElementModes::READ,
1002 m_xPackageFolder,
1003 m_xPackage,
1004 m_xContext,
1005 m_nStorageType);
1007 // TODO/LATER: could use direct copying
1008 aTempRepresent.CopyToStorage( xNewStor, false );
1011 void OStorage_Impl::InsertIntoPackageFolder( const OUString& aName,
1012 const uno::Reference< container::XNameContainer >& xParentPackageFolder )
1014 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1016 SAL_WARN_IF( !m_xPackageFolder.is(), "package.xstor", "An inserted storage is incomplete!" );
1017 uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageFolder, uno::UNO_QUERY );
1018 if ( !xTunnel.is() )
1019 throw uno::RuntimeException( THROW_WHERE );
1021 xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) );
1023 m_bCommited = false;
1026 void OStorage_Impl::Commit()
1028 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1030 if ( !m_bIsModified )
1031 return;
1033 // in case of a new empty storage it is possible that the contents are still not read
1034 // ( the storage of course has no contents, but the initialization is postponed till the first use,
1035 // thus if a new storage was created and committed immediately it must be initialized here )
1036 ReadContents();
1038 // if storage is committed it should have a valid Package representation
1039 SAL_WARN_IF( !m_xPackageFolder.is(), "package.xstor", "The package representation should exist!" );
1040 if ( !m_xPackageFolder.is() )
1041 throw embed::InvalidStorageException( THROW_WHERE );
1043 OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE,
1044 "Commit of readonly storage, should be detected before!\n" );
1046 uno::Reference< container::XNameContainer > xNewPackageFolder;
1048 // here the storage will switch to the temporary package folder
1049 // if the storage was already committed and the parent was not committed after that
1050 // the switch should not be done since the package folder in use is a temporary one;
1051 // it can be detected by m_bCommited flag ( root storage doesn't need temporary representation )
1052 if ( !m_bCommited && !m_bIsRoot )
1054 uno::Sequence< uno::Any > aSeq( 1 );
1055 aSeq[0] <<= sal_True;
1057 xNewPackageFolder = uno::Reference< container::XNameContainer >(
1058 m_xPackage->createInstanceWithArguments( aSeq ),
1059 uno::UNO_QUERY );
1061 else
1062 xNewPackageFolder = m_xPackageFolder;
1064 // remove replaced removed elements
1065 for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1066 pDeletedIter != m_aDeletedList.end();
1067 ++pDeletedIter )
1070 if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage )
1071 RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName );
1073 // the removed elements are not in new temporary storage
1074 if ( m_bCommited || m_bIsRoot )
1075 xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName );
1076 delete *pDeletedIter;
1077 *pDeletedIter = NULL;
1079 m_aDeletedList.clear();
1081 // remove removed elements
1082 SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1083 while ( pElementIter != m_aChildrenList.end() )
1085 // renamed and inserted elements must be really inserted to package later
1086 // since thay can conflict with removed elements
1088 if ( (*pElementIter)->m_bIsRemoved )
1090 if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
1091 RemoveStreamRelInfo( (*pElementIter)->m_aOriginalName );
1093 // the removed elements are not in new temporary storage
1094 if ( m_bCommited || m_bIsRoot )
1095 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1097 SotElement_Impl* pToDelete = *pElementIter;
1099 ++pElementIter; // to let the iterator be valid it should be increased before removing
1101 m_aChildrenList.remove( pToDelete );
1102 delete pToDelete;
1104 else
1105 ++pElementIter;
1108 // there should be no more deleted elements
1109 for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); ++pElementIter )
1111 // if it is a 'duplicate commit' inserted elements must be really inserted to package later
1112 // since thay can conflict with renamed elements
1114 if ( !(*pElementIter)->m_bIsInserted )
1116 // for now stream is opened in direct mode that means that in case
1117 // storage is committed all the streams from it are committed in current state.
1118 // following two steps are separated to allow easily implement transacted mode
1119 // for streams if we need it in future.
1120 // Only hierarchical access uses transacted streams currently
1121 if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream
1122 && !(*pElementIter)->m_pStream->IsTransacted() )
1123 (*pElementIter)->m_pStream->Commit();
1125 // if the storage was not open, there is no need to commit it ???
1126 // the storage should be checked that it is committed
1127 if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited )
1129 // it's temporary PackageFolder should be inserted instead of current one
1130 // also the new copy of PackageFolder should be used by the children storages
1132 // the renamed elements are not in new temporary storage
1133 if ( m_bCommited || m_bIsRoot )
1134 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1136 (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1138 else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed )
1140 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1141 CommitStreamRelInfo( *pElementIter );
1143 // the renamed elements are not in new temporary storage
1144 if ( m_bCommited || m_bIsRoot )
1145 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1147 (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1149 else if ( !m_bCommited && !m_bIsRoot )
1151 // the element must be just copied to the new temporary package folder
1152 // the connection with the original package should not be lost just because
1153 // the element is still referred by the folder in the original hierarchy
1154 uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1155 xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1157 else if ( (*pElementIter)->m_aName.compareTo( (*pElementIter)->m_aOriginalName ) )
1159 // this is the case when xNewPackageFolder refers to m_xPackageFolder
1160 // in case the name was changed and it is not a changed storage - rename the element
1161 uno::Reference< container::XNamed > xNamed;
1162 uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1163 xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1164 xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1166 if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
1168 if ( !(*pElementIter)->m_pStream )
1170 OpenSubStream( *pElementIter );
1171 if ( !(*pElementIter)->m_pStream )
1172 throw uno::RuntimeException( THROW_WHERE );
1175 CommitStreamRelInfo( *pElementIter );
1179 (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1183 for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); ++pElementIter )
1185 // now inserted elements can be inserted to the package
1186 if ( (*pElementIter)->m_bIsInserted )
1188 (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1189 uno::Reference< lang::XUnoTunnel > xNewElement;
1191 if ( (*pElementIter)->m_bIsStorage )
1193 if ( (*pElementIter)->m_pStorage->m_bCommited )
1195 OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" );
1196 if ( !(*pElementIter)->m_pStorage )
1197 throw uno::RuntimeException( THROW_WHERE );
1199 (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1201 (*pElementIter)->m_bIsInserted = false;
1204 else
1206 OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" );
1207 if ( !(*pElementIter)->m_pStream )
1208 throw uno::RuntimeException( THROW_WHERE );
1210 if ( !(*pElementIter)->m_pStream->IsTransacted() )
1211 (*pElementIter)->m_pStream->Commit();
1213 if ( (*pElementIter)->m_pStream->m_bFlushed )
1215 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1216 CommitStreamRelInfo( *pElementIter );
1218 (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1220 (*pElementIter)->m_bIsInserted = false;
1226 if ( m_nStorageType == embed::StorageFormats::PACKAGE )
1228 // move properties to the destination package folder
1229 uno::Reference< beans::XPropertySet > xProps( xNewPackageFolder, uno::UNO_QUERY );
1230 if ( !xProps.is() )
1231 throw uno::RuntimeException( THROW_WHERE );
1233 xProps->setPropertyValue( "MediaType", uno::makeAny( m_aMediaType ) );
1234 xProps->setPropertyValue( "Version", uno::makeAny( m_aVersion ) );
1237 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1238 CommitRelInfo( xNewPackageFolder ); // store own relations and commit complete relations storage
1240 if ( m_bIsRoot )
1242 uno::Reference< util::XChangesBatch > xChangesBatch( m_xPackage, uno::UNO_QUERY );
1244 SAL_WARN_IF( !xChangesBatch.is(), "package.xstor", "Impossible to commit package!" );
1245 if ( !xChangesBatch.is() )
1246 throw uno::RuntimeException( THROW_WHERE );
1250 xChangesBatch->commitChanges();
1252 catch( const lang::WrappedTargetException& r )
1254 // the wrapped UseBackupException means that the target medium can be corrupted
1255 embed::UseBackupException aException;
1256 if ( r.TargetException >>= aException )
1258 m_xStream = uno::Reference< io::XStream >();
1259 m_xInputStream = uno::Reference< io::XInputStream >();
1260 throw aException;
1263 AddLog( aException.Message );
1264 AddLog( THROW_WHERE "Rethrow" );
1265 throw;
1268 else if ( !m_bCommited )
1270 m_xPackageFolder = xNewPackageFolder;
1271 m_bCommited = true;
1274 // after commit the mediatype treated as the correct one
1275 m_bMTFallbackUsed = false;
1278 void OStorage_Impl::Revert()
1280 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1282 if ( !( m_nStorageMode & embed::ElementModes::WRITE ) )
1283 return; // nothing to do
1285 // all the children must be removed
1286 // they will be created later on demand
1288 SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1289 while ( pElementIter != m_aChildrenList.end() )
1291 if ( (*pElementIter)->m_bIsInserted )
1293 SotElement_Impl* pToDelete = *pElementIter;
1295 ++pElementIter; // to let the iterator be valid it should be increased before removing
1297 m_aChildrenList.remove( pToDelete );
1298 delete pToDelete;
1300 else
1302 ClearElement( *pElementIter );
1304 (*pElementIter)->m_aName = (*pElementIter)->m_aOriginalName;
1305 (*pElementIter)->m_bIsRemoved = false;
1307 ++pElementIter;
1311 // return replaced removed elements
1312 for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1313 pDeletedIter != m_aDeletedList.end();
1314 ++pDeletedIter )
1316 m_aChildrenList.push_back( (*pDeletedIter) );
1318 ClearElement( *pDeletedIter );
1320 (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName;
1321 (*pDeletedIter)->m_bIsRemoved = false;
1323 m_aDeletedList.clear();
1325 m_bControlMediaType = false;
1326 m_bControlVersion = false;
1328 GetStorageProperties();
1330 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1332 // currently the relations storage is changed only on commit
1333 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1334 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1335 m_nRelInfoStatus = RELINFO_NO_INIT;
1339 ::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData()
1340 throw ( packages::NoEncryptionException )
1342 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1344 if ( m_nStorageType != embed::StorageFormats::PACKAGE )
1345 throw packages::NoEncryptionException( THROW_WHERE );
1347 if ( m_bIsRoot )
1349 if ( !m_bHasCommonEncryptionData )
1350 throw packages::NoEncryptionException( THROW_WHERE );
1352 return m_aCommonEncryptionData;
1354 else
1356 if ( !m_pParent )
1357 throw packages::NoEncryptionException( THROW_WHERE );
1359 return m_pParent->GetCommonRootEncryptionData();
1363 SotElement_Impl* OStorage_Impl::FindElement( const OUString& rName )
1365 SAL_WARN_IF( rName.isEmpty(), "package.xstor", "Name is empty!" );
1367 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1369 ReadContents();
1371 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1372 pElementIter != m_aChildrenList.end(); ++pElementIter )
1374 if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved )
1375 return *pElementIter;
1378 return NULL;
1381 SotElement_Impl* OStorage_Impl::InsertStream( const OUString& aName, bool bEncr )
1383 SAL_WARN_IF( !m_xPackage.is(), "package.xstor", "Not possible to refer to package as to factory!" );
1384 if ( !m_xPackage.is() )
1385 throw embed::InvalidStorageException( THROW_WHERE);
1387 uno::Sequence< uno::Any > aSeq( 1 );
1388 aSeq[0] <<= sal_False;
1389 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1390 uno::UNO_QUERY );
1392 SAL_WARN_IF( !xNewElement.is(), "package.xstor", "Not possible to create a new stream!" );
1393 if ( !xNewElement.is() )
1394 throw io::IOException( THROW_WHERE );
1396 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1397 if ( !xPackageSubStream.is() )
1398 throw uno::RuntimeException( THROW_WHERE );
1400 OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE || !bEncr, "Only package storage supports encryption!\n" );
1401 if ( m_nStorageType != embed::StorageFormats::PACKAGE && bEncr )
1402 throw packages::NoEncryptionException( THROW_WHERE );
1404 // the mode is not needed for storage stream internal implementation
1405 SotElement_Impl* pNewElement = InsertElement( aName, false );
1406 pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, bEncr, m_nStorageType, true );
1408 m_aChildrenList.push_back( pNewElement );
1409 m_bIsModified = true;
1410 m_bBroadcastModified = true;
1412 return pNewElement;
1415 SotElement_Impl* OStorage_Impl::InsertRawStream( const OUString& aName, const uno::Reference< io::XInputStream >& xInStream )
1417 // insert of raw stream means insert and commit
1418 SAL_WARN_IF( !m_xPackage.is(), "package.xstor", "Not possible to refer to package as to factory!" );
1419 if ( !m_xPackage.is() )
1420 throw embed::InvalidStorageException( THROW_WHERE );
1422 if ( m_nStorageType != embed::StorageFormats::PACKAGE )
1423 throw packages::NoEncryptionException( THROW_WHERE );
1425 uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
1426 uno::Reference< io::XInputStream > xInStrToInsert = xSeek.is() ? xInStream :
1427 GetSeekableTempCopy( xInStream, GetComponentContext() );
1429 uno::Sequence< uno::Any > aSeq( 1 );
1430 aSeq[0] <<= sal_False;
1431 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1432 uno::UNO_QUERY );
1434 SAL_WARN_IF( !xNewElement.is(), "package.xstor", "Not possible to create a new stream!" );
1435 if ( !xNewElement.is() )
1436 throw io::IOException( THROW_WHERE );
1438 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1439 if ( !xPackageSubStream.is() )
1440 throw uno::RuntimeException( THROW_WHERE );
1442 xPackageSubStream->setRawStream( xInStrToInsert );
1444 // the mode is not needed for storage stream internal implementation
1445 SotElement_Impl* pNewElement = InsertElement( aName, false );
1446 pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, true, m_nStorageType, false );
1447 // the stream is inserted and must be treated as a committed one
1448 pNewElement->m_pStream->SetToBeCommited();
1450 m_aChildrenList.push_back( pNewElement );
1451 m_bIsModified = true;
1452 m_bBroadcastModified = true;
1454 return pNewElement;
1457 OStorage_Impl* OStorage_Impl::CreateNewStorageImpl( sal_Int32 nStorageMode )
1459 SAL_WARN_IF( !m_xPackage.is(), "package.xstor", "Not possible to refer to package as to factory!" );
1460 if ( !m_xPackage.is() )
1461 throw embed::InvalidStorageException( THROW_WHERE );
1463 uno::Sequence< uno::Any > aSeq( 1 );
1464 aSeq[0] <<= sal_True;
1465 uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1466 uno::UNO_QUERY );
1468 SAL_WARN_IF( !xNewElement.is(), "package.xstor", "Not possible to create a new storage!" );
1469 if ( !xNewElement.is() )
1470 throw io::IOException( THROW_WHERE );
1472 uno::Reference< container::XNameContainer > xPackageSubFolder( xNewElement, uno::UNO_QUERY );
1473 if ( !xPackageSubFolder.is() )
1474 throw uno::RuntimeException( THROW_WHERE );
1476 OStorage_Impl* pResult =
1477 new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xContext, m_nStorageType );
1478 pResult->m_bIsModified = true;
1480 return pResult;
1483 SotElement_Impl* OStorage_Impl::InsertStorage( const OUString& aName, sal_Int32 nStorageMode )
1485 SotElement_Impl* pNewElement = InsertElement( aName, true );
1487 pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode );
1489 m_aChildrenList.push_back( pNewElement );
1491 return pNewElement;
1494 SotElement_Impl* OStorage_Impl::InsertElement( const OUString& aName, bool bIsStorage )
1496 OSL_ENSURE( FindElement( aName ) == NULL, "Should not try to insert existing element" );
1498 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1500 SotElement_Impl* pDeletedElm = NULL;
1502 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1503 pElementIter != m_aChildrenList.end(); ++pElementIter )
1505 if ( (*pElementIter)->m_aName == aName )
1507 SAL_WARN_IF( !(*pElementIter)->m_bIsRemoved, "package.xstor", "Try to insert an element instead of existing one!" );
1508 if ( (*pElementIter)->m_bIsRemoved )
1510 SAL_WARN_IF( (*pElementIter)->m_bIsInserted, "package.xstor", "Inserted elements must be deleted immediatelly!" );
1511 pDeletedElm = *pElementIter;
1512 break;
1517 if ( pDeletedElm )
1519 if ( pDeletedElm->m_bIsStorage )
1520 OpenSubStorage( pDeletedElm, embed::ElementModes::READWRITE );
1521 else
1522 OpenSubStream( pDeletedElm );
1524 m_aChildrenList.remove( pDeletedElm ); // correct usage of list ???
1525 m_aDeletedList.push_back( pDeletedElm );
1528 // create new element
1529 return new SotElement_Impl( aName, bIsStorage, true );
1532 void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode )
1534 SAL_WARN_IF( !pElement, "package.xstor", "pElement is not set!" );
1535 SAL_WARN_IF( !pElement->m_bIsStorage, "package.xstor", "Storage flag is not set!" );
1537 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1539 if ( !pElement->m_pStorage )
1541 SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted element must be created already!" );
1543 uno::Reference< lang::XUnoTunnel > xTunnel;
1544 m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1545 if ( !xTunnel.is() )
1546 throw container::NoSuchElementException( THROW_WHERE );
1548 uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY );
1550 SAL_WARN_IF( !xPackageSubFolder.is(), "package.xstor", "Can not get XNameContainer interface from folder!" );
1552 if ( !xPackageSubFolder.is() )
1553 throw uno::RuntimeException( THROW_WHERE );
1555 pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xContext, m_nStorageType );
1559 void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
1561 SAL_WARN_IF( !pElement, "package.xstor", "pElement is not set!" );
1562 SAL_WARN_IF( pElement->m_bIsStorage, "package.xstor", "Storage flag is set!" );
1564 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1566 if ( !pElement->m_pStream )
1568 SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted element must be created already!" );
1570 uno::Reference< lang::XUnoTunnel > xTunnel;
1571 m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1572 if ( !xTunnel.is() )
1573 throw container::NoSuchElementException( THROW_WHERE );
1575 uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY );
1576 if ( !xPackageSubStream.is() )
1577 throw uno::RuntimeException( THROW_WHERE );
1579 // the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction
1580 pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, false, m_nStorageType, false, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
1584 uno::Sequence< OUString > OStorage_Impl::GetElementNames()
1586 ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1588 ReadContents();
1590 sal_uInt32 nSize = m_aChildrenList.size();
1591 uno::Sequence< OUString > aElementNames( nSize );
1593 sal_uInt32 nInd = 0;
1594 for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1595 pElementIter != m_aChildrenList.end(); ++pElementIter )
1597 if ( !(*pElementIter)->m_bIsRemoved )
1598 aElementNames[nInd++] = (*pElementIter)->m_aName;
1601 aElementNames.realloc( nInd );
1602 return aElementNames;
1605 void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
1607 SAL_WARN_IF( !pElement, "package.xstor", "Element must be provided!" );
1609 if ( !pElement )
1610 return;
1612 if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() ))
1613 || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) )
1614 throw io::IOException( THROW_WHERE ); // TODO: Access denied
1616 if ( pElement->m_bIsInserted )
1618 m_aChildrenList.remove( pElement );
1619 delete pElement; // ???
1621 else
1623 pElement->m_bIsRemoved = true;
1624 ClearElement( pElement );
1627 // TODO/OFOPXML: the rel stream should be removed as well
1630 void OStorage_Impl::ClearElement( SotElement_Impl* pElement )
1632 if ( pElement->m_pStorage )
1634 delete pElement->m_pStorage;
1635 pElement->m_pStorage = NULL;
1638 if ( pElement->m_pStream )
1640 delete pElement->m_pStream;
1641 pElement->m_pStream = NULL;
1645 void OStorage_Impl::CloneStreamElement( const OUString& aStreamName,
1646 bool bEncryptionDataProvided,
1647 const ::comphelper::SequenceAsHashMap& aEncryptionData,
1648 uno::Reference< io::XStream >& xTargetStream )
1649 throw ( embed::InvalidStorageException,
1650 lang::IllegalArgumentException,
1651 packages::WrongPasswordException,
1652 packages::NoEncryptionException,
1653 container::NoSuchElementException,
1654 io::IOException,
1655 embed::StorageWrappedTargetException,
1656 uno::RuntimeException )
1658 SotElement_Impl *pElement = FindElement( aStreamName );
1659 if ( !pElement )
1661 // element does not exist, throw exception
1662 throw io::IOException( THROW_WHERE ); // TODO: access_denied
1664 else if ( pElement->m_bIsStorage )
1665 throw io::IOException( THROW_WHERE );
1667 if ( !pElement->m_pStream )
1668 OpenSubStream( pElement );
1670 if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() )
1672 // the existence of m_pAntiImpl of the child is not interesting,
1673 // the copy will be created internally
1675 // usual copying is not applicable here, only last flushed version of the
1676 // child stream should be used for copiing. Probably the children m_xPackageStream
1677 // can be used as a base of a new stream, that would be copied to result
1678 // storage. The only problem is that some package streams can be accessed from outside
1679 // at the same time ( now solwed by wrappers that remember own position ).
1681 if ( bEncryptionDataProvided )
1682 pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData );
1683 else
1684 pElement->m_pStream->GetCopyOfLastCommit( xTargetStream );
1686 else
1687 throw io::IOException( THROW_WHERE ); // TODO: general_error
1690 void OStorage_Impl::RemoveStreamRelInfo( const OUString& aOriginalName )
1692 // this method should be used only in OStorage_Impl::Commit() method
1693 // the aOriginalName can be empty, in this case the storage relation info should be removed
1695 if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_xRelStorage.is() )
1697 OUString aRelStreamName = aOriginalName;
1698 aRelStreamName += ".rels";
1700 if ( m_xRelStorage->hasByName( aRelStreamName ) )
1701 m_xRelStorage->removeElement( aRelStreamName );
1705 void OStorage_Impl::CreateRelStorage()
1707 if ( m_nStorageType != embed::StorageFormats::OFOPXML )
1708 return;
1710 if ( !m_xRelStorage.is() )
1712 if ( !m_pRelStorElement )
1714 m_pRelStorElement = new SotElement_Impl( "_rels", true, true );
1715 m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE );
1716 if ( m_pRelStorElement->m_pStorage )
1717 m_pRelStorElement->m_pStorage->m_pParent = NULL; // the relation storage is completely controlled by parent
1720 if ( !m_pRelStorElement->m_pStorage )
1721 OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE );
1723 if ( !m_pRelStorElement->m_pStorage )
1724 throw uno::RuntimeException( THROW_WHERE );
1726 OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, false );
1727 m_xRelStorage = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
1731 void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement )
1733 // this method should be used only in OStorage_Impl::Commit() method
1735 // the stream element must be provided
1736 if ( !pStreamElement )
1737 throw uno::RuntimeException( THROW_WHERE );
1739 if ( m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_pStream )
1741 SAL_WARN_IF( pStreamElement->m_aName.isEmpty(), "package.xstor", "The name must not be empty!" );
1743 if ( !m_xRelStorage.is() )
1745 // Create new rels storage, this is commit scenario so it must be possible
1746 CreateRelStorage();
1749 pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName );
1753 uno::Reference< io::XInputStream > OStorage_Impl::GetRelInfoStreamForName( const OUString& aName )
1755 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1757 ReadContents();
1758 if ( m_xRelStorage.is() )
1760 OUString aRelStreamName = aName;
1761 aRelStreamName += ".rels";
1762 if ( m_xRelStorage->hasByName( aRelStreamName ) )
1764 uno::Reference< io::XStream > xStream = m_xRelStorage->openStreamElement( aRelStreamName, embed::ElementModes::READ );
1765 if ( xStream.is() )
1766 return xStream->getInputStream();
1771 return uno::Reference< io::XInputStream >();
1774 void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContainer >& xNewPackageFolder )
1776 // this method should be used only in OStorage_Impl::Commit() method
1777 OUString aRelsStorName("_rels");
1779 if ( !xNewPackageFolder.is() )
1780 throw uno::RuntimeException( THROW_WHERE );
1782 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1784 if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN )
1785 throw io::IOException( THROW_WHERE );
1787 if ( m_nRelInfoStatus == RELINFO_CHANGED
1788 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1789 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1791 if ( m_nRelInfoStatus == RELINFO_CHANGED )
1793 if ( m_aRelInfo.getLength() )
1795 CreateRelStorage();
1797 uno::Reference< io::XStream > xRelsStream =
1798 m_xRelStorage->openStreamElement( ".rels" ,
1799 embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1801 uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream();
1802 if ( !xOutStream.is() )
1803 throw uno::RuntimeException( THROW_WHERE );
1805 ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aRelInfo, m_xContext );
1807 // set the mediatype
1808 uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1809 xPropSet->setPropertyValue(
1810 "MediaType",
1811 uno::makeAny( OUString( "application/vnd.openxmlformats-package.relationships+xml" ) ) );
1813 m_nRelInfoStatus = RELINFO_READ;
1815 else if ( m_xRelStorage.is() )
1816 RemoveStreamRelInfo( OUString() ); // remove own rel info
1818 else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1819 || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1821 CreateRelStorage();
1823 uno::Reference< io::XStream > xRelsStream =
1824 m_xRelStorage->openStreamElement( ".rels",
1825 embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1827 uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream();
1828 if ( !xOutputStream.is() )
1829 throw uno::RuntimeException( THROW_WHERE );
1831 uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW );
1832 xSeek->seek( 0 );
1833 ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream );
1835 // set the mediatype
1836 uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1837 xPropSet->setPropertyValue(
1838 "MediaType",
1839 uno::makeAny( OUString( "application/vnd.openxmlformats-package.relationships+xml" ) ) );
1841 m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1842 if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1844 m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1845 m_nRelInfoStatus = RELINFO_NO_INIT;
1847 else
1848 m_nRelInfoStatus = RELINFO_READ;
1852 if ( m_xRelStorage.is() )
1854 if ( m_xRelStorage->hasElements() )
1856 uno::Reference< embed::XTransactedObject > xTrans( m_xRelStorage, uno::UNO_QUERY_THROW );
1857 if ( xTrans.is() )
1858 xTrans->commit();
1861 if ( xNewPackageFolder.is() && xNewPackageFolder->hasByName( aRelsStorName ) )
1862 xNewPackageFolder->removeByName( aRelsStorName );
1864 if ( !m_xRelStorage->hasElements() )
1866 // the empty relations storage should not be created
1867 delete m_pRelStorElement;
1868 m_pRelStorElement = NULL;
1869 m_xRelStorage = uno::Reference< embed::XStorage >();
1871 else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() )
1872 m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder );
1877 // OStorage implementation
1879 OStorage::OStorage( uno::Reference< io::XInputStream > xInputStream,
1880 sal_Int32 nMode,
1881 const uno::Sequence< beans::PropertyValue >& xProperties,
1882 uno::Reference< uno::XComponentContext > xContext,
1883 sal_Int32 nStorageType )
1884 : m_pImpl( new OStorage_Impl( xInputStream, nMode, xProperties, xContext, nStorageType ) )
1886 m_pImpl->m_pAntiImpl = this;
1887 m_pData.reset(new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, false));
1890 OStorage::OStorage( uno::Reference< io::XStream > xStream,
1891 sal_Int32 nMode,
1892 const uno::Sequence< beans::PropertyValue >& xProperties,
1893 uno::Reference< uno::XComponentContext > xContext,
1894 sal_Int32 nStorageType )
1895 : m_pImpl( new OStorage_Impl( xStream, nMode, xProperties, xContext, nStorageType ) )
1897 m_pImpl->m_pAntiImpl = this;
1898 m_pData.reset(new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, false));
1901 OStorage::OStorage( OStorage_Impl* pImpl, bool bReadOnlyWrap )
1902 : m_pImpl( pImpl )
1904 // this call can be done only from OStorage_Impl implementation to create child storage
1905 OSL_ENSURE( m_pImpl && m_pImpl->m_rMutexRef.Is(), "The provided pointer & mutex MUST NOT be empty!\n" );
1907 m_pData.reset(new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, bReadOnlyWrap));
1909 OSL_ENSURE( ( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ||
1910 m_pData->m_bReadOnlyWrap,
1911 "The wrapper can not allow writing in case implementation does not!\n" );
1913 if ( !bReadOnlyWrap )
1914 m_pImpl->m_pAntiImpl = this;
1917 OStorage::~OStorage()
1919 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
1920 if ( m_pImpl )
1922 m_refCount++; // to call dispose
1923 try {
1924 dispose();
1926 catch( const uno::RuntimeException& rRuntimeException )
1928 m_pImpl->AddLog( rRuntimeException.Message );
1929 m_pImpl->AddLog( THROW_WHERE "Handled exception" );
1934 void SAL_CALL OStorage::InternalDispose( bool bNotifyImpl )
1936 if ( !m_pImpl )
1938 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
1939 throw lang::DisposedException( THROW_WHERE );
1942 // the source object is also a kind of locker for the current object
1943 // since the listeners could dispose the object while being notified
1944 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
1945 m_pData->m_aListenersContainer.disposeAndClear( aSource );
1946 m_pImpl->m_nModifiedListenerCount = 0;
1948 if ( m_pData->m_bReadOnlyWrap )
1950 OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener.get(),
1951 "If any subelements are open the listener must exist!\n" );
1953 if (m_pData->m_pSubElDispListener.get())
1955 m_pData->m_pSubElDispListener->OwnerIsDisposed();
1957 // iterate through m_pData->m_aOpenSubComponentsList
1958 // deregister m_pData->m_pSubElDispListener and dispose all of them
1959 if ( !m_pData->m_aOpenSubComponentsList.empty() )
1961 for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
1962 pCompIter != m_pData->m_aOpenSubComponentsList.end(); ++pCompIter )
1964 uno::Reference< lang::XComponent > xTmp = (*pCompIter);
1965 if ( xTmp.is() )
1967 xTmp->removeEventListener( uno::Reference< lang::XEventListener >(
1968 static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener.get())));
1970 try {
1971 xTmp->dispose();
1972 } catch( const uno::Exception& rException )
1974 m_pImpl->AddLog( rException.Message );
1975 m_pImpl->AddLog( THROW_WHERE "Quiet exception" );
1980 m_pData->m_aOpenSubComponentsList.clear();
1984 if ( bNotifyImpl )
1985 m_pImpl->RemoveReadOnlyWrap( *this );
1987 else
1989 m_pImpl->m_pAntiImpl = NULL;
1991 if ( bNotifyImpl )
1993 if ( m_pData->m_bIsRoot )
1994 delete m_pImpl;
1995 else
1997 // the non-committed changes for the storage must be removed
1998 m_pImpl->Revert();
2003 m_pImpl = NULL;
2006 void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild )
2008 // this method can only be called by child disposing listener
2010 // this method must not contain any locking
2011 // the locking is done in the listener
2013 if ( !m_pData->m_aOpenSubComponentsList.empty() )
2015 for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
2016 pCompIter != m_pData->m_aOpenSubComponentsList.end(); )
2018 uno::Reference< lang::XComponent > xTmp = (*pCompIter);
2019 if ( !xTmp.is() || xTmp == xChild )
2021 WeakComponentList::iterator pIterToRemove = pCompIter;
2022 ++pCompIter;
2023 m_pData->m_aOpenSubComponentsList.erase( pIterToRemove );
2025 else
2026 ++pCompIter;
2031 void OStorage::BroadcastModifiedIfNecessary()
2033 // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2034 if ( !m_pImpl )
2036 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2037 throw lang::DisposedException( THROW_WHERE );
2040 if ( !m_pImpl->m_bBroadcastModified )
2041 return;
2043 m_pImpl->m_bBroadcastModified = false;
2045 SAL_WARN_IF( m_pData->m_bReadOnlyWrap, "package.xstor", "The storage can not be modified at all!" );
2047 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2049 ::cppu::OInterfaceContainerHelper* pContainer =
2050 m_pData->m_aListenersContainer.getContainer(
2051 cppu::UnoType<util::XModifyListener>::get());
2052 if ( pContainer )
2054 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2055 while ( pIterator.hasMoreElements( ) )
2057 static_cast<util::XModifyListener*>( pIterator.next( ) )->modified( aSource );
2062 void OStorage::BroadcastTransaction( sal_Int8 nMessage )
2064 1 - preCommit
2065 2 - committed
2066 3 - preRevert
2067 4 - reverted
2070 // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2071 if ( !m_pImpl )
2073 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2074 throw lang::DisposedException( THROW_WHERE );
2077 SAL_WARN_IF( m_pData->m_bReadOnlyWrap, "package.xstor", "The storage can not be modified at all!" );
2079 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2081 ::cppu::OInterfaceContainerHelper* pContainer =
2082 m_pData->m_aListenersContainer.getContainer(
2083 cppu::UnoType<embed::XTransactionListener>::get());
2084 if ( pContainer )
2086 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2087 while ( pIterator.hasMoreElements( ) )
2089 OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" );
2091 switch( nMessage )
2093 case STOR_MESS_PRECOMMIT:
2094 static_cast<embed::XTransactionListener*>( pIterator.next( ) )->preCommit( aSource );
2095 break;
2096 case STOR_MESS_COMMITED:
2097 static_cast<embed::XTransactionListener*>( pIterator.next( ) )->commited( aSource );
2098 break;
2099 case STOR_MESS_PREREVERT:
2100 static_cast<embed::XTransactionListener*>( pIterator.next( ) )->preRevert( aSource );
2101 break;
2102 case STOR_MESS_REVERTED:
2103 static_cast<embed::XTransactionListener*>( pIterator.next( ) )->reverted( aSource );
2104 break;
2110 SotElement_Impl* OStorage::OpenStreamElement_Impl( const OUString& aStreamName, sal_Int32 nOpenMode, bool bEncr )
2112 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2114 OSL_ENSURE( !m_pData->m_bReadOnlyWrap || ( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE,
2115 "An element can not be opened for writing in readonly storage!\n" );
2117 SotElement_Impl *pElement = m_pImpl->FindElement( aStreamName );
2118 if ( !pElement )
2120 // element does not exist, check if creation is allowed
2121 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2122 || (( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2123 || ( nOpenMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2125 throw io::IOException("Element does not exist and cannot be "
2126 "created: \"" + aStreamName + "\""); // TODO: access_denied
2129 // create a new StreamElement and insert it into the list
2130 pElement = m_pImpl->InsertStream( aStreamName, bEncr );
2132 else if ( pElement->m_bIsStorage )
2134 throw io::IOException( THROW_WHERE );
2137 SAL_WARN_IF( !pElement, "package.xstor", "In case element can not be created an exception must be thrown!" );
2139 if ( !pElement->m_pStream )
2140 m_pImpl->OpenSubStream( pElement );
2142 if ( !pElement->m_pStream )
2143 throw io::IOException( THROW_WHERE );
2145 return pElement;
2148 void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XComponent >& xComponent )
2150 if ( !xComponent.is() )
2151 throw uno::RuntimeException( THROW_WHERE );
2153 if (!m_pData->m_pSubElDispListener.get())
2155 m_pData->m_pSubElDispListener = new OChildDispListener_Impl( *this );
2158 xComponent->addEventListener( uno::Reference< lang::XEventListener >(
2159 static_cast< ::cppu::OWeakObject* >(m_pData->m_pSubElDispListener.get()), uno::UNO_QUERY));
2161 m_pData->m_aOpenSubComponentsList.push_back( xComponent );
2164 // XInterface
2166 uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
2167 throw( uno::RuntimeException, std::exception )
2169 uno::Any aReturn;
2171 // common interfaces
2172 aReturn <<= ::cppu::queryInterface
2173 ( rType
2174 , static_cast<lang::XTypeProvider*> ( this )
2175 , static_cast<embed::XStorage*> ( this )
2176 , static_cast<embed::XStorage2*> ( this )
2177 , static_cast<embed::XTransactedObject*> ( this )
2178 , static_cast<embed::XTransactionBroadcaster*> ( this )
2179 , static_cast<util::XModifiable*> ( this )
2180 , static_cast<container::XNameAccess*> ( this )
2181 , static_cast<container::XElementAccess*> ( this )
2182 , static_cast<lang::XComponent*> ( this )
2183 , static_cast<beans::XPropertySet*> ( this )
2184 , static_cast<embed::XOptimizedStorage*> ( this ) );
2186 if ( aReturn.hasValue() )
2187 return aReturn ;
2189 aReturn <<= ::cppu::queryInterface
2190 ( rType
2191 , static_cast<embed::XHierarchicalStorageAccess*> ( this )
2192 , static_cast<embed::XHierarchicalStorageAccess2*> ( this ) );
2194 if ( aReturn.hasValue() )
2195 return aReturn ;
2197 if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2199 if ( m_pData->m_bIsRoot )
2201 aReturn <<= ::cppu::queryInterface
2202 ( rType
2203 , static_cast<embed::XStorageRawAccess*> ( this )
2204 , static_cast<embed::XEncryptionProtectedSource*> ( this )
2205 , static_cast<embed::XEncryptionProtectedSource2*> ( this )
2206 , static_cast<embed::XEncryptionProtectedStorage*> ( this ) );
2208 else
2210 aReturn <<= ::cppu::queryInterface
2211 ( rType
2212 , static_cast<embed::XStorageRawAccess*> ( this ) );
2215 else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2217 aReturn <<= ::cppu::queryInterface
2218 ( rType
2219 , static_cast<embed::XRelationshipAccess*> ( this ) );
2222 if ( aReturn.hasValue() )
2223 return aReturn ;
2225 return OWeakObject::queryInterface( rType );
2228 void SAL_CALL OStorage::acquire() throw()
2230 OWeakObject::acquire();
2233 void SAL_CALL OStorage::release() throw()
2235 OWeakObject::release();
2238 // XTypeProvider
2239 uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
2240 throw( uno::RuntimeException, std::exception )
2242 if (! m_pData->m_pTypeCollection)
2244 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2246 if (! m_pData->m_pTypeCollection)
2248 if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2250 if ( m_pData->m_bIsRoot )
2252 m_pData->m_pTypeCollection.reset(new ::cppu::OTypeCollection
2253 ( cppu::UnoType<lang::XTypeProvider>::get()
2254 , cppu::UnoType<embed::XStorage>::get()
2255 , cppu::UnoType<embed::XStorage2>::get()
2256 , cppu::UnoType<embed::XStorageRawAccess>::get()
2257 , cppu::UnoType<embed::XTransactedObject>::get()
2258 , cppu::UnoType<embed::XTransactionBroadcaster>::get()
2259 , cppu::UnoType<util::XModifiable>::get()
2260 , cppu::UnoType<embed::XEncryptionProtectedStorage>::get()
2261 , cppu::UnoType<embed::XEncryptionProtectedSource2>::get()
2262 , cppu::UnoType<embed::XEncryptionProtectedSource>::get()
2263 , cppu::UnoType<beans::XPropertySet>::get()));
2265 else
2267 m_pData->m_pTypeCollection.reset(new ::cppu::OTypeCollection
2268 ( cppu::UnoType<lang::XTypeProvider>::get()
2269 , cppu::UnoType<embed::XStorage>::get()
2270 , cppu::UnoType<embed::XStorage2>::get()
2271 , cppu::UnoType<embed::XStorageRawAccess>::get()
2272 , cppu::UnoType<embed::XTransactedObject>::get()
2273 , cppu::UnoType<embed::XTransactionBroadcaster>::get()
2274 , cppu::UnoType<util::XModifiable>::get()
2275 , cppu::UnoType<beans::XPropertySet>::get()));
2278 else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2280 m_pData->m_pTypeCollection.reset(new ::cppu::OTypeCollection
2281 ( cppu::UnoType<lang::XTypeProvider>::get()
2282 , cppu::UnoType<embed::XStorage>::get()
2283 , cppu::UnoType<embed::XTransactedObject>::get()
2284 , cppu::UnoType<embed::XTransactionBroadcaster>::get()
2285 , cppu::UnoType<util::XModifiable>::get()
2286 , cppu::UnoType<embed::XRelationshipAccess>::get()
2287 , cppu::UnoType<beans::XPropertySet>::get()));
2289 else
2291 m_pData->m_pTypeCollection.reset(new ::cppu::OTypeCollection
2292 ( cppu::UnoType<lang::XTypeProvider>::get()
2293 , cppu::UnoType<embed::XStorage>::get()
2294 , cppu::UnoType<embed::XTransactedObject>::get()
2295 , cppu::UnoType<embed::XTransactionBroadcaster>::get()
2296 , cppu::UnoType<util::XModifiable>::get()
2297 , cppu::UnoType<beans::XPropertySet>::get()));
2302 return m_pData->m_pTypeCollection->getTypes() ;
2305 namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
2307 uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId()
2308 throw( uno::RuntimeException, std::exception )
2310 return css::uno::Sequence<sal_Int8>();
2313 // XStorage
2314 void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
2315 throw ( embed::InvalidStorageException,
2316 io::IOException,
2317 lang::IllegalArgumentException,
2318 embed::StorageWrappedTargetException,
2319 uno::RuntimeException, std::exception )
2321 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2323 if ( !m_pImpl )
2325 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2326 throw lang::DisposedException( THROW_WHERE );
2329 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
2330 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
2332 try {
2333 m_pImpl->CopyToStorage( xDest, false );
2335 catch( const embed::InvalidStorageException& rInvalidStorageException )
2337 m_pImpl->AddLog( rInvalidStorageException.Message );
2338 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2339 throw;
2341 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2343 m_pImpl->AddLog( rIllegalArgumentException.Message );
2344 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2345 throw;
2347 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2349 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2350 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2351 throw;
2353 catch( const io::IOException& rIOException )
2355 m_pImpl->AddLog( rIOException.Message );
2356 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2357 throw;
2359 catch( const uno::RuntimeException& rRuntimeException )
2361 m_pImpl->AddLog( rRuntimeException.Message );
2362 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2363 throw;
2365 catch( const uno::Exception& rException )
2367 m_pImpl->AddLog( rException.Message );
2368 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2370 uno::Any aCaught( ::cppu::getCaughtException() );
2371 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy storage!",
2372 uno::Reference< io::XInputStream >(),
2373 aCaught );
2377 uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement(
2378 const OUString& aStreamName, sal_Int32 nOpenMode )
2379 throw ( embed::InvalidStorageException,
2380 lang::IllegalArgumentException,
2381 packages::WrongPasswordException,
2382 io::IOException,
2383 embed::StorageWrappedTargetException,
2384 uno::RuntimeException, std::exception )
2386 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2388 if ( !m_pImpl )
2390 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2391 throw lang::DisposedException( THROW_WHERE );
2394 if ( aStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, false ) )
2395 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2397 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStreamName == "_rels" )
2398 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
2400 if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2401 throw io::IOException( THROW_WHERE ); // TODO: access denied
2403 uno::Reference< io::XStream > xResult;
2406 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, false );
2407 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
2409 xResult = pElement->m_pStream->GetStream( nOpenMode, false );
2410 SAL_WARN_IF( !xResult.is(), "package.xstor", "The method must throw exception instead of removing empty result!" );
2412 if ( m_pData->m_bReadOnlyWrap )
2414 // before the storage disposes the stream it must deregister itself as listener
2415 uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
2416 if ( !xStreamComponent.is() )
2417 throw uno::RuntimeException( THROW_WHERE );
2419 MakeLinkToSubComponent_Impl( xStreamComponent );
2422 catch( const embed::InvalidStorageException& rInvalidStorageException )
2424 m_pImpl->AddLog( rInvalidStorageException.Message );
2425 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2426 throw;
2428 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2430 m_pImpl->AddLog( rIllegalArgumentException.Message );
2431 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2432 throw;
2434 catch( const packages::WrongPasswordException& rWrongPasswordException )
2436 m_pImpl->AddLog( rWrongPasswordException.Message );
2437 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2438 throw;
2440 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2442 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2443 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2444 throw;
2446 catch( const io::IOException& rIOException )
2448 m_pImpl->AddLog( rIOException.Message );
2449 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2450 throw;
2452 catch( const uno::RuntimeException& rRuntimeException )
2454 m_pImpl->AddLog( rRuntimeException.Message );
2455 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2456 throw;
2458 catch( const uno::Exception& rException )
2460 m_pImpl->AddLog( rException.Message );
2461 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2463 uno::Any aCaught( ::cppu::getCaughtException() );
2464 throw embed::StorageWrappedTargetException(THROW_WHERE "Can't open stream element!",
2465 uno::Reference< io::XInputStream >(),
2466 aCaught );
2469 aGuard.clear();
2471 BroadcastModifiedIfNecessary();
2473 return xResult;
2476 uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement(
2477 const OUString& aStreamName, sal_Int32 nOpenMode, const OUString& aPass )
2478 throw ( embed::InvalidStorageException,
2479 lang::IllegalArgumentException,
2480 packages::NoEncryptionException,
2481 packages::WrongPasswordException,
2482 io::IOException,
2483 embed::StorageWrappedTargetException,
2484 uno::RuntimeException, std::exception )
2486 return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
2489 uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
2490 const OUString& aStorName, sal_Int32 nStorageMode )
2491 throw ( embed::InvalidStorageException,
2492 lang::IllegalArgumentException,
2493 io::IOException,
2494 embed::StorageWrappedTargetException,
2495 uno::RuntimeException, std::exception )
2497 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2499 if ( !m_pImpl )
2501 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2502 throw lang::DisposedException( THROW_WHERE );
2505 if ( aStorName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, false ) )
2506 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2508 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStorName == "_rels" )
2509 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2511 if ( ( nStorageMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2512 throw io::IOException( THROW_WHERE ); // TODO: access denied
2514 if ( ( nStorageMode & embed::ElementModes::TRUNCATE )
2515 && !( nStorageMode & embed::ElementModes::WRITE ) )
2516 throw io::IOException( THROW_WHERE ); // TODO: access denied
2518 // it's always possible to read written storage in this implementation
2519 nStorageMode |= embed::ElementModes::READ;
2521 uno::Reference< embed::XStorage > xResult;
2524 SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
2525 if ( !pElement )
2527 // element does not exist, check if creation is allowed
2528 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2529 || (( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2530 || ( nStorageMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2531 throw io::IOException( THROW_WHERE ); // TODO: access_denied
2533 // create a new StorageElement and insert it into the list
2534 pElement = m_pImpl->InsertStorage( aStorName, nStorageMode );
2536 else if ( !pElement->m_bIsStorage )
2538 throw io::IOException( THROW_WHERE );
2540 else if ( pElement->m_pStorage )
2542 // storage has already been opened; it may be opened another time, if it the mode allows to do so
2543 if ( pElement->m_pStorage->m_pAntiImpl )
2545 throw io::IOException( THROW_WHERE ); // TODO: access_denied
2547 else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty()
2548 && ( nStorageMode & embed::ElementModes::WRITE ) )
2550 throw io::IOException( THROW_WHERE ); // TODO: access_denied
2552 else
2554 // in case parent storage allows writing the readonly mode of the child storage is
2555 // virtual, that means that it is just enough to change the flag to let it be writable
2556 // and since there is no AntiImpl nobody should be notified about it
2557 pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ;
2559 if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
2561 for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin();
2562 pElementIter != pElement->m_pStorage->m_aChildrenList.end(); )
2564 SotElement_Impl* pElementToDel = (*pElementIter);
2565 ++pElementIter;
2567 m_pImpl->RemoveElement( pElementToDel );
2573 if ( !pElement->m_pStorage )
2574 m_pImpl->OpenSubStorage( pElement, nStorageMode );
2576 if ( !pElement->m_pStorage )
2577 throw io::IOException( THROW_WHERE ); // TODO: general_error
2579 bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE );
2580 OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap );
2581 xResult = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
2583 if ( bReadOnlyWrap )
2585 // Before this call is done the object must be refcounted already
2586 pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage );
2588 // before the storage disposes the stream it must deregister itself as listener
2589 uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY );
2590 if ( !xStorageComponent.is() )
2591 throw uno::RuntimeException( THROW_WHERE );
2593 MakeLinkToSubComponent_Impl( xStorageComponent );
2596 catch( const embed::InvalidStorageException& rInvalidStorageException )
2598 m_pImpl->AddLog( rInvalidStorageException.Message );
2599 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2600 throw;
2602 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2604 m_pImpl->AddLog( rIllegalArgumentException.Message );
2605 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2606 throw;
2608 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2610 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2611 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2612 throw;
2614 catch( const io::IOException& rIOException )
2616 m_pImpl->AddLog( rIOException.Message );
2617 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2618 throw;
2620 catch( const uno::RuntimeException& rRuntimeException )
2622 m_pImpl->AddLog( rRuntimeException.Message );
2623 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2624 throw;
2626 catch( const uno::Exception& rException )
2628 m_pImpl->AddLog( rException.Message );
2629 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2631 uno::Any aCaught( ::cppu::getCaughtException() );
2632 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't open storage!",
2633 uno::Reference< io::XInputStream >(),
2634 aCaught );
2637 return xResult;
2640 uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const OUString& aStreamName )
2641 throw ( embed::InvalidStorageException,
2642 lang::IllegalArgumentException,
2643 packages::WrongPasswordException,
2644 io::IOException,
2645 embed::StorageWrappedTargetException,
2646 uno::RuntimeException, std::exception )
2648 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2650 if ( !m_pImpl )
2652 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2653 throw lang::DisposedException( THROW_WHERE );
2656 if ( aStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, false ) )
2657 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2659 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStreamName == "_rels" )
2660 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2664 uno::Reference< io::XStream > xResult;
2665 m_pImpl->CloneStreamElement( aStreamName, false, ::comphelper::SequenceAsHashMap(), xResult );
2666 if ( !xResult.is() )
2667 throw uno::RuntimeException( THROW_WHERE );
2668 return xResult;
2670 catch( const embed::InvalidStorageException& rInvalidStorageException )
2672 m_pImpl->AddLog( rInvalidStorageException.Message );
2673 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2674 throw;
2676 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2678 m_pImpl->AddLog( rIllegalArgumentException.Message );
2679 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2680 throw;
2682 catch( const packages::WrongPasswordException& rWrongPasswordException )
2684 m_pImpl->AddLog( rWrongPasswordException.Message );
2685 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2686 throw;
2688 catch( const io::IOException& rIOException )
2690 m_pImpl->AddLog( rIOException.Message );
2691 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2692 throw;
2694 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2696 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2697 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2698 throw;
2700 catch( const uno::RuntimeException& rRuntimeException )
2702 m_pImpl->AddLog( rRuntimeException.Message );
2703 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2704 throw;
2706 catch( const uno::Exception& rException )
2708 m_pImpl->AddLog( rException.Message );
2709 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2711 uno::Any aCaught( ::cppu::getCaughtException() );
2712 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't clone stream!",
2713 uno::Reference< io::XInputStream >(),
2714 aCaught );
2718 uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement(
2719 const OUString& aStreamName,
2720 const OUString& aPass )
2721 throw ( embed::InvalidStorageException,
2722 lang::IllegalArgumentException,
2723 packages::NoEncryptionException,
2724 packages::WrongPasswordException,
2725 io::IOException,
2726 embed::StorageWrappedTargetException,
2727 uno::RuntimeException, std::exception )
2729 return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
2732 void SAL_CALL OStorage::copyLastCommitTo(
2733 const uno::Reference< embed::XStorage >& xTargetStorage )
2734 throw ( embed::InvalidStorageException,
2735 lang::IllegalArgumentException,
2736 io::IOException,
2737 embed::StorageWrappedTargetException,
2738 uno::RuntimeException, std::exception )
2740 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2742 if ( !m_pImpl )
2744 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2745 throw lang::DisposedException( THROW_WHERE );
2750 m_pImpl->CopyLastCommitTo( xTargetStorage );
2752 catch( const embed::InvalidStorageException& rInvalidStorageException )
2754 m_pImpl->AddLog( rInvalidStorageException.Message );
2755 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2756 throw;
2758 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2760 m_pImpl->AddLog( rIllegalArgumentException.Message );
2761 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2762 throw;
2764 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2766 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2767 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2768 throw;
2770 catch( const io::IOException& rIOException )
2772 m_pImpl->AddLog( rIOException.Message );
2773 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2774 throw;
2776 catch( const uno::RuntimeException& rRuntimeException )
2778 m_pImpl->AddLog( rRuntimeException.Message );
2779 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2780 throw;
2782 catch( const uno::Exception& rException )
2784 m_pImpl->AddLog( rException.Message );
2785 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2787 uno::Any aCaught( ::cppu::getCaughtException() );
2788 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy last commit version!",
2789 uno::Reference< io::XInputStream >(),
2790 aCaught );
2795 void SAL_CALL OStorage::copyStorageElementLastCommitTo(
2796 const OUString& aStorName,
2797 const uno::Reference< embed::XStorage >& xTargetStorage )
2798 throw ( embed::InvalidStorageException,
2799 lang::IllegalArgumentException,
2800 io::IOException,
2801 embed::StorageWrappedTargetException,
2802 uno::RuntimeException, std::exception )
2804 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2806 if ( !m_pImpl )
2808 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2809 throw lang::DisposedException( THROW_WHERE );
2812 if ( aStorName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, false ) )
2813 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2815 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStorName == "_rels" )
2816 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2818 // it's always possible to read written storage in this implementation
2819 sal_Int32 nStorageMode = embed::ElementModes::READ;
2823 SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
2824 if ( !pElement )
2826 // element does not exist, throw exception
2827 throw io::IOException( THROW_WHERE ); // TODO: access_denied
2829 else if ( !pElement->m_bIsStorage )
2831 throw io::IOException( THROW_WHERE );
2834 if ( !pElement->m_pStorage )
2835 m_pImpl->OpenSubStorage( pElement, nStorageMode );
2837 uno::Reference< embed::XStorage > xResult;
2838 if ( pElement->m_pStorage )
2840 // the existence of m_pAntiImpl of the child is not interesting,
2841 // the copy will be created internally
2843 pElement->m_pStorage->CopyLastCommitTo( xTargetStorage );
2845 else
2846 throw io::IOException( THROW_WHERE ); // TODO: general_error
2848 catch( const embed::InvalidStorageException& rInvalidStorageException )
2850 m_pImpl->AddLog( rInvalidStorageException.Message );
2851 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2852 throw;
2854 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2856 m_pImpl->AddLog( rIllegalArgumentException.Message );
2857 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2858 throw;
2860 catch( const io::IOException& rIOException )
2862 m_pImpl->AddLog( rIOException.Message );
2863 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2864 throw;
2866 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
2868 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
2869 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2870 throw;
2872 catch( const uno::RuntimeException& rRuntimeException )
2874 m_pImpl->AddLog( rRuntimeException.Message );
2875 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2876 throw;
2878 catch( const uno::Exception& rException )
2880 m_pImpl->AddLog( rException.Message );
2881 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2883 uno::Any aCaught( ::cppu::getCaughtException() );
2884 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy last commit element version!",
2885 uno::Reference< io::XInputStream >(),
2886 aCaught );
2890 sal_Bool SAL_CALL OStorage::isStreamElement( const OUString& aElementName )
2891 throw ( embed::InvalidStorageException,
2892 lang::IllegalArgumentException,
2893 container::NoSuchElementException,
2894 uno::RuntimeException, std::exception )
2896 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2898 if ( !m_pImpl )
2900 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2901 throw lang::DisposedException( THROW_WHERE );
2904 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
2905 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2907 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels" )
2908 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
2910 SotElement_Impl* pElement = NULL;
2914 pElement = m_pImpl->FindElement( aElementName );
2916 catch( const embed::InvalidStorageException& rInvalidStorageException )
2918 m_pImpl->AddLog( rInvalidStorageException.Message );
2919 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2920 throw;
2922 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2924 m_pImpl->AddLog( rIllegalArgumentException.Message );
2925 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2926 throw;
2928 catch( const container::NoSuchElementException& rNoSuchElementException )
2930 m_pImpl->AddLog( rNoSuchElementException.Message );
2931 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2932 throw;
2934 catch( const uno::RuntimeException& rRuntimeException )
2936 m_pImpl->AddLog( rRuntimeException.Message );
2937 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2938 throw;
2940 catch( const uno::Exception& rException )
2942 m_pImpl->AddLog( rException.Message );
2943 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2945 uno::Any aCaught( ::cppu::getCaughtException() );
2946 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can't detect whether it is a stream!",
2947 uno::Reference< io::XInputStream >(),
2948 aCaught );
2951 if ( !pElement )
2952 throw container::NoSuchElementException( THROW_WHERE ); //???
2954 return !pElement->m_bIsStorage;
2957 sal_Bool SAL_CALL OStorage::isStorageElement( const OUString& aElementName )
2958 throw ( embed::InvalidStorageException,
2959 lang::IllegalArgumentException,
2960 container::NoSuchElementException,
2961 uno::RuntimeException, std::exception )
2963 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2965 if ( !m_pImpl )
2967 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
2968 throw lang::DisposedException( THROW_WHERE );
2971 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
2972 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
2974 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels" )
2975 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
2977 SotElement_Impl* pElement = NULL;
2981 pElement = m_pImpl->FindElement( aElementName );
2983 catch( const embed::InvalidStorageException& rInvalidStorageException )
2985 m_pImpl->AddLog( rInvalidStorageException.Message );
2986 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2987 throw;
2989 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
2991 m_pImpl->AddLog( rIllegalArgumentException.Message );
2992 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2993 throw;
2995 catch( const container::NoSuchElementException& rNoSuchElementException )
2997 m_pImpl->AddLog( rNoSuchElementException.Message );
2998 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
2999 throw;
3001 catch( const uno::RuntimeException& rRuntimeException )
3003 m_pImpl->AddLog( rRuntimeException.Message );
3004 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3005 throw;
3007 catch( const uno::Exception& rException )
3009 m_pImpl->AddLog( rException.Message );
3010 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3012 uno::Any aCaught( ::cppu::getCaughtException() );
3013 throw lang::WrappedTargetRuntimeException( THROW_WHERE "can't detect whether it is a storage",
3014 uno::Reference< io::XInputStream >(),
3015 aCaught );
3018 if ( !pElement )
3019 throw container::NoSuchElementException( THROW_WHERE ); //???
3021 return pElement->m_bIsStorage;
3024 void SAL_CALL OStorage::removeElement( const OUString& aElementName )
3025 throw ( embed::InvalidStorageException,
3026 lang::IllegalArgumentException,
3027 container::NoSuchElementException,
3028 io::IOException,
3029 embed::StorageWrappedTargetException,
3030 uno::RuntimeException, std::exception )
3032 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3034 if ( !m_pImpl )
3036 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3037 throw lang::DisposedException( THROW_WHERE );
3040 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
3041 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3043 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels" )
3044 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
3046 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3047 throw io::IOException( THROW_WHERE ); // TODO: access denied
3051 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3053 if ( !pElement )
3054 throw container::NoSuchElementException( THROW_WHERE ); //???
3056 m_pImpl->RemoveElement( pElement );
3058 m_pImpl->m_bIsModified = true;
3059 m_pImpl->m_bBroadcastModified = true;
3061 catch( const embed::InvalidStorageException& rInvalidStorageException )
3063 m_pImpl->AddLog( rInvalidStorageException.Message );
3064 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3065 throw;
3067 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3069 m_pImpl->AddLog( rIllegalArgumentException.Message );
3070 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3071 throw;
3073 catch( const container::NoSuchElementException& rNoSuchElementException )
3075 m_pImpl->AddLog( rNoSuchElementException.Message );
3076 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3077 throw;
3079 catch( const io::IOException& rIOException )
3081 m_pImpl->AddLog( rIOException.Message );
3082 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3083 throw;
3085 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3087 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3088 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3089 throw;
3091 catch( const uno::RuntimeException& rRuntimeException )
3093 m_pImpl->AddLog( rRuntimeException.Message );
3094 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3095 throw;
3097 catch( const uno::Exception& rException )
3099 m_pImpl->AddLog( rException.Message );
3100 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3102 uno::Any aCaught( ::cppu::getCaughtException() );
3103 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't remove element!",
3104 uno::Reference< io::XInputStream >(),
3105 aCaught );
3108 aGuard.clear();
3110 BroadcastModifiedIfNecessary();
3113 void SAL_CALL OStorage::renameElement( const OUString& aElementName, const OUString& aNewName )
3114 throw ( embed::InvalidStorageException,
3115 lang::IllegalArgumentException,
3116 container::NoSuchElementException,
3117 container::ElementExistException,
3118 io::IOException,
3119 embed::StorageWrappedTargetException,
3120 uno::RuntimeException, std::exception )
3122 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3124 if ( !m_pImpl )
3126 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3127 throw lang::DisposedException( THROW_WHERE );
3130 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
3131 || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
3132 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3134 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
3135 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name
3137 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3138 throw io::IOException( THROW_WHERE ); // TODO: access denied
3142 SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName );
3143 if ( pRefElement )
3144 throw container::ElementExistException( THROW_WHERE ); //???
3146 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3147 if ( !pElement )
3148 throw container::NoSuchElementException( THROW_WHERE ); //???
3150 pElement->m_aName = aNewName;
3152 m_pImpl->m_bIsModified = true;
3153 m_pImpl->m_bBroadcastModified = true;
3155 catch( const embed::InvalidStorageException& rInvalidStorageException )
3157 m_pImpl->AddLog( rInvalidStorageException.Message );
3158 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3159 throw;
3161 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3163 m_pImpl->AddLog( rIllegalArgumentException.Message );
3164 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3165 throw;
3167 catch( const container::NoSuchElementException& rNoSuchElementException )
3169 m_pImpl->AddLog( rNoSuchElementException.Message );
3170 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3171 throw;
3173 catch( const container::ElementExistException& rElementExistException )
3175 m_pImpl->AddLog( rElementExistException.Message );
3176 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3177 throw;
3179 catch( const io::IOException& rIOException )
3181 m_pImpl->AddLog( rIOException.Message );
3182 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3183 throw;
3185 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3187 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3188 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3189 throw;
3191 catch( const uno::RuntimeException& rRuntimeException )
3193 m_pImpl->AddLog( rRuntimeException.Message );
3194 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3195 throw;
3197 catch( const uno::Exception& rException )
3199 m_pImpl->AddLog( rException.Message );
3200 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3202 uno::Any aCaught( ::cppu::getCaughtException() );
3203 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't rename element!",
3204 uno::Reference< io::XInputStream >(),
3205 aCaught );
3208 aGuard.clear();
3210 BroadcastModifiedIfNecessary();
3213 void SAL_CALL OStorage::copyElementTo( const OUString& aElementName,
3214 const uno::Reference< embed::XStorage >& xDest,
3215 const OUString& aNewName )
3216 throw ( embed::InvalidStorageException,
3217 lang::IllegalArgumentException,
3218 container::NoSuchElementException,
3219 container::ElementExistException,
3220 io::IOException,
3221 embed::StorageWrappedTargetException,
3222 uno::RuntimeException, std::exception )
3224 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3226 if ( !m_pImpl )
3228 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3229 throw lang::DisposedException( THROW_WHERE );
3232 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
3233 || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
3234 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3236 if ( !xDest.is() )
3237 // || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3238 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
3240 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
3241 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3245 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3246 if ( !pElement )
3247 throw container::NoSuchElementException( THROW_WHERE );
3249 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3250 if ( !xNameAccess.is() )
3251 throw uno::RuntimeException( THROW_WHERE );
3253 if ( xNameAccess->hasByName( aNewName ) )
3254 throw container::ElementExistException( THROW_WHERE );
3256 m_pImpl->CopyStorageElement( pElement, xDest, aNewName, false );
3258 catch( const embed::InvalidStorageException& rInvalidStorageException )
3260 m_pImpl->AddLog( rInvalidStorageException.Message );
3261 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3262 throw;
3264 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3266 m_pImpl->AddLog( rIllegalArgumentException.Message );
3267 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3268 throw;
3270 catch( const container::NoSuchElementException& rNoSuchElementException )
3272 m_pImpl->AddLog( rNoSuchElementException.Message );
3273 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3274 throw;
3276 catch( const container::ElementExistException& rElementExistException )
3278 m_pImpl->AddLog( rElementExistException.Message );
3279 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3280 throw;
3282 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3284 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3285 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3286 throw;
3288 catch( const io::IOException& rIOException )
3290 m_pImpl->AddLog( rIOException.Message );
3291 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3292 throw;
3294 catch( const uno::RuntimeException& rRuntimeException )
3296 m_pImpl->AddLog( rRuntimeException.Message );
3297 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3298 throw;
3300 catch( const uno::Exception& rException )
3302 m_pImpl->AddLog( rException.Message );
3303 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3305 uno::Any aCaught( ::cppu::getCaughtException() );
3306 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy element!",
3307 uno::Reference< io::XInputStream >(),
3308 aCaught );
3312 void SAL_CALL OStorage::moveElementTo( const OUString& aElementName,
3313 const uno::Reference< embed::XStorage >& xDest,
3314 const OUString& aNewName )
3315 throw ( embed::InvalidStorageException,
3316 lang::IllegalArgumentException,
3317 container::NoSuchElementException,
3318 container::ElementExistException,
3319 io::IOException,
3320 embed::StorageWrappedTargetException,
3321 uno::RuntimeException, std::exception )
3323 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3325 if ( !m_pImpl )
3327 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3328 throw lang::DisposedException( THROW_WHERE );
3331 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
3332 || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
3333 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3335 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3336 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
3338 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
3339 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3341 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3342 throw io::IOException( THROW_WHERE ); // TODO: access denied
3346 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3347 if ( !pElement )
3348 throw container::NoSuchElementException( THROW_WHERE ); //???
3350 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3351 if ( !xNameAccess.is() )
3352 throw uno::RuntimeException( THROW_WHERE );
3354 if ( xNameAccess->hasByName( aNewName ) )
3355 throw container::ElementExistException( THROW_WHERE );
3357 m_pImpl->CopyStorageElement( pElement, xDest, aNewName, false );
3359 m_pImpl->RemoveElement( pElement );
3361 m_pImpl->m_bIsModified = true;
3362 m_pImpl->m_bBroadcastModified = true;
3364 catch( const embed::InvalidStorageException& rInvalidStorageException )
3366 m_pImpl->AddLog( rInvalidStorageException.Message );
3367 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3368 throw;
3370 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3372 m_pImpl->AddLog( rIllegalArgumentException.Message );
3373 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3374 throw;
3376 catch( const container::NoSuchElementException& rNoSuchElementException )
3378 m_pImpl->AddLog( rNoSuchElementException.Message );
3379 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3380 throw;
3382 catch( const container::ElementExistException& rElementExistException )
3384 m_pImpl->AddLog( rElementExistException.Message );
3385 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3386 throw;
3388 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3390 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3391 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3392 throw;
3394 catch( const io::IOException& rIOException )
3396 m_pImpl->AddLog( rIOException.Message );
3397 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3398 throw;
3400 catch( const uno::RuntimeException& rRuntimeException )
3402 m_pImpl->AddLog( rRuntimeException.Message );
3403 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3404 throw;
3406 catch( const uno::Exception& rException )
3408 m_pImpl->AddLog( rException.Message );
3409 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3411 uno::Any aCaught( ::cppu::getCaughtException() );
3412 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't move element!",
3413 uno::Reference< io::XInputStream >(),
3414 aCaught );
3417 aGuard.clear();
3419 BroadcastModifiedIfNecessary();
3422 // XStorage2
3423 uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream(
3424 const OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
3425 throw ( embed::InvalidStorageException,
3426 lang::IllegalArgumentException,
3427 packages::NoEncryptionException,
3428 packages::WrongPasswordException,
3429 io::IOException,
3430 embed::StorageWrappedTargetException,
3431 uno::RuntimeException, std::exception )
3433 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3435 if ( !m_pImpl )
3437 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3438 throw lang::DisposedException( THROW_WHERE );
3441 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3442 packages::NoEncryptionException();
3444 if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
3445 throw io::IOException( THROW_WHERE ); // TODO: access denied
3447 if ( !aEncryptionData.getLength() )
3448 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 3 );
3450 uno::Reference< io::XStream > xResult;
3453 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, true );
3454 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
3456 xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, false );
3457 SAL_WARN_IF( !xResult.is(), "package.xstor", "The method must throw exception instead of removing empty result!" );
3459 if ( m_pData->m_bReadOnlyWrap )
3461 // before the storage disposes the stream it must deregister itself as listener
3462 uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
3463 if ( !xStreamComponent.is() )
3464 throw uno::RuntimeException( THROW_WHERE );
3466 MakeLinkToSubComponent_Impl( xStreamComponent );
3469 catch( const embed::InvalidStorageException& rInvalidStorageException )
3471 m_pImpl->AddLog( rInvalidStorageException.Message );
3472 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3473 throw;
3475 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3477 m_pImpl->AddLog( rIllegalArgumentException.Message );
3478 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3479 throw;
3481 catch( const packages::NoEncryptionException& rNoEncryptionException )
3483 m_pImpl->AddLog( rNoEncryptionException.Message );
3484 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3485 throw;
3487 catch( const packages::WrongPasswordException& rWrongPasswordException )
3489 m_pImpl->AddLog( rWrongPasswordException.Message );
3490 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3491 throw;
3493 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3495 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3496 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3497 throw;
3499 catch( const io::IOException& rIOException )
3501 m_pImpl->AddLog( rIOException.Message );
3502 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3503 throw;
3505 catch( const uno::RuntimeException& rRuntimeException )
3507 m_pImpl->AddLog( rRuntimeException.Message );
3508 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3509 throw;
3511 catch( const uno::Exception& rException )
3513 m_pImpl->AddLog( rException.Message );
3514 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3516 uno::Any aCaught( ::cppu::getCaughtException() );
3517 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't open encrypted stream stream!",
3518 uno::Reference< io::XInputStream >(),
3519 aCaught );
3522 aGuard.clear();
3524 BroadcastModifiedIfNecessary();
3526 return xResult;
3529 uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream(
3530 const OUString& aStreamName,
3531 const uno::Sequence< beans::NamedValue >& aEncryptionData )
3532 throw ( embed::InvalidStorageException,
3533 lang::IllegalArgumentException,
3534 packages::NoEncryptionException,
3535 packages::WrongPasswordException,
3536 io::IOException,
3537 embed::StorageWrappedTargetException,
3538 uno::RuntimeException, std::exception )
3540 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3542 if ( !m_pImpl )
3544 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3545 throw lang::DisposedException( THROW_WHERE );
3548 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3549 packages::NoEncryptionException();
3551 if ( !aEncryptionData.getLength() )
3552 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
3556 uno::Reference< io::XStream > xResult;
3557 m_pImpl->CloneStreamElement( aStreamName, true, aEncryptionData, xResult );
3558 if ( !xResult.is() )
3559 throw uno::RuntimeException( THROW_WHERE );
3560 return xResult;
3562 catch( const embed::InvalidStorageException& rInvalidStorageException )
3564 m_pImpl->AddLog( rInvalidStorageException.Message );
3565 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3566 throw;
3568 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3570 m_pImpl->AddLog( rIllegalArgumentException.Message );
3571 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3572 throw;
3574 catch( const packages::NoEncryptionException& rNoEncryptionException )
3576 m_pImpl->AddLog( rNoEncryptionException.Message );
3577 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3578 throw;
3580 catch( const packages::WrongPasswordException& rWrongPasswordException )
3582 m_pImpl->AddLog( rWrongPasswordException.Message );
3583 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3584 throw;
3586 catch( const io::IOException& rIOException )
3588 m_pImpl->AddLog( rIOException.Message );
3589 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3590 throw;
3592 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3594 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3595 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3596 throw;
3598 catch( const uno::RuntimeException& rRuntimeException )
3600 m_pImpl->AddLog( rRuntimeException.Message );
3601 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3602 throw;
3604 catch( const uno::Exception& rException )
3606 m_pImpl->AddLog( rException.Message );
3607 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3609 uno::Any aCaught( ::cppu::getCaughtException() );
3610 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't clone encrypted stream!",
3611 uno::Reference< io::XInputStream >(),
3612 aCaught );
3616 // XStorageRawAccess
3617 uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement(
3618 const OUString& sStreamName )
3619 throw ( embed::InvalidStorageException,
3620 lang::IllegalArgumentException,
3621 container::NoSuchElementException,
3622 io::IOException,
3623 embed::StorageWrappedTargetException,
3624 uno::RuntimeException, std::exception )
3626 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3628 if ( !m_pImpl )
3630 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3631 throw lang::DisposedException( THROW_WHERE );
3634 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
3635 throw uno::RuntimeException( THROW_WHERE ); // the interface is not supported and must not be accessible
3637 if ( sStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, false ) )
3638 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3640 uno::Reference < io::XInputStream > xTempIn;
3643 SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3644 if ( !pElement )
3645 throw container::NoSuchElementException( THROW_WHERE );
3647 if ( !pElement->m_pStream )
3649 m_pImpl->OpenSubStream( pElement );
3650 if ( !pElement->m_pStream )
3651 throw io::IOException( THROW_WHERE );
3654 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream();
3655 if ( !xRawInStream.is() )
3656 throw io::IOException( THROW_WHERE );
3658 uno::Reference < io::XTempFile > xTempFile = io::TempFile::create( m_pImpl->GetComponentContext() );
3659 uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream();
3660 xTempIn = xTempFile->getInputStream();
3661 uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3663 if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3664 throw io::IOException( THROW_WHERE );
3666 // Copy temporary file to a new one
3667 ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3668 xTempOut->closeOutput();
3669 xSeek->seek( 0 );
3671 catch( const embed::InvalidStorageException& rInvalidStorageException )
3673 m_pImpl->AddLog( rInvalidStorageException.Message );
3674 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3675 throw;
3677 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3679 m_pImpl->AddLog( rIllegalArgumentException.Message );
3680 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3681 throw;
3683 catch( const container::NoSuchElementException& rNoSuchElementException )
3685 m_pImpl->AddLog( rNoSuchElementException.Message );
3686 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3687 throw;
3689 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3691 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3692 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3693 throw;
3695 catch( const io::IOException& rIOException )
3697 m_pImpl->AddLog( rIOException.Message );
3698 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3699 throw;
3701 catch( const uno::RuntimeException& rRuntimeException )
3703 m_pImpl->AddLog( rRuntimeException.Message );
3704 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3705 throw;
3707 catch( const uno::Exception& rException )
3709 m_pImpl->AddLog( rException.Message );
3710 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3712 uno::Any aCaught( ::cppu::getCaughtException() );
3713 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't get plain raw stream!",
3714 uno::Reference< io::XInputStream >(),
3715 aCaught );
3718 return xTempIn;
3721 uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement(
3722 const OUString& sStreamName )
3723 throw ( embed::InvalidStorageException,
3724 lang::IllegalArgumentException,
3725 packages::NoEncryptionException,
3726 container::NoSuchElementException,
3727 io::IOException,
3728 embed::StorageWrappedTargetException,
3729 uno::RuntimeException, std::exception )
3731 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3733 if ( !m_pImpl )
3735 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3736 throw lang::DisposedException( THROW_WHERE );
3739 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3740 throw packages::NoEncryptionException( THROW_WHERE );
3742 if ( sStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, false ) )
3743 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3745 uno::Reference < io::XInputStream > xTempIn;
3748 SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3749 if ( !pElement )
3750 throw container::NoSuchElementException( THROW_WHERE );
3752 if ( !pElement->m_pStream )
3754 m_pImpl->OpenSubStream( pElement );
3755 if ( !pElement->m_pStream )
3756 throw io::IOException( THROW_WHERE );
3759 if ( !pElement->m_pStream->IsEncrypted() )
3760 throw packages::NoEncryptionException( THROW_WHERE );
3762 uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
3763 if ( !xRawInStream.is() )
3764 throw io::IOException( THROW_WHERE );
3766 uno::Reference < io::XTempFile > xTempFile = io::TempFile::create(m_pImpl->GetComponentContext());
3767 uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream();
3768 xTempIn = xTempFile->getInputStream();
3769 uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3771 if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3772 throw io::IOException( THROW_WHERE );
3774 // Copy temporary file to a new one
3775 ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3776 xTempOut->closeOutput();
3777 xSeek->seek( 0 );
3780 catch( const embed::InvalidStorageException& rInvalidStorageException )
3782 m_pImpl->AddLog( rInvalidStorageException.Message );
3783 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3784 throw;
3786 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3788 m_pImpl->AddLog( rIllegalArgumentException.Message );
3789 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3790 throw;
3792 catch( const packages::NoEncryptionException& rNoEncryptionException )
3794 m_pImpl->AddLog( rNoEncryptionException.Message );
3795 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3796 throw;
3798 catch( const container::NoSuchElementException& rNoSuchElementException )
3800 m_pImpl->AddLog( rNoSuchElementException.Message );
3801 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3802 throw;
3804 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3806 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3807 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3808 throw;
3810 catch( const io::IOException& rIOException )
3812 m_pImpl->AddLog( rIOException.Message );
3813 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3814 throw;
3816 catch( const uno::RuntimeException& rRuntimeException )
3818 m_pImpl->AddLog( rRuntimeException.Message );
3819 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3820 throw;
3822 catch( const uno::Exception& rException )
3824 m_pImpl->AddLog( rException.Message );
3825 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3827 uno::Any aCaught( ::cppu::getCaughtException() );
3828 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't get raw stream!",
3829 uno::Reference< io::XInputStream >(),
3830 aCaught );
3833 return xTempIn;
3836 void SAL_CALL OStorage::insertRawEncrStreamElement( const OUString& aStreamName,
3837 const uno::Reference< io::XInputStream >& xInStream )
3838 throw ( embed::InvalidStorageException,
3839 lang::IllegalArgumentException,
3840 packages::NoRawFormatException,
3841 container::ElementExistException,
3842 io::IOException,
3843 embed::StorageWrappedTargetException,
3844 uno::RuntimeException, std::exception)
3846 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3848 if ( !m_pImpl )
3850 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3851 throw lang::DisposedException( THROW_WHERE );
3854 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3855 throw embed::InvalidStorageException( THROW_WHERE );
3857 if ( aStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, false ) )
3858 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
3860 if ( !xInStream.is() )
3861 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
3863 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3864 throw io::IOException( THROW_WHERE ); // TODO: access denied
3868 SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
3869 if ( pElement )
3870 throw container::ElementExistException( THROW_WHERE );
3872 m_pImpl->InsertRawStream( aStreamName, xInStream );
3874 catch( const embed::InvalidStorageException& rInvalidStorageException )
3876 m_pImpl->AddLog( rInvalidStorageException.Message );
3877 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3878 throw;
3880 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
3882 m_pImpl->AddLog( rIllegalArgumentException.Message );
3883 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3884 throw;
3886 catch( const packages::NoRawFormatException& rNoRawFormatException )
3888 m_pImpl->AddLog( rNoRawFormatException.Message );
3889 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3890 throw;
3892 catch( const container::ElementExistException& rElementExistException )
3894 m_pImpl->AddLog( rElementExistException.Message );
3895 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3896 throw;
3898 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3900 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3901 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3902 throw;
3904 catch( const io::IOException& rIOException )
3906 m_pImpl->AddLog( rIOException.Message );
3907 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3908 throw;
3910 catch( const uno::RuntimeException& rRuntimeException )
3912 m_pImpl->AddLog( rRuntimeException.Message );
3913 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3914 throw;
3916 catch( const uno::Exception& rException )
3918 m_pImpl->AddLog( rException.Message );
3919 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3921 uno::Any aCaught( ::cppu::getCaughtException() );
3922 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't insert raw stream!",
3923 uno::Reference< io::XInputStream >(),
3924 aCaught );
3928 // XTransactedObject
3929 void SAL_CALL OStorage::commit()
3930 throw ( io::IOException,
3931 embed::StorageWrappedTargetException,
3932 uno::RuntimeException, std::exception )
3934 uno::Reference< util::XModifiable > xParentModif;
3936 try {
3937 BroadcastTransaction( STOR_MESS_PRECOMMIT );
3939 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3941 if ( !m_pImpl )
3943 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
3944 throw lang::DisposedException( THROW_WHERE );
3947 if ( m_pData->m_bReadOnlyWrap )
3948 throw io::IOException( THROW_WHERE ); // TODO: access_denied
3950 m_pImpl->Commit(); // the root storage initiates the storing to source
3952 // when the storage is committed the parent is modified
3953 if ( m_pImpl->m_pParent && m_pImpl->m_pParent->m_pAntiImpl )
3954 xParentModif = (util::XModifiable*)m_pImpl->m_pParent->m_pAntiImpl;
3956 catch( const io::IOException& rIOException )
3958 m_pImpl->AddLog( rIOException.Message );
3959 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3960 throw;
3962 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3964 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3965 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3966 throw;
3968 catch( const uno::RuntimeException& rRuntimeException )
3970 m_pImpl->AddLog( rRuntimeException.Message );
3971 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3972 throw;
3974 catch( const uno::Exception& rException )
3976 m_pImpl->AddLog( rException.Message );
3977 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
3979 uno::Any aCaught( ::cppu::getCaughtException() );
3980 throw embed::StorageWrappedTargetException( THROW_WHERE "Problems on commit!",
3981 static_cast< ::cppu::OWeakObject* >( this ),
3982 aCaught );
3985 setModified( sal_False );
3986 if ( xParentModif.is() )
3987 xParentModif->setModified( sal_True );
3989 BroadcastTransaction( STOR_MESS_COMMITED );
3992 void SAL_CALL OStorage::revert()
3993 throw ( io::IOException,
3994 embed::StorageWrappedTargetException,
3995 uno::RuntimeException, std::exception )
3997 // the method removes all the changes done after last commit
3999 BroadcastTransaction( STOR_MESS_PREREVERT );
4001 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4003 if ( !m_pImpl )
4005 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4006 throw lang::DisposedException( THROW_WHERE );
4009 for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin();
4010 pElementIter != m_pImpl->m_aChildrenList.end(); ++pElementIter )
4012 if ( ((*pElementIter)->m_pStorage
4013 && ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() ))
4014 || ((*pElementIter)->m_pStream
4015 && ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) )
4016 throw io::IOException( THROW_WHERE ); // TODO: access denied
4019 if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated )
4020 return; // nothing to do
4022 try {
4023 m_pImpl->Revert();
4024 m_pImpl->m_bIsModified = false;
4025 m_pImpl->m_bBroadcastModified = true;
4027 catch( const io::IOException& rIOException )
4029 m_pImpl->AddLog( rIOException.Message );
4030 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4031 throw;
4033 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
4035 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
4036 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4037 throw;
4039 catch( const uno::RuntimeException& rRuntimeException )
4041 m_pImpl->AddLog( rRuntimeException.Message );
4042 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4043 throw;
4045 catch( const uno::Exception& rException )
4047 m_pImpl->AddLog( rException.Message );
4048 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4050 uno::Any aCaught( ::cppu::getCaughtException() );
4051 throw embed::StorageWrappedTargetException( THROW_WHERE "Problems on revert!",
4052 static_cast< ::cppu::OWeakObject* >( this ),
4053 aCaught );
4056 aGuard.clear();
4058 setModified( sal_False );
4059 BroadcastTransaction( STOR_MESS_REVERTED );
4062 // XTransactionBroadcaster
4063 void SAL_CALL OStorage::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4064 throw ( uno::RuntimeException, std::exception )
4066 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4068 if ( !m_pImpl )
4070 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4071 throw lang::DisposedException( THROW_WHERE );
4074 m_pData->m_aListenersContainer.addInterface( cppu::UnoType<embed::XTransactionListener>::get(),
4075 aListener );
4078 void SAL_CALL OStorage::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4079 throw ( uno::RuntimeException, std::exception )
4081 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4083 if ( !m_pImpl )
4085 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4086 throw lang::DisposedException( THROW_WHERE );
4089 m_pData->m_aListenersContainer.removeInterface( cppu::UnoType<embed::XTransactionListener>::get(),
4090 aListener );
4093 // XModifiable
4094 // TODO: if there will be no demand on this interface it will be removed from implementation,
4095 // I do not want to remove it now since it is still possible that it will be inserted
4096 // to the service back.
4098 sal_Bool SAL_CALL OStorage::isModified()
4099 throw ( uno::RuntimeException, std::exception )
4101 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4103 if ( !m_pImpl )
4105 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4106 throw lang::DisposedException( THROW_WHERE );
4109 return m_pImpl->m_bIsModified;
4112 void SAL_CALL OStorage::setModified( sal_Bool bModified )
4113 throw ( beans::PropertyVetoException,
4114 uno::RuntimeException, std::exception )
4116 ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4118 if ( !m_pImpl )
4120 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4121 throw lang::DisposedException( THROW_WHERE );
4124 if ( m_pData->m_bReadOnlyWrap )
4125 throw beans::PropertyVetoException( THROW_WHERE ); // TODO: access denied
4127 if ( m_pImpl->m_bIsModified != bool(bModified) )
4128 m_pImpl->m_bIsModified = bModified;
4130 aGuard.clear();
4131 if ( bModified )
4133 m_pImpl->m_bBroadcastModified = true;
4134 BroadcastModifiedIfNecessary();
4138 void SAL_CALL OStorage::addModifyListener(
4139 const uno::Reference< util::XModifyListener >& aListener )
4140 throw ( uno::RuntimeException, std::exception )
4142 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4144 if ( !m_pImpl )
4146 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4147 throw lang::DisposedException( THROW_WHERE );
4150 osl_atomic_increment( &m_pImpl->m_nModifiedListenerCount );
4151 m_pData->m_aListenersContainer.addInterface(
4152 cppu::UnoType<util::XModifyListener>::get(), aListener );
4155 void SAL_CALL OStorage::removeModifyListener(
4156 const uno::Reference< util::XModifyListener >& aListener )
4157 throw ( uno::RuntimeException, std::exception )
4159 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4161 if ( !m_pImpl )
4163 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4164 throw lang::DisposedException( THROW_WHERE );
4167 osl_atomic_decrement( &m_pImpl->m_nModifiedListenerCount );
4168 m_pData->m_aListenersContainer.removeInterface(
4169 cppu::UnoType<util::XModifyListener>::get(), aListener );
4172 // XNameAccess
4174 uno::Any SAL_CALL OStorage::getByName( const OUString& aName )
4175 throw ( container::NoSuchElementException,
4176 lang::WrappedTargetException,
4177 uno::RuntimeException, std::exception )
4179 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4181 if ( !m_pImpl )
4183 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4184 throw lang::DisposedException( THROW_WHERE );
4187 if ( aName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, false ) )
4188 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
4190 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aName == "_rels" )
4191 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
4193 uno::Any aResult;
4196 SotElement_Impl* pElement = m_pImpl->FindElement( aName );
4197 if ( !pElement )
4198 throw container::NoSuchElementException( THROW_WHERE );
4200 if ( pElement->m_bIsStorage )
4201 aResult <<= openStorageElement( aName, embed::ElementModes::READ );
4202 else
4203 aResult <<= openStreamElement( aName, embed::ElementModes::READ );
4205 catch( const container::NoSuchElementException& rNoSuchElementException )
4207 m_pImpl->AddLog( rNoSuchElementException.Message );
4208 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4209 throw;
4211 catch( const lang::WrappedTargetException& rWrappedTargetException )
4213 m_pImpl->AddLog( rWrappedTargetException.Message );
4214 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4215 throw;
4217 catch( const uno::RuntimeException& rRuntimeException )
4219 m_pImpl->AddLog( rRuntimeException.Message );
4220 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4221 throw;
4223 catch( const uno::Exception& rException )
4225 m_pImpl->AddLog( rException.Message );
4226 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4228 uno::Any aCaught( ::cppu::getCaughtException() );
4229 throw lang::WrappedTargetException( THROW_WHERE "Can not open storage!",
4230 static_cast< OWeakObject* >( this ),
4231 aCaught );
4234 return aResult;
4237 uno::Sequence< OUString > SAL_CALL OStorage::getElementNames()
4238 throw ( uno::RuntimeException, std::exception )
4240 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4242 if ( !m_pImpl )
4244 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4245 throw lang::DisposedException( THROW_WHERE );
4250 return m_pImpl->GetElementNames();
4252 catch( const uno::RuntimeException& rRuntimeException )
4254 m_pImpl->AddLog( rRuntimeException.Message );
4255 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4256 throw;
4258 catch ( const uno::Exception& rException )
4260 m_pImpl->AddLog( rException.Message );
4261 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4263 uno::Any aCaught( ::cppu::getCaughtException() );
4264 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open storage!",
4265 static_cast< OWeakObject* >( this ),
4266 aCaught );
4270 sal_Bool SAL_CALL OStorage::hasByName( const OUString& aName )
4271 throw ( uno::RuntimeException, std::exception )
4273 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4275 if ( !m_pImpl )
4277 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4278 throw lang::DisposedException( THROW_WHERE );
4281 if ( aName.isEmpty() )
4282 return sal_False;
4284 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aName == "_rels" )
4285 return sal_False;
4287 SotElement_Impl* pElement = NULL;
4290 pElement = m_pImpl->FindElement( aName );
4292 catch( const uno::RuntimeException& rRuntimeException )
4294 m_pImpl->AddLog( rRuntimeException.Message );
4295 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4296 throw;
4298 catch ( const uno::Exception& rException )
4300 m_pImpl->AddLog( rException.Message );
4301 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4303 uno::Any aCaught( ::cppu::getCaughtException() );
4304 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open storage!",
4305 static_cast< OWeakObject* >( this ),
4306 aCaught );
4309 return ( pElement != NULL );
4312 uno::Type SAL_CALL OStorage::getElementType()
4313 throw ( uno::RuntimeException, std::exception )
4315 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4317 if ( !m_pImpl )
4319 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4320 throw lang::DisposedException( THROW_WHERE );
4323 // it is a multitype container
4324 return uno::Type();
4327 sal_Bool SAL_CALL OStorage::hasElements()
4328 throw ( uno::RuntimeException, std::exception )
4330 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4332 if ( !m_pImpl )
4334 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4335 throw lang::DisposedException( THROW_WHERE );
4340 return ( m_pImpl->GetChildrenList().size() != 0 );
4342 catch( const uno::RuntimeException& rRuntimeException )
4344 m_pImpl->AddLog( rRuntimeException.Message );
4345 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4346 throw;
4348 catch( const uno::Exception& rException )
4350 m_pImpl->AddLog( rException.Message );
4351 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4353 uno::Any aCaught( ::cppu::getCaughtException() );
4354 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open storage!",
4355 static_cast< OWeakObject* >( this ),
4356 aCaught );
4360 // XComponent
4361 void SAL_CALL OStorage::dispose()
4362 throw ( uno::RuntimeException, std::exception )
4364 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4366 if ( !m_pImpl )
4368 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4369 throw lang::DisposedException( THROW_WHERE );
4374 InternalDispose( true );
4376 catch( const uno::RuntimeException& rRuntimeException )
4378 m_pImpl->AddLog( rRuntimeException.Message );
4379 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4380 throw;
4382 catch( const uno::Exception& rException )
4384 m_pImpl->AddLog( rException.Message );
4385 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4387 uno::Any aCaught( ::cppu::getCaughtException() );
4388 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open storage!",
4389 static_cast< OWeakObject* >( this ),
4390 aCaught );
4394 void SAL_CALL OStorage::addEventListener(
4395 const uno::Reference< lang::XEventListener >& xListener )
4396 throw ( uno::RuntimeException, std::exception )
4398 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4400 if ( !m_pImpl )
4402 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4403 throw lang::DisposedException( THROW_WHERE );
4406 m_pData->m_aListenersContainer.addInterface(
4407 cppu::UnoType<lang::XEventListener>::get(), xListener );
4410 void SAL_CALL OStorage::removeEventListener(
4411 const uno::Reference< lang::XEventListener >& xListener )
4412 throw ( uno::RuntimeException, std::exception )
4414 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4416 if ( !m_pImpl )
4418 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4419 throw lang::DisposedException( THROW_WHERE );
4422 m_pData->m_aListenersContainer.removeInterface(
4423 cppu::UnoType<lang::XEventListener>::get(), xListener );
4426 // XEncryptionProtectedSource
4428 void SAL_CALL OStorage::setEncryptionPassword( const OUString& aPass )
4429 throw ( uno::RuntimeException,
4430 io::IOException, std::exception )
4432 setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
4435 void SAL_CALL OStorage::removeEncryption()
4436 throw ( uno::RuntimeException,
4437 io::IOException, std::exception )
4439 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4441 if ( !m_pImpl )
4443 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4444 throw lang::DisposedException( THROW_WHERE );
4447 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4448 throw uno::RuntimeException( THROW_WHERE ); // the interface must be visible only for package storage
4450 SAL_WARN_IF( !m_pData->m_bIsRoot, "package.xstor", "removeEncryption() method is not available for nonroot storages!" );
4451 if ( m_pData->m_bIsRoot )
4453 try {
4454 m_pImpl->ReadContents();
4456 catch ( const uno::RuntimeException& rRuntimeException )
4458 m_pImpl->AddLog( rRuntimeException.Message );
4459 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4460 throw;
4462 catch ( const uno::Exception& rException )
4464 m_pImpl->AddLog( rException.Message );
4465 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4467 uno::Any aCaught( ::cppu::getCaughtException() );
4468 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4469 static_cast< OWeakObject* >( this ),
4470 aCaught );
4473 // TODO: check if the password is valid
4474 // update all streams that was encrypted with old password
4476 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4479 xPackPropSet->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY,
4480 uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
4482 m_pImpl->m_bHasCommonEncryptionData = false;
4483 m_pImpl->m_aCommonEncryptionData.clear();
4485 catch( const uno::RuntimeException& rRException )
4487 m_pImpl->AddLog( rRException.Message );
4488 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4490 SAL_WARN( "package.xstor", "The call must not fail, it is pretty simple!" );
4491 throw;
4493 catch( const uno::Exception& rException )
4495 m_pImpl->AddLog( rException.Message );
4496 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4498 SAL_WARN( "package.xstor", "The call must not fail, it is pretty simple!" );
4499 throw io::IOException( THROW_WHERE );
4504 // XEncryptionProtectedSource2
4506 void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
4507 throw ( io::IOException,
4508 uno::RuntimeException, std::exception )
4510 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4512 if ( !m_pImpl )
4514 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4515 throw lang::DisposedException( THROW_WHERE );
4518 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4519 throw uno::RuntimeException( THROW_WHERE ); // the interface must be visible only for package storage
4521 if ( !aEncryptionData.getLength() )
4522 throw uno::RuntimeException( THROW_WHERE "Unexpected empty encryption data!" );
4524 SAL_WARN_IF( !m_pData->m_bIsRoot, "package.xstor", "setEncryptionData() method is not available for nonroot storages!" );
4525 if ( m_pData->m_bIsRoot )
4527 try {
4528 m_pImpl->ReadContents();
4530 catch ( const uno::RuntimeException& rRuntimeException )
4532 m_pImpl->AddLog( rRuntimeException.Message );
4533 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4534 throw;
4536 catch ( const uno::Exception& rException )
4538 m_pImpl->AddLog( rException.Message );
4539 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4541 uno::Any aCaught( ::cppu::getCaughtException() );
4542 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4543 static_cast< OWeakObject* >( this ),
4544 aCaught );
4547 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4550 ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData );
4551 xPackPropSet->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY,
4552 uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) );
4554 m_pImpl->m_bHasCommonEncryptionData = true;
4555 m_pImpl->m_aCommonEncryptionData = aEncryptionMap;
4557 catch( const uno::Exception& rException )
4559 m_pImpl->AddLog( rException.Message );
4560 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4562 throw io::IOException( THROW_WHERE );
4567 sal_Bool SAL_CALL OStorage::hasEncryptionData()
4568 throw ( uno::RuntimeException, std::exception )
4570 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4572 return m_pImpl && m_pImpl->m_bHasCommonEncryptionData;
4575 // XEncryptionProtectedStorage
4577 void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms )
4578 throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
4580 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4582 if ( !m_pImpl )
4584 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4585 throw lang::DisposedException( THROW_WHERE );
4588 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4589 throw uno::RuntimeException( THROW_WHERE ); // the interface must be visible only for package storage
4591 if ( !aAlgorithms.getLength() )
4592 throw uno::RuntimeException( THROW_WHERE "Unexpected empty encryption algorithms list!" );
4594 SAL_WARN_IF( !m_pData->m_bIsRoot, "package.xstor", "setEncryptionAlgorithms() method is not available for nonroot storages!" );
4595 if ( m_pData->m_bIsRoot )
4597 try {
4598 m_pImpl->ReadContents();
4600 catch ( const uno::RuntimeException& aRuntimeException )
4602 m_pImpl->AddLog( aRuntimeException.Message );
4603 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4604 throw;
4606 catch ( const uno::Exception& aException )
4608 m_pImpl->AddLog( aException.Message );
4609 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4611 uno::Any aCaught( ::cppu::getCaughtException() );
4612 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4613 static_cast< OWeakObject* >( this ),
4614 aCaught );
4617 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4620 xPackPropSet->setPropertyValue( ENCRYPTION_ALGORITHMS_PROPERTY,
4621 uno::makeAny( aAlgorithms ) );
4623 catch ( const uno::RuntimeException& aRuntimeException )
4625 m_pImpl->AddLog( aRuntimeException.Message );
4626 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4627 throw;
4629 catch( const uno::Exception& aException )
4631 m_pImpl->AddLog( aException.Message );
4632 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4634 uno::Any aCaught( ::cppu::getCaughtException() );
4635 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4636 static_cast< OWeakObject* >( this ),
4637 aCaught );
4642 uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms()
4643 throw (uno::RuntimeException, std::exception)
4645 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4647 if ( !m_pImpl )
4649 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4650 throw lang::DisposedException( THROW_WHERE );
4653 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4654 throw uno::RuntimeException( THROW_WHERE ); // the interface must be visible only for package storage
4656 uno::Sequence< beans::NamedValue > aResult;
4657 SAL_WARN_IF( !m_pData->m_bIsRoot, "package.xstor", "getEncryptionAlgorithms() method is not available for nonroot storages!" );
4658 if ( m_pData->m_bIsRoot )
4660 try {
4661 m_pImpl->ReadContents();
4663 catch ( const uno::RuntimeException& aRuntimeException )
4665 m_pImpl->AddLog( aRuntimeException.Message );
4666 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4667 throw;
4669 catch ( const uno::Exception& aException )
4671 m_pImpl->AddLog( aException.Message );
4672 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4674 uno::Any aCaught( ::cppu::getCaughtException() );
4675 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4676 static_cast< OWeakObject* >( this ),
4677 aCaught );
4680 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4683 xPackPropSet->getPropertyValue( ENCRYPTION_ALGORITHMS_PROPERTY ) >>= aResult;
4685 catch ( const uno::RuntimeException& aRuntimeException )
4687 m_pImpl->AddLog( aRuntimeException.Message );
4688 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4689 throw;
4691 catch( const uno::Exception& aException )
4693 m_pImpl->AddLog( aException.Message );
4694 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4696 uno::Any aCaught( ::cppu::getCaughtException() );
4697 throw lang::WrappedTargetRuntimeException( THROW_WHERE "Can not open package!",
4698 static_cast< OWeakObject* >( this ),
4699 aCaught );
4703 return aResult;
4706 // XPropertySet
4708 uno::Reference< beans::XPropertySetInfo > SAL_CALL OStorage::getPropertySetInfo()
4709 throw ( uno::RuntimeException, std::exception )
4711 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4713 if ( !m_pImpl )
4715 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4716 throw lang::DisposedException( THROW_WHERE );
4719 //TODO:
4720 return uno::Reference< beans::XPropertySetInfo >();
4723 void SAL_CALL OStorage::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
4724 throw ( beans::UnknownPropertyException,
4725 beans::PropertyVetoException,
4726 lang::IllegalArgumentException,
4727 lang::WrappedTargetException,
4728 uno::RuntimeException, std::exception )
4730 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4732 if ( !m_pImpl )
4734 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4735 throw lang::DisposedException( THROW_WHERE );
4738 //TODO: think about interaction handler
4740 // WORKAROUND:
4741 // The old document might have no version in the manifest.xml, so we have to allow to set the version
4742 // even for readonly storages, so that the version from content.xml can be used.
4743 if ( m_pData->m_bReadOnlyWrap && aPropertyName != "Version" )
4744 throw uno::RuntimeException( THROW_WHERE ); // TODO: Access denied
4746 if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
4747 throw beans::UnknownPropertyException( THROW_WHERE );
4748 else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
4750 if ( aPropertyName == "MediaType" )
4752 aValue >>= m_pImpl->m_aMediaType;
4753 m_pImpl->m_bControlMediaType = true;
4755 m_pImpl->m_bBroadcastModified = true;
4756 m_pImpl->m_bIsModified = true;
4758 else if ( aPropertyName == "Version" )
4760 aValue >>= m_pImpl->m_aVersion;
4761 m_pImpl->m_bControlVersion = true;
4763 // this property can be set even for readonly storage
4764 if ( !m_pData->m_bReadOnlyWrap )
4766 m_pImpl->m_bBroadcastModified = true;
4767 m_pImpl->m_bIsModified = true;
4770 else if ( ( m_pData->m_bIsRoot && ( aPropertyName == HAS_ENCRYPTED_ENTRIES_PROPERTY
4771 || aPropertyName == HAS_NONENCRYPTED_ENTRIES_PROPERTY
4772 || aPropertyName == IS_INCONSISTENT_PROPERTY
4773 || aPropertyName == "URL"
4774 || aPropertyName == "RepairPackage" ) )
4775 || aPropertyName == "IsRoot"
4776 || aPropertyName == MEDIATYPE_FALLBACK_USED_PROPERTY )
4777 throw beans::PropertyVetoException( THROW_WHERE );
4778 else
4779 throw beans::UnknownPropertyException( THROW_WHERE );
4781 else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
4783 if ( aPropertyName == "RelationsInfoStream" )
4785 uno::Reference< io::XInputStream > xInRelStream;
4786 if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
4788 uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
4789 if ( !xSeek.is() )
4791 // currently this is an internal property that is used for optimization
4792 // and the stream must support XSeekable interface
4793 // TODO/LATER: in future it can be changed if property is used from outside
4794 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
4797 m_pImpl->m_xNewRelInfoStream = xInRelStream;
4798 m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
4799 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
4800 m_pImpl->m_bBroadcastModified = true;
4801 m_pImpl->m_bIsModified = true;
4803 else
4804 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
4806 else if ( aPropertyName == "RelationsInfo" )
4808 if ( aValue >>= m_pImpl->m_aRelInfo )
4810 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
4811 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
4812 m_pImpl->m_bBroadcastModified = true;
4813 m_pImpl->m_bIsModified = true;
4815 else
4816 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
4818 else if ( ( m_pData->m_bIsRoot && ( aPropertyName == "URL" || aPropertyName == "RepairPackage") )
4819 || aPropertyName == "IsRoot" )
4820 throw beans::PropertyVetoException( THROW_WHERE );
4821 else
4822 throw beans::UnknownPropertyException( THROW_WHERE );
4824 else
4825 throw beans::UnknownPropertyException( THROW_WHERE );
4827 BroadcastModifiedIfNecessary();
4830 uno::Any SAL_CALL OStorage::getPropertyValue( const OUString& aPropertyName )
4831 throw ( beans::UnknownPropertyException,
4832 lang::WrappedTargetException,
4833 uno::RuntimeException, std::exception )
4835 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4837 if ( !m_pImpl )
4839 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4840 throw lang::DisposedException( THROW_WHERE );
4843 if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
4844 && ( aPropertyName == "MediaType" || aPropertyName == MEDIATYPE_FALLBACK_USED_PROPERTY || aPropertyName == "Version" ) )
4848 m_pImpl->ReadContents();
4850 catch ( const uno::RuntimeException& rRuntimeException )
4852 m_pImpl->AddLog( rRuntimeException.Message );
4853 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4854 throw;
4856 catch ( const uno::Exception& rException )
4858 m_pImpl->AddLog( rException.Message );
4859 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4861 uno::Any aCaught( ::cppu::getCaughtException() );
4862 throw lang::WrappedTargetException(
4863 "Can't read contents!",
4864 static_cast< OWeakObject* >( this ),
4865 aCaught );
4868 if ( aPropertyName == "MediaType" )
4869 return uno::makeAny( m_pImpl->m_aMediaType );
4870 else if ( aPropertyName == "Version" )
4871 return uno::makeAny( m_pImpl->m_aVersion );
4872 else
4873 return uno::makeAny( m_pImpl->m_bMTFallbackUsed );
4875 else if ( aPropertyName == "IsRoot" )
4877 return uno::makeAny( m_pData->m_bIsRoot );
4879 else if ( aPropertyName == "OpenMode" )
4881 return uno::makeAny( m_pImpl->m_nStorageMode );
4883 else if ( m_pData->m_bIsRoot )
4885 if ( aPropertyName == "URL"
4886 || aPropertyName == "RepairPackage" )
4888 for ( sal_Int32 aInd = 0; aInd < m_pImpl->m_xProperties.getLength(); aInd++ )
4890 if ( m_pImpl->m_xProperties[aInd].Name.equals( aPropertyName ) )
4891 return m_pImpl->m_xProperties[aInd].Value;
4894 if ( aPropertyName == "URL" )
4895 return uno::makeAny( OUString() );
4897 return uno::makeAny( sal_False ); // RepairPackage
4899 else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
4900 && ( aPropertyName == HAS_ENCRYPTED_ENTRIES_PROPERTY
4901 || aPropertyName == HAS_NONENCRYPTED_ENTRIES_PROPERTY
4902 || aPropertyName == IS_INCONSISTENT_PROPERTY ) )
4904 try {
4905 m_pImpl->ReadContents();
4906 uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
4907 if ( !xPackPropSet.is() )
4908 throw uno::RuntimeException( THROW_WHERE );
4910 return xPackPropSet->getPropertyValue( aPropertyName );
4912 catch ( const uno::RuntimeException& rRuntimeException )
4914 m_pImpl->AddLog( rRuntimeException.Message );
4915 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4916 throw;
4918 catch ( const uno::Exception& rException )
4920 m_pImpl->AddLog( rException.Message );
4921 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
4923 uno::Any aCaught( ::cppu::getCaughtException() );
4924 throw lang::WrappedTargetException( THROW_WHERE "Can not open package!",
4925 static_cast< OWeakObject* >( this ),
4926 aCaught );
4931 throw beans::UnknownPropertyException( THROW_WHERE );
4934 void SAL_CALL OStorage::addPropertyChangeListener(
4935 const OUString& /*aPropertyName*/,
4936 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
4937 throw ( beans::UnknownPropertyException,
4938 lang::WrappedTargetException,
4939 uno::RuntimeException, std::exception )
4941 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4943 if ( !m_pImpl )
4945 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4946 throw lang::DisposedException( THROW_WHERE );
4949 //TODO:
4952 void SAL_CALL OStorage::removePropertyChangeListener(
4953 const OUString& /*aPropertyName*/,
4954 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
4955 throw ( beans::UnknownPropertyException,
4956 lang::WrappedTargetException,
4957 uno::RuntimeException, std::exception )
4959 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4961 if ( !m_pImpl )
4963 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4964 throw lang::DisposedException( THROW_WHERE );
4967 //TODO:
4970 void SAL_CALL OStorage::addVetoableChangeListener(
4971 const OUString& /*PropertyName*/,
4972 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
4973 throw ( beans::UnknownPropertyException,
4974 lang::WrappedTargetException,
4975 uno::RuntimeException, std::exception )
4977 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4979 if ( !m_pImpl )
4981 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
4982 throw lang::DisposedException( THROW_WHERE );
4985 //TODO:
4988 void SAL_CALL OStorage::removeVetoableChangeListener(
4989 const OUString& /*PropertyName*/,
4990 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
4991 throw ( beans::UnknownPropertyException,
4992 lang::WrappedTargetException,
4993 uno::RuntimeException, std::exception )
4995 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4997 if ( !m_pImpl )
4999 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5000 throw lang::DisposedException( THROW_WHERE );
5003 //TODO:
5006 // XRelationshipAccess
5008 // TODO/LATER: the storage and stream implementations of this interface are very similar, they could use a helper class
5010 sal_Bool SAL_CALL OStorage::hasByID( const OUString& sID )
5011 throw ( io::IOException,
5012 uno::RuntimeException, std::exception )
5014 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5016 if ( !m_pImpl )
5018 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5019 throw lang::DisposedException( THROW_WHERE );
5022 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5023 throw uno::RuntimeException( THROW_WHERE );
5027 getRelationshipByID( sID );
5028 return sal_True;
5030 catch( const container::NoSuchElementException& rNoSuchElementException )
5032 m_pImpl->AddLog( rNoSuchElementException.Message );
5033 m_pImpl->AddLog( THROW_WHERE "Quiet exception" );
5036 return sal_False;
5039 OUString SAL_CALL OStorage::getTargetByID( const OUString& sID )
5040 throw ( container::NoSuchElementException,
5041 io::IOException,
5042 uno::RuntimeException, std::exception )
5044 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5046 if ( !m_pImpl )
5048 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5049 throw lang::DisposedException( THROW_WHERE );
5052 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5053 throw uno::RuntimeException( THROW_WHERE );
5055 uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5056 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5057 if ( aSeq[nInd].First == "Target" )
5058 return aSeq[nInd].Second;
5060 return OUString();
5063 OUString SAL_CALL OStorage::getTypeByID( const OUString& sID )
5064 throw ( container::NoSuchElementException,
5065 io::IOException,
5066 uno::RuntimeException, std::exception )
5068 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5070 if ( !m_pImpl )
5072 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5073 throw lang::DisposedException( THROW_WHERE );
5076 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5077 throw uno::RuntimeException( THROW_WHERE );
5079 uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5080 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5081 if ( aSeq[nInd].First == "Type" )
5082 return aSeq[nInd].Second;
5084 return OUString();
5087 uno::Sequence< beans::StringPair > SAL_CALL OStorage::getRelationshipByID( const OUString& sID )
5088 throw ( container::NoSuchElementException,
5089 io::IOException,
5090 uno::RuntimeException, std::exception )
5092 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5094 if ( !m_pImpl )
5096 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5097 throw lang::DisposedException( THROW_WHERE );
5100 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5101 throw uno::RuntimeException( THROW_WHERE );
5103 // TODO/LATER: in future the unification of the ID could be checked
5104 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5105 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5106 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5107 if ( aSeq[nInd1][nInd2].First == "Id" )
5109 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5110 return aSeq[nInd1];
5111 break;
5114 throw container::NoSuchElementException( THROW_WHERE );
5117 uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getRelationshipsByType( const OUString& sType )
5118 throw ( io::IOException,
5119 uno::RuntimeException, std::exception )
5121 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5123 if ( !m_pImpl )
5125 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5126 throw lang::DisposedException( THROW_WHERE );
5129 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5130 throw uno::RuntimeException( THROW_WHERE );
5132 uno::Sequence< uno::Sequence< beans::StringPair > > aResult;
5133 sal_Int32 nEntriesNum = 0;
5135 // TODO/LATER: in future the unification of the ID could be checked
5136 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5137 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5138 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5139 if ( aSeq[nInd1][nInd2].First == "Type" )
5141 // the type is usually an URL, so the check should be case insensitive
5142 if ( aSeq[nInd1][nInd2].Second.equalsIgnoreAsciiCase( sType ) )
5144 aResult.realloc( ++nEntriesNum );
5145 aResult[nEntriesNum-1] = aSeq[nInd1];
5147 break;
5150 return aResult;
5153 uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getAllRelationships()
5154 throw (io::IOException, uno::RuntimeException, std::exception)
5156 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5158 if ( !m_pImpl )
5160 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5161 throw lang::DisposedException( THROW_WHERE );
5164 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5165 throw uno::RuntimeException( THROW_WHERE );
5167 uno::Sequence< uno::Sequence< beans::StringPair > > aRet;
5170 aRet = m_pImpl->GetAllRelationshipsIfAny();
5172 catch (const io::IOException&)
5174 throw;
5176 catch (const uno::RuntimeException&)
5178 throw;
5180 catch (const uno::Exception &)
5182 uno::Any aCaught( ::cppu::getCaughtException() );
5183 throw lang::WrappedTargetRuntimeException(THROW_WHERE "Can't getAllRelationships!",
5184 uno::Reference< uno::XInterface >(),
5185 aCaught);
5188 return aRet;
5191 void SAL_CALL OStorage::insertRelationshipByID( const OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, sal_Bool bReplace )
5192 throw ( container::ElementExistException,
5193 io::IOException,
5194 uno::RuntimeException, std::exception )
5196 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5198 if ( !m_pImpl )
5200 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5201 throw lang::DisposedException( THROW_WHERE );
5204 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5205 throw uno::RuntimeException( THROW_WHERE );
5207 OUString aIDTag( "Id" );
5209 sal_Int32 nIDInd = -1;
5211 // TODO/LATER: in future the unification of the ID could be checked
5212 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5213 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5214 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5215 if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) )
5217 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5218 nIDInd = nInd1;
5220 break;
5223 if ( nIDInd == -1 || bReplace )
5225 if ( nIDInd == -1 )
5227 nIDInd = aSeq.getLength();
5228 aSeq.realloc( nIDInd + 1 );
5231 aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
5233 aSeq[nIDInd][0].First = aIDTag;
5234 aSeq[nIDInd][0].Second = sID;
5235 sal_Int32 nIndTarget = 1;
5236 for ( sal_Int32 nIndOrig = 0;
5237 nIndOrig < aEntry.getLength();
5238 nIndOrig++ )
5240 if ( !aEntry[nIndOrig].First.equals( aIDTag ) )
5241 aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
5244 aSeq[nIDInd].realloc( nIndTarget );
5246 else
5247 throw container::ElementExistException( THROW_WHERE );
5249 m_pImpl->m_aRelInfo = aSeq;
5250 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5251 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5254 void SAL_CALL OStorage::removeRelationshipByID( const OUString& sID )
5255 throw ( container::NoSuchElementException,
5256 io::IOException,
5257 uno::RuntimeException, std::exception )
5259 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5261 if ( !m_pImpl )
5263 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5264 throw lang::DisposedException( THROW_WHERE );
5267 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5268 throw uno::RuntimeException( THROW_WHERE );
5270 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5271 for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5272 for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5273 if ( aSeq[nInd1][nInd2].First == "Id" )
5275 if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5277 sal_Int32 nLength = aSeq.getLength();
5278 aSeq[nInd1] = aSeq[nLength-1];
5279 aSeq.realloc( nLength - 1 );
5281 m_pImpl->m_aRelInfo = aSeq;
5282 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5283 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5285 // TODO/LATER: in future the unification of the ID could be checked
5286 return;
5289 break;
5292 throw container::NoSuchElementException( THROW_WHERE );
5295 void SAL_CALL OStorage::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, sal_Bool bReplace )
5296 throw ( container::ElementExistException,
5297 io::IOException,
5298 uno::RuntimeException, std::exception )
5300 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5302 if ( !m_pImpl )
5304 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5305 throw lang::DisposedException( THROW_WHERE );
5308 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5309 throw uno::RuntimeException( THROW_WHERE );
5311 OUString aIDTag( "Id" );
5312 uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5313 uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() );
5314 sal_Int32 nResultInd = 0;
5316 for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ )
5317 for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ )
5318 if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) )
5320 sal_Int32 nIndSourceSame = -1;
5322 for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5323 for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5325 if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5327 if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) )
5329 if ( !bReplace )
5330 throw container::ElementExistException( THROW_WHERE );
5332 nIndSourceSame = nIndSource1;
5335 break;
5339 if ( nIndSourceSame == -1 )
5341 // no such element in the provided sequence
5342 aResultSeq[nResultInd++] = aSeq[nIndTarget1];
5345 break;
5348 for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5350 aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() );
5351 bool bHasID = false;
5352 sal_Int32 nResInd2 = 1;
5354 for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5355 if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5357 aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2];
5358 bHasID = true;
5360 else if ( nResInd2 < aResultSeq[nResultInd].getLength() )
5361 aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2];
5362 else
5363 throw io::IOException( THROW_WHERE ); // TODO: illegal relation ( no ID )
5365 if ( !bHasID )
5366 throw io::IOException( THROW_WHERE ); // TODO: illegal relations
5368 nResultInd++;
5371 aResultSeq.realloc( nResultInd );
5372 m_pImpl->m_aRelInfo = aResultSeq;
5373 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5374 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5377 void SAL_CALL OStorage::clearRelationships()
5378 throw ( io::IOException,
5379 uno::RuntimeException, std::exception )
5381 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5383 if ( !m_pImpl )
5385 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5386 throw lang::DisposedException( THROW_WHERE );
5389 if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5390 throw uno::RuntimeException( THROW_WHERE );
5392 m_pImpl->m_aRelInfo.realloc( 0 );
5393 m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5394 m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5397 // XOptimizedStorage
5398 void SAL_CALL OStorage::insertRawNonEncrStreamElementDirect(
5399 const OUString& /*sStreamName*/,
5400 const uno::Reference< io::XInputStream >& /*xInStream*/ )
5401 throw ( embed::InvalidStorageException,
5402 lang::IllegalArgumentException,
5403 packages::NoRawFormatException,
5404 container::ElementExistException,
5405 io::IOException,
5406 embed::StorageWrappedTargetException,
5407 uno::RuntimeException, std::exception )
5409 // not implemented currently because there is still no demand
5410 // might need to be implemented if direct copying of compressed streams is used
5411 throw io::IOException( THROW_WHERE );
5414 void SAL_CALL OStorage::insertStreamElementDirect(
5415 const OUString& aStreamName,
5416 const uno::Reference< io::XInputStream >& xInStream,
5417 const uno::Sequence< beans::PropertyValue >& aProps )
5418 throw ( embed::InvalidStorageException,
5419 lang::IllegalArgumentException,
5420 container::ElementExistException,
5421 io::IOException,
5422 embed::StorageWrappedTargetException,
5423 uno::RuntimeException, std::exception )
5425 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5427 if ( !m_pImpl )
5429 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5430 throw lang::DisposedException( THROW_WHERE );
5433 if ( aStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, false ) )
5434 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
5436 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStreamName == "_rels" )
5437 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
5439 if ( m_pData->m_bReadOnlyWrap )
5440 throw io::IOException( THROW_WHERE ); // TODO: access denied
5444 SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
5446 if ( pElement )
5447 throw container::ElementExistException( THROW_WHERE );
5449 pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, false );
5450 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
5452 pElement->m_pStream->InsertStreamDirectly( xInStream, aProps );
5454 catch( const embed::InvalidStorageException& rInvalidStorageException )
5456 m_pImpl->AddLog( rInvalidStorageException.Message );
5457 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5458 throw;
5460 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5462 m_pImpl->AddLog( rIllegalArgumentException.Message );
5463 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5464 throw;
5466 catch( const container::ElementExistException& rElementExistException )
5468 m_pImpl->AddLog( rElementExistException.Message );
5469 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5470 throw;
5472 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5474 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5475 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5476 throw;
5478 catch( const io::IOException& rIOException )
5480 m_pImpl->AddLog( rIOException.Message );
5481 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5482 throw;
5484 catch( const uno::RuntimeException& rRuntimeException )
5486 m_pImpl->AddLog( rRuntimeException.Message );
5487 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5488 throw;
5490 catch( const uno::Exception& rException )
5492 m_pImpl->AddLog( rException.Message );
5493 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5495 uno::Any aCaught( ::cppu::getCaughtException() );
5496 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't insert stream directly!",
5497 uno::Reference< io::XInputStream >(),
5498 aCaught );
5502 void SAL_CALL OStorage::copyElementDirectlyTo(
5503 const OUString& aElementName,
5504 const uno::Reference< embed::XOptimizedStorage >& xDest,
5505 const OUString& aNewName )
5506 throw ( embed::InvalidStorageException,
5507 lang::IllegalArgumentException,
5508 container::NoSuchElementException,
5509 container::ElementExistException,
5510 io::IOException,
5511 embed::StorageWrappedTargetException,
5512 uno::RuntimeException, std::exception )
5514 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5516 if ( !m_pImpl )
5518 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5519 throw lang::DisposedException( THROW_WHERE );
5522 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false )
5523 || aNewName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, false ) )
5524 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
5526 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
5527 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
5529 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && ( aElementName == "_rels" || aNewName == "_rels" ) )
5530 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); // unacceptable name
5534 SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
5535 if ( !pElement )
5536 throw container::NoSuchElementException( THROW_WHERE );
5538 uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
5539 if ( !xNameAccess.is() )
5540 throw uno::RuntimeException( THROW_WHERE );
5542 if ( xNameAccess->hasByName( aNewName ) )
5543 throw container::ElementExistException( THROW_WHERE );
5545 // let the element be copied directly
5546 uno::Reference< embed::XStorage > xStorDest( xDest, uno::UNO_QUERY_THROW );
5547 m_pImpl->CopyStorageElement( pElement, xStorDest, aNewName, true );
5549 catch( const embed::InvalidStorageException& rInvalidStorageException )
5551 m_pImpl->AddLog( rInvalidStorageException.Message );
5552 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5553 throw;
5555 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5557 m_pImpl->AddLog( rIllegalArgumentException.Message );
5558 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5559 throw;
5561 catch( const container::NoSuchElementException& rNoSuchElementException )
5563 m_pImpl->AddLog( rNoSuchElementException.Message );
5564 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5565 throw;
5567 catch( const container::ElementExistException& rElementExistException )
5569 m_pImpl->AddLog( rElementExistException.Message );
5570 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5571 throw;
5573 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5575 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5576 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5577 throw;
5579 catch( const io::IOException& rIOException )
5581 m_pImpl->AddLog( rIOException.Message );
5582 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5583 throw;
5585 catch( const uno::RuntimeException& rRuntimeException )
5587 m_pImpl->AddLog( rRuntimeException.Message );
5588 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5589 throw;
5591 catch( const uno::Exception& rException )
5593 m_pImpl->AddLog( rException.Message );
5594 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5596 uno::Any aCaught( ::cppu::getCaughtException() );
5597 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy element direcly!",
5598 uno::Reference< io::XInputStream >(),
5599 aCaught );
5603 void SAL_CALL OStorage::writeAndAttachToStream( const uno::Reference< io::XStream >& xStream )
5604 throw ( embed::InvalidStorageException,
5605 lang::IllegalArgumentException,
5606 io::IOException,
5607 embed::StorageWrappedTargetException,
5608 uno::RuntimeException, std::exception )
5610 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5612 if ( !m_pImpl )
5614 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5615 throw lang::DisposedException( THROW_WHERE );
5618 if ( !m_pData->m_bIsRoot )
5619 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
5621 if ( !m_pImpl->m_pSwitchStream )
5622 throw uno::RuntimeException( THROW_WHERE );
5626 m_pImpl->m_pSwitchStream->CopyAndSwitchPersistenceTo( xStream );
5628 catch( const embed::InvalidStorageException& rInvalidStorageException )
5630 m_pImpl->AddLog( rInvalidStorageException.Message );
5631 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5632 throw;
5634 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5636 m_pImpl->AddLog( rIllegalArgumentException.Message );
5637 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5638 throw;
5640 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5642 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5643 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5644 throw;
5646 catch( const io::IOException& rIOException )
5648 m_pImpl->AddLog( rIOException.Message );
5649 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5650 throw;
5652 catch( const uno::RuntimeException& rRuntimeException )
5654 m_pImpl->AddLog( rRuntimeException.Message );
5655 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5656 throw;
5658 catch( const uno::Exception& rException )
5660 m_pImpl->AddLog( rException.Message );
5661 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5663 uno::Any aCaught( ::cppu::getCaughtException() );
5664 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't write and attach to stream!",
5665 uno::Reference< io::XInputStream >(),
5666 aCaught );
5671 void SAL_CALL OStorage::attachToURL( const OUString& sURL,
5672 sal_Bool bReadOnly )
5673 throw ( embed::InvalidStorageException,
5674 lang::IllegalArgumentException,
5675 io::IOException,
5676 embed::StorageWrappedTargetException,
5677 uno::RuntimeException, std::exception )
5679 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5681 if ( !m_pImpl )
5683 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5684 throw lang::DisposedException( THROW_WHERE );
5687 if ( !m_pData->m_bIsRoot )
5688 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
5690 if ( !m_pImpl->m_pSwitchStream )
5691 throw uno::RuntimeException( THROW_WHERE );
5693 uno::Reference < ucb::XSimpleFileAccess3 > xAccess(
5694 ucb::SimpleFileAccess::create( m_pImpl->m_xContext ) );
5698 if ( bReadOnly )
5700 uno::Reference< io::XInputStream > xInputStream = xAccess->openFileRead( sURL );
5701 m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xInputStream );
5703 else
5705 uno::Reference< io::XStream > xStream = xAccess->openFileReadWrite( sURL );
5706 m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xStream );
5709 catch( const embed::InvalidStorageException& rInvalidStorageException )
5711 m_pImpl->AddLog( rInvalidStorageException.Message );
5712 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5713 throw;
5715 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5717 m_pImpl->AddLog( rIllegalArgumentException.Message );
5718 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5719 throw;
5721 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5723 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5724 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5725 throw;
5727 catch( const io::IOException& rIOException )
5729 m_pImpl->AddLog( rIOException.Message );
5730 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5731 throw;
5733 catch( const uno::RuntimeException& rRuntimeException )
5735 m_pImpl->AddLog( rRuntimeException.Message );
5736 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5737 throw;
5739 catch( const uno::Exception& rException )
5741 m_pImpl->AddLog( rException.Message );
5742 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5744 uno::Any aCaught( ::cppu::getCaughtException() );
5745 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't attach to URL!",
5746 uno::Reference< io::XInputStream >(),
5747 aCaught );
5751 uno::Any SAL_CALL OStorage::getElementPropertyValue( const OUString& aElementName, const OUString& aPropertyName )
5752 throw ( embed::InvalidStorageException,
5753 lang::IllegalArgumentException,
5754 container::NoSuchElementException,
5755 io::IOException,
5756 beans::UnknownPropertyException,
5757 beans::PropertyVetoException,
5758 embed::StorageWrappedTargetException,
5759 uno::RuntimeException, std::exception)
5761 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5763 if ( !m_pImpl )
5765 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5766 throw lang::DisposedException( THROW_WHERE );
5769 if ( aElementName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
5770 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
5772 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aElementName == "_rels" )
5773 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
5777 SotElement_Impl *pElement = m_pImpl->FindElement( aElementName );
5778 if ( !pElement )
5779 throw container::NoSuchElementException( THROW_WHERE );
5781 // TODO/LATER: Currently it is only implemented for MediaType property of substorages, might be changed in future
5782 if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != embed::StorageFormats::PACKAGE || aPropertyName != "MediaType" )
5783 throw beans::PropertyVetoException( THROW_WHERE );
5785 if ( !pElement->m_pStorage )
5786 m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ );
5788 if ( !pElement->m_pStorage )
5789 throw io::IOException( THROW_WHERE ); // TODO: general_error
5791 pElement->m_pStorage->ReadContents();
5792 return uno::makeAny( pElement->m_pStorage->m_aMediaType );
5794 catch( const embed::InvalidStorageException& rInvalidStorageException )
5796 m_pImpl->AddLog( rInvalidStorageException.Message );
5797 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5798 throw;
5800 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5802 m_pImpl->AddLog( rIllegalArgumentException.Message );
5803 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5804 throw;
5806 catch( const container::NoSuchElementException& rNoSuchElementException )
5808 m_pImpl->AddLog( rNoSuchElementException.Message );
5809 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5810 throw;
5812 catch( const beans::UnknownPropertyException& rUnknownPropertyException )
5814 m_pImpl->AddLog( rUnknownPropertyException.Message );
5815 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5816 throw;
5818 catch( const beans::PropertyVetoException& rPropertyVetoException )
5820 m_pImpl->AddLog( rPropertyVetoException.Message );
5821 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5822 throw;
5824 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5826 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5827 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5828 throw;
5830 catch( const io::IOException& rIOException )
5832 m_pImpl->AddLog( rIOException.Message );
5833 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5834 throw;
5836 catch( const uno::RuntimeException& rRuntimeException )
5838 m_pImpl->AddLog( rRuntimeException.Message );
5839 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5840 throw;
5842 catch( const uno::Exception& rException )
5844 m_pImpl->AddLog( rException.Message );
5845 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5847 uno::Any aCaught( ::cppu::getCaughtException() );
5848 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't get element property!",
5849 uno::Reference< io::XInputStream >(),
5850 aCaught );
5854 void SAL_CALL OStorage::copyStreamElementData( const OUString& aStreamName, const uno::Reference< io::XStream >& xTargetStream )
5855 throw ( embed::InvalidStorageException,
5856 lang::IllegalArgumentException,
5857 packages::WrongPasswordException,
5858 io::IOException,
5859 embed::StorageWrappedTargetException,
5860 uno::RuntimeException, std::exception )
5862 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5864 if ( !m_pImpl )
5866 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5867 throw lang::DisposedException( THROW_WHERE );
5870 if ( aStreamName.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, false ) )
5871 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
5873 if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aStreamName == "_rels" )
5874 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
5876 if ( !xTargetStream.is() )
5877 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
5881 uno::Reference< io::XStream > xNonconstRef = xTargetStream;
5882 m_pImpl->CloneStreamElement( aStreamName, false, ::comphelper::SequenceAsHashMap(), xNonconstRef );
5884 SAL_WARN_IF( xNonconstRef != xTargetStream, "package.xstor", "The provided stream reference seems not be filled in correctly!" );
5885 if ( xNonconstRef != xTargetStream )
5886 throw uno::RuntimeException( THROW_WHERE ); // if the stream reference is set it must not be changed!
5888 catch( const embed::InvalidStorageException& rInvalidStorageException )
5890 m_pImpl->AddLog( rInvalidStorageException.Message );
5891 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5892 throw;
5894 catch( const lang::IllegalArgumentException& rIllegalArgumentException )
5896 m_pImpl->AddLog( rIllegalArgumentException.Message );
5897 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5898 throw;
5900 catch( const packages::WrongPasswordException& rWrongPasswordException )
5902 m_pImpl->AddLog( rWrongPasswordException.Message );
5903 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5904 throw;
5906 catch( const io::IOException& rIOException )
5908 m_pImpl->AddLog( rIOException.Message );
5909 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5910 throw;
5912 catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
5914 m_pImpl->AddLog( rStorageWrappedTargetException.Message );
5915 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5916 throw;
5918 catch( const uno::RuntimeException& rRuntimeException )
5920 m_pImpl->AddLog( rRuntimeException.Message );
5921 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5922 throw;
5924 catch( const uno::Exception& rException )
5926 m_pImpl->AddLog( rException.Message );
5927 m_pImpl->AddLog( THROW_WHERE "Rethrow" );
5929 uno::Any aCaught( ::cppu::getCaughtException() );
5930 throw embed::StorageWrappedTargetException( THROW_WHERE "Can't copy stream data!",
5931 uno::Reference< io::XInputStream >(),
5932 aCaught );
5937 // XHierarchicalStorageAccess
5938 uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamElementByHierarchicalName( const OUString& aStreamPath, ::sal_Int32 nOpenMode )
5939 throw ( embed::InvalidStorageException,
5940 lang::IllegalArgumentException,
5941 packages::WrongPasswordException,
5942 io::IOException,
5943 embed::StorageWrappedTargetException,
5944 uno::RuntimeException, std::exception )
5946 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5948 if ( !m_pImpl )
5950 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
5951 throw lang::DisposedException( THROW_WHERE );
5954 if ( aStreamPath.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, true ) )
5955 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
5957 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
5958 && ( nOpenMode & embed::ElementModes::WRITE ) )
5959 throw io::IOException( THROW_WHERE ); // Access denied
5961 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
5962 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
5964 uno::Reference< embed::XExtendedStorageStream > xResult;
5965 if ( aListPath.size() == 1 )
5969 // that must be a direct request for a stream
5970 // the transacted version of the stream should be opened
5972 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, false );
5973 assert(pElement && pElement->m_pStream && "In case element can not be created an exception must be thrown!");
5975 xResult = uno::Reference< embed::XExtendedStorageStream >(
5976 pElement->m_pStream->GetStream( nOpenMode, true ),
5977 uno::UNO_QUERY_THROW );
5979 catch ( const container::NoSuchElementException & )
5981 throw io::IOException( THROW_WHERE ); // file not found
5984 else
5986 // there are still storages in between
5987 if ( !m_pData->m_rHierarchyHolder.is() )
5988 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
5989 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
5991 xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
5992 ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
5993 aListPath,
5994 nOpenMode );
5997 if ( !xResult.is() )
5998 throw uno::RuntimeException( THROW_WHERE );
6000 return xResult;
6003 uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamElementByHierarchicalName( const OUString& aStreamPath, ::sal_Int32 nOpenMode, const OUString& sPassword )
6004 throw ( embed::InvalidStorageException,
6005 lang::IllegalArgumentException,
6006 packages::NoEncryptionException,
6007 packages::WrongPasswordException,
6008 io::IOException,
6009 embed::StorageWrappedTargetException,
6010 uno::RuntimeException, std::exception )
6012 return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) );
6015 void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const OUString& aStreamPath )
6016 throw ( embed::InvalidStorageException,
6017 lang::IllegalArgumentException,
6018 container::NoSuchElementException,
6019 io::IOException,
6020 embed::StorageWrappedTargetException,
6021 uno::RuntimeException, std::exception )
6023 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6025 if ( !m_pImpl )
6027 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
6028 throw lang::DisposedException( THROW_WHERE );
6031 if ( aStreamPath.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, true ) )
6032 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
6034 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
6035 throw io::IOException( THROW_WHERE ); // Access denied
6037 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6038 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6040 if ( !m_pData->m_rHierarchyHolder.is() )
6041 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6042 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6044 m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );
6047 // XHierarchicalStorageAccess2
6048 uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
6049 throw ( embed::InvalidStorageException,
6050 lang::IllegalArgumentException,
6051 packages::NoEncryptionException,
6052 packages::WrongPasswordException,
6053 container::NoSuchElementException,
6054 io::IOException,
6055 embed::StorageWrappedTargetException,
6056 uno::RuntimeException, std::exception )
6058 ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6060 if ( !m_pImpl )
6062 SAL_INFO("package.xstor", THROW_WHERE "Disposed!");
6063 throw lang::DisposedException( THROW_WHERE );
6066 if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
6067 throw packages::NoEncryptionException( THROW_WHERE );
6069 if ( aStreamPath.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, true ) )
6070 throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 );
6072 if ( !aEncryptionData.getLength() )
6073 throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 3 );
6075 if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
6076 && ( nOpenMode & embed::ElementModes::WRITE ) )
6077 throw io::IOException( THROW_WHERE ); // Access denied
6079 OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6080 OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6082 uno::Reference< embed::XExtendedStorageStream > xResult;
6083 if ( aListPath.size() == 1 )
6085 // that must be a direct request for a stream
6086 // the transacted version of the stream should be opened
6088 SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, true );
6089 OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
6091 xResult = uno::Reference< embed::XExtendedStorageStream >(
6092 pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, true ),
6093 uno::UNO_QUERY_THROW );
6095 else
6097 // there are still storages in between
6098 if ( !m_pData->m_rHierarchyHolder.is() )
6099 m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6100 uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6102 xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
6103 ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
6104 aListPath,
6105 nOpenMode,
6106 aEncryptionData );
6109 if ( !xResult.is() )
6110 throw uno::RuntimeException( THROW_WHERE );
6112 return xResult;
6115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */