xref: /aoo42x/main/package/source/xstor/xstorage.cxx (revision 30acf5e8)
1a3872823SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a3872823SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a3872823SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a3872823SAndrew Rist  * distributed with this work for additional information
6a3872823SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a3872823SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a3872823SAndrew Rist  * "License"); you may not use this file except in compliance
9a3872823SAndrew Rist  * with the License.  You may obtain a copy of the License at
10a3872823SAndrew Rist  *
11a3872823SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a3872823SAndrew Rist  *
13a3872823SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a3872823SAndrew Rist  * software distributed under the License is distributed on an
15a3872823SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a3872823SAndrew Rist  * KIND, either express or implied.  See the License for the
17a3872823SAndrew Rist  * specific language governing permissions and limitations
18a3872823SAndrew Rist  * under the License.
19a3872823SAndrew Rist  *
20a3872823SAndrew Rist  *************************************************************/
21a3872823SAndrew Rist 
22a3872823SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_package.hxx"
26cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/StorageFormats.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
34cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
35cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
39cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
41cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <PackageConstants.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
47cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
48cdf0e10cSrcweir #include <rtl/logfile.hxx>
49cdf0e10cSrcweir #include <rtl/instance.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
53cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
54cdf0e10cSrcweir #include <comphelper/ofopxmlhelper.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include "xstorage.hxx"
57cdf0e10cSrcweir #include "owriteablestream.hxx"
58cdf0e10cSrcweir #include "disposelistener.hxx"
59cdf0e10cSrcweir #include "switchpersistencestream.hxx"
60cdf0e10cSrcweir #include "ohierarchyholder.hxx"
61cdf0e10cSrcweir 
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //=========================================================
65cdf0e10cSrcweir 
66cdf0e10cSrcweir typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir struct StorInternalData_Impl
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	SotMutexHolderRef m_rSharedMutexRef;
71cdf0e10cSrcweir 	::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners
72cdf0e10cSrcweir 	::cppu::OTypeCollection* m_pTypeCollection;
73cdf0e10cSrcweir 	sal_Bool m_bIsRoot;
74a893be29SPedro Giffuni 	sal_Int32 m_nStorageType; // the mode in which the storage is used
75cdf0e10cSrcweir 	sal_Bool m_bReadOnlyWrap;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	OChildDispListener_Impl* m_pSubElDispListener;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	WeakComponentList m_aOpenSubComponentsList;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	::rtl::Reference< OHierarchyHolder_Impl > m_rHierarchyHolder;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	// the mutex reference MUST NOT be empty
StorInternalData_ImplStorInternalData_Impl84cdf0e10cSrcweir 	StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Int32 nStorageType, sal_Bool bReadOnlyWrap )
85cdf0e10cSrcweir 	: m_rSharedMutexRef( rMutexRef )
86cdf0e10cSrcweir 	, m_aListenersContainer( rMutexRef->GetMutex() )
87cdf0e10cSrcweir 	, m_pTypeCollection( NULL )
88cdf0e10cSrcweir 	, m_bIsRoot( bRoot )
89cdf0e10cSrcweir 	, m_nStorageType( nStorageType )
90cdf0e10cSrcweir 	, m_bReadOnlyWrap( bReadOnlyWrap )
91cdf0e10cSrcweir 	, m_pSubElDispListener( NULL )
92cdf0e10cSrcweir 	{}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	~StorInternalData_Impl();
95cdf0e10cSrcweir };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //=========================================================
98cdf0e10cSrcweir ::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // static
completeStorageStreamCopy_Impl(const uno::Reference<io::XStream> & xSource,const uno::Reference<io::XStream> & xDest,sal_Int32 nStorageType,const uno::Sequence<uno::Sequence<beans::StringPair>> & aRelInfo)101cdf0e10cSrcweir void OStorage_Impl::completeStorageStreamCopy_Impl(
102cdf0e10cSrcweir 							const uno::Reference< io::XStream >& xSource,
103cdf0e10cSrcweir 							const uno::Reference< io::XStream >& xDest,
104cdf0e10cSrcweir 							sal_Int32 nStorageType,
105cdf0e10cSrcweir 							const uno::Sequence< uno::Sequence< beans::StringPair > >& aRelInfo )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xSourceProps( xSource, uno::UNO_QUERY );
108cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY );
109cdf0e10cSrcweir 		if ( !xSourceProps.is() || !xDestProps.is() )
110cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream();
113cdf0e10cSrcweir 		if ( !xDestOutStream.is() )
114cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xSourceInStream = xSource->getInputStream();
117cdf0e10cSrcweir 		if ( !xSourceInStream.is() )
118cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		// TODO: headers of encripted streams should be copied also
121cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xSourceInStream, xDestOutStream );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		uno::Sequence< ::rtl::OUString > aPropNames( 1 );
124cdf0e10cSrcweir 		aPropNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		if ( nStorageType == embed::StorageFormats::PACKAGE )
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			aPropNames.realloc( 3 );
129cdf0e10cSrcweir 			aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
130cdf0e10cSrcweir 			aPropNames[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 		else if ( nStorageType == embed::StorageFormats::OFOPXML )
133cdf0e10cSrcweir 		{
134*30acf5e8Spfg 			// TODO/LATER: in future it might make sense to provide the stream if there is one
135cdf0e10cSrcweir 			uno::Reference< embed::XRelationshipAccess > xRelAccess( xDest, uno::UNO_QUERY_THROW );
136cdf0e10cSrcweir 			xRelAccess->clearRelationships();
137cdf0e10cSrcweir 			xRelAccess->insertRelationships( aRelInfo, sal_False );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 			aPropNames.realloc( 2 );
140cdf0e10cSrcweir 			aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		for ( int ind = 0; ind < aPropNames.getLength(); ind++ )
144cdf0e10cSrcweir 			xDestProps->setPropertyValue( aPropNames[ind], xSourceProps->getPropertyValue( aPropNames[ind] ) );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
GetSeekableTempCopy(uno::Reference<io::XInputStream> xInStream,uno::Reference<lang::XMultiServiceFactory> xFactory)147cdf0e10cSrcweir uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInputStream > xInStream,
148cdf0e10cSrcweir 														uno::Reference< lang::XMultiServiceFactory > xFactory )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	uno::Reference < io::XOutputStream > xTempOut(
151cdf0e10cSrcweir 						xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
152cdf0e10cSrcweir 						uno::UNO_QUERY );
153cdf0e10cSrcweir 	uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	if ( !xTempOut.is() || !xTempIn.is() )
156cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
159cdf0e10cSrcweir 	xTempOut->closeOutput();
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	return xTempIn;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
~StorInternalData_Impl()164cdf0e10cSrcweir StorInternalData_Impl::~StorInternalData_Impl()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	if ( m_pTypeCollection )
167cdf0e10cSrcweir 		delete m_pTypeCollection;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
SotElement_Impl(const::rtl::OUString & rName,sal_Bool bStor,sal_Bool bNew)171cdf0e10cSrcweir SotElement_Impl::SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew )
172cdf0e10cSrcweir : m_aName( rName )
173cdf0e10cSrcweir , m_aOriginalName( rName )
174cdf0e10cSrcweir , m_bIsRemoved( sal_False )
175cdf0e10cSrcweir , m_bIsInserted( bNew )
176cdf0e10cSrcweir , m_bIsStorage( bStor )
177cdf0e10cSrcweir , m_pStorage( NULL )
178cdf0e10cSrcweir , m_pStream( NULL )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
~SotElement_Impl()182cdf0e10cSrcweir SotElement_Impl::~SotElement_Impl()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	if ( m_pStorage )
185cdf0e10cSrcweir 		delete m_pStorage;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	if ( m_pStream )
188cdf0e10cSrcweir 		delete m_pStream;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir //-----------------------------------------------
192cdf0e10cSrcweir // most of properties are holt by the storage but are not used
OStorage_Impl(uno::Reference<io::XInputStream> xInputStream,sal_Int32 nMode,uno::Sequence<beans::PropertyValue> xProperties,uno::Reference<lang::XMultiServiceFactory> xFactory,sal_Int32 nStorageType)193cdf0e10cSrcweir OStorage_Impl::OStorage_Impl(	uno::Reference< io::XInputStream > xInputStream,
194cdf0e10cSrcweir 								sal_Int32 nMode,
195cdf0e10cSrcweir 								uno::Sequence< beans::PropertyValue > xProperties,
196cdf0e10cSrcweir 								uno::Reference< lang::XMultiServiceFactory > xFactory,
197cdf0e10cSrcweir 								sal_Int32 nStorageType )
198cdf0e10cSrcweir : m_rMutexRef( new SotMutexHolder )
199cdf0e10cSrcweir , m_pAntiImpl( NULL )
200cdf0e10cSrcweir , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
201cdf0e10cSrcweir , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
202cdf0e10cSrcweir , m_bBroadcastModified( sal_False )
203cdf0e10cSrcweir , m_bCommited( sal_False )
204cdf0e10cSrcweir , m_bIsRoot( sal_True )
205cdf0e10cSrcweir , m_bListCreated( sal_False )
206cdf0e10cSrcweir , m_xFactory( xFactory )
207cdf0e10cSrcweir , m_xProperties( xProperties )
208cdf0e10cSrcweir , m_bHasCommonEncryptionData( sal_False )
209cdf0e10cSrcweir , m_pParent( NULL )
210cdf0e10cSrcweir , m_bControlMediaType( sal_False )
211cdf0e10cSrcweir , m_bMTFallbackUsed( sal_False )
212cdf0e10cSrcweir , m_bControlVersion( sal_False )
213cdf0e10cSrcweir , m_pSwitchStream( NULL )
214cdf0e10cSrcweir , m_nStorageType( nStorageType )
215cdf0e10cSrcweir , m_pRelStorElement( NULL )
216cdf0e10cSrcweir , m_nRelInfoStatus( RELINFO_NO_INIT )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	// all the checks done below by assertion statements must be done by factory
219cdf0e10cSrcweir 	OSL_ENSURE( xInputStream.is(), "No input stream is provided!\n" );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xInputStream );
222cdf0e10cSrcweir 	m_xInputStream = m_pSwitchStream->getInputStream();
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	if ( m_nStorageMode & embed::ElementModes::WRITE )
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir 		// check that the stream allows to write
227cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "No stream for writing is provided!\n" );
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir //-----------------------------------------------
232cdf0e10cSrcweir // most of properties are holt by the storage but are not used
OStorage_Impl(uno::Reference<io::XStream> xStream,sal_Int32 nMode,uno::Sequence<beans::PropertyValue> xProperties,uno::Reference<lang::XMultiServiceFactory> xFactory,sal_Int32 nStorageType)233cdf0e10cSrcweir OStorage_Impl::OStorage_Impl(	uno::Reference< io::XStream > xStream,
234cdf0e10cSrcweir 								sal_Int32 nMode,
235cdf0e10cSrcweir 								uno::Sequence< beans::PropertyValue > xProperties,
236cdf0e10cSrcweir 								uno::Reference< lang::XMultiServiceFactory > xFactory,
237cdf0e10cSrcweir 								sal_Int32 nStorageType )
238cdf0e10cSrcweir : m_rMutexRef( new SotMutexHolder )
239cdf0e10cSrcweir , m_pAntiImpl( NULL )
240cdf0e10cSrcweir , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
241cdf0e10cSrcweir , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
242cdf0e10cSrcweir , m_bBroadcastModified( sal_False )
243cdf0e10cSrcweir , m_bCommited( sal_False )
244cdf0e10cSrcweir , m_bIsRoot( sal_True )
245cdf0e10cSrcweir , m_bListCreated( sal_False )
246cdf0e10cSrcweir , m_xFactory( xFactory )
247cdf0e10cSrcweir , m_xProperties( xProperties )
248cdf0e10cSrcweir , m_bHasCommonEncryptionData( sal_False )
249cdf0e10cSrcweir , m_pParent( NULL )
250cdf0e10cSrcweir , m_bControlMediaType( sal_False )
251cdf0e10cSrcweir , m_bMTFallbackUsed( sal_False )
252cdf0e10cSrcweir , m_bControlVersion( sal_False )
253cdf0e10cSrcweir , m_pSwitchStream( NULL )
254cdf0e10cSrcweir , m_nStorageType( nStorageType )
255cdf0e10cSrcweir , m_pRelStorElement( NULL )
256cdf0e10cSrcweir , m_nRelInfoStatus( RELINFO_NO_INIT )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	// all the checks done below by assertion statements must be done by factory
259cdf0e10cSrcweir 	OSL_ENSURE( xStream.is(), "No stream is provided!\n" );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	if ( m_nStorageMode & embed::ElementModes::WRITE )
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xStream );
264cdf0e10cSrcweir 		m_xStream = static_cast< io::XStream* >( m_pSwitchStream );
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 	else
267cdf0e10cSrcweir 	{
268cdf0e10cSrcweir 		m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory,
269cdf0e10cSrcweir 																						  xStream->getInputStream() );
270cdf0e10cSrcweir 		m_xInputStream = m_pSwitchStream->getInputStream();
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir //-----------------------------------------------
OStorage_Impl(OStorage_Impl * pParent,sal_Int32 nMode,uno::Reference<container::XNameContainer> xPackageFolder,uno::Reference<lang::XSingleServiceFactory> xPackage,uno::Reference<lang::XMultiServiceFactory> xFactory,sal_Int32 nStorageType)275cdf0e10cSrcweir OStorage_Impl::OStorage_Impl(	OStorage_Impl* pParent,
276cdf0e10cSrcweir 								sal_Int32 nMode,
277cdf0e10cSrcweir 								uno::Reference< container::XNameContainer > xPackageFolder,
278cdf0e10cSrcweir 								uno::Reference< lang::XSingleServiceFactory > xPackage,
279cdf0e10cSrcweir 								uno::Reference< lang::XMultiServiceFactory > xFactory,
280cdf0e10cSrcweir 								sal_Int32 nStorageType )
281cdf0e10cSrcweir : m_rMutexRef( new SotMutexHolder )
282cdf0e10cSrcweir , m_pAntiImpl( NULL )
283cdf0e10cSrcweir , m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE )
284cdf0e10cSrcweir , m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) )
285cdf0e10cSrcweir , m_bBroadcastModified( sal_False )
286cdf0e10cSrcweir , m_bCommited( sal_False )
287cdf0e10cSrcweir , m_bIsRoot( sal_False )
288cdf0e10cSrcweir , m_bListCreated( sal_False )
289cdf0e10cSrcweir , m_xPackageFolder( xPackageFolder )
290cdf0e10cSrcweir , m_xPackage( xPackage )
291cdf0e10cSrcweir , m_xFactory( xFactory )
292cdf0e10cSrcweir , m_bHasCommonEncryptionData( sal_False )
293cdf0e10cSrcweir , m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage
294cdf0e10cSrcweir , m_bControlMediaType( sal_False )
295cdf0e10cSrcweir , m_bMTFallbackUsed( sal_False )
296cdf0e10cSrcweir , m_bControlVersion( sal_False )
297cdf0e10cSrcweir , m_pSwitchStream( NULL )
298cdf0e10cSrcweir , m_nStorageType( nStorageType )
299cdf0e10cSrcweir , m_pRelStorElement( NULL )
300cdf0e10cSrcweir , m_nRelInfoStatus( RELINFO_NO_INIT )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	OSL_ENSURE( xPackageFolder.is(), "No package folder!\n" );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir //-----------------------------------------------
~OStorage_Impl()306cdf0e10cSrcweir OStorage_Impl::~OStorage_Impl()
307cdf0e10cSrcweir {
308cdf0e10cSrcweir 	{
309cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
310cdf0e10cSrcweir 		if ( m_pAntiImpl ) // root storage wrapper must set this member to NULL before destruction of object
311cdf0e10cSrcweir 		{
312cdf0e10cSrcweir 			OSL_ENSURE( !m_bIsRoot, "The root storage wrapper must be disposed already" );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 			try {
315cdf0e10cSrcweir 				m_pAntiImpl->InternalDispose( sal_False );
316cdf0e10cSrcweir 			}
317cdf0e10cSrcweir 			catch ( uno::Exception& aException )
318cdf0e10cSrcweir             {
319cdf0e10cSrcweir                 AddLog( aException.Message );
320cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
321cdf0e10cSrcweir             }
322cdf0e10cSrcweir 			m_pAntiImpl = NULL;
323cdf0e10cSrcweir 		}
324cdf0e10cSrcweir 		else if ( !m_aReadOnlyWrapList.empty() )
325cdf0e10cSrcweir 		{
326cdf0e10cSrcweir 			for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
327cdf0e10cSrcweir 				  pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ )
328cdf0e10cSrcweir 			{
329cdf0e10cSrcweir 				uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
330cdf0e10cSrcweir 				if ( xTmp.is() )
331cdf0e10cSrcweir 					try {
332cdf0e10cSrcweir 						pStorageIter->m_pPointer->InternalDispose( sal_False );
333cdf0e10cSrcweir 					} catch( uno::Exception& aException )
334cdf0e10cSrcweir                     {
335cdf0e10cSrcweir                         AddLog( aException.Message );
336cdf0e10cSrcweir                         AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
337cdf0e10cSrcweir                     }
338cdf0e10cSrcweir 			}
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 			m_aReadOnlyWrapList.clear();
341cdf0e10cSrcweir 		}
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 		m_pParent = NULL;
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
347cdf0e10cSrcweir 		  pElementIter != m_aChildrenList.end(); pElementIter++ )
348cdf0e10cSrcweir 		delete *pElementIter;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	m_aChildrenList.clear();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
353cdf0e10cSrcweir 		  pDeletedIter != m_aDeletedList.end(); pDeletedIter++ )
354cdf0e10cSrcweir 		delete *pDeletedIter;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	m_aDeletedList.clear();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement )
359cdf0e10cSrcweir 	{
360cdf0e10cSrcweir 		delete m_pRelStorElement;
361cdf0e10cSrcweir 		m_pRelStorElement = NULL;
362cdf0e10cSrcweir 	}
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	m_xPackageFolder = uno::Reference< container::XNameContainer >();
365cdf0e10cSrcweir 	m_xPackage = uno::Reference< lang::XSingleServiceFactory >();
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 	::rtl::OUString aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
368cdf0e10cSrcweir 	for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ )
369cdf0e10cSrcweir 	{
370cdf0e10cSrcweir 		if ( m_xProperties[aInd].Name.equals( aPropertyName ) )
371cdf0e10cSrcweir 		{
372cdf0e10cSrcweir 			// the storage is URL based so all the streams are opened by factory and should be closed
373cdf0e10cSrcweir 			try
374cdf0e10cSrcweir 			{
375cdf0e10cSrcweir 				if ( m_xInputStream.is() )
376cdf0e10cSrcweir 				{
377cdf0e10cSrcweir 					m_xInputStream->closeInput();
378cdf0e10cSrcweir 					m_xInputStream = uno::Reference< io::XInputStream >();
379cdf0e10cSrcweir 				}
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 				if ( m_xStream.is() )
382cdf0e10cSrcweir 				{
383cdf0e10cSrcweir 					uno::Reference< io::XInputStream > xInStr = m_xStream->getInputStream();
384cdf0e10cSrcweir 					if ( xInStr.is() )
385cdf0e10cSrcweir 						xInStr->closeInput();
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 					uno::Reference< io::XOutputStream > xOutStr = m_xStream->getOutputStream();
388cdf0e10cSrcweir 					if ( xOutStr.is() )
389cdf0e10cSrcweir 						xOutStr->closeOutput();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 					m_xStream = uno::Reference< io::XStream >();
392cdf0e10cSrcweir 				}
393cdf0e10cSrcweir 			}
394cdf0e10cSrcweir 			catch( uno::Exception& aException )
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
397cdf0e10cSrcweir                 AddLog( aException.Message );
398cdf0e10cSrcweir             }
399cdf0e10cSrcweir 		}
400cdf0e10cSrcweir 	}
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir //-----------------------------------------------
AddLog(const::rtl::OUString & aMessage)404cdf0e10cSrcweir void OStorage_Impl::AddLog( const ::rtl::OUString& aMessage )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     if ( !m_xLogRing.is() )
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         try
409cdf0e10cSrcweir         {
410cdf0e10cSrcweir             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
411cdf0e10cSrcweir             if ( aContext.is() )
412cdf0e10cSrcweir                 m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW );
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir         catch( uno::Exception& )
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             // No log
417cdf0e10cSrcweir         }
418cdf0e10cSrcweir     }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     if ( m_xLogRing.is() )
421cdf0e10cSrcweir         m_xLogRing->logString( aMessage );
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir //-----------------------------------------------
SetReadOnlyWrap(OStorage & aStorage)425cdf0e10cSrcweir void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	// Weak reference is used inside the holder so the refcount must not be zero at this point
428cdf0e10cSrcweir 	OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" );
429cdf0e10cSrcweir 	m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) );
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir //-----------------------------------------------
RemoveReadOnlyWrap(OStorage & aStorage)433cdf0e10cSrcweir void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir 	for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin();
436cdf0e10cSrcweir 	  pStorageIter != m_aReadOnlyWrapList.end();)
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef;
439cdf0e10cSrcweir 		if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage )
440cdf0e10cSrcweir 		{
441cdf0e10cSrcweir 			try {
442cdf0e10cSrcweir 				pStorageIter->m_pPointer->InternalDispose( sal_False );
443cdf0e10cSrcweir 			} catch( uno::Exception& aException )
444cdf0e10cSrcweir             {
445cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
446cdf0e10cSrcweir                 AddLog( aException.Message );
447cdf0e10cSrcweir             }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 			OStorageList_Impl::iterator pIterToDelete( pStorageIter );
450cdf0e10cSrcweir 			pStorageIter++;
451cdf0e10cSrcweir 			m_aReadOnlyWrapList.erase( pIterToDelete );
452cdf0e10cSrcweir 		}
453cdf0e10cSrcweir 		else
454cdf0e10cSrcweir 			pStorageIter++;
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir //-----------------------------------------------
OpenOwnPackage()459cdf0e10cSrcweir void OStorage_Impl::OpenOwnPackage()
460cdf0e10cSrcweir {
461*30acf5e8Spfg 	OSL_ENSURE( m_bIsRoot, "Opening of the package has no sense!\n" );
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	if ( !m_xPackageFolder.is() )
466cdf0e10cSrcweir 	{
467cdf0e10cSrcweir 		if ( !m_xPackage.is() )
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir         	uno::Sequence< uno::Any > aArguments( 2 );
470cdf0e10cSrcweir 			if ( m_nStorageMode & embed::ElementModes::WRITE )
471cdf0e10cSrcweir 				aArguments[ 0 ] <<= m_xStream;
472cdf0e10cSrcweir 			else
473cdf0e10cSrcweir 			{
474cdf0e10cSrcweir 				OSL_ENSURE( m_xInputStream.is(), "Input stream must be set for readonly access!\n" );
475cdf0e10cSrcweir 				aArguments[ 0 ] <<= m_xInputStream;
476cdf0e10cSrcweir 				// TODO: if input stream is not seekable or XSeekable interface is supported
477cdf0e10cSrcweir 				// on XStream object a wrapper must be used
478cdf0e10cSrcweir 			}
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 			// do not allow elements to remove themself from the old container in case of insertion to another container
481cdf0e10cSrcweir 			aArguments[ 1 ] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowRemoveOnInsert" ) ),
482cdf0e10cSrcweir 													uno::makeAny( (sal_Bool)sal_False ) );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 			sal_Int32 nArgNum = 2;
485cdf0e10cSrcweir 			for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ )
486cdf0e10cSrcweir 			{
487cdf0e10cSrcweir 				if ( m_xProperties[aInd].Name.equalsAscii( "RepairPackage" )
488cdf0e10cSrcweir 				  || m_xProperties[aInd].Name.equalsAscii( "ProgressHandler" ) )
489cdf0e10cSrcweir 				{
490cdf0e10cSrcweir 					beans::NamedValue aNamedValue( m_xProperties[aInd].Name,
491cdf0e10cSrcweir 													m_xProperties[aInd].Value );
492cdf0e10cSrcweir 					aArguments.realloc( ++nArgNum );
493cdf0e10cSrcweir 					aArguments[nArgNum-1] <<= aNamedValue;
494cdf0e10cSrcweir 				}
495cdf0e10cSrcweir 				else if ( m_xProperties[aInd].Name.equalsAscii( "Password" ) )
496cdf0e10cSrcweir 				{
497cdf0e10cSrcweir 					// TODO: implement password setting for documents
498cdf0e10cSrcweir 					// the password entry must be removed after setting
499cdf0e10cSrcweir 				}
500cdf0e10cSrcweir 			}
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			if ( m_nStorageType == embed::StorageFormats::ZIP )
503cdf0e10cSrcweir 			{
504cdf0e10cSrcweir 				// let the package support only plain zip format
505cdf0e10cSrcweir 				beans::NamedValue aNamedValue;
506cdf0e10cSrcweir 				aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
507cdf0e10cSrcweir 				aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) );
508cdf0e10cSrcweir 				aArguments.realloc( ++nArgNum );
509cdf0e10cSrcweir 				aArguments[nArgNum-1] <<= aNamedValue;
510cdf0e10cSrcweir 			}
511cdf0e10cSrcweir 			else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
512cdf0e10cSrcweir 			{
513cdf0e10cSrcweir 				// let the package support OFOPXML media type handling
514cdf0e10cSrcweir 				beans::NamedValue aNamedValue;
515cdf0e10cSrcweir 				aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
516cdf0e10cSrcweir 				aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) );
517cdf0e10cSrcweir 				aArguments.realloc( ++nArgNum );
518cdf0e10cSrcweir 				aArguments[nArgNum-1] <<= aNamedValue;
519cdf0e10cSrcweir 			}
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         	m_xPackage = uno::Reference< lang::XSingleServiceFactory > (
522cdf0e10cSrcweir 										GetServiceFactory()->createInstanceWithArguments(
523cdf0e10cSrcweir 											::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.packages.comp.ZipPackage" ) ),
524cdf0e10cSrcweir                 							aArguments ),
525cdf0e10cSrcweir 										uno::UNO_QUERY );
526cdf0e10cSrcweir 		}
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 		uno::Reference< container::XHierarchicalNameAccess > xHNameAccess( m_xPackage, uno::UNO_QUERY );
529cdf0e10cSrcweir 		OSL_ENSURE( xHNameAccess.is(), "The package could not be created!\n" );
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 		if ( xHNameAccess.is() )
532cdf0e10cSrcweir 		{
533cdf0e10cSrcweir 			uno::Any aFolder = xHNameAccess->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
534cdf0e10cSrcweir 			aFolder >>= m_xPackageFolder;
535cdf0e10cSrcweir 		}
536cdf0e10cSrcweir 	}
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 	OSL_ENSURE( m_xPackageFolder.is(), "The package root folder can not be opened!\n" );
539cdf0e10cSrcweir 	if ( !m_xPackageFolder.is() )
540cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir //-----------------------------------------------
GetServiceFactory()544cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > OStorage_Impl::GetServiceFactory()
545cdf0e10cSrcweir {
546cdf0e10cSrcweir 	if ( m_xFactory.is() )
547cdf0e10cSrcweir 		return m_xFactory;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	return ::comphelper::getProcessServiceFactory();
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir //-----------------------------------------------
GetChildrenList()553cdf0e10cSrcweir SotElementList_Impl& OStorage_Impl::GetChildrenList()
554cdf0e10cSrcweir {
555cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	ReadContents();
558cdf0e10cSrcweir 	return m_aChildrenList;
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir //-----------------------------------------------
GetStorageProperties()562cdf0e10cSrcweir void OStorage_Impl::GetStorageProperties()
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::PACKAGE )
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xProps( m_xPackageFolder, uno::UNO_QUERY_THROW );
567cdf0e10cSrcweir 
568cdf0e10cSrcweir         if ( !m_bControlMediaType )
569cdf0e10cSrcweir         {
570cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW );
571cdf0e10cSrcweir             xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir             xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType;
574cdf0e10cSrcweir             m_bControlMediaType = sal_True;
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         if ( !m_bControlVersion )
578cdf0e10cSrcweir         {
579cdf0e10cSrcweir             xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= m_aVersion;
580cdf0e10cSrcweir             m_bControlVersion = sal_True;
581cdf0e10cSrcweir         }
582cdf0e10cSrcweir     }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	// the properties of OFOPXML will be handled directly
585cdf0e10cSrcweir }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir //-----------------------------------------------
ReadRelInfoIfNecessary()588cdf0e10cSrcweir void OStorage_Impl::ReadRelInfoIfNecessary()
589cdf0e10cSrcweir {
590cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::OFOPXML )
591cdf0e10cSrcweir 		return;
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 	if ( m_nRelInfoStatus == RELINFO_NO_INIT )
594cdf0e10cSrcweir 	{
595cdf0e10cSrcweir 		// Init from original stream
596cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() );
597cdf0e10cSrcweir 		if ( xRelInfoStream.is() )
598cdf0e10cSrcweir 			m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
599cdf0e10cSrcweir 									xRelInfoStream,
600cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ),
601cdf0e10cSrcweir 									m_xFactory );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 		m_nRelInfoStatus = RELINFO_READ;
604cdf0e10cSrcweir 	}
605cdf0e10cSrcweir 	else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
606cdf0e10cSrcweir 	{
607cdf0e10cSrcweir 		// Init from the new stream
608cdf0e10cSrcweir 		try
609cdf0e10cSrcweir 		{
610cdf0e10cSrcweir 			if ( m_xNewRelInfoStream.is() )
611cdf0e10cSrcweir 				m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
612cdf0e10cSrcweir 										m_xNewRelInfoStream,
613cdf0e10cSrcweir 										::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ),
614cdf0e10cSrcweir 										m_xFactory );
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 			m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ;
617cdf0e10cSrcweir 		}
618cdf0e10cSrcweir 		catch( uno::Exception )
619cdf0e10cSrcweir 		{
620cdf0e10cSrcweir 			m_nRelInfoStatus = RELINFO_CHANGED_BROKEN;
621cdf0e10cSrcweir 		}
622cdf0e10cSrcweir 	}
623cdf0e10cSrcweir }
624cdf0e10cSrcweir 
625cdf0e10cSrcweir //-----------------------------------------------
ReadContents()626cdf0e10cSrcweir void OStorage_Impl::ReadContents()
627cdf0e10cSrcweir {
628cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
629cdf0e10cSrcweir 
630cdf0e10cSrcweir     if ( m_bListCreated )
631cdf0e10cSrcweir         return;
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 	if ( m_bIsRoot )
634cdf0e10cSrcweir 		OpenOwnPackage();
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 	uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xPackageFolder, uno::UNO_QUERY );
637cdf0e10cSrcweir 	if ( !xEnumAccess.is() )
638cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 	uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
641cdf0e10cSrcweir 	if ( !xEnum.is() )
642cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     m_bListCreated = sal_True;
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 	while( xEnum->hasMoreElements() )
647cdf0e10cSrcweir 	{
648cdf0e10cSrcweir 		try {
649cdf0e10cSrcweir 			uno::Reference< container::XNamed > xNamed;
650cdf0e10cSrcweir 			xEnum->nextElement() >>= xNamed;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 			if ( !xNamed.is() )
653cdf0e10cSrcweir 			{
654cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "XNamed is not supported!\n" );
655cdf0e10cSrcweir 				throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
656cdf0e10cSrcweir 			}
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 			::rtl::OUString aName = xNamed->getName();
659cdf0e10cSrcweir 			OSL_ENSURE( aName.getLength(), "Empty name!\n" );
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 			uno::Reference< container::XNameContainer > xNameContainer( xNamed, uno::UNO_QUERY );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 			SotElement_Impl* pNewElement = new SotElement_Impl( aName, xNameContainer.is(), sal_False );
664cdf0e10cSrcweir 			if ( m_nStorageType == embed::StorageFormats::OFOPXML && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
665cdf0e10cSrcweir 			{
666cdf0e10cSrcweir 				if ( !pNewElement->m_bIsStorage )
667cdf0e10cSrcweir 					throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Unexpected format
668cdf0e10cSrcweir 
669cdf0e10cSrcweir 				m_pRelStorElement = pNewElement;
670cdf0e10cSrcweir 				CreateRelStorage();
671cdf0e10cSrcweir 			}
672cdf0e10cSrcweir 			else
673cdf0e10cSrcweir 			{
674cdf0e10cSrcweir 				if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
675cdf0e10cSrcweir 				{
676cdf0e10cSrcweir 					// if a storage is truncated all of it elements are marked as deleted
677cdf0e10cSrcweir 					pNewElement->m_bIsRemoved = sal_True;
678cdf0e10cSrcweir 				}
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 				m_aChildrenList.push_back( pNewElement );
681cdf0e10cSrcweir 			}
682cdf0e10cSrcweir 		}
683cdf0e10cSrcweir 		catch( container::NoSuchElementException& aNoSuchElementException )
684cdf0e10cSrcweir         {
685cdf0e10cSrcweir             AddLog( aNoSuchElementException.Message );
686cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "NoSuchElement" ) ) );
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "hasMoreElements() implementation has problems!\n" );
689cdf0e10cSrcweir 			break;
690cdf0e10cSrcweir 		}
691cdf0e10cSrcweir 	}
692cdf0e10cSrcweir 	if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
693cdf0e10cSrcweir 	{
694cdf0e10cSrcweir 		// if a storage is truncated the relations information should be cleaned
695cdf0e10cSrcweir 		m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
696cdf0e10cSrcweir 		m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
697cdf0e10cSrcweir 		m_nRelInfoStatus = RELINFO_CHANGED;
698cdf0e10cSrcweir 	}
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	// cache changeable folder properties
701cdf0e10cSrcweir 	GetStorageProperties();
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir //-----------------------------------------------
CopyToStorage(const uno::Reference<embed::XStorage> & xDest,sal_Bool bDirect)705cdf0e10cSrcweir void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDest, sal_Bool bDirect )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xPropSet( xDest, uno::UNO_QUERY );
710cdf0e10cSrcweir 	if ( !xPropSet.is() )
711cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 	sal_Int32 nDestMode = embed::ElementModes::READ;
714cdf0e10cSrcweir 	xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nDestMode;
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 	if ( !( nDestMode & embed::ElementModes::WRITE ) )
717cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 	ReadContents();
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 	if ( !m_xPackageFolder.is() )
722cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
725cdf0e10cSrcweir 		  pElementIter != m_aChildrenList.end(); pElementIter++ )
726cdf0e10cSrcweir     {
727cdf0e10cSrcweir 		if ( !(*pElementIter)->m_bIsRemoved )
728cdf0e10cSrcweir 			CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect );
729cdf0e10cSrcweir 	}
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 	// move storage properties to the destination one ( means changeable properties )
732cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::PACKAGE )
733cdf0e10cSrcweir 	{
734cdf0e10cSrcweir 		::rtl::OUString aMediaTypeString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
735cdf0e10cSrcweir 		::rtl::OUString aVersionString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) );
736cdf0e10cSrcweir 		xPropSet->setPropertyValue( aMediaTypeString, uno::makeAny( m_aMediaType ) );
737cdf0e10cSrcweir 		xPropSet->setPropertyValue( aVersionString, uno::makeAny( m_aVersion ) );
738cdf0e10cSrcweir 	}
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::PACKAGE )
741cdf0e10cSrcweir 	{
742cdf0e10cSrcweir 		// if this is a root storage, the common key from current one should be moved there
743cdf0e10cSrcweir 		sal_Bool bIsRoot = sal_False;
744cdf0e10cSrcweir 		::rtl::OUString aRootString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsRoot" ) );
745cdf0e10cSrcweir 		if ( ( xPropSet->getPropertyValue( aRootString ) >>= bIsRoot ) && bIsRoot )
746cdf0e10cSrcweir 		{
747cdf0e10cSrcweir 			try
748cdf0e10cSrcweir 			{
749cdf0e10cSrcweir 				uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY );
750cdf0e10cSrcweir 				if ( xEncr.is() )
751cdf0e10cSrcweir                 {
752cdf0e10cSrcweir 					xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir                     uno::Sequence< beans::NamedValue > aAlgorithms;
755cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW );
756cdf0e10cSrcweir                     xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) )
757cdf0e10cSrcweir                         >>= aAlgorithms;
758cdf0e10cSrcweir                     xEncr->setEncryptionAlgorithms( aAlgorithms );
759cdf0e10cSrcweir                 }
760cdf0e10cSrcweir 			}
761cdf0e10cSrcweir 			catch( packages::NoEncryptionException& aNoEncryptionException )
762cdf0e10cSrcweir             {
763cdf0e10cSrcweir                 AddLog( aNoEncryptionException.Message );
764cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) );
765cdf0e10cSrcweir             }
766cdf0e10cSrcweir 		}
767cdf0e10cSrcweir 	}
768cdf0e10cSrcweir 	else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
769cdf0e10cSrcweir 	{
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 		// TODO/LATER: currently the optimization is not active
772cdf0e10cSrcweir 		// uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own stream
773cdf0e10cSrcweir 		// if ( xRelInfoStream.is() )
774cdf0e10cSrcweir 		// {
775cdf0e10cSrcweir 		// 	// Relations info stream is a writeonly property, introduced only to optimyze copying
776cdf0e10cSrcweir 		// 	// Should be used carefuly since no check for stream consistency is done, and the stream must not stay locked
777cdf0e10cSrcweir 		//
778cdf0e10cSrcweir 		// 	::rtl::OUString aRelInfoString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) );
779cdf0e10cSrcweir 		// 	xPropSet->setPropertyValue( aRelInfoString, uno::makeAny( GetSeekableTempCopy( xRelInfoStream, m_xFactory ) ) );
780cdf0e10cSrcweir 		// }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 		uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
783cdf0e10cSrcweir 		if ( !xRels.is() )
784cdf0e10cSrcweir 			throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 		xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
787cdf0e10cSrcweir 	}
788cdf0e10cSrcweir 
789*30acf5e8Spfg 	// if possible the destination storage should be committed after successful copying
790cdf0e10cSrcweir 	uno::Reference< embed::XTransactedObject > xObjToCommit( xDest, uno::UNO_QUERY );
791cdf0e10cSrcweir 	if ( xObjToCommit.is() )
792cdf0e10cSrcweir 		xObjToCommit->commit();
793cdf0e10cSrcweir }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir //-----------------------------------------------
CopyStorageElement(SotElement_Impl * pElement,uno::Reference<embed::XStorage> xDest,::rtl::OUString aName,sal_Bool bDirect)796cdf0e10cSrcweir void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
797cdf0e10cSrcweir 										uno::Reference< embed::XStorage > xDest,
798cdf0e10cSrcweir 										::rtl::OUString aName,
799cdf0e10cSrcweir 										sal_Bool bDirect )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir 	OSL_ENSURE( xDest.is(), "No destination storage!\n" );
802cdf0e10cSrcweir 	OSL_ENSURE( aName.getLength(), "Empty element name!\n" );
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xDestAccess( xDest, uno::UNO_QUERY );
807cdf0e10cSrcweir 	if ( !xDestAccess.is() )
808cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 	if ( xDestAccess->hasByName( aName )
811cdf0e10cSrcweir 	  && !( pElement->m_bIsStorage && xDest->isStorageElement( aName ) ) )
812cdf0e10cSrcweir 		xDest->removeElement( aName );
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 	if ( pElement->m_bIsStorage )
815cdf0e10cSrcweir 	{
816cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xSubDest =
817cdf0e10cSrcweir 									xDest->openStorageElement(  aName,
818cdf0e10cSrcweir 																embed::ElementModes::WRITE );
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 		OSL_ENSURE( xSubDest.is(), "No destination substorage!\n" );
821cdf0e10cSrcweir 
822cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
823cdf0e10cSrcweir 		{
824cdf0e10cSrcweir 			OpenSubStorage( pElement, embed::ElementModes::READ );
825cdf0e10cSrcweir 			if ( !pElement->m_pStorage )
826cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
827cdf0e10cSrcweir 		}
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 		pElement->m_pStorage->CopyToStorage( xSubDest, bDirect );
830cdf0e10cSrcweir 	}
831cdf0e10cSrcweir 	else
832cdf0e10cSrcweir 	{
833cdf0e10cSrcweir 		if ( !pElement->m_pStream )
834cdf0e10cSrcweir 		{
835cdf0e10cSrcweir 			OpenSubStream( pElement );
836cdf0e10cSrcweir 			if ( !pElement->m_pStream )
837cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
838cdf0e10cSrcweir 		}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 		if ( !pElement->m_pStream->IsEncrypted() )
841cdf0e10cSrcweir 		{
842cdf0e10cSrcweir 			if ( bDirect )
843cdf0e10cSrcweir 			{
844cdf0e10cSrcweir 				// fill in the properties for the stream
845cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aStrProps(0);
846cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties();
847cdf0e10cSrcweir 				sal_Int32 nNum = 0;
848cdf0e10cSrcweir 				for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ )
849cdf0e10cSrcweir 				{
850cdf0e10cSrcweir 					if ( aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) )
851cdf0e10cSrcweir 					  || aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "Compressed" ) ) ) )
852cdf0e10cSrcweir 					{
853cdf0e10cSrcweir 						aStrProps.realloc( ++nNum );
854cdf0e10cSrcweir 						aStrProps[nNum-1].Name = aSrcPkgProps[ind].Name;
855cdf0e10cSrcweir 						aStrProps[nNum-1].Value = aSrcPkgProps[ind].Value;
856cdf0e10cSrcweir 					}
857cdf0e10cSrcweir 				}
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 				if ( m_nStorageType == embed::StorageFormats::PACKAGE )
860cdf0e10cSrcweir 				{
861cdf0e10cSrcweir 					aStrProps.realloc( ++nNum );
862cdf0e10cSrcweir 					aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
863cdf0e10cSrcweir 					aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonEncryption_Impl() );
864cdf0e10cSrcweir 				}
865cdf0e10cSrcweir 				else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
866cdf0e10cSrcweir 				{
867cdf0e10cSrcweir 					// TODO/LATER: currently the optimization is not active
868cdf0e10cSrcweir 					// uno::Reference< io::XInputStream > xInStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own rels stream
869cdf0e10cSrcweir 					// if ( xInStream.is() )
870cdf0e10cSrcweir 					// {
871cdf0e10cSrcweir 					// 	aStrProps.realloc( ++nNum );
872cdf0e10cSrcweir 					// 	aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) );
873cdf0e10cSrcweir 					// 	aStrProps[nNum-1].Value <<= GetSeekableTempCopy( xInStream, m_xFactory );
874cdf0e10cSrcweir 					// }
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 					uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY );
877cdf0e10cSrcweir 					if ( !xRels.is() )
878cdf0e10cSrcweir 						throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 					xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False );
881cdf0e10cSrcweir 				}
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 				uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW );
884cdf0e10cSrcweir 				uno::Reference < io::XInputStream > xInputToInsert;
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 				if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() )
887cdf0e10cSrcweir 				{
888cdf0e10cSrcweir 					OSL_ENSURE( pElement->m_pStream->m_xPackageStream.is(), "No package stream!" );
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 					// if the stream is modified - the temporary file must be used for insertion
891cdf0e10cSrcweir 					xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream();
892cdf0e10cSrcweir 				}
893cdf0e10cSrcweir 				else
894cdf0e10cSrcweir 				{
895cdf0e10cSrcweir 					// for now get just nonseekable access to the stream
896cdf0e10cSrcweir 					// TODO/LATER: the raw stream can be used
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 					xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream();
899cdf0e10cSrcweir 				}
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 				if ( !xInputToInsert.is() )
902cdf0e10cSrcweir 						throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 				xOptDest->insertStreamElementDirect( aName, xInputToInsert, aStrProps );
905cdf0e10cSrcweir 			}
906cdf0e10cSrcweir 			else
907cdf0e10cSrcweir 			{
908cdf0e10cSrcweir 				uno::Reference< io::XStream > xSubStr =
909cdf0e10cSrcweir 											xDest->openStreamElement( aName,
910cdf0e10cSrcweir 											embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
911cdf0e10cSrcweir 				OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 				pElement->m_pStream->CopyInternallyTo_Impl( xSubStr );
914cdf0e10cSrcweir 			}
915cdf0e10cSrcweir 		}
916cdf0e10cSrcweir 		else if ( m_nStorageType != embed::StorageFormats::PACKAGE )
917cdf0e10cSrcweir 		{
918cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Encryption is only supported in package storage!\n" );
919cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
920cdf0e10cSrcweir 		}
921cdf0e10cSrcweir 		else if ( pElement->m_pStream->HasCachedEncryptionData()
922cdf0e10cSrcweir 			 && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) )
923cdf0e10cSrcweir 		{
924cdf0e10cSrcweir             ::comphelper::SequenceAsHashMap aCommonEncryptionData;
925cdf0e10cSrcweir 			sal_Bool bHasCommonEncryptionData = sal_False;
926cdf0e10cSrcweir 			try
927cdf0e10cSrcweir 			{
928cdf0e10cSrcweir 				aCommonEncryptionData = GetCommonRootEncryptionData();
929cdf0e10cSrcweir 				bHasCommonEncryptionData = sal_True;
930cdf0e10cSrcweir 			}
931cdf0e10cSrcweir 			catch( packages::NoEncryptionException& aNoEncryptionException )
932cdf0e10cSrcweir             {
933cdf0e10cSrcweir                 AddLog( aNoEncryptionException.Message );
934cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) );
935cdf0e10cSrcweir             }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 			if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) )
938cdf0e10cSrcweir 			{
939cdf0e10cSrcweir 				// If the stream can be opened with the common storage password
940cdf0e10cSrcweir 				// it must be stored with the common storage password as well
941cdf0e10cSrcweir 				uno::Reference< io::XStream > xDestStream =
942cdf0e10cSrcweir 											xDest->openStreamElement( aName,
943cdf0e10cSrcweir 												embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
944cdf0e10cSrcweir 
945cdf0e10cSrcweir 				pElement->m_pStream->CopyInternallyTo_Impl( xDestStream );
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
948cdf0e10cSrcweir 				xProps->setPropertyValue(
949cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ),
950cdf0e10cSrcweir 					uno::Any( (sal_Bool) sal_True ) );
951cdf0e10cSrcweir 			}
952cdf0e10cSrcweir 			else
953cdf0e10cSrcweir 			{
954cdf0e10cSrcweir 				// the stream is already opened for writing or was changed
955cdf0e10cSrcweir                 uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW );
956cdf0e10cSrcweir 				uno::Reference< io::XStream > xSubStr =
957cdf0e10cSrcweir 											xDest2->openEncryptedStream( aName,
958cdf0e10cSrcweir 												embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
959cdf0e10cSrcweir 												pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() );
960cdf0e10cSrcweir 				OSL_ENSURE( xSubStr.is(), "No destination substream!\n" );
961cdf0e10cSrcweir 
962cdf0e10cSrcweir 				pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() );
963cdf0e10cSrcweir 			}
964cdf0e10cSrcweir 		}
965cdf0e10cSrcweir 		else
966cdf0e10cSrcweir 		{
967cdf0e10cSrcweir 			// the stream is not opened at all, so it can be just opened for reading
968cdf0e10cSrcweir 			try
969cdf0e10cSrcweir 			{
970cdf0e10cSrcweir 				// If the stream can be opened with the common storage password
971cdf0e10cSrcweir 				// it must be stored with the common storage password as well
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 				uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ,
974cdf0e10cSrcweir 																							sal_False );
975cdf0e10cSrcweir 				uno::Reference< io::XStream > xDestStream =
976cdf0e10cSrcweir 											xDest->openStreamElement( aName,
977cdf0e10cSrcweir 												embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
978cdf0e10cSrcweir 				OSL_ENSURE( xDestStream.is(), "No destination substream!\n" );
979cdf0e10cSrcweir 				completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
982cdf0e10cSrcweir 				xProps->setPropertyValue(
983cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ),
984cdf0e10cSrcweir 					uno::Any( (sal_Bool) sal_True ) );
985cdf0e10cSrcweir 			}
986cdf0e10cSrcweir 			catch( packages::WrongPasswordException& aWrongPasswordException )
987cdf0e10cSrcweir 			{
988cdf0e10cSrcweir                 AddLog( aWrongPasswordException.Message );
989cdf0e10cSrcweir                 AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) );
990cdf0e10cSrcweir 
991cdf0e10cSrcweir 				// If the common storage password does not allow to open the stream
992cdf0e10cSrcweir 				// it could be copyed in raw way, the problem is that the StartKey should be the same
993cdf0e10cSrcweir                 // in the ODF1.2 package, so an invalid package could be produced if the stream
994cdf0e10cSrcweir                 // is copied from ODF1.1 package, where it is allowed to have different StartKeys
995cdf0e10cSrcweir 				uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW );
996cdf0e10cSrcweir 				uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
997cdf0e10cSrcweir 				xRawDest->insertRawEncrStreamElement( aName, xRawInStream );
998cdf0e10cSrcweir 			}
999cdf0e10cSrcweir 		}
1000cdf0e10cSrcweir 	}
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir //-----------------------------------------------
GetAllRelationshipsIfAny()1004cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelationshipsIfAny()
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::OFOPXML )
1007cdf0e10cSrcweir 		return uno::Sequence< uno::Sequence< beans::StringPair > >();
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 	ReadRelInfoIfNecessary();
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 	if ( m_nRelInfoStatus == RELINFO_READ
1012cdf0e10cSrcweir 	  || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
1013cdf0e10cSrcweir 		return m_aRelInfo;
1014cdf0e10cSrcweir 	else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1015cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong relinfo stream!" ) ),
1016cdf0e10cSrcweir 									uno::Reference< uno::XInterface >() );
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir //-----------------------------------------------
CopyLastCommitTo(const uno::Reference<embed::XStorage> & xNewStor)1020cdf0e10cSrcweir void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor )
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1023cdf0e10cSrcweir 
1024*30acf5e8Spfg 	OSL_ENSURE( m_xPackageFolder.is(), "A committed storage is incomplete!\n" );
1025cdf0e10cSrcweir 	if ( !m_xPackageFolder.is() )
1026cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir 	OStorage_Impl aTempRepresent( NULL,
1029cdf0e10cSrcweir 								embed::ElementModes::READ,
1030cdf0e10cSrcweir 								m_xPackageFolder,
1031cdf0e10cSrcweir 								m_xPackage,
1032cdf0e10cSrcweir 								m_xFactory,
1033cdf0e10cSrcweir 								m_nStorageType);
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 	// TODO/LATER: could use direct copying
1036cdf0e10cSrcweir 	aTempRepresent.CopyToStorage( xNewStor, sal_False );
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir //-----------------------------------------------
InsertIntoPackageFolder(const::rtl::OUString & aName,const uno::Reference<container::XNameContainer> & xParentPackageFolder)1040cdf0e10cSrcweir void OStorage_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName,
1041cdf0e10cSrcweir 											 const uno::Reference< container::XNameContainer >& xParentPackageFolder )
1042cdf0e10cSrcweir {
1043cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir 	OSL_ENSURE( m_xPackageFolder.is(), "An inserted storage is incomplete!\n" );
1046cdf0e10cSrcweir 	uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageFolder, uno::UNO_QUERY );
1047cdf0e10cSrcweir 	if ( !xTunnel.is() )
1048cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 	xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) );
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 	m_bCommited = sal_False;
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir //-----------------------------------------------
Commit()1056cdf0e10cSrcweir void OStorage_Impl::Commit()
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 	if ( !m_bIsModified )
1061cdf0e10cSrcweir 		return;
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 	// in case of a new empty storage it is possible that the contents are still not read
1064cdf0e10cSrcweir 	// ( the storage of course has no contents, but the initialization is postponed till the first use,
1065*30acf5e8Spfg 	//   thus if a new storage was created and committed immediately it must be initialized here )
1066cdf0e10cSrcweir 	ReadContents();
1067cdf0e10cSrcweir 
1068*30acf5e8Spfg 	// if storage is committed it should have a valid Package representation
1069cdf0e10cSrcweir 	OSL_ENSURE( m_xPackageFolder.is(), "The package representation should exist!\n" );
1070cdf0e10cSrcweir 	if ( !m_xPackageFolder.is() )
1071cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir 	OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE,
1074cdf0e10cSrcweir 				"Commit of readonly storage, should be detected before!\n" );
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xNewPackageFolder;
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 	// here the storage will switch to the temporary package folder
1079*30acf5e8Spfg 	// if the storage was already committed and the parent was not committed after that
1080cdf0e10cSrcweir 	// the switch should not be done since the package folder in use is a temporary one;
1081cdf0e10cSrcweir 	// it can be detected by m_bCommited flag ( root storage doesn't need temporary representation )
1082cdf0e10cSrcweir 	if ( !m_bCommited && !m_bIsRoot )
1083cdf0e10cSrcweir 	{
1084cdf0e10cSrcweir 		uno::Sequence< uno::Any > aSeq( 1 );
1085cdf0e10cSrcweir 		aSeq[0] <<= sal_True;
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 		xNewPackageFolder = uno::Reference< container::XNameContainer >(
1088cdf0e10cSrcweir 													m_xPackage->createInstanceWithArguments( aSeq ),
1089cdf0e10cSrcweir 													uno::UNO_QUERY );
1090cdf0e10cSrcweir 	}
1091cdf0e10cSrcweir 	else
1092cdf0e10cSrcweir 		xNewPackageFolder = m_xPackageFolder;
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir 	// remove replaced removed elements
1095cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1096cdf0e10cSrcweir 		  pDeletedIter != m_aDeletedList.end();
1097cdf0e10cSrcweir 		  pDeletedIter++ )
1098cdf0e10cSrcweir 	{
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 		if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage )
1101cdf0e10cSrcweir 			RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName );
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir 		// the removed elements are not in new temporary storage
1104cdf0e10cSrcweir 		if ( m_bCommited || m_bIsRoot )
1105cdf0e10cSrcweir 			xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName );
1106cdf0e10cSrcweir 		delete *pDeletedIter;
1107cdf0e10cSrcweir 		*pDeletedIter = NULL;
1108cdf0e10cSrcweir 	}
1109cdf0e10cSrcweir 	m_aDeletedList.clear();
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 	// remove removed elements
1112cdf0e10cSrcweir 	SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1113cdf0e10cSrcweir 	while (  pElementIter != m_aChildrenList.end() )
1114cdf0e10cSrcweir     {
1115cdf0e10cSrcweir 		// renamed and inserted elements must be really inserted to package later
1116cdf0e10cSrcweir 		// since thay can conflict with removed elements
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir 		if ( (*pElementIter)->m_bIsRemoved )
1119cdf0e10cSrcweir 		{
1120cdf0e10cSrcweir 			if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
1121cdf0e10cSrcweir 				RemoveStreamRelInfo( (*pElementIter)->m_aOriginalName );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 			// the removed elements are not in new temporary storage
1124cdf0e10cSrcweir 			if ( m_bCommited || m_bIsRoot )
1125cdf0e10cSrcweir 				xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 			SotElement_Impl* pToDelete = *pElementIter;
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 			pElementIter++; // to let the iterator be valid it should be increased before removing
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 			m_aChildrenList.remove( pToDelete );
1132cdf0e10cSrcweir 			delete pToDelete;
1133cdf0e10cSrcweir 		}
1134cdf0e10cSrcweir 		else
1135cdf0e10cSrcweir 			pElementIter++;
1136cdf0e10cSrcweir 	}
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir 	// there should be no more deleted elements
1139cdf0e10cSrcweir 	for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ )
1140cdf0e10cSrcweir     {
1141cdf0e10cSrcweir 		// if it is a 'duplicate commit' inserted elements must be really inserted to package later
1142cdf0e10cSrcweir 		// since thay can conflict with renamed elements
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 		if ( !(*pElementIter)->m_bIsInserted )
1145cdf0e10cSrcweir 		{
1146cdf0e10cSrcweir 			// for now stream is opened in direct mode that means that in case
1147*30acf5e8Spfg 			// storage is committed all the streams from it are committed in current state.
1148cdf0e10cSrcweir 			// following two steps are separated to allow easily implement transacted mode
1149cdf0e10cSrcweir 			// for streams if we need it in future.
1150cdf0e10cSrcweir 			// Only hierarchical access uses transacted streams currently
1151cdf0e10cSrcweir 			if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream
1152cdf0e10cSrcweir 			  && !(*pElementIter)->m_pStream->IsTransacted() )
1153cdf0e10cSrcweir 				(*pElementIter)->m_pStream->Commit();
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir 			// if the storage was not open, there is no need to commit it ???
1156*30acf5e8Spfg 			// the storage should be checked that it is committed
1157cdf0e10cSrcweir 			if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited )
1158cdf0e10cSrcweir 			{
1159cdf0e10cSrcweir 				// it's temporary PackageFolder should be inserted instead of current one
1160cdf0e10cSrcweir 				// also the new copy of PackageFolder should be used by the children storages
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 				// the renamed elements are not in new temporary storage
1163cdf0e10cSrcweir 				if ( m_bCommited || m_bIsRoot )
1164cdf0e10cSrcweir 					xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 				(*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1167cdf0e10cSrcweir 			}
1168cdf0e10cSrcweir 			else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed )
1169cdf0e10cSrcweir 			{
1170cdf0e10cSrcweir 				if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1171cdf0e10cSrcweir 					CommitStreamRelInfo( *pElementIter );
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 				// the renamed elements are not in new temporary storage
1174cdf0e10cSrcweir 				if ( m_bCommited || m_bIsRoot )
1175cdf0e10cSrcweir 					xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir 				(*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1178cdf0e10cSrcweir 			}
1179cdf0e10cSrcweir 			else if ( !m_bCommited && !m_bIsRoot )
1180cdf0e10cSrcweir 			{
1181cdf0e10cSrcweir 				// the element must be just copied to the new temporary package folder
1182cdf0e10cSrcweir 				// the connection with the original package should not be lost just because
1183a893be29SPedro Giffuni 				// the element is still referred by the folder in the original hierarchy
1184cdf0e10cSrcweir 				uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1185cdf0e10cSrcweir 				xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1186cdf0e10cSrcweir 			}
1187cdf0e10cSrcweir 			else if ( (*pElementIter)->m_aName.compareTo( (*pElementIter)->m_aOriginalName ) )
1188cdf0e10cSrcweir 			{
1189cdf0e10cSrcweir 				// this is the case when xNewPackageFolder refers to m_xPackageFolder
1190cdf0e10cSrcweir 				// in case the name was changed and it is not a changed storage - rename the element
1191cdf0e10cSrcweir 				uno::Reference< container::XNamed > xNamed;
1192cdf0e10cSrcweir 				uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName );
1193cdf0e10cSrcweir 				xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
1194cdf0e10cSrcweir 				xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement );
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir 				if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
1197cdf0e10cSrcweir 				{
1198cdf0e10cSrcweir 					if ( !(*pElementIter)->m_pStream )
1199cdf0e10cSrcweir 					{
1200cdf0e10cSrcweir 						OpenSubStream( *pElementIter );
1201cdf0e10cSrcweir 						if ( !(*pElementIter)->m_pStream )
1202cdf0e10cSrcweir 							throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1203cdf0e10cSrcweir 					}
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir 					CommitStreamRelInfo( *pElementIter );
1206cdf0e10cSrcweir 				}
1207cdf0e10cSrcweir 			}
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 			(*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1210cdf0e10cSrcweir 		}
1211cdf0e10cSrcweir 	}
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir 	for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ )
1214cdf0e10cSrcweir     {
1215cdf0e10cSrcweir 		// now inserted elements can be inserted to the package
1216cdf0e10cSrcweir 		if ( (*pElementIter)->m_bIsInserted )
1217cdf0e10cSrcweir 		{
1218cdf0e10cSrcweir 			(*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName;
1219cdf0e10cSrcweir 			uno::Reference< lang::XUnoTunnel > xNewElement;
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 			if ( (*pElementIter)->m_bIsStorage )
1222cdf0e10cSrcweir 			{
1223cdf0e10cSrcweir 				if ( (*pElementIter)->m_pStorage->m_bCommited )
1224cdf0e10cSrcweir 				{
1225cdf0e10cSrcweir 					OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" );
1226cdf0e10cSrcweir 					if ( !(*pElementIter)->m_pStorage )
1227cdf0e10cSrcweir 						throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 					(*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 					(*pElementIter)->m_bIsInserted = sal_False;
1232cdf0e10cSrcweir 				}
1233cdf0e10cSrcweir 			}
1234cdf0e10cSrcweir 			else
1235cdf0e10cSrcweir 			{
1236cdf0e10cSrcweir 				OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" );
1237cdf0e10cSrcweir 				if ( !(*pElementIter)->m_pStream )
1238cdf0e10cSrcweir 					throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir 				if ( !(*pElementIter)->m_pStream->IsTransacted() )
1241cdf0e10cSrcweir 					(*pElementIter)->m_pStream->Commit();
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 				if ( (*pElementIter)->m_pStream->m_bFlushed )
1244cdf0e10cSrcweir 				{
1245cdf0e10cSrcweir 					if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1246cdf0e10cSrcweir 						CommitStreamRelInfo( *pElementIter );
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir 					(*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 					(*pElementIter)->m_bIsInserted = sal_False;
1251cdf0e10cSrcweir 				}
1252cdf0e10cSrcweir 			}
1253cdf0e10cSrcweir 		}
1254cdf0e10cSrcweir 	}
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::PACKAGE )
1257cdf0e10cSrcweir 	{
1258cdf0e10cSrcweir 		// move properties to the destination package folder
1259cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xProps( xNewPackageFolder, uno::UNO_QUERY );
1260cdf0e10cSrcweir 		if ( !xProps.is() )
1261cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir 		xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), uno::makeAny( m_aMediaType ) );
1264cdf0e10cSrcweir 		xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), uno::makeAny( m_aVersion ) );
1265cdf0e10cSrcweir 	}
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1268cdf0e10cSrcweir 		CommitRelInfo( xNewPackageFolder ); // store own relations and commit complete relations storage
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir 	if ( m_bIsRoot )
1271cdf0e10cSrcweir 	{
1272cdf0e10cSrcweir 		uno::Reference< util::XChangesBatch > xChangesBatch( m_xPackage, uno::UNO_QUERY );
1273cdf0e10cSrcweir 
1274cdf0e10cSrcweir 		OSL_ENSURE( xChangesBatch.is(), "Impossible to commit package!\n" );
1275cdf0e10cSrcweir 		if ( !xChangesBatch.is() )
1276cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir 		try
1279cdf0e10cSrcweir 		{
1280cdf0e10cSrcweir 			xChangesBatch->commitChanges();
1281cdf0e10cSrcweir 		}
1282cdf0e10cSrcweir 		catch( lang::WrappedTargetException& r )
1283cdf0e10cSrcweir 		{
1284cdf0e10cSrcweir 			// the wrapped UseBackupException means that the target medium can be corrupted
1285cdf0e10cSrcweir 			embed::UseBackupException aException;
1286cdf0e10cSrcweir 			if ( r.TargetException >>= aException )
1287cdf0e10cSrcweir 			{
1288cdf0e10cSrcweir 				m_xStream = uno::Reference< io::XStream >();
1289cdf0e10cSrcweir 				m_xInputStream = uno::Reference< io::XInputStream >();
1290cdf0e10cSrcweir 				throw aException;
1291cdf0e10cSrcweir 			}
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir             AddLog( aException.Message );
1294cdf0e10cSrcweir             AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
1295cdf0e10cSrcweir             throw;
1296cdf0e10cSrcweir 		}
1297cdf0e10cSrcweir 	}
1298cdf0e10cSrcweir 	else if ( !m_bCommited )
1299cdf0e10cSrcweir 	{
1300cdf0e10cSrcweir 		m_xPackageFolder = xNewPackageFolder;
1301cdf0e10cSrcweir 		m_bCommited = sal_True;
1302cdf0e10cSrcweir 	}
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 	// after commit the mediatype treated as the correct one
1305cdf0e10cSrcweir 	m_bMTFallbackUsed = sal_False;
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir //-----------------------------------------------
Revert()1309cdf0e10cSrcweir void OStorage_Impl::Revert()
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 	if ( !( m_nStorageMode & embed::ElementModes::WRITE ) )
1314cdf0e10cSrcweir 		return; // nothing to do
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 	// all the children must be removed
1317cdf0e10cSrcweir 	// they will be created later on demand
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir 	SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1320cdf0e10cSrcweir 	while (  pElementIter != m_aChildrenList.end() )
1321cdf0e10cSrcweir     {
1322cdf0e10cSrcweir 		if ( (*pElementIter)->m_bIsInserted )
1323cdf0e10cSrcweir 		{
1324cdf0e10cSrcweir 			SotElement_Impl* pToDelete = *pElementIter;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 			pElementIter++; // to let the iterator be valid it should be increased before removing
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir 			m_aChildrenList.remove( pToDelete );
1329cdf0e10cSrcweir 			delete pToDelete;
1330cdf0e10cSrcweir 		}
1331cdf0e10cSrcweir 		else
1332cdf0e10cSrcweir 		{
1333cdf0e10cSrcweir 			ClearElement( *pElementIter );
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 			(*pElementIter)->m_aName = (*pElementIter)->m_aOriginalName;
1336cdf0e10cSrcweir 			(*pElementIter)->m_bIsRemoved = sal_False;
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 			pElementIter++;
1339cdf0e10cSrcweir 		}
1340cdf0e10cSrcweir 	}
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 	// return replaced removed elements
1343cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin();
1344cdf0e10cSrcweir 		  pDeletedIter != m_aDeletedList.end();
1345cdf0e10cSrcweir 		  pDeletedIter++ )
1346cdf0e10cSrcweir 	{
1347cdf0e10cSrcweir 		m_aChildrenList.push_back( (*pDeletedIter) );
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir 		ClearElement( *pDeletedIter );
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir 		(*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName;
1352cdf0e10cSrcweir 		(*pDeletedIter)->m_bIsRemoved = sal_False;
1353cdf0e10cSrcweir 	}
1354cdf0e10cSrcweir 	m_aDeletedList.clear();
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir     m_bControlMediaType = sal_False;
1357cdf0e10cSrcweir     m_bControlVersion = sal_False;
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir 	GetStorageProperties();
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1362cdf0e10cSrcweir 	{
1363cdf0e10cSrcweir 		// currently the relations storage is changed only on commit
1364cdf0e10cSrcweir 		m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1365cdf0e10cSrcweir 		m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1366cdf0e10cSrcweir 		m_nRelInfoStatus = RELINFO_NO_INIT;
1367cdf0e10cSrcweir 	}
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir //-----------------------------------------------
GetCommonRootEncryptionData()1371cdf0e10cSrcweir ::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData()
1372cdf0e10cSrcweir 	throw ( packages::NoEncryptionException )
1373cdf0e10cSrcweir {
1374cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::PACKAGE )
1377cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir 	if ( m_bIsRoot )
1380cdf0e10cSrcweir 	{
1381cdf0e10cSrcweir 		if ( !m_bHasCommonEncryptionData )
1382cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir 		return m_aCommonEncryptionData;
1385cdf0e10cSrcweir 	}
1386cdf0e10cSrcweir 	else
1387cdf0e10cSrcweir 	{
1388cdf0e10cSrcweir 		if ( !m_pParent )
1389cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir 		return m_pParent->GetCommonRootEncryptionData();
1392cdf0e10cSrcweir 	}
1393cdf0e10cSrcweir }
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir //-----------------------------------------------
FindElement(const::rtl::OUString & rName)1396cdf0e10cSrcweir SotElement_Impl* OStorage_Impl::FindElement( const ::rtl::OUString& rName )
1397cdf0e10cSrcweir {
1398cdf0e10cSrcweir     OSL_ENSURE( rName.getLength(), "Name is empty!" );
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir 	ReadContents();
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1405cdf0e10cSrcweir 		  pElementIter != m_aChildrenList.end(); pElementIter++ )
1406cdf0e10cSrcweir     {
1407cdf0e10cSrcweir         if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved )
1408cdf0e10cSrcweir             return *pElementIter;
1409cdf0e10cSrcweir 	}
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir     return NULL;
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir //-----------------------------------------------
InsertStream(::rtl::OUString aName,sal_Bool bEncr)1415cdf0e10cSrcweir SotElement_Impl* OStorage_Impl::InsertStream( ::rtl::OUString aName, sal_Bool bEncr )
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir 	OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1418cdf0e10cSrcweir 	if ( !m_xPackage.is() )
1419cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir 	uno::Sequence< uno::Any > aSeq( 1 );
1422cdf0e10cSrcweir 	aSeq[0] <<= sal_False;
1423cdf0e10cSrcweir 	uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1424cdf0e10cSrcweir 													uno::UNO_QUERY );
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 	OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" );
1427cdf0e10cSrcweir 	if ( !xNewElement.is() )
1428cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir 	uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1431cdf0e10cSrcweir 	if ( !xPackageSubStream.is() )
1432cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE || !bEncr, "Only package storage supports encryption!\n" );
1435cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::PACKAGE && bEncr )
1436cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir 	// the mode is not needed for storage stream internal implementation
1439cdf0e10cSrcweir 	SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
1440cdf0e10cSrcweir 	pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType, sal_True );
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir 	m_aChildrenList.push_back( pNewElement );
1443cdf0e10cSrcweir 	m_bIsModified = sal_True;
1444cdf0e10cSrcweir 	m_bBroadcastModified = sal_True;
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	return pNewElement;
1447cdf0e10cSrcweir }
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir //-----------------------------------------------
InsertRawStream(::rtl::OUString aName,const uno::Reference<io::XInputStream> & xInStream)1450cdf0e10cSrcweir SotElement_Impl* OStorage_Impl::InsertRawStream( ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInStream )
1451cdf0e10cSrcweir {
1452cdf0e10cSrcweir 	// insert of raw stream means insert and commit
1453cdf0e10cSrcweir 	OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1454cdf0e10cSrcweir 	if ( !m_xPackage.is() )
1455cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::PACKAGE )
1458cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
1461cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xInStrToInsert = xSeek.is() ? xInStream :
1462cdf0e10cSrcweir 																	 GetSeekableTempCopy( xInStream, GetServiceFactory() );
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 	uno::Sequence< uno::Any > aSeq( 1 );
1465cdf0e10cSrcweir 	aSeq[0] <<= sal_False;
1466cdf0e10cSrcweir 	uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1467cdf0e10cSrcweir 													uno::UNO_QUERY );
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir 	OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" );
1470cdf0e10cSrcweir 	if ( !xNewElement.is() )
1471cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir 	uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY );
1474cdf0e10cSrcweir 	if ( !xPackageSubStream.is() )
1475cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir 	xPackageSubStream->setRawStream( xInStrToInsert );
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 	// the mode is not needed for storage stream internal implementation
1480cdf0e10cSrcweir 	SotElement_Impl* pNewElement = InsertElement( aName, sal_False );
1481cdf0e10cSrcweir 	pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType, sal_False );
1482*30acf5e8Spfg 	// the stream is inserted and must be treated as a committed one
1483cdf0e10cSrcweir 	pNewElement->m_pStream->SetToBeCommited();
1484cdf0e10cSrcweir 
1485cdf0e10cSrcweir 	m_aChildrenList.push_back( pNewElement );
1486cdf0e10cSrcweir 	m_bIsModified = sal_True;
1487cdf0e10cSrcweir 	m_bBroadcastModified = sal_True;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 	return pNewElement;
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir //-----------------------------------------------
CreateNewStorageImpl(sal_Int32 nStorageMode)1493cdf0e10cSrcweir OStorage_Impl* OStorage_Impl::CreateNewStorageImpl( sal_Int32 nStorageMode )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir 	OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" );
1496cdf0e10cSrcweir 	if ( !m_xPackage.is() )
1497cdf0e10cSrcweir 		throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 	uno::Sequence< uno::Any > aSeq( 1 );
1500cdf0e10cSrcweir 	aSeq[0] <<= sal_True;
1501cdf0e10cSrcweir 	uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ),
1502cdf0e10cSrcweir 													uno::UNO_QUERY );
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir 	OSL_ENSURE( xNewElement.is(), "Not possible to create a new storage!\n" );
1505cdf0e10cSrcweir 	if ( !xNewElement.is() )
1506cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xPackageSubFolder( xNewElement, uno::UNO_QUERY );
1509cdf0e10cSrcweir 	if ( !xPackageSubFolder.is() )
1510cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir 	OStorage_Impl* pResult =
1513cdf0e10cSrcweir 			new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType );
1514cdf0e10cSrcweir 	pResult->m_bIsModified = sal_True;
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	return pResult;
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir //-----------------------------------------------
InsertStorage(::rtl::OUString aName,sal_Int32 nStorageMode)1520cdf0e10cSrcweir SotElement_Impl* OStorage_Impl::InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode )
1521cdf0e10cSrcweir {
1522cdf0e10cSrcweir 	SotElement_Impl* pNewElement = InsertElement( aName, sal_True );
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir 	pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode );
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir 	m_aChildrenList.push_back( pNewElement );
1527cdf0e10cSrcweir 
1528cdf0e10cSrcweir 	return pNewElement;
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir //-----------------------------------------------
InsertElement(::rtl::OUString aName,sal_Bool bIsStorage)1532cdf0e10cSrcweir SotElement_Impl* OStorage_Impl::InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage )
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir     OSL_ENSURE( FindElement( aName ) == NULL, "Should not try to insert existing element" );
1535cdf0e10cSrcweir 
1536cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir     SotElement_Impl* pDeletedElm = NULL;
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1541cdf0e10cSrcweir 		  pElementIter != m_aChildrenList.end(); pElementIter++ )
1542cdf0e10cSrcweir     {
1543cdf0e10cSrcweir         if ( (*pElementIter)->m_aName == aName )
1544cdf0e10cSrcweir 		{
1545cdf0e10cSrcweir 			OSL_ENSURE( (*pElementIter)->m_bIsRemoved, "Try to insert an element instead of existing one!\n" );
1546cdf0e10cSrcweir 			if ( (*pElementIter)->m_bIsRemoved )
1547cdf0e10cSrcweir 			{
1548a893be29SPedro Giffuni 				OSL_ENSURE( !(*pElementIter)->m_bIsInserted, "Inserted elements must be deleted immediately!\n" );
1549cdf0e10cSrcweir             	pDeletedElm = *pElementIter;
1550cdf0e10cSrcweir 				break;
1551cdf0e10cSrcweir 			}
1552cdf0e10cSrcweir 		}
1553cdf0e10cSrcweir     }
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 	if ( pDeletedElm )
1556cdf0e10cSrcweir 	{
1557cdf0e10cSrcweir 		if ( pDeletedElm->m_bIsStorage )
1558cdf0e10cSrcweir 			OpenSubStorage( pDeletedElm, embed::ElementModes::READWRITE );
1559cdf0e10cSrcweir 		else
1560cdf0e10cSrcweir 			OpenSubStream( pDeletedElm );
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir         m_aChildrenList.remove( pDeletedElm );  // correct usage of list ???
1563cdf0e10cSrcweir 		m_aDeletedList.push_back( pDeletedElm );
1564cdf0e10cSrcweir 	}
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 	// create new element
1567cdf0e10cSrcweir 	return new SotElement_Impl( aName, bIsStorage, sal_True );
1568cdf0e10cSrcweir }
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir //-----------------------------------------------
OpenSubStorage(SotElement_Impl * pElement,sal_Int32 nStorageMode)1571cdf0e10cSrcweir void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir 	OSL_ENSURE( pElement, "pElement is not set!\n" );
1574cdf0e10cSrcweir 	OSL_ENSURE( pElement->m_bIsStorage, "Storage flag is not set!\n" );
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir 	if ( !pElement->m_pStorage )
1579cdf0e10cSrcweir 	{
1580cdf0e10cSrcweir 		OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" );
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir 		uno::Reference< lang::XUnoTunnel > xTunnel;
1583cdf0e10cSrcweir 		m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1584cdf0e10cSrcweir 		if ( !xTunnel.is() )
1585cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY );
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir 		OSL_ENSURE( xPackageSubFolder.is(), "Can not get XNameContainer interface from folder!\n" );
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir 		if ( !xPackageSubFolder.is() )
1592cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir 		pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType );
1595cdf0e10cSrcweir 	}
1596cdf0e10cSrcweir }
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir //-----------------------------------------------
OpenSubStream(SotElement_Impl * pElement)1599cdf0e10cSrcweir void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir 	OSL_ENSURE( pElement, "pElement is not set!\n" );
1602cdf0e10cSrcweir 	OSL_ENSURE( !pElement->m_bIsStorage, "Storage flag is set!\n" );
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir 	if ( !pElement->m_pStream )
1607cdf0e10cSrcweir 	{
1608cdf0e10cSrcweir 		OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" );
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir 		uno::Reference< lang::XUnoTunnel > xTunnel;
1611cdf0e10cSrcweir 		m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel;
1612cdf0e10cSrcweir 		if ( !xTunnel.is() )
1613cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir 		uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY );
1616cdf0e10cSrcweir 		if ( !xPackageSubStream.is() )
1617cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir 		// the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction
1620cdf0e10cSrcweir         pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, sal_False, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
1621cdf0e10cSrcweir 	}
1622cdf0e10cSrcweir }
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir //-----------------------------------------------
GetElementNames()1625cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > OStorage_Impl::GetElementNames()
1626cdf0e10cSrcweir {
1627cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 	ReadContents();
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir 	sal_uInt32 nSize = m_aChildrenList.size();
1632cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aElementNames( nSize );
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 	sal_uInt32 nInd = 0;
1635cdf0e10cSrcweir     for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin();
1636cdf0e10cSrcweir 		  pElementIter != m_aChildrenList.end(); pElementIter++ )
1637cdf0e10cSrcweir 	{
1638cdf0e10cSrcweir 		if ( !(*pElementIter)->m_bIsRemoved )
1639cdf0e10cSrcweir         	aElementNames[nInd++] = (*pElementIter)->m_aName;
1640cdf0e10cSrcweir 	}
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 	aElementNames.realloc( nInd );
1643cdf0e10cSrcweir     return aElementNames;
1644cdf0e10cSrcweir }
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir //-----------------------------------------------
RemoveElement(SotElement_Impl * pElement)1647cdf0e10cSrcweir void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
1648cdf0e10cSrcweir {
1649cdf0e10cSrcweir 	OSL_ENSURE( pElement, "Element must be provided!" );
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir 	if ( !pElement )
1652cdf0e10cSrcweir 		return;
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir 	if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() ))
1655cdf0e10cSrcweir 	  || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) )
1656cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir 	if ( pElement->m_bIsInserted )
1659cdf0e10cSrcweir 	{
1660cdf0e10cSrcweir 		m_aChildrenList.remove( pElement );
1661cdf0e10cSrcweir 		delete pElement; // ???
1662cdf0e10cSrcweir 	}
1663cdf0e10cSrcweir 	else
1664cdf0e10cSrcweir 	{
1665cdf0e10cSrcweir 		pElement->m_bIsRemoved = sal_True;
1666cdf0e10cSrcweir 		ClearElement( pElement );
1667cdf0e10cSrcweir 	}
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir 	// TODO/OFOPXML: the rel stream should be removed as well
1670cdf0e10cSrcweir }
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir //-----------------------------------------------
ClearElement(SotElement_Impl * pElement)1673cdf0e10cSrcweir void OStorage_Impl::ClearElement( SotElement_Impl* pElement )
1674cdf0e10cSrcweir {
1675cdf0e10cSrcweir 	if ( pElement->m_pStorage )
1676cdf0e10cSrcweir 	{
1677cdf0e10cSrcweir 		delete pElement->m_pStorage;
1678cdf0e10cSrcweir 		pElement->m_pStorage = NULL;
1679cdf0e10cSrcweir 	}
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir 	if ( pElement->m_pStream )
1682cdf0e10cSrcweir 	{
1683cdf0e10cSrcweir 		delete pElement->m_pStream;
1684cdf0e10cSrcweir 		pElement->m_pStream = NULL;
1685cdf0e10cSrcweir 	}
1686cdf0e10cSrcweir }
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir //-----------------------------------------------
CloneStreamElement(const::rtl::OUString & aStreamName,sal_Bool bEncryptionDataProvided,const::comphelper::SequenceAsHashMap & aEncryptionData,uno::Reference<io::XStream> & xTargetStream)1689cdf0e10cSrcweir void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName,
1690cdf0e10cSrcweir 										sal_Bool bEncryptionDataProvided,
1691cdf0e10cSrcweir 										const ::comphelper::SequenceAsHashMap& aEncryptionData,
1692cdf0e10cSrcweir 										uno::Reference< io::XStream >& xTargetStream )
1693cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
1694cdf0e10cSrcweir 				lang::IllegalArgumentException,
1695cdf0e10cSrcweir 				packages::WrongPasswordException,
1696cdf0e10cSrcweir 				io::IOException,
1697cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
1698cdf0e10cSrcweir 				uno::RuntimeException )
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir     SotElement_Impl *pElement = FindElement( aStreamName );
1701cdf0e10cSrcweir     if ( !pElement )
1702cdf0e10cSrcweir     {
1703cdf0e10cSrcweir         // element does not exist, throw exception
1704cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
1705cdf0e10cSrcweir     }
1706cdf0e10cSrcweir 	else if ( pElement->m_bIsStorage )
1707cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir 	if ( !pElement->m_pStream )
1710cdf0e10cSrcweir 		OpenSubStream( pElement );
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir 	if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() )
1713cdf0e10cSrcweir     {
1714cdf0e10cSrcweir 		// the existence of m_pAntiImpl of the child is not interesting,
1715cdf0e10cSrcweir 		// the copy will be created internally
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir 		// usual copying is not applicable here, only last flushed version of the
1718cdf0e10cSrcweir 		// child stream should be used for copiing. Probably the childs m_xPackageStream
1719cdf0e10cSrcweir 		// can be used as a base of a new stream, that would be copied to result
1720cdf0e10cSrcweir 		// storage. The only problem is that some package streams can be accessed from outside
1721cdf0e10cSrcweir 		// at the same time ( now solwed by wrappers that remember own position ).
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 		if ( bEncryptionDataProvided )
1724cdf0e10cSrcweir 			pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData );
1725cdf0e10cSrcweir 		else
1726cdf0e10cSrcweir 			pElement->m_pStream->GetCopyOfLastCommit( xTargetStream );
1727cdf0e10cSrcweir 	}
1728cdf0e10cSrcweir 	else
1729cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir 
1732cdf0e10cSrcweir //-----------------------------------------------
RemoveStreamRelInfo(const::rtl::OUString & aOriginalName)1733cdf0e10cSrcweir void OStorage_Impl::RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName )
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir 	// this method should be used only in OStorage_Impl::Commit() method
1736cdf0e10cSrcweir 	// the aOriginalName can be empty, in this case the storage relation info should be removed
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_xRelStorage.is() )
1739cdf0e10cSrcweir 	{
1740cdf0e10cSrcweir 		::rtl::OUString aRelStreamName = aOriginalName;
1741cdf0e10cSrcweir 		aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir 		if ( m_xRelStorage->hasByName( aRelStreamName ) )
1744cdf0e10cSrcweir 			m_xRelStorage->removeElement( aRelStreamName );
1745cdf0e10cSrcweir 	}
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir //-----------------------------------------------
CreateRelStorage()1749cdf0e10cSrcweir void OStorage_Impl::CreateRelStorage()
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir 	if ( m_nStorageType != embed::StorageFormats::OFOPXML )
1752cdf0e10cSrcweir 		return;
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir 	if ( !m_xRelStorage.is() )
1755cdf0e10cSrcweir 	{
1756cdf0e10cSrcweir 		if ( !m_pRelStorElement )
1757cdf0e10cSrcweir 		{
1758cdf0e10cSrcweir 			m_pRelStorElement = new SotElement_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ), sal_True, sal_True );
1759cdf0e10cSrcweir 			m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE );
1760cdf0e10cSrcweir 			if ( m_pRelStorElement->m_pStorage )
1761cdf0e10cSrcweir 				m_pRelStorElement->m_pStorage->m_pParent = NULL; // the relation storage is completely controlled by parent
1762cdf0e10cSrcweir 		}
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir 		if ( !m_pRelStorElement->m_pStorage )
1765cdf0e10cSrcweir 			OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE );
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir 		if ( !m_pRelStorElement->m_pStorage )
1768cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir 		OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, sal_False );
1771cdf0e10cSrcweir 		m_xRelStorage = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
1772cdf0e10cSrcweir 	}
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir //-----------------------------------------------
CommitStreamRelInfo(SotElement_Impl * pStreamElement)1776cdf0e10cSrcweir void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement )
1777cdf0e10cSrcweir {
1778cdf0e10cSrcweir 	// this method should be used only in OStorage_Impl::Commit() method
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 	// the stream element must be provided
1781cdf0e10cSrcweir 	if ( !pStreamElement )
1782cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_pStream )
1785cdf0e10cSrcweir 	{
1786cdf0e10cSrcweir 		OSL_ENSURE( pStreamElement->m_aName.getLength(), "The name must not be empty!\n" );
1787cdf0e10cSrcweir 
1788cdf0e10cSrcweir 		if ( !m_xRelStorage.is() )
1789cdf0e10cSrcweir 		{
1790cdf0e10cSrcweir 			// Create new rels storage, this is commit scenario so it must be possible
1791cdf0e10cSrcweir 			CreateRelStorage();
1792cdf0e10cSrcweir 		}
1793cdf0e10cSrcweir 
1794cdf0e10cSrcweir 		pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName );
1795cdf0e10cSrcweir 	}
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir //-----------------------------------------------
GetRelInfoStreamForName(const::rtl::OUString & aName)1799cdf0e10cSrcweir uno::Reference< io::XInputStream > OStorage_Impl::GetRelInfoStreamForName( const ::rtl::OUString& aName )
1800cdf0e10cSrcweir {
1801cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1802cdf0e10cSrcweir 	{
1803cdf0e10cSrcweir 		ReadContents();
1804cdf0e10cSrcweir 		if ( m_xRelStorage.is() )
1805cdf0e10cSrcweir 		{
1806cdf0e10cSrcweir 			::rtl::OUString aRelStreamName = aName;
1807cdf0e10cSrcweir 			aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1808cdf0e10cSrcweir 			if ( m_xRelStorage->hasByName( aRelStreamName ) )
1809cdf0e10cSrcweir 			{
1810cdf0e10cSrcweir 				uno::Reference< io::XStream > xStream = m_xRelStorage->openStreamElement( aRelStreamName, embed::ElementModes::READ );
1811cdf0e10cSrcweir 				if ( xStream.is() )
1812cdf0e10cSrcweir 					return xStream->getInputStream();
1813cdf0e10cSrcweir 			}
1814cdf0e10cSrcweir 		}
1815cdf0e10cSrcweir 	}
1816cdf0e10cSrcweir 
1817cdf0e10cSrcweir 	return uno::Reference< io::XInputStream >();
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir //-----------------------------------------------
CommitRelInfo(const uno::Reference<container::XNameContainer> & xNewPackageFolder)1821cdf0e10cSrcweir void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContainer >& xNewPackageFolder )
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir 	// this method should be used only in OStorage_Impl::Commit() method
1824cdf0e10cSrcweir 	::rtl::OUString aRelsStorName( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) );
1825cdf0e10cSrcweir 
1826cdf0e10cSrcweir 	if ( !xNewPackageFolder.is() )
1827cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1828cdf0e10cSrcweir 
1829cdf0e10cSrcweir 	if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1830cdf0e10cSrcweir 	{
1831cdf0e10cSrcweir 		if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN )
1832cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir 		if ( m_nRelInfoStatus == RELINFO_CHANGED
1835cdf0e10cSrcweir 		  || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1836cdf0e10cSrcweir 		  || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1837cdf0e10cSrcweir 		{
1838cdf0e10cSrcweir 			if ( m_nRelInfoStatus == RELINFO_CHANGED )
1839cdf0e10cSrcweir 			{
1840cdf0e10cSrcweir 				if ( m_aRelInfo.getLength() )
1841cdf0e10cSrcweir 				{
1842cdf0e10cSrcweir 					CreateRelStorage();
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir 					uno::Reference< io::XStream > xRelsStream =
1845cdf0e10cSrcweir 						m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ),
1846cdf0e10cSrcweir 															embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir 					uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream();
1849cdf0e10cSrcweir 					if ( !xOutStream.is() )
1850cdf0e10cSrcweir 						throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir 					::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aRelInfo, m_xFactory );
1853cdf0e10cSrcweir 
1854cdf0e10cSrcweir 					// set the mediatype
1855cdf0e10cSrcweir 					uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1856cdf0e10cSrcweir 					xPropSet->setPropertyValue(
1857cdf0e10cSrcweir 						::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1858cdf0e10cSrcweir 						uno::makeAny( ::rtl::OUString(
1859cdf0e10cSrcweir 						 	RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 					m_nRelInfoStatus = RELINFO_READ;
1862cdf0e10cSrcweir 				}
1863cdf0e10cSrcweir 				else if ( m_xRelStorage.is() )
1864cdf0e10cSrcweir 					RemoveStreamRelInfo( ::rtl::OUString() ); // remove own rel info
1865cdf0e10cSrcweir 			}
1866cdf0e10cSrcweir 			else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1867cdf0e10cSrcweir 		  			|| m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1868cdf0e10cSrcweir 			{
1869cdf0e10cSrcweir 				CreateRelStorage();
1870cdf0e10cSrcweir 
1871cdf0e10cSrcweir 				uno::Reference< io::XStream > xRelsStream =
1872cdf0e10cSrcweir 					m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ),
1873cdf0e10cSrcweir 														embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir 				uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream();
1876cdf0e10cSrcweir 				if ( !xOutputStream.is() )
1877cdf0e10cSrcweir 					throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1878cdf0e10cSrcweir 
1879cdf0e10cSrcweir 				uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW );
1880cdf0e10cSrcweir 				xSeek->seek( 0 );
1881cdf0e10cSrcweir 				::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream );
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir 				// set the mediatype
1884cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1885cdf0e10cSrcweir 				xPropSet->setPropertyValue(
1886cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1887cdf0e10cSrcweir 					uno::makeAny( ::rtl::OUString(
1888cdf0e10cSrcweir 					 	RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir 				m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1891cdf0e10cSrcweir 		  		if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1892cdf0e10cSrcweir 				{
1893cdf0e10cSrcweir 					m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
1894cdf0e10cSrcweir 					m_nRelInfoStatus = RELINFO_NO_INIT;
1895cdf0e10cSrcweir 				}
1896cdf0e10cSrcweir 				else
1897cdf0e10cSrcweir 					m_nRelInfoStatus = RELINFO_READ;
1898cdf0e10cSrcweir 			}
1899cdf0e10cSrcweir 		}
1900cdf0e10cSrcweir 
1901cdf0e10cSrcweir 		if ( m_xRelStorage.is() )
1902cdf0e10cSrcweir 		{
1903cdf0e10cSrcweir 			if ( m_xRelStorage->hasElements() )
1904cdf0e10cSrcweir 			{
1905cdf0e10cSrcweir 				uno::Reference< embed::XTransactedObject > xTrans( m_xRelStorage, uno::UNO_QUERY_THROW );
1906cdf0e10cSrcweir 				if ( xTrans.is() )
1907cdf0e10cSrcweir 					xTrans->commit();
1908cdf0e10cSrcweir 			}
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir 			if ( xNewPackageFolder.is() && xNewPackageFolder->hasByName( aRelsStorName ) )
1911cdf0e10cSrcweir 				xNewPackageFolder->removeByName( aRelsStorName );
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir 			if ( !m_xRelStorage->hasElements() )
1914cdf0e10cSrcweir 			{
1915cdf0e10cSrcweir 				// the empty relations storage should not be created
1916cdf0e10cSrcweir 				delete m_pRelStorElement;
1917cdf0e10cSrcweir 				m_pRelStorElement = NULL;
1918cdf0e10cSrcweir 				m_xRelStorage = uno::Reference< embed::XStorage >();
1919cdf0e10cSrcweir 			}
1920cdf0e10cSrcweir 			else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() )
1921cdf0e10cSrcweir 				m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder );
1922cdf0e10cSrcweir 		}
1923cdf0e10cSrcweir 	}
1924cdf0e10cSrcweir }
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir //=====================================================
1927cdf0e10cSrcweir // OStorage implementation
1928cdf0e10cSrcweir //=====================================================
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir //-----------------------------------------------
OStorage(uno::Reference<io::XInputStream> xInputStream,sal_Int32 nMode,uno::Sequence<beans::PropertyValue> xProperties,uno::Reference<lang::XMultiServiceFactory> xFactory,sal_Int32 nStorageType)1931cdf0e10cSrcweir OStorage::OStorage(	uno::Reference< io::XInputStream > xInputStream,
1932cdf0e10cSrcweir 					sal_Int32 nMode,
1933cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > xProperties,
1934cdf0e10cSrcweir 					uno::Reference< lang::XMultiServiceFactory > xFactory,
1935cdf0e10cSrcweir 					sal_Int32 nStorageType )
1936cdf0e10cSrcweir : m_pImpl( new OStorage_Impl( xInputStream, nMode, xProperties, xFactory, nStorageType ) )
1937cdf0e10cSrcweir {
1938cdf0e10cSrcweir 	m_pImpl->m_pAntiImpl = this;
1939cdf0e10cSrcweir 	m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False );
1940cdf0e10cSrcweir }
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir //-----------------------------------------------
OStorage(uno::Reference<io::XStream> xStream,sal_Int32 nMode,uno::Sequence<beans::PropertyValue> xProperties,uno::Reference<lang::XMultiServiceFactory> xFactory,sal_Int32 nStorageType)1943cdf0e10cSrcweir OStorage::OStorage(	uno::Reference< io::XStream > xStream,
1944cdf0e10cSrcweir 					sal_Int32 nMode,
1945cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > xProperties,
1946cdf0e10cSrcweir 					uno::Reference< lang::XMultiServiceFactory > xFactory,
1947cdf0e10cSrcweir 					sal_Int32 nStorageType )
1948cdf0e10cSrcweir : m_pImpl( new OStorage_Impl( xStream, nMode, xProperties, xFactory, nStorageType ) )
1949cdf0e10cSrcweir {
1950cdf0e10cSrcweir 	m_pImpl->m_pAntiImpl = this;
1951cdf0e10cSrcweir 	m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False );
1952cdf0e10cSrcweir }
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir //-----------------------------------------------
OStorage(OStorage_Impl * pImpl,sal_Bool bReadOnlyWrap)1955cdf0e10cSrcweir OStorage::OStorage(	OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap )
1956cdf0e10cSrcweir : m_pImpl( pImpl )
1957cdf0e10cSrcweir {
1958cdf0e10cSrcweir 	// this call can be done only from OStorage_Impl implementation to create child storage
1959cdf0e10cSrcweir 	OSL_ENSURE( m_pImpl && m_pImpl->m_rMutexRef.Is(), "The provided pointer & mutex MUST NOT be empty!\n" );
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir 	m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, bReadOnlyWrap );
1962cdf0e10cSrcweir 
1963cdf0e10cSrcweir 	OSL_ENSURE( ( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ||
1964cdf0e10cSrcweir 					m_pData->m_bReadOnlyWrap,
1965cdf0e10cSrcweir 				"The wrapper can not allow writing in case implementation does not!\n" );
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir 	if ( !bReadOnlyWrap )
1968cdf0e10cSrcweir 		m_pImpl->m_pAntiImpl = this;
1969cdf0e10cSrcweir }
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir //-----------------------------------------------
~OStorage()1972cdf0e10cSrcweir OStorage::~OStorage()
1973cdf0e10cSrcweir {
1974cdf0e10cSrcweir 	{
1975cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
1976cdf0e10cSrcweir 		if ( m_pImpl )
1977cdf0e10cSrcweir 		{
1978cdf0e10cSrcweir 			m_refCount++; // to call dispose
1979cdf0e10cSrcweir 			try {
1980cdf0e10cSrcweir 				dispose();
1981cdf0e10cSrcweir 			}
1982cdf0e10cSrcweir 			catch( uno::RuntimeException& aRuntimeException )
1983cdf0e10cSrcweir 			{
1984cdf0e10cSrcweir                 m_pImpl->AddLog( aRuntimeException.Message );
1985cdf0e10cSrcweir                 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) );
1986cdf0e10cSrcweir             }
1987cdf0e10cSrcweir 		}
1988cdf0e10cSrcweir 	}
1989cdf0e10cSrcweir 
1990cdf0e10cSrcweir 	if ( m_pData )
1991cdf0e10cSrcweir 	{
1992cdf0e10cSrcweir 		if ( m_pData->m_pSubElDispListener )
1993cdf0e10cSrcweir 		{
1994cdf0e10cSrcweir 			m_pData->m_pSubElDispListener->release();
1995cdf0e10cSrcweir 			m_pData->m_pSubElDispListener = NULL;
1996cdf0e10cSrcweir 		}
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir 		if ( m_pData->m_pTypeCollection )
1999cdf0e10cSrcweir 		{
2000cdf0e10cSrcweir 			delete m_pData->m_pTypeCollection;
2001cdf0e10cSrcweir 			m_pData->m_pTypeCollection = NULL;
2002cdf0e10cSrcweir 		}
2003cdf0e10cSrcweir 
2004cdf0e10cSrcweir 		delete m_pData;
2005cdf0e10cSrcweir 	}
2006cdf0e10cSrcweir }
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir //-----------------------------------------------
InternalDispose(sal_Bool bNotifyImpl)2009cdf0e10cSrcweir void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl )
2010cdf0e10cSrcweir {
2011cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::InternalDispose" );
2012cdf0e10cSrcweir 
2013cdf0e10cSrcweir 	if ( !m_pImpl )
2014cdf0e10cSrcweir     {
2015cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2016cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2017cdf0e10cSrcweir     }
2018cdf0e10cSrcweir 
2019cdf0e10cSrcweir 	// the source object is also a kind of locker for the current object
2020cdf0e10cSrcweir 	// since the listeners could dispose the object while being notified
2021cdf0e10cSrcweir    	lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2022cdf0e10cSrcweir 	m_pData->m_aListenersContainer.disposeAndClear( aSource );
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir 	if ( m_pData->m_bReadOnlyWrap )
2025cdf0e10cSrcweir 	{
2026cdf0e10cSrcweir 		OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener,
2027cdf0e10cSrcweir 					"If any subelements are open the listener must exist!\n" );
2028cdf0e10cSrcweir 
2029cdf0e10cSrcweir 		if ( m_pData->m_pSubElDispListener )
2030cdf0e10cSrcweir 		{
2031cdf0e10cSrcweir 			m_pData->m_pSubElDispListener->OwnerIsDisposed();
2032cdf0e10cSrcweir 
2033cdf0e10cSrcweir 			// iterate through m_pData->m_aOpenSubComponentsList
2034cdf0e10cSrcweir 			// deregister m_pData->m_pSubElDispListener and dispose all of them
2035cdf0e10cSrcweir 			if ( !m_pData->m_aOpenSubComponentsList.empty() )
2036cdf0e10cSrcweir 			{
2037cdf0e10cSrcweir 				for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
2038cdf0e10cSrcweir 				  	pCompIter != m_pData->m_aOpenSubComponentsList.end(); pCompIter++ )
2039cdf0e10cSrcweir 				{
2040cdf0e10cSrcweir 					uno::Reference< lang::XComponent > xTmp = (*pCompIter);
2041cdf0e10cSrcweir 					if ( xTmp.is() )
2042cdf0e10cSrcweir 					{
2043cdf0e10cSrcweir 						xTmp->removeEventListener( uno::Reference< lang::XEventListener >(
2044cdf0e10cSrcweir 									static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) );
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir 						try {
2047cdf0e10cSrcweir 							xTmp->dispose();
2048cdf0e10cSrcweir 						} catch( uno::Exception& aException )
2049cdf0e10cSrcweir                         {
2050cdf0e10cSrcweir                             m_pImpl->AddLog( aException.Message );
2051cdf0e10cSrcweir                             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
2052cdf0e10cSrcweir                         }
2053cdf0e10cSrcweir 					}
2054cdf0e10cSrcweir 				}
2055cdf0e10cSrcweir 
2056cdf0e10cSrcweir 				m_pData->m_aOpenSubComponentsList.clear();
2057cdf0e10cSrcweir 			}
2058cdf0e10cSrcweir 		}
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir 		if ( bNotifyImpl )
2061cdf0e10cSrcweir 			m_pImpl->RemoveReadOnlyWrap( *this );
2062cdf0e10cSrcweir 	}
2063cdf0e10cSrcweir 	else
2064cdf0e10cSrcweir 	{
2065cdf0e10cSrcweir 		m_pImpl->m_pAntiImpl = NULL;
2066cdf0e10cSrcweir 
2067cdf0e10cSrcweir 		if ( bNotifyImpl )
2068cdf0e10cSrcweir 		{
2069cdf0e10cSrcweir 			if ( m_pData->m_bIsRoot )
2070cdf0e10cSrcweir 				delete m_pImpl;
2071cdf0e10cSrcweir 			else
2072cdf0e10cSrcweir 			{
2073cdf0e10cSrcweir 				// the noncommited changes for the storage must be removed
2074cdf0e10cSrcweir 				m_pImpl->Revert();
2075cdf0e10cSrcweir 			}
2076cdf0e10cSrcweir 		}
2077cdf0e10cSrcweir 	}
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 	m_pImpl = NULL;
2080cdf0e10cSrcweir }
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir //-----------------------------------------------
ChildIsDisposed(const uno::Reference<uno::XInterface> & xChild)2083cdf0e10cSrcweir void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild )
2084cdf0e10cSrcweir {
2085cdf0e10cSrcweir 	// this method can only be called by child disposing listener
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir 	// this method must not contain any locking
2088cdf0e10cSrcweir 	// the locking is done in the listener
2089cdf0e10cSrcweir 
2090cdf0e10cSrcweir 	if ( !m_pData->m_aOpenSubComponentsList.empty() )
2091cdf0e10cSrcweir 	{
2092cdf0e10cSrcweir 		for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin();
2093cdf0e10cSrcweir 		  	pCompIter != m_pData->m_aOpenSubComponentsList.end(); )
2094cdf0e10cSrcweir 		{
2095cdf0e10cSrcweir 			uno::Reference< lang::XComponent > xTmp = (*pCompIter);
2096cdf0e10cSrcweir 			if ( !xTmp.is() || xTmp == xChild )
2097cdf0e10cSrcweir 			{
2098cdf0e10cSrcweir 				WeakComponentList::iterator pIterToRemove = pCompIter;
2099cdf0e10cSrcweir 				pCompIter++;
2100cdf0e10cSrcweir 				m_pData->m_aOpenSubComponentsList.erase( pIterToRemove );
2101cdf0e10cSrcweir 			}
2102cdf0e10cSrcweir 			else
2103cdf0e10cSrcweir 				pCompIter++;
2104cdf0e10cSrcweir 		}
2105cdf0e10cSrcweir 	}
2106cdf0e10cSrcweir }
2107cdf0e10cSrcweir 
2108cdf0e10cSrcweir //-----------------------------------------------
BroadcastModifiedIfNecessary()2109cdf0e10cSrcweir void OStorage::BroadcastModifiedIfNecessary()
2110cdf0e10cSrcweir {
2111cdf0e10cSrcweir 	// no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2112cdf0e10cSrcweir 	if ( !m_pImpl )
2113cdf0e10cSrcweir     {
2114cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2115cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2116cdf0e10cSrcweir     }
2117cdf0e10cSrcweir 
2118cdf0e10cSrcweir 	if ( !m_pImpl->m_bBroadcastModified )
2119cdf0e10cSrcweir 		return;
2120cdf0e10cSrcweir 
2121cdf0e10cSrcweir 	m_pImpl->m_bBroadcastModified = sal_False;
2122cdf0e10cSrcweir 
2123cdf0e10cSrcweir 	OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" );
2124cdf0e10cSrcweir 
2125cdf0e10cSrcweir    	lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir    	::cppu::OInterfaceContainerHelper* pContainer =
2128cdf0e10cSrcweir 			m_pData->m_aListenersContainer.getContainer(
2129cdf0e10cSrcweir 				::getCppuType( ( const uno::Reference< util::XModifyListener >*) NULL ) );
2130cdf0e10cSrcweir    	if ( pContainer )
2131cdf0e10cSrcweir 	{
2132cdf0e10cSrcweir        	::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2133cdf0e10cSrcweir        	while ( pIterator.hasMoreElements( ) )
2134cdf0e10cSrcweir        	{
2135cdf0e10cSrcweir            	( ( util::XModifyListener* )pIterator.next( ) )->modified( aSource );
2136cdf0e10cSrcweir        	}
2137cdf0e10cSrcweir 	}
2138cdf0e10cSrcweir }
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir //-----------------------------------------------
BroadcastTransaction(sal_Int8 nMessage)2141cdf0e10cSrcweir void OStorage::BroadcastTransaction( sal_Int8 nMessage )
2142cdf0e10cSrcweir /*
2143cdf0e10cSrcweir 	1 - preCommit
2144*30acf5e8Spfg 	2 - committed
2145cdf0e10cSrcweir 	3 - preRevert
2146cdf0e10cSrcweir 	4 - reverted
2147cdf0e10cSrcweir */
2148cdf0e10cSrcweir {
2149cdf0e10cSrcweir 	// no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
2150cdf0e10cSrcweir 	if ( !m_pImpl )
2151cdf0e10cSrcweir     {
2152cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2153cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2154cdf0e10cSrcweir     }
2155cdf0e10cSrcweir 
2156cdf0e10cSrcweir 	OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" );
2157cdf0e10cSrcweir 
2158cdf0e10cSrcweir    	lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2159cdf0e10cSrcweir 
2160cdf0e10cSrcweir    	::cppu::OInterfaceContainerHelper* pContainer =
2161cdf0e10cSrcweir 			m_pData->m_aListenersContainer.getContainer(
2162cdf0e10cSrcweir 				::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) );
2163cdf0e10cSrcweir    	if ( pContainer )
2164cdf0e10cSrcweir 	{
2165cdf0e10cSrcweir        	::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
2166cdf0e10cSrcweir        	while ( pIterator.hasMoreElements( ) )
2167cdf0e10cSrcweir        	{
2168cdf0e10cSrcweir 			OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" );
2169cdf0e10cSrcweir 
2170cdf0e10cSrcweir 			switch( nMessage )
2171cdf0e10cSrcweir 			{
2172cdf0e10cSrcweir 				case STOR_MESS_PRECOMMIT:
2173cdf0e10cSrcweir            			( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource );
2174cdf0e10cSrcweir 					break;
2175cdf0e10cSrcweir 				case STOR_MESS_COMMITED:
2176cdf0e10cSrcweir            			( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource );
2177cdf0e10cSrcweir 					break;
2178cdf0e10cSrcweir 				case STOR_MESS_PREREVERT:
2179cdf0e10cSrcweir            			( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource );
2180cdf0e10cSrcweir 					break;
2181cdf0e10cSrcweir 				case STOR_MESS_REVERTED:
2182cdf0e10cSrcweir            			( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource );
2183cdf0e10cSrcweir 					break;
2184cdf0e10cSrcweir 			}
2185cdf0e10cSrcweir        	}
2186cdf0e10cSrcweir 	}
2187cdf0e10cSrcweir }
2188cdf0e10cSrcweir 
2189cdf0e10cSrcweir //-----------------------------------------------
OpenStreamElement_Impl(const::rtl::OUString & aStreamName,sal_Int32 nOpenMode,sal_Bool bEncr)2190cdf0e10cSrcweir SotElement_Impl* OStorage::OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr )
2191cdf0e10cSrcweir {
2192cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir 	OSL_ENSURE( !m_pData->m_bReadOnlyWrap || ( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE,
2195cdf0e10cSrcweir 				"An element can not be opened for writing in readonly storage!\n" );
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir     SotElement_Impl *pElement = m_pImpl->FindElement( aStreamName );
2198cdf0e10cSrcweir     if ( !pElement )
2199cdf0e10cSrcweir     {
2200cdf0e10cSrcweir         // element does not exist, check if creation is allowed
2201cdf0e10cSrcweir 		if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2202cdf0e10cSrcweir           || (( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2203cdf0e10cSrcweir           || ( nOpenMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2204cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2205cdf0e10cSrcweir 
2206cdf0e10cSrcweir         // create a new StreamElement and insert it into the list
2207cdf0e10cSrcweir 		pElement = m_pImpl->InsertStream( aStreamName, bEncr );
2208cdf0e10cSrcweir     }
2209cdf0e10cSrcweir 	else if ( pElement->m_bIsStorage )
2210cdf0e10cSrcweir 	{
2211cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2212cdf0e10cSrcweir 	}
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir 	OSL_ENSURE( pElement, "In case element can not be created an exception must be thrown!" );
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir 	if ( !pElement->m_pStream )
2217cdf0e10cSrcweir 		m_pImpl->OpenSubStream( pElement );
2218cdf0e10cSrcweir 
2219cdf0e10cSrcweir 	if ( !pElement->m_pStream )
2220cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir 	return pElement;
2223cdf0e10cSrcweir }
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir //-----------------------------------------------
MakeLinkToSubComponent_Impl(const uno::Reference<lang::XComponent> & xComponent)2226cdf0e10cSrcweir void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XComponent >& xComponent )
2227cdf0e10cSrcweir {
2228cdf0e10cSrcweir 	if ( !xComponent.is() )
2229cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2230cdf0e10cSrcweir 
2231cdf0e10cSrcweir 	if ( !m_pData->m_pSubElDispListener )
2232cdf0e10cSrcweir 	{
2233cdf0e10cSrcweir 		m_pData->m_pSubElDispListener = new OChildDispListener_Impl( *this );
2234cdf0e10cSrcweir 		m_pData->m_pSubElDispListener->acquire();
2235cdf0e10cSrcweir 	}
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir 	xComponent->addEventListener( uno::Reference< lang::XEventListener >(
2238cdf0e10cSrcweir 		static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) );
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir 	m_pData->m_aOpenSubComponentsList.push_back( xComponent );
2241cdf0e10cSrcweir }
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir //____________________________________________________________________________________________________
2244cdf0e10cSrcweir //	XInterface
2245cdf0e10cSrcweir //____________________________________________________________________________________________________
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir //-----------------------------------------------
queryInterface(const uno::Type & rType)2248cdf0e10cSrcweir uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType )
2249cdf0e10cSrcweir 		throw( uno::RuntimeException )
2250cdf0e10cSrcweir {
2251cdf0e10cSrcweir 	uno::Any aReturn;
2252cdf0e10cSrcweir 
2253cdf0e10cSrcweir 	// common interfaces
2254cdf0e10cSrcweir 	aReturn <<= ::cppu::queryInterface
2255cdf0e10cSrcweir 				(	rType
2256cdf0e10cSrcweir 				,	static_cast<lang::XTypeProvider*> ( this )
2257cdf0e10cSrcweir 				,	static_cast<embed::XStorage*> ( this )
2258cdf0e10cSrcweir 				,	static_cast<embed::XStorage2*> ( this )
2259cdf0e10cSrcweir 				,	static_cast<embed::XTransactedObject*> ( this )
2260cdf0e10cSrcweir 				,	static_cast<embed::XTransactionBroadcaster*> ( this )
2261cdf0e10cSrcweir 				,	static_cast<util::XModifiable*> ( this )
2262cdf0e10cSrcweir 				,	static_cast<container::XNameAccess*> ( this )
2263cdf0e10cSrcweir 				,	static_cast<container::XElementAccess*> ( this )
2264cdf0e10cSrcweir 				,	static_cast<lang::XComponent*> ( this )
2265cdf0e10cSrcweir 				,	static_cast<beans::XPropertySet*> ( this )
2266cdf0e10cSrcweir 				,	static_cast<embed::XOptimizedStorage*> ( this ) );
2267cdf0e10cSrcweir 
2268cdf0e10cSrcweir 	if ( aReturn.hasValue() == sal_True )
2269cdf0e10cSrcweir 		return aReturn ;
2270cdf0e10cSrcweir 
2271cdf0e10cSrcweir 	aReturn <<= ::cppu::queryInterface
2272cdf0e10cSrcweir 				(	rType
2273cdf0e10cSrcweir 				,	static_cast<embed::XHierarchicalStorageAccess*> ( this )
2274cdf0e10cSrcweir 				,	static_cast<embed::XHierarchicalStorageAccess2*> ( this ) );
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir 	if ( aReturn.hasValue() == sal_True )
2277cdf0e10cSrcweir 		return aReturn ;
2278cdf0e10cSrcweir 
2279cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2280cdf0e10cSrcweir 	{
2281cdf0e10cSrcweir 		if ( m_pData->m_bIsRoot )
2282cdf0e10cSrcweir 		{
2283cdf0e10cSrcweir 			aReturn <<= ::cppu::queryInterface
2284cdf0e10cSrcweir 						(	rType
2285cdf0e10cSrcweir 						,	static_cast<embed::XStorageRawAccess*> ( this )
2286cdf0e10cSrcweir 						,	static_cast<embed::XEncryptionProtectedSource*> ( this )
2287cdf0e10cSrcweir 						,	static_cast<embed::XEncryptionProtectedSource2*> ( this )
2288cdf0e10cSrcweir 						,	static_cast<embed::XEncryptionProtectedStorage*> ( this ) );
2289cdf0e10cSrcweir 		}
2290cdf0e10cSrcweir 		else
2291cdf0e10cSrcweir 		{
2292cdf0e10cSrcweir 			aReturn <<= ::cppu::queryInterface
2293cdf0e10cSrcweir 						(	rType
2294cdf0e10cSrcweir 						,	static_cast<embed::XStorageRawAccess*> ( this ) );
2295cdf0e10cSrcweir 		}
2296cdf0e10cSrcweir 	}
2297cdf0e10cSrcweir 	else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2298cdf0e10cSrcweir 	{
2299cdf0e10cSrcweir 		aReturn <<= ::cppu::queryInterface
2300cdf0e10cSrcweir 					(	rType
2301cdf0e10cSrcweir 					,	static_cast<embed::XRelationshipAccess*> ( this ) );
2302cdf0e10cSrcweir 	}
2303cdf0e10cSrcweir 
2304cdf0e10cSrcweir 	if ( aReturn.hasValue() == sal_True )
2305cdf0e10cSrcweir 		return aReturn ;
2306cdf0e10cSrcweir 
2307cdf0e10cSrcweir 	return OWeakObject::queryInterface( rType );
2308cdf0e10cSrcweir }
2309cdf0e10cSrcweir 
2310cdf0e10cSrcweir //-----------------------------------------------
acquire()2311cdf0e10cSrcweir void SAL_CALL OStorage::acquire() throw()
2312cdf0e10cSrcweir {
2313cdf0e10cSrcweir 	OWeakObject::acquire();
2314cdf0e10cSrcweir }
2315cdf0e10cSrcweir 
2316cdf0e10cSrcweir //-----------------------------------------------
release()2317cdf0e10cSrcweir void SAL_CALL OStorage::release() throw()
2318cdf0e10cSrcweir {
2319cdf0e10cSrcweir 	OWeakObject::release();
2320cdf0e10cSrcweir }
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir //____________________________________________________________________________________________________
2323cdf0e10cSrcweir //	XTypeProvider
2324cdf0e10cSrcweir //____________________________________________________________________________________________________
2325cdf0e10cSrcweir 
2326cdf0e10cSrcweir //-----------------------------------------------
getTypes()2327cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes()
2328cdf0e10cSrcweir 		throw( uno::RuntimeException )
2329cdf0e10cSrcweir {
2330cdf0e10cSrcweir 	if ( m_pData->m_pTypeCollection == NULL )
2331cdf0e10cSrcweir 	{
2332cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2333cdf0e10cSrcweir 
2334cdf0e10cSrcweir 		if ( m_pData->m_pTypeCollection == NULL )
2335cdf0e10cSrcweir 		{
2336cdf0e10cSrcweir 			if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2337cdf0e10cSrcweir 			{
2338cdf0e10cSrcweir 				if ( m_pData->m_bIsRoot )
2339cdf0e10cSrcweir 				{
2340cdf0e10cSrcweir 					m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2341cdf0e10cSrcweir 									(	::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2342cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2343cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL )
2344cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
2345cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2346cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2347cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2348cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL )
2349cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
2350cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
2351cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2352cdf0e10cSrcweir 				}
2353cdf0e10cSrcweir 				else
2354cdf0e10cSrcweir 				{
2355cdf0e10cSrcweir 					m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2356cdf0e10cSrcweir 									(	::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2357cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2358cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL )
2359cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL )
2360cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2361cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2362cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2363cdf0e10cSrcweir 									,	::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2364cdf0e10cSrcweir 				}
2365cdf0e10cSrcweir 			}
2366cdf0e10cSrcweir 			else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2367cdf0e10cSrcweir 			{
2368cdf0e10cSrcweir 				m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2369cdf0e10cSrcweir 								(	::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2370cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2371cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2372cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2373cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2374cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL )
2375cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2376cdf0e10cSrcweir 			}
2377cdf0e10cSrcweir 			else
2378cdf0e10cSrcweir 			{
2379cdf0e10cSrcweir 				m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2380cdf0e10cSrcweir 								(	::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2381cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
2382cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2383cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2384cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL )
2385cdf0e10cSrcweir 								,	::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
2386cdf0e10cSrcweir 			}
2387cdf0e10cSrcweir 		}
2388cdf0e10cSrcweir 	}
2389cdf0e10cSrcweir 
2390cdf0e10cSrcweir 	return m_pData->m_pTypeCollection->getTypes() ;
2391cdf0e10cSrcweir }
2392cdf0e10cSrcweir 
2393cdf0e10cSrcweir namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
2394cdf0e10cSrcweir 
2395cdf0e10cSrcweir //-----------------------------------------------
getImplementationId()2396cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId()
2397cdf0e10cSrcweir 		throw( uno::RuntimeException )
2398cdf0e10cSrcweir {
2399cdf0e10cSrcweir     ::cppu::OImplementationId &rID = lcl_ImplId::get();
2400cdf0e10cSrcweir     return rID.getImplementationId();
2401cdf0e10cSrcweir }
2402cdf0e10cSrcweir 
2403cdf0e10cSrcweir //____________________________________________________________________________________________________
2404cdf0e10cSrcweir //	XStorage
2405cdf0e10cSrcweir //____________________________________________________________________________________________________
2406cdf0e10cSrcweir 
2407cdf0e10cSrcweir 
2408cdf0e10cSrcweir //-----------------------------------------------
copyToStorage(const uno::Reference<embed::XStorage> & xDest)2409cdf0e10cSrcweir void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
2410cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2411cdf0e10cSrcweir 				io::IOException,
2412cdf0e10cSrcweir 				lang::IllegalArgumentException,
2413cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2414cdf0e10cSrcweir 				uno::RuntimeException )
2415cdf0e10cSrcweir {
2416cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyToStorage" );
2417cdf0e10cSrcweir 
2418cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2419cdf0e10cSrcweir 
2420cdf0e10cSrcweir 	if ( !m_pImpl )
2421cdf0e10cSrcweir     {
2422cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2423cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2424cdf0e10cSrcweir     }
2425cdf0e10cSrcweir 
2426cdf0e10cSrcweir 	if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
2427cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir 	try {
2430cdf0e10cSrcweir 		m_pImpl->CopyToStorage( xDest, sal_False );
2431cdf0e10cSrcweir 	}
2432cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2433cdf0e10cSrcweir     {
2434cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2435cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2436cdf0e10cSrcweir         throw;
2437cdf0e10cSrcweir 	}
2438cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2439cdf0e10cSrcweir     {
2440cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2441cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2442cdf0e10cSrcweir         throw;
2443cdf0e10cSrcweir 	}
2444cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2445cdf0e10cSrcweir     {
2446cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2447cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2448cdf0e10cSrcweir         throw;
2449cdf0e10cSrcweir 	}
2450cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2451cdf0e10cSrcweir     {
2452cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2453cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2454cdf0e10cSrcweir         throw;
2455cdf0e10cSrcweir 	}
2456cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2457cdf0e10cSrcweir     {
2458cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2459cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2460cdf0e10cSrcweir         throw;
2461cdf0e10cSrcweir 	}
2462cdf0e10cSrcweir 	catch( uno::Exception& aException )
2463cdf0e10cSrcweir 	{
2464cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
2465cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2466cdf0e10cSrcweir 
2467cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
2468cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy storage!" ) ),
2469cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
2470cdf0e10cSrcweir 												 aCaught );
2471cdf0e10cSrcweir 	}
2472cdf0e10cSrcweir }
2473cdf0e10cSrcweir 
2474cdf0e10cSrcweir //-----------------------------------------------
openStreamElement(const::rtl::OUString & aStreamName,sal_Int32 nOpenMode)2475cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement(
2476cdf0e10cSrcweir 	const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode )
2477cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2478cdf0e10cSrcweir 				lang::IllegalArgumentException,
2479cdf0e10cSrcweir 				packages::WrongPasswordException,
2480cdf0e10cSrcweir 				io::IOException,
2481cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2482cdf0e10cSrcweir 				uno::RuntimeException )
2483cdf0e10cSrcweir {
2484cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStreamElement" );
2485cdf0e10cSrcweir 
2486cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2487cdf0e10cSrcweir 
2488cdf0e10cSrcweir 	if ( !m_pImpl )
2489cdf0e10cSrcweir     {
2490cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2491cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2492cdf0e10cSrcweir     }
2493cdf0e10cSrcweir 
2494cdf0e10cSrcweir 	if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
2495cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2496cdf0e10cSrcweir 
2497cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
2498cdf0e10cSrcweir 	  && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2499cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
2500cdf0e10cSrcweir 
2501cdf0e10cSrcweir 	if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2502cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2503cdf0e10cSrcweir 
2504cdf0e10cSrcweir 	uno::Reference< io::XStream > xResult;
2505cdf0e10cSrcweir 	try
2506cdf0e10cSrcweir 	{
2507cdf0e10cSrcweir     	SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_False );
2508cdf0e10cSrcweir 		OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
2509cdf0e10cSrcweir 
2510cdf0e10cSrcweir 		xResult = pElement->m_pStream->GetStream( nOpenMode, sal_False );
2511cdf0e10cSrcweir 		OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
2512cdf0e10cSrcweir 
2513cdf0e10cSrcweir 		if ( m_pData->m_bReadOnlyWrap )
2514cdf0e10cSrcweir 		{
2515cdf0e10cSrcweir 			// before the storage disposes the stream it must deregister itself as listener
2516cdf0e10cSrcweir 			uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
2517cdf0e10cSrcweir 			if ( !xStreamComponent.is() )
2518cdf0e10cSrcweir 				throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2519cdf0e10cSrcweir 
2520cdf0e10cSrcweir 			MakeLinkToSubComponent_Impl( xStreamComponent );
2521cdf0e10cSrcweir 		}
2522cdf0e10cSrcweir 	}
2523cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2524cdf0e10cSrcweir     {
2525cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2526cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2527cdf0e10cSrcweir         throw;
2528cdf0e10cSrcweir 	}
2529cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2530cdf0e10cSrcweir     {
2531cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2532cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2533cdf0e10cSrcweir         throw;
2534cdf0e10cSrcweir 	}
2535cdf0e10cSrcweir 	catch( packages::WrongPasswordException& aWrongPasswordException )
2536cdf0e10cSrcweir     {
2537cdf0e10cSrcweir         m_pImpl->AddLog( aWrongPasswordException.Message );
2538cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2539cdf0e10cSrcweir         throw;
2540cdf0e10cSrcweir 	}
2541cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2542cdf0e10cSrcweir     {
2543cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2544cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2545cdf0e10cSrcweir         throw;
2546cdf0e10cSrcweir 	}
2547cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2548cdf0e10cSrcweir     {
2549cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2550cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2551cdf0e10cSrcweir         throw;
2552cdf0e10cSrcweir 	}
2553cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2554cdf0e10cSrcweir     {
2555cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2556cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2557cdf0e10cSrcweir         throw;
2558cdf0e10cSrcweir 	}
2559cdf0e10cSrcweir 	catch( uno::Exception& aException )
2560cdf0e10cSrcweir 	{
2561cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
2562cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2563cdf0e10cSrcweir 
2564cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
2565cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open stream element!" ) ),
2566cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
2567cdf0e10cSrcweir 												 aCaught );
2568cdf0e10cSrcweir 	}
2569cdf0e10cSrcweir 
2570cdf0e10cSrcweir 	aGuard.clear();
2571cdf0e10cSrcweir 
2572cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
2573cdf0e10cSrcweir 
2574cdf0e10cSrcweir 	return xResult;
2575cdf0e10cSrcweir }
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir //-----------------------------------------------
openEncryptedStreamElement(const::rtl::OUString & aStreamName,sal_Int32 nOpenMode,const::rtl::OUString & aPass)2578cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement(
2579cdf0e10cSrcweir 	const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass )
2580cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2581cdf0e10cSrcweir 				lang::IllegalArgumentException,
2582cdf0e10cSrcweir 				packages::NoEncryptionException,
2583cdf0e10cSrcweir 				packages::WrongPasswordException,
2584cdf0e10cSrcweir 				io::IOException,
2585cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2586cdf0e10cSrcweir 				uno::RuntimeException )
2587cdf0e10cSrcweir {
2588cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" );
2589cdf0e10cSrcweir 
2590cdf0e10cSrcweir     return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
2591cdf0e10cSrcweir }
2592cdf0e10cSrcweir 
2593cdf0e10cSrcweir //-----------------------------------------------
openStorageElement(const::rtl::OUString & aStorName,sal_Int32 nStorageMode)2594cdf0e10cSrcweir uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
2595cdf0e10cSrcweir 			const ::rtl::OUString& aStorName, sal_Int32 nStorageMode )
2596cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2597cdf0e10cSrcweir 				lang::IllegalArgumentException,
2598cdf0e10cSrcweir 				io::IOException,
2599cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2600cdf0e10cSrcweir 				uno::RuntimeException )
2601cdf0e10cSrcweir {
2602cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStorageElement" );
2603cdf0e10cSrcweir 
2604cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir 	if ( !m_pImpl )
2607cdf0e10cSrcweir     {
2608cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2609cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2610cdf0e10cSrcweir     }
2611cdf0e10cSrcweir 
2612cdf0e10cSrcweir 	if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) )
2613cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2614cdf0e10cSrcweir 
2615cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
2616cdf0e10cSrcweir 	  && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2617cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2618cdf0e10cSrcweir 
2619cdf0e10cSrcweir 	if ( ( nStorageMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
2620cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2621cdf0e10cSrcweir 
2622cdf0e10cSrcweir 	if ( ( nStorageMode & embed::ElementModes::TRUNCATE )
2623cdf0e10cSrcweir 	  && !( nStorageMode & embed::ElementModes::WRITE ) )
2624cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
2625cdf0e10cSrcweir 
2626*30acf5e8Spfg 	// it's always possible to read written storage in this implementation
2627cdf0e10cSrcweir 	nStorageMode |= embed::ElementModes::READ;
2628cdf0e10cSrcweir 
2629cdf0e10cSrcweir 	uno::Reference< embed::XStorage > xResult;
2630cdf0e10cSrcweir 	try
2631cdf0e10cSrcweir 	{
2632cdf0e10cSrcweir     	SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
2633cdf0e10cSrcweir     	if ( !pElement )
2634cdf0e10cSrcweir     	{
2635cdf0e10cSrcweir         	// element does not exist, check if creation is allowed
2636cdf0e10cSrcweir 			if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
2637cdf0e10cSrcweir           	|| (( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE )
2638cdf0e10cSrcweir           	|| ( nStorageMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE )
2639cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2640cdf0e10cSrcweir 
2641cdf0e10cSrcweir         	// create a new StorageElement and insert it into the list
2642cdf0e10cSrcweir 			pElement = m_pImpl->InsertStorage( aStorName, nStorageMode );
2643cdf0e10cSrcweir     	}
2644cdf0e10cSrcweir 		else if ( !pElement->m_bIsStorage )
2645cdf0e10cSrcweir 		{
2646cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2647cdf0e10cSrcweir 		}
2648cdf0e10cSrcweir 		else if ( pElement->m_pStorage )
2649cdf0e10cSrcweir     	{
2650cdf0e10cSrcweir         	// storage has already been opened; it may be opened another time, if it the mode allows to do so
2651cdf0e10cSrcweir         	if ( pElement->m_pStorage->m_pAntiImpl )
2652cdf0e10cSrcweir         	{
2653cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2654cdf0e10cSrcweir         	}
2655cdf0e10cSrcweir 			else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty()
2656cdf0e10cSrcweir 					&& ( nStorageMode & embed::ElementModes::WRITE ) )
2657cdf0e10cSrcweir 			{
2658cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2659cdf0e10cSrcweir 			}
2660cdf0e10cSrcweir         	else
2661cdf0e10cSrcweir         	{
2662cdf0e10cSrcweir 				// in case parent storage allows writing the readonly mode of the child storage is
2663cdf0e10cSrcweir 				// virtual, that means that it is just enough to change the flag to let it be writable
2664cdf0e10cSrcweir 				// and since there is no AntiImpl nobody should be notified about it
2665cdf0e10cSrcweir 				pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ;
2666cdf0e10cSrcweir 
2667cdf0e10cSrcweir 				if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
2668cdf0e10cSrcweir 				{
2669cdf0e10cSrcweir 					for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin();
2670cdf0e10cSrcweir  				  		pElementIter != pElement->m_pStorage->m_aChildrenList.end(); )
2671cdf0e10cSrcweir    					{
2672cdf0e10cSrcweir 						SotElement_Impl* pElementToDel = (*pElementIter);
2673cdf0e10cSrcweir 						pElementIter++;
2674cdf0e10cSrcweir 
2675cdf0e10cSrcweir 						m_pImpl->RemoveElement( pElementToDel );
2676cdf0e10cSrcweir    					}
2677cdf0e10cSrcweir 				}
2678cdf0e10cSrcweir         	}
2679cdf0e10cSrcweir     	}
2680cdf0e10cSrcweir 
2681cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
2682cdf0e10cSrcweir 			m_pImpl->OpenSubStorage( pElement, nStorageMode );
2683cdf0e10cSrcweir 
2684cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
2685cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
2686cdf0e10cSrcweir 
2687cdf0e10cSrcweir 		sal_Bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE );
2688cdf0e10cSrcweir 		OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap );
2689cdf0e10cSrcweir 		xResult = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage );
2690cdf0e10cSrcweir 
2691cdf0e10cSrcweir 		if ( bReadOnlyWrap )
2692cdf0e10cSrcweir 		{
2693cdf0e10cSrcweir 			// Before this call is done the object must be refcounted already
2694cdf0e10cSrcweir 			pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage );
2695cdf0e10cSrcweir 
2696cdf0e10cSrcweir 			// before the storage disposes the stream it must deregister itself as listener
2697cdf0e10cSrcweir 			uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY );
2698cdf0e10cSrcweir 			if ( !xStorageComponent.is() )
2699cdf0e10cSrcweir 				throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir 			MakeLinkToSubComponent_Impl( xStorageComponent );
2702cdf0e10cSrcweir 		}
2703cdf0e10cSrcweir 	}
2704cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2705cdf0e10cSrcweir     {
2706cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2707cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2708cdf0e10cSrcweir         throw;
2709cdf0e10cSrcweir 	}
2710cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2711cdf0e10cSrcweir     {
2712cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2713cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2714cdf0e10cSrcweir         throw;
2715cdf0e10cSrcweir 	}
2716cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2717cdf0e10cSrcweir     {
2718cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2719cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2720cdf0e10cSrcweir         throw;
2721cdf0e10cSrcweir 	}
2722cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2723cdf0e10cSrcweir     {
2724cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2725cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2726cdf0e10cSrcweir         throw;
2727cdf0e10cSrcweir 	}
2728cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2729cdf0e10cSrcweir     {
2730cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2731cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2732cdf0e10cSrcweir         throw;
2733cdf0e10cSrcweir 	}
2734cdf0e10cSrcweir 	catch( uno::Exception& aException )
2735cdf0e10cSrcweir 	{
2736cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
2737cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2738cdf0e10cSrcweir 
2739cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
2740cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open storage!" ) ),
2741cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
2742cdf0e10cSrcweir 												 aCaught );
2743cdf0e10cSrcweir 	}
2744cdf0e10cSrcweir 
2745cdf0e10cSrcweir 	return xResult;
2746cdf0e10cSrcweir }
2747cdf0e10cSrcweir 
2748cdf0e10cSrcweir //-----------------------------------------------
cloneStreamElement(const::rtl::OUString & aStreamName)2749cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl::OUString& aStreamName )
2750cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2751cdf0e10cSrcweir 				lang::IllegalArgumentException,
2752cdf0e10cSrcweir 				packages::WrongPasswordException,
2753cdf0e10cSrcweir 				io::IOException,
2754cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2755cdf0e10cSrcweir 				uno::RuntimeException )
2756cdf0e10cSrcweir {
2757cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneStreamElement" );
2758cdf0e10cSrcweir 
2759cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2760cdf0e10cSrcweir 
2761cdf0e10cSrcweir 	if ( !m_pImpl )
2762cdf0e10cSrcweir     {
2763cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2764cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2765cdf0e10cSrcweir     }
2766cdf0e10cSrcweir 
2767cdf0e10cSrcweir 	if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
2768cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2769cdf0e10cSrcweir 
2770cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
2771cdf0e10cSrcweir 	  && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2772cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2773cdf0e10cSrcweir 
2774cdf0e10cSrcweir 	try
2775cdf0e10cSrcweir 	{
2776cdf0e10cSrcweir 		uno::Reference< io::XStream > xResult;
2777cdf0e10cSrcweir 		m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xResult );
2778cdf0e10cSrcweir 		if ( !xResult.is() )
2779cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2780cdf0e10cSrcweir 		return xResult;
2781cdf0e10cSrcweir 	}
2782cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2783cdf0e10cSrcweir     {
2784cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2785cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2786cdf0e10cSrcweir         throw;
2787cdf0e10cSrcweir 	}
2788cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2789cdf0e10cSrcweir     {
2790cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2791cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2792cdf0e10cSrcweir         throw;
2793cdf0e10cSrcweir 	}
2794cdf0e10cSrcweir 	catch( packages::WrongPasswordException& aWrongPasswordException )
2795cdf0e10cSrcweir     {
2796cdf0e10cSrcweir         m_pImpl->AddLog( aWrongPasswordException.Message );
2797cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2798cdf0e10cSrcweir         throw;
2799cdf0e10cSrcweir 	}
2800cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2801cdf0e10cSrcweir     {
2802cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2803cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2804cdf0e10cSrcweir         throw;
2805cdf0e10cSrcweir 	}
2806cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2807cdf0e10cSrcweir     {
2808cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2809cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2810cdf0e10cSrcweir         throw;
2811cdf0e10cSrcweir 	}
2812cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2813cdf0e10cSrcweir     {
2814cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2815cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2816cdf0e10cSrcweir         throw;
2817cdf0e10cSrcweir 	}
2818cdf0e10cSrcweir 	catch( uno::Exception& aException )
2819cdf0e10cSrcweir 	{
2820cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
2821cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2822cdf0e10cSrcweir 
2823cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
2824cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone stream!" ) ),
2825cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
2826cdf0e10cSrcweir 												 aCaught );
2827cdf0e10cSrcweir 	}
2828cdf0e10cSrcweir }
2829cdf0e10cSrcweir 
2830cdf0e10cSrcweir //-----------------------------------------------
cloneEncryptedStreamElement(const::rtl::OUString & aStreamName,const::rtl::OUString & aPass)2831cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement(
2832cdf0e10cSrcweir 	const ::rtl::OUString& aStreamName,
2833cdf0e10cSrcweir 	const ::rtl::OUString& aPass )
2834cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2835cdf0e10cSrcweir 				lang::IllegalArgumentException,
2836cdf0e10cSrcweir 				packages::NoEncryptionException,
2837cdf0e10cSrcweir 				packages::WrongPasswordException,
2838cdf0e10cSrcweir 				io::IOException,
2839cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2840cdf0e10cSrcweir 				uno::RuntimeException )
2841cdf0e10cSrcweir {
2842cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" );
2843cdf0e10cSrcweir 
2844cdf0e10cSrcweir     return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
2845cdf0e10cSrcweir }
2846cdf0e10cSrcweir 
2847cdf0e10cSrcweir //-----------------------------------------------
copyLastCommitTo(const uno::Reference<embed::XStorage> & xTargetStorage)2848cdf0e10cSrcweir void SAL_CALL OStorage::copyLastCommitTo(
2849cdf0e10cSrcweir 			const uno::Reference< embed::XStorage >& xTargetStorage )
2850cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2851cdf0e10cSrcweir 				lang::IllegalArgumentException,
2852cdf0e10cSrcweir 				io::IOException,
2853cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2854cdf0e10cSrcweir 				uno::RuntimeException )
2855cdf0e10cSrcweir {
2856cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyLastCommitTo" );
2857cdf0e10cSrcweir 
2858cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2859cdf0e10cSrcweir 
2860cdf0e10cSrcweir 	if ( !m_pImpl )
2861cdf0e10cSrcweir     {
2862cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2863cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2864cdf0e10cSrcweir     }
2865cdf0e10cSrcweir 
2866cdf0e10cSrcweir 	try
2867cdf0e10cSrcweir 	{
2868cdf0e10cSrcweir 		m_pImpl->CopyLastCommitTo( xTargetStorage );
2869cdf0e10cSrcweir 	}
2870cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2871cdf0e10cSrcweir     {
2872cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2873cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2874cdf0e10cSrcweir         throw;
2875cdf0e10cSrcweir 	}
2876cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2877cdf0e10cSrcweir     {
2878cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2879cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2880cdf0e10cSrcweir         throw;
2881cdf0e10cSrcweir 	}
2882cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2883cdf0e10cSrcweir     {
2884cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2885cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2886cdf0e10cSrcweir         throw;
2887cdf0e10cSrcweir 	}
2888cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2889cdf0e10cSrcweir     {
2890cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2891cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2892cdf0e10cSrcweir         throw;
2893cdf0e10cSrcweir 	}
2894cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2895cdf0e10cSrcweir     {
2896cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2897cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2898cdf0e10cSrcweir         throw;
2899cdf0e10cSrcweir 	}
2900cdf0e10cSrcweir 	catch( uno::Exception& aException )
2901cdf0e10cSrcweir 	{
2902cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
2903cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2904cdf0e10cSrcweir 
2905cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
2906cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit version!" ) ),
2907cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
2908cdf0e10cSrcweir 												 aCaught );
2909cdf0e10cSrcweir 	}
2910cdf0e10cSrcweir 
2911cdf0e10cSrcweir }
2912cdf0e10cSrcweir 
2913cdf0e10cSrcweir //-----------------------------------------------
copyStorageElementLastCommitTo(const::rtl::OUString & aStorName,const uno::Reference<embed::XStorage> & xTargetStorage)2914cdf0e10cSrcweir void SAL_CALL OStorage::copyStorageElementLastCommitTo(
2915cdf0e10cSrcweir 			const ::rtl::OUString& aStorName,
2916cdf0e10cSrcweir 			const uno::Reference< embed::XStorage >& xTargetStorage )
2917cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
2918cdf0e10cSrcweir 				lang::IllegalArgumentException,
2919cdf0e10cSrcweir 				io::IOException,
2920cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
2921cdf0e10cSrcweir 				uno::RuntimeException )
2922cdf0e10cSrcweir {
2923cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyStorageElementLastCommitTo" );
2924cdf0e10cSrcweir 
2925cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2926cdf0e10cSrcweir 
2927cdf0e10cSrcweir 	if ( !m_pImpl )
2928cdf0e10cSrcweir     {
2929cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2930cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2931cdf0e10cSrcweir     }
2932cdf0e10cSrcweir 
2933cdf0e10cSrcweir 	if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) )
2934cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
2935cdf0e10cSrcweir 
2936cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
2937cdf0e10cSrcweir 	  && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
2938cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
2939cdf0e10cSrcweir 
2940*30acf5e8Spfg 	// it's always possible to read written storage in this implementation
2941cdf0e10cSrcweir 	sal_Int32 nStorageMode = embed::ElementModes::READ;
2942cdf0e10cSrcweir 
2943cdf0e10cSrcweir 	try
2944cdf0e10cSrcweir 	{
2945cdf0e10cSrcweir     	SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
2946cdf0e10cSrcweir     	if ( !pElement )
2947cdf0e10cSrcweir     	{
2948cdf0e10cSrcweir         	// element does not exist, throw exception
2949cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
2950cdf0e10cSrcweir     	}
2951cdf0e10cSrcweir 		else if ( !pElement->m_bIsStorage )
2952cdf0e10cSrcweir 		{
2953cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
2954cdf0e10cSrcweir 		}
2955cdf0e10cSrcweir 
2956cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
2957cdf0e10cSrcweir 			m_pImpl->OpenSubStorage( pElement, nStorageMode );
2958cdf0e10cSrcweir 
2959cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xResult;
2960cdf0e10cSrcweir 		if ( pElement->m_pStorage )
2961cdf0e10cSrcweir     	{
2962cdf0e10cSrcweir 			// the existence of m_pAntiImpl of the child is not interesting,
2963cdf0e10cSrcweir 			// the copy will be created internally
2964cdf0e10cSrcweir 
2965cdf0e10cSrcweir 			pElement->m_pStorage->CopyLastCommitTo( xTargetStorage );
2966cdf0e10cSrcweir 		}
2967cdf0e10cSrcweir 		else
2968cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
2969cdf0e10cSrcweir 	}
2970cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
2971cdf0e10cSrcweir     {
2972cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
2973cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2974cdf0e10cSrcweir         throw;
2975cdf0e10cSrcweir 	}
2976cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
2977cdf0e10cSrcweir     {
2978cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
2979cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2980cdf0e10cSrcweir         throw;
2981cdf0e10cSrcweir 	}
2982cdf0e10cSrcweir 	catch( io::IOException& aIOException )
2983cdf0e10cSrcweir     {
2984cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
2985cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2986cdf0e10cSrcweir         throw;
2987cdf0e10cSrcweir 	}
2988cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
2989cdf0e10cSrcweir     {
2990cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
2991cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2992cdf0e10cSrcweir         throw;
2993cdf0e10cSrcweir 	}
2994cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
2995cdf0e10cSrcweir     {
2996cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
2997cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2998cdf0e10cSrcweir         throw;
2999cdf0e10cSrcweir 	}
3000cdf0e10cSrcweir 	catch( uno::Exception& aException )
3001cdf0e10cSrcweir 	{
3002cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3003cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3004cdf0e10cSrcweir 
3005cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3006cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit element version!" ) ),
3007cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3008cdf0e10cSrcweir 												 aCaught );
3009cdf0e10cSrcweir 	}
3010cdf0e10cSrcweir }
3011cdf0e10cSrcweir 
3012cdf0e10cSrcweir //-----------------------------------------------
isStreamElement(const::rtl::OUString & aElementName)3013cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName )
3014cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3015cdf0e10cSrcweir 				lang::IllegalArgumentException,
3016cdf0e10cSrcweir 				container::NoSuchElementException,
3017cdf0e10cSrcweir 				uno::RuntimeException )
3018cdf0e10cSrcweir {
3019cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3020cdf0e10cSrcweir 
3021cdf0e10cSrcweir 	if ( !m_pImpl )
3022cdf0e10cSrcweir     {
3023cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3024cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3025cdf0e10cSrcweir     }
3026cdf0e10cSrcweir 
3027cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3028cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3029cdf0e10cSrcweir 
3030cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3031cdf0e10cSrcweir 	  && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3032cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
3033cdf0e10cSrcweir 
3034cdf0e10cSrcweir 	SotElement_Impl* pElement = NULL;
3035cdf0e10cSrcweir 
3036cdf0e10cSrcweir 	try
3037cdf0e10cSrcweir 	{
3038cdf0e10cSrcweir 		pElement = m_pImpl->FindElement( aElementName );
3039cdf0e10cSrcweir 	}
3040cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3041cdf0e10cSrcweir     {
3042cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3043cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3044cdf0e10cSrcweir         throw;
3045cdf0e10cSrcweir 	}
3046cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3047cdf0e10cSrcweir     {
3048cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3049cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3050cdf0e10cSrcweir         throw;
3051cdf0e10cSrcweir 	}
3052cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3053cdf0e10cSrcweir     {
3054cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3055cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3056cdf0e10cSrcweir         throw;
3057cdf0e10cSrcweir 	}
3058cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3059cdf0e10cSrcweir     {
3060cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3061cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3062cdf0e10cSrcweir         throw;
3063cdf0e10cSrcweir 	}
3064cdf0e10cSrcweir 	catch( uno::Exception& aException )
3065cdf0e10cSrcweir 	{
3066cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3067cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3068cdf0e10cSrcweir 
3069cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3070cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ),
3071cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3072cdf0e10cSrcweir 												 aCaught );
3073cdf0e10cSrcweir 	}
3074cdf0e10cSrcweir 
3075cdf0e10cSrcweir 	if ( !pElement )
3076cdf0e10cSrcweir 		throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3077cdf0e10cSrcweir 
3078cdf0e10cSrcweir 	return !pElement->m_bIsStorage;
3079cdf0e10cSrcweir }
3080cdf0e10cSrcweir 
3081cdf0e10cSrcweir //-----------------------------------------------
isStorageElement(const::rtl::OUString & aElementName)3082cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementName )
3083cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3084cdf0e10cSrcweir 				lang::IllegalArgumentException,
3085cdf0e10cSrcweir 				container::NoSuchElementException,
3086cdf0e10cSrcweir 				uno::RuntimeException )
3087cdf0e10cSrcweir {
3088cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3089cdf0e10cSrcweir 
3090cdf0e10cSrcweir 	if ( !m_pImpl )
3091cdf0e10cSrcweir     {
3092cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3093cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3094cdf0e10cSrcweir     }
3095cdf0e10cSrcweir 
3096cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3097cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3098cdf0e10cSrcweir 
3099cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3100cdf0e10cSrcweir 	  && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3101cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
3102cdf0e10cSrcweir 
3103cdf0e10cSrcweir 	SotElement_Impl* pElement = NULL;
3104cdf0e10cSrcweir 
3105cdf0e10cSrcweir 	try
3106cdf0e10cSrcweir 	{
3107cdf0e10cSrcweir 		pElement = m_pImpl->FindElement( aElementName );
3108cdf0e10cSrcweir 	}
3109cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3110cdf0e10cSrcweir     {
3111cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3112cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3113cdf0e10cSrcweir         throw;
3114cdf0e10cSrcweir 	}
3115cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3116cdf0e10cSrcweir     {
3117cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3118cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3119cdf0e10cSrcweir         throw;
3120cdf0e10cSrcweir 	}
3121cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3122cdf0e10cSrcweir     {
3123cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3124cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3125cdf0e10cSrcweir         throw;
3126cdf0e10cSrcweir 	}
3127cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3128cdf0e10cSrcweir     {
3129cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3130cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3131cdf0e10cSrcweir         throw;
3132cdf0e10cSrcweir 	}
3133cdf0e10cSrcweir 	catch( uno::Exception& aException )
3134cdf0e10cSrcweir 	{
3135cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3136cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3137cdf0e10cSrcweir 
3138cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3139cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "can't detect whether it is a storage" ) ),
3140cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3141cdf0e10cSrcweir 												 aCaught );
3142cdf0e10cSrcweir 	}
3143cdf0e10cSrcweir 
3144cdf0e10cSrcweir 	if ( !pElement )
3145cdf0e10cSrcweir 		throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3146cdf0e10cSrcweir 
3147cdf0e10cSrcweir 	return pElement->m_bIsStorage;
3148cdf0e10cSrcweir }
3149cdf0e10cSrcweir 
3150cdf0e10cSrcweir //-----------------------------------------------
removeElement(const::rtl::OUString & aElementName)3151cdf0e10cSrcweir void SAL_CALL OStorage::removeElement( const ::rtl::OUString& aElementName )
3152cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3153cdf0e10cSrcweir 				lang::IllegalArgumentException,
3154cdf0e10cSrcweir 				container::NoSuchElementException,
3155cdf0e10cSrcweir 				io::IOException,
3156cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3157cdf0e10cSrcweir 				uno::RuntimeException )
3158cdf0e10cSrcweir {
3159cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeElement" );
3160cdf0e10cSrcweir 
3161cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3162cdf0e10cSrcweir 
3163cdf0e10cSrcweir 	if ( !m_pImpl )
3164cdf0e10cSrcweir     {
3165cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3166cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3167cdf0e10cSrcweir     }
3168cdf0e10cSrcweir 
3169cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
3170cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3171cdf0e10cSrcweir 
3172cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3173cdf0e10cSrcweir 	  && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
3174cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
3175cdf0e10cSrcweir 
3176cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3177cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3178cdf0e10cSrcweir 
3179cdf0e10cSrcweir 	try
3180cdf0e10cSrcweir 	{
3181cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3182cdf0e10cSrcweir 
3183cdf0e10cSrcweir 		if ( !pElement )
3184cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3185cdf0e10cSrcweir 
3186cdf0e10cSrcweir 		m_pImpl->RemoveElement( pElement );
3187cdf0e10cSrcweir 
3188cdf0e10cSrcweir 		m_pImpl->m_bIsModified = sal_True;
3189cdf0e10cSrcweir 		m_pImpl->m_bBroadcastModified = sal_True;
3190cdf0e10cSrcweir 	}
3191cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3192cdf0e10cSrcweir     {
3193cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3194cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3195cdf0e10cSrcweir         throw;
3196cdf0e10cSrcweir 	}
3197cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3198cdf0e10cSrcweir     {
3199cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3200cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3201cdf0e10cSrcweir         throw;
3202cdf0e10cSrcweir 	}
3203cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3204cdf0e10cSrcweir     {
3205cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3206cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3207cdf0e10cSrcweir         throw;
3208cdf0e10cSrcweir 	}
3209cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3210cdf0e10cSrcweir     {
3211cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3212cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3213cdf0e10cSrcweir         throw;
3214cdf0e10cSrcweir 	}
3215cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3216cdf0e10cSrcweir     {
3217cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3218cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3219cdf0e10cSrcweir         throw;
3220cdf0e10cSrcweir 	}
3221cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3222cdf0e10cSrcweir     {
3223cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3224cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3225cdf0e10cSrcweir         throw;
3226cdf0e10cSrcweir 	}
3227cdf0e10cSrcweir 	catch( uno::Exception& aException )
3228cdf0e10cSrcweir 	{
3229cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3230cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3231cdf0e10cSrcweir 
3232cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3233cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't remove element!" ) ),
3234cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3235cdf0e10cSrcweir 												 aCaught );
3236cdf0e10cSrcweir 	}
3237cdf0e10cSrcweir 
3238cdf0e10cSrcweir 	aGuard.clear();
3239cdf0e10cSrcweir 
3240cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
3241cdf0e10cSrcweir }
3242cdf0e10cSrcweir 
3243cdf0e10cSrcweir //-----------------------------------------------
renameElement(const::rtl::OUString & aElementName,const::rtl::OUString & aNewName)3244cdf0e10cSrcweir void SAL_CALL OStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName )
3245cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3246cdf0e10cSrcweir 				lang::IllegalArgumentException,
3247cdf0e10cSrcweir 				container::NoSuchElementException,
3248cdf0e10cSrcweir 				container::ElementExistException,
3249cdf0e10cSrcweir 				io::IOException,
3250cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3251cdf0e10cSrcweir 				uno::RuntimeException )
3252cdf0e10cSrcweir {
3253cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::renameElement" );
3254cdf0e10cSrcweir 
3255cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3256cdf0e10cSrcweir 
3257cdf0e10cSrcweir 	if ( !m_pImpl )
3258cdf0e10cSrcweir     {
3259cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3260cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3261cdf0e10cSrcweir     }
3262cdf0e10cSrcweir 
3263cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3264cdf0e10cSrcweir 	  || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3265cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3266cdf0e10cSrcweir 
3267cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3268cdf0e10cSrcweir 	  && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3269cdf0e10cSrcweir 	    || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3270cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name
3271cdf0e10cSrcweir 
3272cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3273cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3274cdf0e10cSrcweir 
3275cdf0e10cSrcweir 	try
3276cdf0e10cSrcweir 	{
3277cdf0e10cSrcweir 		SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName );
3278cdf0e10cSrcweir 		if ( pRefElement )
3279cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3280cdf0e10cSrcweir 
3281cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3282cdf0e10cSrcweir 		if ( !pElement )
3283cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3284cdf0e10cSrcweir 
3285cdf0e10cSrcweir 		pElement->m_aName = aNewName;
3286cdf0e10cSrcweir 
3287cdf0e10cSrcweir 		m_pImpl->m_bIsModified = sal_True;
3288cdf0e10cSrcweir 		m_pImpl->m_bBroadcastModified = sal_True;
3289cdf0e10cSrcweir 	}
3290cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3291cdf0e10cSrcweir     {
3292cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3293cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3294cdf0e10cSrcweir         throw;
3295cdf0e10cSrcweir 	}
3296cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3297cdf0e10cSrcweir     {
3298cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3299cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3300cdf0e10cSrcweir         throw;
3301cdf0e10cSrcweir 	}
3302cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3303cdf0e10cSrcweir     {
3304cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3305cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3306cdf0e10cSrcweir         throw;
3307cdf0e10cSrcweir 	}
3308cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
3309cdf0e10cSrcweir     {
3310cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
3311cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3312cdf0e10cSrcweir         throw;
3313cdf0e10cSrcweir 	}
3314cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3315cdf0e10cSrcweir     {
3316cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3317cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3318cdf0e10cSrcweir         throw;
3319cdf0e10cSrcweir 	}
3320cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3321cdf0e10cSrcweir     {
3322cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3323cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3324cdf0e10cSrcweir         throw;
3325cdf0e10cSrcweir 	}
3326cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3327cdf0e10cSrcweir     {
3328cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3329cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3330cdf0e10cSrcweir         throw;
3331cdf0e10cSrcweir 	}
3332cdf0e10cSrcweir 	catch( uno::Exception& aException )
3333cdf0e10cSrcweir 	{
3334cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3335cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3336cdf0e10cSrcweir 
3337cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3338cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't rename element!" ) ),
3339cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3340cdf0e10cSrcweir 												 aCaught );
3341cdf0e10cSrcweir 	}
3342cdf0e10cSrcweir 
3343cdf0e10cSrcweir 	aGuard.clear();
3344cdf0e10cSrcweir 
3345cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
3346cdf0e10cSrcweir }
3347cdf0e10cSrcweir 
3348cdf0e10cSrcweir //-----------------------------------------------
copyElementTo(const::rtl::OUString & aElementName,const uno::Reference<embed::XStorage> & xDest,const::rtl::OUString & aNewName)3349cdf0e10cSrcweir void SAL_CALL OStorage::copyElementTo(	const ::rtl::OUString& aElementName,
3350cdf0e10cSrcweir 										const uno::Reference< embed::XStorage >& xDest,
3351cdf0e10cSrcweir 										const ::rtl::OUString& aNewName )
3352cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3353cdf0e10cSrcweir 				lang::IllegalArgumentException,
3354cdf0e10cSrcweir 				container::NoSuchElementException,
3355cdf0e10cSrcweir 				container::ElementExistException,
3356cdf0e10cSrcweir 				io::IOException,
3357cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3358cdf0e10cSrcweir 				uno::RuntimeException )
3359cdf0e10cSrcweir {
3360cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementTo" );
3361cdf0e10cSrcweir 
3362cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3363cdf0e10cSrcweir 
3364cdf0e10cSrcweir 	if ( !m_pImpl )
3365cdf0e10cSrcweir     {
3366cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3367cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3368cdf0e10cSrcweir     }
3369cdf0e10cSrcweir 
3370cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3371cdf0e10cSrcweir 	  || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3372cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3373cdf0e10cSrcweir 
3374cdf0e10cSrcweir 	if ( !xDest.is() )
3375cdf0e10cSrcweir 		// || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3376cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3377cdf0e10cSrcweir 
3378cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3379cdf0e10cSrcweir 	  && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3380cdf0e10cSrcweir 	    || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3381cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3382cdf0e10cSrcweir 
3383cdf0e10cSrcweir 	try
3384cdf0e10cSrcweir 	{
3385cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3386cdf0e10cSrcweir 		if ( !pElement )
3387cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3388cdf0e10cSrcweir 
3389cdf0e10cSrcweir 		uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3390cdf0e10cSrcweir 		if ( !xNameAccess.is() )
3391cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3392cdf0e10cSrcweir 
3393cdf0e10cSrcweir 		if ( xNameAccess->hasByName( aNewName ) )
3394cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3395cdf0e10cSrcweir 
3396cdf0e10cSrcweir 		m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False );
3397cdf0e10cSrcweir 	}
3398cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3399cdf0e10cSrcweir     {
3400cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3401cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3402cdf0e10cSrcweir         throw;
3403cdf0e10cSrcweir 	}
3404cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3405cdf0e10cSrcweir     {
3406cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3407cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3408cdf0e10cSrcweir         throw;
3409cdf0e10cSrcweir 	}
3410cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3411cdf0e10cSrcweir     {
3412cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3413cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3414cdf0e10cSrcweir         throw;
3415cdf0e10cSrcweir 	}
3416cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
3417cdf0e10cSrcweir     {
3418cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
3419cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3420cdf0e10cSrcweir         throw;
3421cdf0e10cSrcweir 	}
3422cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3423cdf0e10cSrcweir     {
3424cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3425cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3426cdf0e10cSrcweir         throw;
3427cdf0e10cSrcweir 	}
3428cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3429cdf0e10cSrcweir     {
3430cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3431cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3432cdf0e10cSrcweir         throw;
3433cdf0e10cSrcweir 	}
3434cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3435cdf0e10cSrcweir     {
3436cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3437cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3438cdf0e10cSrcweir         throw;
3439cdf0e10cSrcweir 	}
3440cdf0e10cSrcweir 	catch( uno::Exception& aException )
3441cdf0e10cSrcweir 	{
3442cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3443cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3444cdf0e10cSrcweir 
3445cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3446cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element!" ) ),
3447cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3448cdf0e10cSrcweir 												 aCaught );
3449cdf0e10cSrcweir 	}
3450cdf0e10cSrcweir }
3451cdf0e10cSrcweir 
3452cdf0e10cSrcweir 
3453cdf0e10cSrcweir //-----------------------------------------------
moveElementTo(const::rtl::OUString & aElementName,const uno::Reference<embed::XStorage> & xDest,const::rtl::OUString & aNewName)3454cdf0e10cSrcweir void SAL_CALL OStorage::moveElementTo(	const ::rtl::OUString& aElementName,
3455cdf0e10cSrcweir 										const uno::Reference< embed::XStorage >& xDest,
3456cdf0e10cSrcweir 										const ::rtl::OUString& aNewName )
3457cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3458cdf0e10cSrcweir 				lang::IllegalArgumentException,
3459cdf0e10cSrcweir 				container::NoSuchElementException,
3460cdf0e10cSrcweir 				container::ElementExistException,
3461cdf0e10cSrcweir 				io::IOException,
3462cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3463cdf0e10cSrcweir 				uno::RuntimeException )
3464cdf0e10cSrcweir {
3465cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::moveElementTo" );
3466cdf0e10cSrcweir 
3467cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3468cdf0e10cSrcweir 
3469cdf0e10cSrcweir 	if ( !m_pImpl )
3470cdf0e10cSrcweir     {
3471cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3472cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3473cdf0e10cSrcweir     }
3474cdf0e10cSrcweir 
3475cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
3476cdf0e10cSrcweir 	  || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
3477cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3478cdf0e10cSrcweir 
3479cdf0e10cSrcweir 	if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
3480cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3481cdf0e10cSrcweir 
3482cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
3483cdf0e10cSrcweir 	  && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
3484cdf0e10cSrcweir 	    || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
3485cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name
3486cdf0e10cSrcweir 
3487cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
3488cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3489cdf0e10cSrcweir 
3490cdf0e10cSrcweir 	try
3491cdf0e10cSrcweir 	{
3492cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
3493cdf0e10cSrcweir 		if ( !pElement )
3494cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //???
3495cdf0e10cSrcweir 
3496cdf0e10cSrcweir 		uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
3497cdf0e10cSrcweir 		if ( !xNameAccess.is() )
3498cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3499cdf0e10cSrcweir 
3500cdf0e10cSrcweir 		if ( xNameAccess->hasByName( aNewName ) )
3501cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3502cdf0e10cSrcweir 
3503cdf0e10cSrcweir 		m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False );
3504cdf0e10cSrcweir 
3505cdf0e10cSrcweir 		m_pImpl->RemoveElement( pElement );
3506cdf0e10cSrcweir 
3507cdf0e10cSrcweir 		m_pImpl->m_bIsModified = sal_True;
3508cdf0e10cSrcweir 		m_pImpl->m_bBroadcastModified = sal_True;
3509cdf0e10cSrcweir 	}
3510cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3511cdf0e10cSrcweir     {
3512cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3513cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3514cdf0e10cSrcweir         throw;
3515cdf0e10cSrcweir 	}
3516cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3517cdf0e10cSrcweir     {
3518cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3519cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3520cdf0e10cSrcweir         throw;
3521cdf0e10cSrcweir 	}
3522cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3523cdf0e10cSrcweir     {
3524cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3525cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3526cdf0e10cSrcweir         throw;
3527cdf0e10cSrcweir 	}
3528cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
3529cdf0e10cSrcweir     {
3530cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
3531cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3532cdf0e10cSrcweir         throw;
3533cdf0e10cSrcweir 	}
3534cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3535cdf0e10cSrcweir     {
3536cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3537cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3538cdf0e10cSrcweir         throw;
3539cdf0e10cSrcweir 	}
3540cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3541cdf0e10cSrcweir     {
3542cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3543cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3544cdf0e10cSrcweir         throw;
3545cdf0e10cSrcweir 	}
3546cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3547cdf0e10cSrcweir     {
3548cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3549cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3550cdf0e10cSrcweir         throw;
3551cdf0e10cSrcweir 	}
3552cdf0e10cSrcweir 	catch( uno::Exception& aException )
3553cdf0e10cSrcweir 	{
3554cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3555cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3556cdf0e10cSrcweir 
3557cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3558cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't move element!" ) ),
3559cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3560cdf0e10cSrcweir 												 aCaught );
3561cdf0e10cSrcweir 	}
3562cdf0e10cSrcweir 
3563cdf0e10cSrcweir 	aGuard.clear();
3564cdf0e10cSrcweir 
3565cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
3566cdf0e10cSrcweir }
3567cdf0e10cSrcweir 
3568cdf0e10cSrcweir //____________________________________________________________________________________________________
3569cdf0e10cSrcweir //	XStorage2
3570cdf0e10cSrcweir //____________________________________________________________________________________________________
3571cdf0e10cSrcweir 
3572cdf0e10cSrcweir //-----------------------------------------------
openEncryptedStream(const::rtl::OUString & aStreamName,sal_Int32 nOpenMode,const uno::Sequence<beans::NamedValue> & aEncryptionData)3573cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream(
3574cdf0e10cSrcweir 	const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
3575cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3576cdf0e10cSrcweir 				lang::IllegalArgumentException,
3577cdf0e10cSrcweir 				packages::NoEncryptionException,
3578cdf0e10cSrcweir 				packages::WrongPasswordException,
3579cdf0e10cSrcweir 				io::IOException,
3580cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3581cdf0e10cSrcweir 				uno::RuntimeException )
3582cdf0e10cSrcweir {
3583cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStream" );
3584cdf0e10cSrcweir 
3585cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3586cdf0e10cSrcweir 
3587cdf0e10cSrcweir 	if ( !m_pImpl )
3588cdf0e10cSrcweir     {
3589cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3590cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3591cdf0e10cSrcweir     }
3592cdf0e10cSrcweir 
3593cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3594cdf0e10cSrcweir 		packages::NoEncryptionException();
3595cdf0e10cSrcweir 
3596cdf0e10cSrcweir 	if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap )
3597cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
3598cdf0e10cSrcweir 
3599cdf0e10cSrcweir 	if ( !aEncryptionData.getLength() )
3600cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
3601cdf0e10cSrcweir 
3602cdf0e10cSrcweir 	uno::Reference< io::XStream > xResult;
3603cdf0e10cSrcweir 	try
3604cdf0e10cSrcweir 	{
3605cdf0e10cSrcweir     	SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True );
3606cdf0e10cSrcweir 		OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
3607cdf0e10cSrcweir 
3608cdf0e10cSrcweir 		xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_False );
3609cdf0e10cSrcweir 		OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" );
3610cdf0e10cSrcweir 
3611cdf0e10cSrcweir 		if ( m_pData->m_bReadOnlyWrap )
3612cdf0e10cSrcweir 		{
3613cdf0e10cSrcweir 			// before the storage disposes the stream it must deregister itself as listener
3614cdf0e10cSrcweir 			uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY );
3615cdf0e10cSrcweir 			if ( !xStreamComponent.is() )
3616cdf0e10cSrcweir 				throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3617cdf0e10cSrcweir 
3618cdf0e10cSrcweir 			MakeLinkToSubComponent_Impl( xStreamComponent );
3619cdf0e10cSrcweir 		}
3620cdf0e10cSrcweir 	}
3621cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3622cdf0e10cSrcweir     {
3623cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3624cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3625cdf0e10cSrcweir         throw;
3626cdf0e10cSrcweir 	}
3627cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3628cdf0e10cSrcweir     {
3629cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3630cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3631cdf0e10cSrcweir         throw;
3632cdf0e10cSrcweir 	}
3633cdf0e10cSrcweir 	catch( packages::NoEncryptionException& aNoEncryptionException )
3634cdf0e10cSrcweir     {
3635cdf0e10cSrcweir         m_pImpl->AddLog( aNoEncryptionException.Message );
3636cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3637cdf0e10cSrcweir         throw;
3638cdf0e10cSrcweir 	}
3639cdf0e10cSrcweir 	catch( packages::WrongPasswordException& aWrongPasswordException )
3640cdf0e10cSrcweir     {
3641cdf0e10cSrcweir         m_pImpl->AddLog( aWrongPasswordException.Message );
3642cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3643cdf0e10cSrcweir         throw;
3644cdf0e10cSrcweir 	}
3645cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3646cdf0e10cSrcweir     {
3647cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3648cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3649cdf0e10cSrcweir         throw;
3650cdf0e10cSrcweir 	}
3651cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3652cdf0e10cSrcweir     {
3653cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3654cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3655cdf0e10cSrcweir         throw;
3656cdf0e10cSrcweir 	}
3657cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3658cdf0e10cSrcweir     {
3659cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3660cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3661cdf0e10cSrcweir         throw;
3662cdf0e10cSrcweir 	}
3663cdf0e10cSrcweir 	catch( uno::Exception& aException )
3664cdf0e10cSrcweir 	{
3665cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3666cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3667cdf0e10cSrcweir 
3668cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3669cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ),
3670cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3671cdf0e10cSrcweir 												 aCaught );
3672cdf0e10cSrcweir 	}
3673cdf0e10cSrcweir 
3674cdf0e10cSrcweir 	aGuard.clear();
3675cdf0e10cSrcweir 
3676cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
3677cdf0e10cSrcweir 
3678cdf0e10cSrcweir 	return xResult;
3679cdf0e10cSrcweir }
3680cdf0e10cSrcweir 
3681cdf0e10cSrcweir //-----------------------------------------------
cloneEncryptedStream(const::rtl::OUString & aStreamName,const uno::Sequence<beans::NamedValue> & aEncryptionData)3682cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream(
3683cdf0e10cSrcweir 	const ::rtl::OUString& aStreamName,
3684cdf0e10cSrcweir 	const uno::Sequence< beans::NamedValue >& aEncryptionData )
3685cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3686cdf0e10cSrcweir 				lang::IllegalArgumentException,
3687cdf0e10cSrcweir 				packages::NoEncryptionException,
3688cdf0e10cSrcweir 				packages::WrongPasswordException,
3689cdf0e10cSrcweir 				io::IOException,
3690cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3691cdf0e10cSrcweir 				uno::RuntimeException )
3692cdf0e10cSrcweir {
3693cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStream" );
3694cdf0e10cSrcweir 
3695cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3696cdf0e10cSrcweir 
3697cdf0e10cSrcweir 	if ( !m_pImpl )
3698cdf0e10cSrcweir     {
3699cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3700cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3701cdf0e10cSrcweir     }
3702cdf0e10cSrcweir 
3703cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3704cdf0e10cSrcweir 		packages::NoEncryptionException();
3705cdf0e10cSrcweir 
3706cdf0e10cSrcweir 	if ( !aEncryptionData.getLength() )
3707cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
3708cdf0e10cSrcweir 
3709cdf0e10cSrcweir 	try
3710cdf0e10cSrcweir 	{
3711cdf0e10cSrcweir 		uno::Reference< io::XStream > xResult;
3712cdf0e10cSrcweir 		m_pImpl->CloneStreamElement( aStreamName, sal_True, aEncryptionData, xResult );
3713cdf0e10cSrcweir 		if ( !xResult.is() )
3714cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3715cdf0e10cSrcweir 		return xResult;
3716cdf0e10cSrcweir 	}
3717cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3718cdf0e10cSrcweir     {
3719cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3720cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3721cdf0e10cSrcweir         throw;
3722cdf0e10cSrcweir 	}
3723cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3724cdf0e10cSrcweir     {
3725cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3726cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3727cdf0e10cSrcweir         throw;
3728cdf0e10cSrcweir 	}
3729cdf0e10cSrcweir 	catch( packages::NoEncryptionException& aNoEncryptionException )
3730cdf0e10cSrcweir     {
3731cdf0e10cSrcweir         m_pImpl->AddLog( aNoEncryptionException.Message );
3732cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3733cdf0e10cSrcweir         throw;
3734cdf0e10cSrcweir 	}
3735cdf0e10cSrcweir 	catch( packages::WrongPasswordException& aWrongPasswordException )
3736cdf0e10cSrcweir     {
3737cdf0e10cSrcweir         m_pImpl->AddLog( aWrongPasswordException.Message );
3738cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3739cdf0e10cSrcweir         throw;
3740cdf0e10cSrcweir 	}
3741cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3742cdf0e10cSrcweir     {
3743cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3744cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3745cdf0e10cSrcweir         throw;
3746cdf0e10cSrcweir 	}
3747cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3748cdf0e10cSrcweir     {
3749cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3750cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3751cdf0e10cSrcweir         throw;
3752cdf0e10cSrcweir 	}
3753cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3754cdf0e10cSrcweir     {
3755cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3756cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3757cdf0e10cSrcweir         throw;
3758cdf0e10cSrcweir 	}
3759cdf0e10cSrcweir 	catch( uno::Exception& aException )
3760cdf0e10cSrcweir 	{
3761cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3762cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3763cdf0e10cSrcweir 
3764cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3765cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ),
3766cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3767cdf0e10cSrcweir 												 aCaught );
3768cdf0e10cSrcweir 	}
3769cdf0e10cSrcweir }
3770cdf0e10cSrcweir 
3771cdf0e10cSrcweir 
3772cdf0e10cSrcweir //____________________________________________________________________________________________________
3773cdf0e10cSrcweir //	XStorageRawAccess
3774cdf0e10cSrcweir //____________________________________________________________________________________________________
3775cdf0e10cSrcweir 
3776cdf0e10cSrcweir //-----------------------------------------------
getPlainRawStreamElement(const::rtl::OUString & sStreamName)3777cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement(
3778cdf0e10cSrcweir 			const ::rtl::OUString& sStreamName )
3779cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3780cdf0e10cSrcweir 				lang::IllegalArgumentException,
3781cdf0e10cSrcweir 				container::NoSuchElementException,
3782cdf0e10cSrcweir 				io::IOException,
3783cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3784cdf0e10cSrcweir 				uno::RuntimeException )
3785cdf0e10cSrcweir {
3786cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPlainRawStreamElement" );
3787cdf0e10cSrcweir 
3788cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3789cdf0e10cSrcweir 
3790cdf0e10cSrcweir 	if ( !m_pImpl )
3791cdf0e10cSrcweir     {
3792cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3793cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3794cdf0e10cSrcweir     }
3795cdf0e10cSrcweir 
3796cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
3797cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface is not supported and must not be accessible
3798cdf0e10cSrcweir 
3799cdf0e10cSrcweir 	if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) )
3800cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3801cdf0e10cSrcweir 
3802cdf0e10cSrcweir 	uno::Reference < io::XInputStream > xTempIn;
3803cdf0e10cSrcweir 	try
3804cdf0e10cSrcweir 	{
3805cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3806cdf0e10cSrcweir 		if ( !pElement )
3807cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3808cdf0e10cSrcweir 
3809cdf0e10cSrcweir 		if ( !pElement->m_pStream )
3810cdf0e10cSrcweir 		{
3811cdf0e10cSrcweir 			m_pImpl->OpenSubStream( pElement );
3812cdf0e10cSrcweir 			if ( !pElement->m_pStream )
3813cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3814cdf0e10cSrcweir 		}
3815cdf0e10cSrcweir 
3816cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream();
3817cdf0e10cSrcweir 		if ( !xRawInStream.is() )
3818cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3819cdf0e10cSrcweir 
3820cdf0e10cSrcweir 		uno::Reference < io::XOutputStream > xTempOut(
3821cdf0e10cSrcweir 							m_pImpl->GetServiceFactory()->createInstance (
3822cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
3823cdf0e10cSrcweir 							uno::UNO_QUERY );
3824cdf0e10cSrcweir 		xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY );
3825cdf0e10cSrcweir 		uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3826cdf0e10cSrcweir 
3827cdf0e10cSrcweir 		if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3828cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3829cdf0e10cSrcweir 
3830cdf0e10cSrcweir 		// Copy temporary file to a new one
3831cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3832cdf0e10cSrcweir 		xTempOut->closeOutput();
3833cdf0e10cSrcweir 		xSeek->seek( 0 );
3834cdf0e10cSrcweir 	}
3835cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3836cdf0e10cSrcweir     {
3837cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3838cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3839cdf0e10cSrcweir         throw;
3840cdf0e10cSrcweir 	}
3841cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3842cdf0e10cSrcweir     {
3843cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3844cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3845cdf0e10cSrcweir         throw;
3846cdf0e10cSrcweir 	}
3847cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3848cdf0e10cSrcweir     {
3849cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3850cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3851cdf0e10cSrcweir         throw;
3852cdf0e10cSrcweir 	}
3853cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3854cdf0e10cSrcweir     {
3855cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3856cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3857cdf0e10cSrcweir         throw;
3858cdf0e10cSrcweir 	}
3859cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3860cdf0e10cSrcweir     {
3861cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3862cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3863cdf0e10cSrcweir         throw;
3864cdf0e10cSrcweir 	}
3865cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3866cdf0e10cSrcweir     {
3867cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3868cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3869cdf0e10cSrcweir         throw;
3870cdf0e10cSrcweir 	}
3871cdf0e10cSrcweir 	catch( uno::Exception& aException )
3872cdf0e10cSrcweir 	{
3873cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3874cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3875cdf0e10cSrcweir 
3876cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3877cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get plain raw stream!" ) ),
3878cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3879cdf0e10cSrcweir 												 aCaught );
3880cdf0e10cSrcweir 	}
3881cdf0e10cSrcweir 
3882cdf0e10cSrcweir 	return xTempIn;
3883cdf0e10cSrcweir }
3884cdf0e10cSrcweir 
3885cdf0e10cSrcweir //-----------------------------------------------
getRawEncrStreamElement(const::rtl::OUString & sStreamName)3886cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement(
3887cdf0e10cSrcweir 			const ::rtl::OUString& sStreamName )
3888cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
3889cdf0e10cSrcweir 				lang::IllegalArgumentException,
3890cdf0e10cSrcweir 				packages::NoEncryptionException,
3891cdf0e10cSrcweir 				container::NoSuchElementException,
3892cdf0e10cSrcweir 				io::IOException,
3893cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
3894cdf0e10cSrcweir 				uno::RuntimeException )
3895cdf0e10cSrcweir {
3896cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getRawEncrStreamElement" );
3897cdf0e10cSrcweir 
3898cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3899cdf0e10cSrcweir 
3900cdf0e10cSrcweir 	if ( !m_pImpl )
3901cdf0e10cSrcweir     {
3902cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3903cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3904cdf0e10cSrcweir     }
3905cdf0e10cSrcweir 
3906cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
3907cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3908cdf0e10cSrcweir 
3909cdf0e10cSrcweir 	if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) )
3910cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
3911cdf0e10cSrcweir 
3912cdf0e10cSrcweir 	uno::Reference < io::XInputStream > xTempIn;
3913cdf0e10cSrcweir 	try
3914cdf0e10cSrcweir 	{
3915cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName );
3916cdf0e10cSrcweir 		if ( !pElement )
3917cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3918cdf0e10cSrcweir 
3919cdf0e10cSrcweir 		if ( !pElement->m_pStream )
3920cdf0e10cSrcweir 		{
3921cdf0e10cSrcweir 			m_pImpl->OpenSubStream( pElement );
3922cdf0e10cSrcweir 			if ( !pElement->m_pStream )
3923cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3924cdf0e10cSrcweir 		}
3925cdf0e10cSrcweir 
3926cdf0e10cSrcweir 		if ( !pElement->m_pStream->IsEncrypted() )
3927cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3928cdf0e10cSrcweir 
3929cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
3930cdf0e10cSrcweir 		if ( !xRawInStream.is() )
3931cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3932cdf0e10cSrcweir 
3933cdf0e10cSrcweir 		uno::Reference < io::XOutputStream > xTempOut(
3934cdf0e10cSrcweir 							m_pImpl->GetServiceFactory()->createInstance (
3935cdf0e10cSrcweir 									::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
3936cdf0e10cSrcweir 							uno::UNO_QUERY );
3937cdf0e10cSrcweir 		xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY );
3938cdf0e10cSrcweir 		uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY );
3939cdf0e10cSrcweir 
3940cdf0e10cSrcweir 		if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() )
3941cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
3942cdf0e10cSrcweir 
3943cdf0e10cSrcweir 		// Copy temporary file to a new one
3944cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut );
3945cdf0e10cSrcweir 		xTempOut->closeOutput();
3946cdf0e10cSrcweir 		xSeek->seek( 0 );
3947cdf0e10cSrcweir 
3948cdf0e10cSrcweir 	}
3949cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
3950cdf0e10cSrcweir     {
3951cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
3952cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3953cdf0e10cSrcweir         throw;
3954cdf0e10cSrcweir 	}
3955cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
3956cdf0e10cSrcweir     {
3957cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
3958cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3959cdf0e10cSrcweir         throw;
3960cdf0e10cSrcweir 	}
3961cdf0e10cSrcweir 	catch( packages::NoEncryptionException& aNoEncryptionException )
3962cdf0e10cSrcweir     {
3963cdf0e10cSrcweir         m_pImpl->AddLog( aNoEncryptionException.Message );
3964cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3965cdf0e10cSrcweir         throw;
3966cdf0e10cSrcweir 	}
3967cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
3968cdf0e10cSrcweir     {
3969cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
3970cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3971cdf0e10cSrcweir         throw;
3972cdf0e10cSrcweir 	}
3973cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
3974cdf0e10cSrcweir     {
3975cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
3976cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3977cdf0e10cSrcweir         throw;
3978cdf0e10cSrcweir 	}
3979cdf0e10cSrcweir 	catch( io::IOException& aIOException )
3980cdf0e10cSrcweir     {
3981cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
3982cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3983cdf0e10cSrcweir         throw;
3984cdf0e10cSrcweir 	}
3985cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
3986cdf0e10cSrcweir     {
3987cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
3988cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3989cdf0e10cSrcweir         throw;
3990cdf0e10cSrcweir 	}
3991cdf0e10cSrcweir 	catch( uno::Exception& aException )
3992cdf0e10cSrcweir 	{
3993cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
3994cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3995cdf0e10cSrcweir 
3996cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
3997cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get raw stream!" ) ),
3998cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
3999cdf0e10cSrcweir 												 aCaught );
4000cdf0e10cSrcweir 	}
4001cdf0e10cSrcweir 
4002cdf0e10cSrcweir 	return xTempIn;
4003cdf0e10cSrcweir }
4004cdf0e10cSrcweir 
4005cdf0e10cSrcweir //-----------------------------------------------
insertRawEncrStreamElement(const::rtl::OUString & aStreamName,const uno::Reference<io::XInputStream> & xInStream)4006cdf0e10cSrcweir void SAL_CALL OStorage::insertRawEncrStreamElement( const ::rtl::OUString& aStreamName,
4007cdf0e10cSrcweir 								const uno::Reference< io::XInputStream >& xInStream )
4008cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
4009cdf0e10cSrcweir 				lang::IllegalArgumentException,
4010cdf0e10cSrcweir 				packages::NoRawFormatException,
4011cdf0e10cSrcweir 				container::ElementExistException,
4012cdf0e10cSrcweir 				io::IOException,
4013cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
4014cdf0e10cSrcweir 				uno::RuntimeException)
4015cdf0e10cSrcweir {
4016cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertRawEncrStreamElement" );
4017cdf0e10cSrcweir 
4018cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4019cdf0e10cSrcweir 
4020cdf0e10cSrcweir 	if ( !m_pImpl )
4021cdf0e10cSrcweir     {
4022cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4023cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4024cdf0e10cSrcweir     }
4025cdf0e10cSrcweir 
4026cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4027cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4028cdf0e10cSrcweir 
4029cdf0e10cSrcweir 	if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
4030cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
4031cdf0e10cSrcweir 
4032cdf0e10cSrcweir 	if ( !xInStream.is() )
4033cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
4034cdf0e10cSrcweir 
4035cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
4036cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
4037cdf0e10cSrcweir 
4038cdf0e10cSrcweir 	try
4039cdf0e10cSrcweir 	{
4040cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
4041cdf0e10cSrcweir 		if ( pElement )
4042cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4043cdf0e10cSrcweir 
4044cdf0e10cSrcweir 		m_pImpl->InsertRawStream( aStreamName, xInStream );
4045cdf0e10cSrcweir 	}
4046cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
4047cdf0e10cSrcweir     {
4048cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
4049cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4050cdf0e10cSrcweir         throw;
4051cdf0e10cSrcweir 	}
4052cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
4053cdf0e10cSrcweir     {
4054cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
4055cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4056cdf0e10cSrcweir         throw;
4057cdf0e10cSrcweir 	}
4058cdf0e10cSrcweir 	catch( packages::NoRawFormatException& aNoRawFormatException )
4059cdf0e10cSrcweir     {
4060cdf0e10cSrcweir         m_pImpl->AddLog( aNoRawFormatException.Message );
4061cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4062cdf0e10cSrcweir         throw;
4063cdf0e10cSrcweir 	}
4064cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
4065cdf0e10cSrcweir     {
4066cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
4067cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4068cdf0e10cSrcweir         throw;
4069cdf0e10cSrcweir 	}
4070cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4071cdf0e10cSrcweir     {
4072cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4073cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4074cdf0e10cSrcweir         throw;
4075cdf0e10cSrcweir 	}
4076cdf0e10cSrcweir 	catch( io::IOException& aIOException )
4077cdf0e10cSrcweir     {
4078cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
4079cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4080cdf0e10cSrcweir         throw;
4081cdf0e10cSrcweir 	}
4082cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4083cdf0e10cSrcweir     {
4084cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4085cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4086cdf0e10cSrcweir         throw;
4087cdf0e10cSrcweir 	}
4088cdf0e10cSrcweir 	catch( uno::Exception& aException )
4089cdf0e10cSrcweir 	{
4090cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
4091cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4092cdf0e10cSrcweir 
4093cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
4094cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert raw stream!" ) ),
4095cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
4096cdf0e10cSrcweir 												 aCaught );
4097cdf0e10cSrcweir 	}
4098cdf0e10cSrcweir }
4099cdf0e10cSrcweir 
4100cdf0e10cSrcweir //____________________________________________________________________________________________________
4101cdf0e10cSrcweir //	XTransactedObject
4102cdf0e10cSrcweir //____________________________________________________________________________________________________
4103cdf0e10cSrcweir 
4104cdf0e10cSrcweir //-----------------------------------------------
commit()4105cdf0e10cSrcweir void SAL_CALL OStorage::commit()
4106cdf0e10cSrcweir 		throw ( io::IOException,
4107cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
4108cdf0e10cSrcweir 				uno::RuntimeException )
4109cdf0e10cSrcweir {
4110cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::commit" );
4111cdf0e10cSrcweir 
4112cdf0e10cSrcweir 	uno::Reference< util::XModifiable > xParentModif;
4113cdf0e10cSrcweir 
4114cdf0e10cSrcweir 	try {
4115cdf0e10cSrcweir 		BroadcastTransaction( STOR_MESS_PRECOMMIT );
4116cdf0e10cSrcweir 
4117cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4118cdf0e10cSrcweir 
4119cdf0e10cSrcweir 		if ( !m_pImpl )
4120cdf0e10cSrcweir         {
4121cdf0e10cSrcweir             ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4122cdf0e10cSrcweir             throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4123cdf0e10cSrcweir         }
4124cdf0e10cSrcweir 
4125cdf0e10cSrcweir     	if ( m_pData->m_bReadOnlyWrap )
4126cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied
4127cdf0e10cSrcweir 
4128cdf0e10cSrcweir 		m_pImpl->Commit(); // the root storage initiates the storing to source
4129cdf0e10cSrcweir 
4130*30acf5e8Spfg 		// when the storage is committed the parent is modified
4131cdf0e10cSrcweir 		if ( m_pImpl->m_pParent && m_pImpl->m_pParent->m_pAntiImpl )
4132cdf0e10cSrcweir 			xParentModif = (util::XModifiable*)m_pImpl->m_pParent->m_pAntiImpl;
4133cdf0e10cSrcweir 	}
4134cdf0e10cSrcweir 	catch( io::IOException& aIOException )
4135cdf0e10cSrcweir     {
4136cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
4137cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4138cdf0e10cSrcweir         throw;
4139cdf0e10cSrcweir 	}
4140cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4141cdf0e10cSrcweir     {
4142cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4143cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4144cdf0e10cSrcweir         throw;
4145cdf0e10cSrcweir 	}
4146cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4147cdf0e10cSrcweir     {
4148cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4149cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4150cdf0e10cSrcweir         throw;
4151cdf0e10cSrcweir 	}
4152cdf0e10cSrcweir 	catch( uno::Exception& aException )
4153cdf0e10cSrcweir 	{
4154cdf0e10cSrcweir         m_pImpl->AddLog( aException.Message );
4155cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4156cdf0e10cSrcweir 
4157cdf0e10cSrcweir         uno::Any aCaught( ::cppu::getCaughtException() );
4158cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on commit!" ) ),
4159cdf0e10cSrcweir 								  uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
4160cdf0e10cSrcweir 								  aCaught );
4161cdf0e10cSrcweir 	}
4162cdf0e10cSrcweir 
4163cdf0e10cSrcweir 	setModified( sal_False );
4164cdf0e10cSrcweir 	if ( xParentModif.is() )
4165cdf0e10cSrcweir 		xParentModif->setModified( sal_True );
4166cdf0e10cSrcweir 
4167cdf0e10cSrcweir 	BroadcastTransaction( STOR_MESS_COMMITED );
4168cdf0e10cSrcweir }
4169cdf0e10cSrcweir 
4170cdf0e10cSrcweir //-----------------------------------------------
revert()4171cdf0e10cSrcweir void SAL_CALL OStorage::revert()
4172cdf0e10cSrcweir 		throw ( io::IOException,
4173cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
4174cdf0e10cSrcweir 				uno::RuntimeException )
4175cdf0e10cSrcweir {
4176cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::revert" );
4177cdf0e10cSrcweir 
4178cdf0e10cSrcweir 	// the method removes all the changes done after last commit
4179cdf0e10cSrcweir 
4180cdf0e10cSrcweir 	BroadcastTransaction( STOR_MESS_PREREVERT );
4181cdf0e10cSrcweir 
4182cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4183cdf0e10cSrcweir 
4184cdf0e10cSrcweir 	if ( !m_pImpl )
4185cdf0e10cSrcweir     {
4186cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4187cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4188cdf0e10cSrcweir     }
4189cdf0e10cSrcweir 
4190cdf0e10cSrcweir 	for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin();
4191cdf0e10cSrcweir 		  pElementIter != m_pImpl->m_aChildrenList.end(); pElementIter++ )
4192cdf0e10cSrcweir 	{
4193cdf0e10cSrcweir 		if ( ((*pElementIter)->m_pStorage
4194cdf0e10cSrcweir 				&& ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() ))
4195cdf0e10cSrcweir 		  || ((*pElementIter)->m_pStream
4196cdf0e10cSrcweir 		  		&& ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) )
4197cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
4198cdf0e10cSrcweir 	}
4199cdf0e10cSrcweir 
4200cdf0e10cSrcweir 	if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated )
4201cdf0e10cSrcweir 		return; // nothing to do
4202cdf0e10cSrcweir 
4203cdf0e10cSrcweir 	try {
4204cdf0e10cSrcweir 		m_pImpl->Revert();
4205cdf0e10cSrcweir 		m_pImpl->m_bIsModified = sal_False;
4206cdf0e10cSrcweir 		m_pImpl->m_bBroadcastModified = sal_True;
4207cdf0e10cSrcweir 	}
4208cdf0e10cSrcweir 	catch( io::IOException& aIOException )
4209cdf0e10cSrcweir     {
4210cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
4211cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4212cdf0e10cSrcweir         throw;
4213cdf0e10cSrcweir 	}
4214cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
4215cdf0e10cSrcweir     {
4216cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
4217cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4218cdf0e10cSrcweir         throw;
4219cdf0e10cSrcweir 	}
4220cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4221cdf0e10cSrcweir     {
4222cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4223cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4224cdf0e10cSrcweir         throw;
4225cdf0e10cSrcweir 	}
4226cdf0e10cSrcweir 	catch( uno::Exception& aException )
4227cdf0e10cSrcweir 	{
4228cdf0e10cSrcweir         m_pImpl->AddLog( aException.Message );
4229cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4230cdf0e10cSrcweir 
4231cdf0e10cSrcweir         uno::Any aCaught( ::cppu::getCaughtException() );
4232cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on revert!" ) ),
4233cdf0e10cSrcweir 								  uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
4234cdf0e10cSrcweir 								  aCaught );
4235cdf0e10cSrcweir 	}
4236cdf0e10cSrcweir 
4237cdf0e10cSrcweir 	aGuard.clear();
4238cdf0e10cSrcweir 
4239cdf0e10cSrcweir 	setModified( sal_False );
4240cdf0e10cSrcweir 	BroadcastTransaction( STOR_MESS_REVERTED );
4241cdf0e10cSrcweir }
4242cdf0e10cSrcweir 
4243cdf0e10cSrcweir //____________________________________________________________________________________________________
4244cdf0e10cSrcweir //	XTransactionBroadcaster
4245cdf0e10cSrcweir //____________________________________________________________________________________________________
4246cdf0e10cSrcweir 
4247cdf0e10cSrcweir //-----------------------------------------------
addTransactionListener(const uno::Reference<embed::XTransactionListener> & aListener)4248cdf0e10cSrcweir void SAL_CALL OStorage::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4249cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4250cdf0e10cSrcweir {
4251cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4252cdf0e10cSrcweir 
4253cdf0e10cSrcweir 	if ( !m_pImpl )
4254cdf0e10cSrcweir     {
4255cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4256cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4257cdf0e10cSrcweir     }
4258cdf0e10cSrcweir 
4259cdf0e10cSrcweir 	m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
4260cdf0e10cSrcweir 												aListener );
4261cdf0e10cSrcweir }
4262cdf0e10cSrcweir 
4263cdf0e10cSrcweir //-----------------------------------------------
removeTransactionListener(const uno::Reference<embed::XTransactionListener> & aListener)4264cdf0e10cSrcweir void SAL_CALL OStorage::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
4265cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4266cdf0e10cSrcweir {
4267cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4268cdf0e10cSrcweir 
4269cdf0e10cSrcweir 	if ( !m_pImpl )
4270cdf0e10cSrcweir     {
4271cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4272cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4273cdf0e10cSrcweir     }
4274cdf0e10cSrcweir 
4275cdf0e10cSrcweir 	m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
4276cdf0e10cSrcweir 													aListener );
4277cdf0e10cSrcweir }
4278cdf0e10cSrcweir 
4279cdf0e10cSrcweir //____________________________________________________________________________________________________
4280cdf0e10cSrcweir //	XModifiable
4281cdf0e10cSrcweir //  TODO: if there will be no demand on this interface it will be removed from implementation,
4282cdf0e10cSrcweir //		  I do not want to remove it now since it is still possible that it will be inserted
4283cdf0e10cSrcweir //		  to the service back.
4284cdf0e10cSrcweir //____________________________________________________________________________________________________
4285cdf0e10cSrcweir 
4286cdf0e10cSrcweir //-----------------------------------------------
isModified()4287cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::isModified()
4288cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4289cdf0e10cSrcweir {
4290cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4291cdf0e10cSrcweir 
4292cdf0e10cSrcweir 	if ( !m_pImpl )
4293cdf0e10cSrcweir     {
4294cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4295cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4296cdf0e10cSrcweir     }
4297cdf0e10cSrcweir 
4298cdf0e10cSrcweir 	return m_pImpl->m_bIsModified;
4299cdf0e10cSrcweir }
4300cdf0e10cSrcweir 
4301cdf0e10cSrcweir 
4302cdf0e10cSrcweir //-----------------------------------------------
setModified(sal_Bool bModified)4303cdf0e10cSrcweir void SAL_CALL OStorage::setModified( sal_Bool bModified )
4304cdf0e10cSrcweir 		throw ( beans::PropertyVetoException,
4305cdf0e10cSrcweir 				uno::RuntimeException )
4306cdf0e10cSrcweir {
4307cdf0e10cSrcweir 	::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4308cdf0e10cSrcweir 
4309cdf0e10cSrcweir 	if ( !m_pImpl )
4310cdf0e10cSrcweir     {
4311cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4312cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4313cdf0e10cSrcweir     }
4314cdf0e10cSrcweir 
4315cdf0e10cSrcweir 	if ( m_pData->m_bReadOnlyWrap )
4316cdf0e10cSrcweir 		throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
4317cdf0e10cSrcweir 
4318cdf0e10cSrcweir 	if ( m_pImpl->m_bIsModified != bModified )
4319cdf0e10cSrcweir 		m_pImpl->m_bIsModified = bModified;
4320cdf0e10cSrcweir 
4321cdf0e10cSrcweir 	aGuard.clear();
4322cdf0e10cSrcweir 	if ( bModified )
4323cdf0e10cSrcweir 	{
4324cdf0e10cSrcweir 		m_pImpl->m_bBroadcastModified = sal_True;
4325cdf0e10cSrcweir 		BroadcastModifiedIfNecessary();
4326cdf0e10cSrcweir 	}
4327cdf0e10cSrcweir }
4328cdf0e10cSrcweir 
4329cdf0e10cSrcweir //-----------------------------------------------
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)4330cdf0e10cSrcweir void SAL_CALL OStorage::addModifyListener(
4331cdf0e10cSrcweir 			const uno::Reference< util::XModifyListener >& aListener )
4332cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4333cdf0e10cSrcweir {
4334cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4335cdf0e10cSrcweir 
4336cdf0e10cSrcweir 	if ( !m_pImpl )
4337cdf0e10cSrcweir     {
4338cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4339cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4340cdf0e10cSrcweir     }
4341cdf0e10cSrcweir 
4342cdf0e10cSrcweir 	m_pData->m_aListenersContainer.addInterface(
4343cdf0e10cSrcweir 								::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener );
4344cdf0e10cSrcweir }
4345cdf0e10cSrcweir 
4346cdf0e10cSrcweir 
4347cdf0e10cSrcweir //-----------------------------------------------
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)4348cdf0e10cSrcweir void SAL_CALL OStorage::removeModifyListener(
4349cdf0e10cSrcweir 			const uno::Reference< util::XModifyListener >& aListener )
4350cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4351cdf0e10cSrcweir {
4352cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4353cdf0e10cSrcweir 
4354cdf0e10cSrcweir 	if ( !m_pImpl )
4355cdf0e10cSrcweir     {
4356cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4357cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4358cdf0e10cSrcweir     }
4359cdf0e10cSrcweir 
4360cdf0e10cSrcweir 	m_pData->m_aListenersContainer.removeInterface(
4361cdf0e10cSrcweir 								::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener );
4362cdf0e10cSrcweir }
4363cdf0e10cSrcweir 
4364cdf0e10cSrcweir //____________________________________________________________________________________________________
4365cdf0e10cSrcweir //	XNameAccess
4366cdf0e10cSrcweir //____________________________________________________________________________________________________
4367cdf0e10cSrcweir 
4368cdf0e10cSrcweir //-----------------------------------------------
getByName(const::rtl::OUString & aName)4369cdf0e10cSrcweir uno::Any SAL_CALL OStorage::getByName( const ::rtl::OUString& aName )
4370cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
4371cdf0e10cSrcweir 				lang::WrappedTargetException,
4372cdf0e10cSrcweir 				uno::RuntimeException )
4373cdf0e10cSrcweir {
4374cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getByName" );
4375cdf0e10cSrcweir 
4376cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4377cdf0e10cSrcweir 
4378cdf0e10cSrcweir 	if ( !m_pImpl )
4379cdf0e10cSrcweir     {
4380cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4381cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4382cdf0e10cSrcweir     }
4383cdf0e10cSrcweir 
4384cdf0e10cSrcweir 	if ( !aName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_False ) )
4385cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
4386cdf0e10cSrcweir 
4387cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
4388cdf0e10cSrcweir 	  && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
4389cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name
4390cdf0e10cSrcweir 
4391cdf0e10cSrcweir 	uno::Any aResult;
4392cdf0e10cSrcweir 	try
4393cdf0e10cSrcweir 	{
4394cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aName );
4395cdf0e10cSrcweir 		if ( !pElement )
4396cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4397cdf0e10cSrcweir 
4398cdf0e10cSrcweir 		if ( pElement->m_bIsStorage )
4399cdf0e10cSrcweir 			aResult <<= openStorageElement( aName, embed::ElementModes::READ );
4400cdf0e10cSrcweir 		else
4401cdf0e10cSrcweir 			aResult <<= openStreamElement( aName, embed::ElementModes::READ );
4402cdf0e10cSrcweir 	}
4403cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
4404cdf0e10cSrcweir     {
4405cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
4406cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4407cdf0e10cSrcweir         throw;
4408cdf0e10cSrcweir 	}
4409cdf0e10cSrcweir 	catch( lang::WrappedTargetException& aWrappedTargetException )
4410cdf0e10cSrcweir     {
4411cdf0e10cSrcweir         m_pImpl->AddLog( aWrappedTargetException.Message );
4412cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4413cdf0e10cSrcweir         throw;
4414cdf0e10cSrcweir 	}
4415cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4416cdf0e10cSrcweir     {
4417cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4418cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4419cdf0e10cSrcweir         throw;
4420cdf0e10cSrcweir 	}
4421cdf0e10cSrcweir 	catch ( uno::Exception& aException )
4422cdf0e10cSrcweir 	{
4423cdf0e10cSrcweir    		m_pImpl->AddLog( aException.Message );
4424cdf0e10cSrcweir    		m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4425cdf0e10cSrcweir 
4426cdf0e10cSrcweir    		uno::Any aCaught( ::cppu::getCaughtException() );
4427cdf0e10cSrcweir 		throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4428cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4429cdf0e10cSrcweir 																				uno::UNO_QUERY ),
4430cdf0e10cSrcweir 											aCaught );
4431cdf0e10cSrcweir 	}
4432cdf0e10cSrcweir 
4433cdf0e10cSrcweir 	return aResult;
4434cdf0e10cSrcweir }
4435cdf0e10cSrcweir 
4436cdf0e10cSrcweir 
4437cdf0e10cSrcweir //-----------------------------------------------
getElementNames()4438cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OStorage::getElementNames()
4439cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4440cdf0e10cSrcweir {
4441cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementNames" );
4442cdf0e10cSrcweir 
4443cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4444cdf0e10cSrcweir 
4445cdf0e10cSrcweir 	if ( !m_pImpl )
4446cdf0e10cSrcweir     {
4447cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4448cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4449cdf0e10cSrcweir     }
4450cdf0e10cSrcweir 
4451cdf0e10cSrcweir 	try
4452cdf0e10cSrcweir 	{
4453cdf0e10cSrcweir 		return m_pImpl->GetElementNames();
4454cdf0e10cSrcweir 	}
4455cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4456cdf0e10cSrcweir     {
4457cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4458cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4459cdf0e10cSrcweir         throw;
4460cdf0e10cSrcweir 	}
4461cdf0e10cSrcweir 	catch ( uno::Exception& aException )
4462cdf0e10cSrcweir 	{
4463cdf0e10cSrcweir    		m_pImpl->AddLog( aException.Message );
4464cdf0e10cSrcweir    		m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4465cdf0e10cSrcweir 
4466cdf0e10cSrcweir    		uno::Any aCaught( ::cppu::getCaughtException() );
4467cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4468cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4469cdf0e10cSrcweir 																				uno::UNO_QUERY ),
4470cdf0e10cSrcweir 											aCaught );
4471cdf0e10cSrcweir 	}
4472cdf0e10cSrcweir }
4473cdf0e10cSrcweir 
4474cdf0e10cSrcweir 
4475cdf0e10cSrcweir //-----------------------------------------------
hasByName(const::rtl::OUString & aName)4476cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::hasByName( const ::rtl::OUString& aName )
4477cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4478cdf0e10cSrcweir {
4479cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasByName" );
4480cdf0e10cSrcweir 
4481cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4482cdf0e10cSrcweir 
4483cdf0e10cSrcweir 	if ( !m_pImpl )
4484cdf0e10cSrcweir     {
4485cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4486cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4487cdf0e10cSrcweir     }
4488cdf0e10cSrcweir 
4489cdf0e10cSrcweir 	if ( !aName.getLength() )
4490cdf0e10cSrcweir 		return sal_False;
4491cdf0e10cSrcweir 
4492cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
4493cdf0e10cSrcweir 	  && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
4494cdf0e10cSrcweir 		return sal_False;
4495cdf0e10cSrcweir 
4496cdf0e10cSrcweir 	SotElement_Impl* pElement = NULL;
4497cdf0e10cSrcweir 	try
4498cdf0e10cSrcweir 	{
4499cdf0e10cSrcweir 		pElement = m_pImpl->FindElement( aName );
4500cdf0e10cSrcweir 	}
4501cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4502cdf0e10cSrcweir     {
4503cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4504cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4505cdf0e10cSrcweir         throw;
4506cdf0e10cSrcweir 	}
4507cdf0e10cSrcweir 	catch ( uno::Exception& aException )
4508cdf0e10cSrcweir 	{
4509cdf0e10cSrcweir    		m_pImpl->AddLog( aException.Message );
4510cdf0e10cSrcweir    		m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4511cdf0e10cSrcweir 
4512cdf0e10cSrcweir    		uno::Any aCaught( ::cppu::getCaughtException() );
4513cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4514cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4515cdf0e10cSrcweir 																				uno::UNO_QUERY ),
4516cdf0e10cSrcweir 											aCaught );
4517cdf0e10cSrcweir 	}
4518cdf0e10cSrcweir 
4519cdf0e10cSrcweir 	return ( pElement != NULL );
4520cdf0e10cSrcweir }
4521cdf0e10cSrcweir 
4522cdf0e10cSrcweir 
4523cdf0e10cSrcweir //-----------------------------------------------
getElementType()4524cdf0e10cSrcweir uno::Type SAL_CALL OStorage::getElementType()
4525cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4526cdf0e10cSrcweir {
4527cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4528cdf0e10cSrcweir 
4529cdf0e10cSrcweir 	if ( !m_pImpl )
4530cdf0e10cSrcweir     {
4531cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4532cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4533cdf0e10cSrcweir     }
4534cdf0e10cSrcweir 
4535cdf0e10cSrcweir 	// it is a multitype container
4536cdf0e10cSrcweir 	return uno::Type();
4537cdf0e10cSrcweir }
4538cdf0e10cSrcweir 
4539cdf0e10cSrcweir 
4540cdf0e10cSrcweir //-----------------------------------------------
hasElements()4541cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::hasElements()
4542cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4543cdf0e10cSrcweir {
4544cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasElements" );
4545cdf0e10cSrcweir 
4546cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4547cdf0e10cSrcweir 
4548cdf0e10cSrcweir 	if ( !m_pImpl )
4549cdf0e10cSrcweir     {
4550cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4551cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4552cdf0e10cSrcweir     }
4553cdf0e10cSrcweir 
4554cdf0e10cSrcweir 	try
4555cdf0e10cSrcweir 	{
4556cdf0e10cSrcweir 		return ( m_pImpl->GetChildrenList().size() != 0 );
4557cdf0e10cSrcweir 	}
4558cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4559cdf0e10cSrcweir     {
4560cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4561cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4562cdf0e10cSrcweir         throw;
4563cdf0e10cSrcweir 	}
4564cdf0e10cSrcweir 	catch ( uno::Exception& aException )
4565cdf0e10cSrcweir 	{
4566cdf0e10cSrcweir    		m_pImpl->AddLog( aException.Message );
4567cdf0e10cSrcweir    		m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4568cdf0e10cSrcweir 
4569cdf0e10cSrcweir    		uno::Any aCaught( ::cppu::getCaughtException() );
4570cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4571cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4572cdf0e10cSrcweir 																				uno::UNO_QUERY ),
4573cdf0e10cSrcweir 											aCaught );
4574cdf0e10cSrcweir 	}
4575cdf0e10cSrcweir }
4576cdf0e10cSrcweir 
4577cdf0e10cSrcweir 
4578cdf0e10cSrcweir //____________________________________________________________________________________________________
4579cdf0e10cSrcweir //	XComponent
4580cdf0e10cSrcweir //____________________________________________________________________________________________________
4581cdf0e10cSrcweir 
4582cdf0e10cSrcweir //-----------------------------------------------
dispose()4583cdf0e10cSrcweir void SAL_CALL OStorage::dispose()
4584cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4585cdf0e10cSrcweir {
4586cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4587cdf0e10cSrcweir 
4588cdf0e10cSrcweir 	if ( !m_pImpl )
4589cdf0e10cSrcweir     {
4590cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4591cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4592cdf0e10cSrcweir     }
4593cdf0e10cSrcweir 
4594cdf0e10cSrcweir 	try
4595cdf0e10cSrcweir 	{
4596cdf0e10cSrcweir 		InternalDispose( sal_True );
4597cdf0e10cSrcweir 	}
4598cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
4599cdf0e10cSrcweir     {
4600cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
4601cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4602cdf0e10cSrcweir         throw;
4603cdf0e10cSrcweir 	}
4604cdf0e10cSrcweir 	catch ( uno::Exception& aException )
4605cdf0e10cSrcweir 	{
4606cdf0e10cSrcweir    		m_pImpl->AddLog( aException.Message );
4607cdf0e10cSrcweir    		m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4608cdf0e10cSrcweir 
4609cdf0e10cSrcweir    		uno::Any aCaught( ::cppu::getCaughtException() );
4610cdf0e10cSrcweir 		throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ),
4611cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4612cdf0e10cSrcweir 																				uno::UNO_QUERY ),
4613cdf0e10cSrcweir 											aCaught );
4614cdf0e10cSrcweir 	}
4615cdf0e10cSrcweir }
4616cdf0e10cSrcweir 
4617cdf0e10cSrcweir //-----------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)4618cdf0e10cSrcweir void SAL_CALL OStorage::addEventListener(
4619cdf0e10cSrcweir 			const uno::Reference< lang::XEventListener >& xListener )
4620cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4621cdf0e10cSrcweir {
4622cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4623cdf0e10cSrcweir 
4624cdf0e10cSrcweir 	if ( !m_pImpl )
4625cdf0e10cSrcweir     {
4626cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4627cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4628cdf0e10cSrcweir     }
4629cdf0e10cSrcweir 
4630cdf0e10cSrcweir 	m_pData->m_aListenersContainer.addInterface(
4631cdf0e10cSrcweir 								::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener );
4632cdf0e10cSrcweir }
4633cdf0e10cSrcweir 
4634cdf0e10cSrcweir //-----------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)4635cdf0e10cSrcweir void SAL_CALL OStorage::removeEventListener(
4636cdf0e10cSrcweir 			const uno::Reference< lang::XEventListener >& xListener )
4637cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4638cdf0e10cSrcweir {
4639cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4640cdf0e10cSrcweir 
4641cdf0e10cSrcweir 	if ( !m_pImpl )
4642cdf0e10cSrcweir     {
4643cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4644cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4645cdf0e10cSrcweir     }
4646cdf0e10cSrcweir 
4647cdf0e10cSrcweir 	m_pData->m_aListenersContainer.removeInterface(
4648cdf0e10cSrcweir 								::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener );
4649cdf0e10cSrcweir }
4650cdf0e10cSrcweir 
4651cdf0e10cSrcweir //____________________________________________________________________________________________________
4652cdf0e10cSrcweir //	XEncryptionProtectedSource
4653cdf0e10cSrcweir //____________________________________________________________________________________________________
4654cdf0e10cSrcweir 
setEncryptionPassword(const::rtl::OUString & aPass)4655cdf0e10cSrcweir void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass )
4656cdf0e10cSrcweir 	throw ( uno::RuntimeException,
4657cdf0e10cSrcweir 			io::IOException )
4658cdf0e10cSrcweir {
4659cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" );
4660cdf0e10cSrcweir     setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
4661cdf0e10cSrcweir }
4662cdf0e10cSrcweir 
4663cdf0e10cSrcweir //-----------------------------------------------
removeEncryption()4664cdf0e10cSrcweir void SAL_CALL OStorage::removeEncryption()
4665cdf0e10cSrcweir 	throw ( uno::RuntimeException,
4666cdf0e10cSrcweir 			io::IOException )
4667cdf0e10cSrcweir {
4668cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" );
4669cdf0e10cSrcweir 
4670cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4671cdf0e10cSrcweir 
4672cdf0e10cSrcweir 	if ( !m_pImpl )
4673cdf0e10cSrcweir     {
4674cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4675cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4676cdf0e10cSrcweir     }
4677cdf0e10cSrcweir 
4678cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4679cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4680cdf0e10cSrcweir 
4681cdf0e10cSrcweir 	OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" );
4682cdf0e10cSrcweir 	if ( m_pData->m_bIsRoot )
4683cdf0e10cSrcweir 	{
4684cdf0e10cSrcweir 		try {
4685cdf0e10cSrcweir 			m_pImpl->ReadContents();
4686cdf0e10cSrcweir 		}
4687cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4688cdf0e10cSrcweir         {
4689cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4690cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4691cdf0e10cSrcweir             throw;
4692cdf0e10cSrcweir 		}
4693cdf0e10cSrcweir 		catch ( uno::Exception& aException )
4694cdf0e10cSrcweir         {
4695cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4696cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4697cdf0e10cSrcweir 
4698cdf0e10cSrcweir         	uno::Any aCaught( ::cppu::getCaughtException() );
4699cdf0e10cSrcweir 			throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4700cdf0e10cSrcweir 												uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4701cdf0e10cSrcweir 																					uno::UNO_QUERY ),
4702cdf0e10cSrcweir 												aCaught );
4703cdf0e10cSrcweir 		}
4704cdf0e10cSrcweir 
4705cdf0e10cSrcweir 		// TODO: check if the password is valid
4706cdf0e10cSrcweir 		// update all streams that was encrypted with old password
4707cdf0e10cSrcweir 
4708cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4709cdf0e10cSrcweir 		try
4710cdf0e10cSrcweir 		{
4711cdf0e10cSrcweir 			xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
4712cdf0e10cSrcweir 											uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
4713cdf0e10cSrcweir 
4714cdf0e10cSrcweir 			m_pImpl->m_bHasCommonEncryptionData = sal_False;
4715cdf0e10cSrcweir 			m_pImpl->m_aCommonEncryptionData.clear();
4716cdf0e10cSrcweir 		}
4717cdf0e10cSrcweir         catch( uno::RuntimeException& aRException )
4718cdf0e10cSrcweir         {
4719cdf0e10cSrcweir             m_pImpl->AddLog( aRException.Message );
4720cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4721cdf0e10cSrcweir 
4722cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" );
4723cdf0e10cSrcweir 			throw;
4724cdf0e10cSrcweir         }
4725cdf0e10cSrcweir 		catch( uno::Exception& aException )
4726cdf0e10cSrcweir 		{
4727cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4728cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4729cdf0e10cSrcweir 
4730cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" );
4731cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4732cdf0e10cSrcweir 		}
4733cdf0e10cSrcweir 	}
4734cdf0e10cSrcweir }
4735cdf0e10cSrcweir 
4736cdf0e10cSrcweir //____________________________________________________________________________________________________
4737cdf0e10cSrcweir //	XEncryptionProtectedSource2
4738cdf0e10cSrcweir //____________________________________________________________________________________________________
4739cdf0e10cSrcweir 
setEncryptionData(const uno::Sequence<beans::NamedValue> & aEncryptionData)4740cdf0e10cSrcweir void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
4741cdf0e10cSrcweir     throw ( io::IOException,
4742cdf0e10cSrcweir             uno::RuntimeException )
4743cdf0e10cSrcweir {
4744cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionData" );
4745cdf0e10cSrcweir 
4746cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4747cdf0e10cSrcweir 
4748cdf0e10cSrcweir 	if ( !m_pImpl )
4749cdf0e10cSrcweir     {
4750cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4751cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4752cdf0e10cSrcweir     }
4753cdf0e10cSrcweir 
4754cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4755cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4756cdf0e10cSrcweir 
4757cdf0e10cSrcweir     if ( !aEncryptionData.getLength() )
4758cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption data!") ), uno::Reference< uno::XInterface >() );
4759cdf0e10cSrcweir 
4760cdf0e10cSrcweir 	OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionData() method is not available for nonroot storages!\n" );
4761cdf0e10cSrcweir 	if ( m_pData->m_bIsRoot )
4762cdf0e10cSrcweir 	{
4763cdf0e10cSrcweir 		try {
4764cdf0e10cSrcweir 			m_pImpl->ReadContents();
4765cdf0e10cSrcweir 		}
4766cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4767cdf0e10cSrcweir         {
4768cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4769cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4770cdf0e10cSrcweir             throw;
4771cdf0e10cSrcweir 		}
4772cdf0e10cSrcweir 		catch ( uno::Exception& aException )
4773cdf0e10cSrcweir         {
4774cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4775cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4776cdf0e10cSrcweir 
4777cdf0e10cSrcweir         	uno::Any aCaught( ::cppu::getCaughtException() );
4778cdf0e10cSrcweir 			throw lang::WrappedTargetRuntimeException(
4779cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4780cdf0e10cSrcweir 								uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ), uno::UNO_QUERY ),
4781cdf0e10cSrcweir 								aCaught );
4782cdf0e10cSrcweir 		}
4783cdf0e10cSrcweir 
4784cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4785cdf0e10cSrcweir 		try
4786cdf0e10cSrcweir 		{
4787cdf0e10cSrcweir             ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData );
4788cdf0e10cSrcweir 			xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
4789cdf0e10cSrcweir 											uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) );
4790cdf0e10cSrcweir 
4791cdf0e10cSrcweir 			m_pImpl->m_bHasCommonEncryptionData = sal_True;
4792cdf0e10cSrcweir 			m_pImpl->m_aCommonEncryptionData = aEncryptionMap;
4793cdf0e10cSrcweir 		}
4794cdf0e10cSrcweir 		catch( uno::Exception& aException )
4795cdf0e10cSrcweir 		{
4796cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4797cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4798cdf0e10cSrcweir 
4799cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4800cdf0e10cSrcweir 		}
4801cdf0e10cSrcweir 	}
4802cdf0e10cSrcweir }
4803cdf0e10cSrcweir 
4804cdf0e10cSrcweir //____________________________________________________________________________________________________
4805cdf0e10cSrcweir //	XEncryptionProtectedStorage
4806cdf0e10cSrcweir //____________________________________________________________________________________________________
4807cdf0e10cSrcweir 
4808cdf0e10cSrcweir //-----------------------------------------------
setEncryptionAlgorithms(const uno::Sequence<beans::NamedValue> & aAlgorithms)4809cdf0e10cSrcweir void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms )
4810cdf0e10cSrcweir     throw (lang::IllegalArgumentException, uno::RuntimeException)
4811cdf0e10cSrcweir {
4812cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" );
4813cdf0e10cSrcweir 
4814cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4815cdf0e10cSrcweir 
4816cdf0e10cSrcweir 	if ( !m_pImpl )
4817cdf0e10cSrcweir     {
4818cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4819cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4820cdf0e10cSrcweir     }
4821cdf0e10cSrcweir 
4822cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4823cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4824cdf0e10cSrcweir 
4825cdf0e10cSrcweir     if ( !aAlgorithms.getLength() )
4826cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() );
4827cdf0e10cSrcweir 
4828cdf0e10cSrcweir 	OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" );
4829cdf0e10cSrcweir 	if ( m_pData->m_bIsRoot )
4830cdf0e10cSrcweir 	{
4831cdf0e10cSrcweir 		try {
4832cdf0e10cSrcweir 			m_pImpl->ReadContents();
4833cdf0e10cSrcweir 		}
4834cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4835cdf0e10cSrcweir         {
4836cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4837cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4838cdf0e10cSrcweir             throw;
4839cdf0e10cSrcweir 		}
4840cdf0e10cSrcweir 		catch ( uno::Exception& aException )
4841cdf0e10cSrcweir         {
4842cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4843cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4844cdf0e10cSrcweir 
4845cdf0e10cSrcweir         	uno::Any aCaught( ::cppu::getCaughtException() );
4846cdf0e10cSrcweir 			throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4847cdf0e10cSrcweir 												uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4848cdf0e10cSrcweir 																					uno::UNO_QUERY ),
4849cdf0e10cSrcweir 												aCaught );
4850cdf0e10cSrcweir 		}
4851cdf0e10cSrcweir 
4852cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4853cdf0e10cSrcweir 		try
4854cdf0e10cSrcweir 		{
4855cdf0e10cSrcweir 			xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ),
4856cdf0e10cSrcweir 											uno::makeAny( aAlgorithms ) );
4857cdf0e10cSrcweir 		}
4858cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4859cdf0e10cSrcweir         {
4860cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4861cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4862cdf0e10cSrcweir             throw;
4863cdf0e10cSrcweir 		}
4864cdf0e10cSrcweir         catch( lang::IllegalArgumentException& aIAException )
4865cdf0e10cSrcweir         {
4866cdf0e10cSrcweir             m_pImpl->AddLog( aIAException.Message );
4867cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4868cdf0e10cSrcweir 
4869cdf0e10cSrcweir             throw;
4870cdf0e10cSrcweir         }
4871cdf0e10cSrcweir 		catch( uno::Exception& aException )
4872cdf0e10cSrcweir 		{
4873cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4874cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4875cdf0e10cSrcweir 
4876cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4877cdf0e10cSrcweir 		}
4878cdf0e10cSrcweir     }
4879cdf0e10cSrcweir }
4880cdf0e10cSrcweir 
4881cdf0e10cSrcweir //-----------------------------------------------
getEncryptionAlgorithms()4882cdf0e10cSrcweir uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms()
4883cdf0e10cSrcweir     throw (uno::RuntimeException)
4884cdf0e10cSrcweir {
4885cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getEncryptionAlgorithms" );
4886cdf0e10cSrcweir 
4887cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4888cdf0e10cSrcweir 
4889cdf0e10cSrcweir 	if ( !m_pImpl )
4890cdf0e10cSrcweir     {
4891cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4892cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4893cdf0e10cSrcweir     }
4894cdf0e10cSrcweir 
4895cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
4896cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage
4897cdf0e10cSrcweir 
4898cdf0e10cSrcweir     uno::Sequence< beans::NamedValue > aResult;
4899cdf0e10cSrcweir 	OSL_ENSURE( m_pData->m_bIsRoot, "getEncryptionAlgorithms() method is not available for nonroot storages!\n" );
4900cdf0e10cSrcweir 	if ( m_pData->m_bIsRoot )
4901cdf0e10cSrcweir 	{
4902cdf0e10cSrcweir 		try {
4903cdf0e10cSrcweir 			m_pImpl->ReadContents();
4904cdf0e10cSrcweir 		}
4905cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4906cdf0e10cSrcweir         {
4907cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4908cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4909cdf0e10cSrcweir             throw;
4910cdf0e10cSrcweir 		}
4911cdf0e10cSrcweir 		catch ( uno::Exception& aException )
4912cdf0e10cSrcweir         {
4913cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4914cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4915cdf0e10cSrcweir 
4916cdf0e10cSrcweir         	uno::Any aCaught( ::cppu::getCaughtException() );
4917cdf0e10cSrcweir 			throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
4918cdf0e10cSrcweir 												uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
4919cdf0e10cSrcweir 																					uno::UNO_QUERY ),
4920cdf0e10cSrcweir 												aCaught );
4921cdf0e10cSrcweir 		}
4922cdf0e10cSrcweir 
4923cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW );
4924cdf0e10cSrcweir 		try
4925cdf0e10cSrcweir 		{
4926cdf0e10cSrcweir 			xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) >>= aResult;
4927cdf0e10cSrcweir 		}
4928cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
4929cdf0e10cSrcweir         {
4930cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
4931cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4932cdf0e10cSrcweir             throw;
4933cdf0e10cSrcweir 		}
4934cdf0e10cSrcweir 		catch( uno::Exception& aException )
4935cdf0e10cSrcweir 		{
4936cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
4937cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
4938cdf0e10cSrcweir 
4939cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4940cdf0e10cSrcweir 		}
4941cdf0e10cSrcweir     }
4942cdf0e10cSrcweir 
4943cdf0e10cSrcweir     return aResult;
4944cdf0e10cSrcweir }
4945cdf0e10cSrcweir 
4946cdf0e10cSrcweir 
4947cdf0e10cSrcweir //____________________________________________________________________________________________________
4948cdf0e10cSrcweir //	XPropertySet
4949cdf0e10cSrcweir //____________________________________________________________________________________________________
4950cdf0e10cSrcweir 
4951cdf0e10cSrcweir //-----------------------------------------------
getPropertySetInfo()4952cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL OStorage::getPropertySetInfo()
4953cdf0e10cSrcweir 		throw ( uno::RuntimeException )
4954cdf0e10cSrcweir {
4955cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4956cdf0e10cSrcweir 
4957cdf0e10cSrcweir 	if ( !m_pImpl )
4958cdf0e10cSrcweir     {
4959cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4960cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4961cdf0e10cSrcweir     }
4962cdf0e10cSrcweir 
4963cdf0e10cSrcweir 	//TODO:
4964cdf0e10cSrcweir 	return uno::Reference< beans::XPropertySetInfo >();
4965cdf0e10cSrcweir }
4966cdf0e10cSrcweir 
4967cdf0e10cSrcweir 
4968cdf0e10cSrcweir //-----------------------------------------------
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aValue)4969cdf0e10cSrcweir void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue )
4970cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
4971cdf0e10cSrcweir 				beans::PropertyVetoException,
4972cdf0e10cSrcweir 				lang::IllegalArgumentException,
4973cdf0e10cSrcweir 				lang::WrappedTargetException,
4974cdf0e10cSrcweir 				uno::RuntimeException )
4975cdf0e10cSrcweir {
4976cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setPropertyValue" );
4977cdf0e10cSrcweir 
4978cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
4979cdf0e10cSrcweir 
4980cdf0e10cSrcweir 	if ( !m_pImpl )
4981cdf0e10cSrcweir     {
4982cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
4983cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4984cdf0e10cSrcweir     }
4985cdf0e10cSrcweir 
4986cdf0e10cSrcweir 	//TODO: think about interaction handler
4987cdf0e10cSrcweir 
4988cdf0e10cSrcweir     // WORKAROUND:
4989cdf0e10cSrcweir     // The old document might have no version in the manifest.xml, so we have to allow to set the version
4990cdf0e10cSrcweir     // even for readonly storages, so that the version from content.xml can be used.
4991cdf0e10cSrcweir 	if ( m_pData->m_bReadOnlyWrap && !aPropertyName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) )
4992cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied
4993cdf0e10cSrcweir 
4994cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
4995cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
4996cdf0e10cSrcweir 	else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
4997cdf0e10cSrcweir 	{
4998cdf0e10cSrcweir 		if ( aPropertyName.equalsAscii( "MediaType" ) )
4999cdf0e10cSrcweir 		{
5000cdf0e10cSrcweir 			aValue >>= m_pImpl->m_aMediaType;
5001cdf0e10cSrcweir 			m_pImpl->m_bControlMediaType = sal_True;
5002cdf0e10cSrcweir 
5003cdf0e10cSrcweir             m_pImpl->m_bBroadcastModified = sal_True;
5004cdf0e10cSrcweir             m_pImpl->m_bIsModified = sal_True;
5005cdf0e10cSrcweir 		}
5006cdf0e10cSrcweir 		else if ( aPropertyName.equalsAscii( "Version" ) )
5007cdf0e10cSrcweir 		{
5008cdf0e10cSrcweir 			aValue >>= m_pImpl->m_aVersion;
5009cdf0e10cSrcweir 			m_pImpl->m_bControlVersion = sal_True;
5010cdf0e10cSrcweir 
5011cdf0e10cSrcweir             // this property can be set even for readonly storage
5012cdf0e10cSrcweir             if ( !m_pData->m_bReadOnlyWrap )
5013cdf0e10cSrcweir             {
5014cdf0e10cSrcweir                 m_pImpl->m_bBroadcastModified = sal_True;
5015cdf0e10cSrcweir                 m_pImpl->m_bIsModified = sal_True;
5016cdf0e10cSrcweir             }
5017cdf0e10cSrcweir 		}
5018cdf0e10cSrcweir 		else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY )
5019cdf0e10cSrcweir 									|| aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY )
5020cdf0e10cSrcweir 									|| aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY )
5021cdf0e10cSrcweir 									|| aPropertyName.equalsAscii( "URL" )
5022cdf0e10cSrcweir 									|| aPropertyName.equalsAscii( "RepairPackage" ) ) )
5023cdf0e10cSrcweir 		   || aPropertyName.equalsAscii( "IsRoot" )
5024cdf0e10cSrcweir 		   || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) )
5025cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5026cdf0e10cSrcweir 		else
5027cdf0e10cSrcweir 			throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5028cdf0e10cSrcweir 	}
5029cdf0e10cSrcweir 	else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
5030cdf0e10cSrcweir 	{
5031cdf0e10cSrcweir 		if ( aPropertyName.equalsAscii( "RelationsInfoStream" ) )
5032cdf0e10cSrcweir 		{
5033cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xInRelStream;
5034cdf0e10cSrcweir 			if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
5035cdf0e10cSrcweir 			{
5036cdf0e10cSrcweir 				uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
5037cdf0e10cSrcweir 				if ( !xSeek.is() )
5038cdf0e10cSrcweir 				{
5039cdf0e10cSrcweir 					// currently this is an internal property that is used for optimization
5040cdf0e10cSrcweir 					// and the stream must support XSeekable interface
5041cdf0e10cSrcweir 					// TODO/LATER: in future it can be changed if property is used from outside
5042cdf0e10cSrcweir 					throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5043cdf0e10cSrcweir 				}
5044cdf0e10cSrcweir 
5045cdf0e10cSrcweir 				m_pImpl->m_xNewRelInfoStream = xInRelStream;
5046cdf0e10cSrcweir 				m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
5047cdf0e10cSrcweir 				m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
5048cdf0e10cSrcweir 				m_pImpl->m_bBroadcastModified = sal_True;
5049cdf0e10cSrcweir 				m_pImpl->m_bIsModified = sal_True;
5050cdf0e10cSrcweir 			}
5051cdf0e10cSrcweir 			else
5052cdf0e10cSrcweir 				throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5053cdf0e10cSrcweir 		}
5054cdf0e10cSrcweir 		else if ( aPropertyName.equalsAscii( "RelationsInfo" ) )
5055cdf0e10cSrcweir 		{
5056cdf0e10cSrcweir 			if ( aValue >>= m_pImpl->m_aRelInfo )
5057cdf0e10cSrcweir 			{
5058cdf0e10cSrcweir 				m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5059cdf0e10cSrcweir 				m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5060cdf0e10cSrcweir 				m_pImpl->m_bBroadcastModified = sal_True;
5061cdf0e10cSrcweir 				m_pImpl->m_bIsModified = sal_True;
5062cdf0e10cSrcweir 			}
5063cdf0e10cSrcweir 			else
5064cdf0e10cSrcweir 				throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5065cdf0e10cSrcweir 		}
5066cdf0e10cSrcweir 		else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "URL" )
5067cdf0e10cSrcweir 									|| aPropertyName.equalsAscii( "RepairPackage" ) ) )
5068cdf0e10cSrcweir 		   || aPropertyName.equalsAscii( "IsRoot" ) )
5069cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5070cdf0e10cSrcweir 		else
5071cdf0e10cSrcweir 			throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5072cdf0e10cSrcweir 	}
5073cdf0e10cSrcweir 	else
5074cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5075cdf0e10cSrcweir 
5076cdf0e10cSrcweir 	BroadcastModifiedIfNecessary();
5077cdf0e10cSrcweir }
5078cdf0e10cSrcweir 
5079cdf0e10cSrcweir 
5080cdf0e10cSrcweir //-----------------------------------------------
getPropertyValue(const::rtl::OUString & aPropertyName)5081cdf0e10cSrcweir uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyName )
5082cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
5083cdf0e10cSrcweir 				lang::WrappedTargetException,
5084cdf0e10cSrcweir 				uno::RuntimeException )
5085cdf0e10cSrcweir {
5086cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPropertyValue" );
5087cdf0e10cSrcweir 
5088cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5089cdf0e10cSrcweir 
5090cdf0e10cSrcweir 	if ( !m_pImpl )
5091cdf0e10cSrcweir     {
5092cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5093cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5094cdf0e10cSrcweir     }
5095cdf0e10cSrcweir 
5096cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
5097cdf0e10cSrcweir 	  && ( aPropertyName.equalsAscii( "MediaType" )
5098cdf0e10cSrcweir         || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY )
5099cdf0e10cSrcweir 	    || aPropertyName.equalsAscii( "Version" ) ) )
5100cdf0e10cSrcweir 	{
5101cdf0e10cSrcweir 		try
5102cdf0e10cSrcweir 		{
5103cdf0e10cSrcweir 			m_pImpl->ReadContents();
5104cdf0e10cSrcweir 		}
5105cdf0e10cSrcweir 		catch ( uno::RuntimeException& aRuntimeException )
5106cdf0e10cSrcweir         {
5107cdf0e10cSrcweir             m_pImpl->AddLog( aRuntimeException.Message );
5108cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5109cdf0e10cSrcweir             throw;
5110cdf0e10cSrcweir 		}
5111cdf0e10cSrcweir 		catch ( uno::Exception& aException )
5112cdf0e10cSrcweir         {
5113cdf0e10cSrcweir             m_pImpl->AddLog( aException.Message );
5114cdf0e10cSrcweir             m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5115cdf0e10cSrcweir 
5116cdf0e10cSrcweir         	uno::Any aCaught( ::cppu::getCaughtException() );
5117cdf0e10cSrcweir 			throw lang::WrappedTargetException(
5118cdf0e10cSrcweir 										::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't read contents!" ) ),
5119cdf0e10cSrcweir 										uno::Reference< XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ),
5120cdf0e10cSrcweir 										aCaught );
5121cdf0e10cSrcweir 		}
5122cdf0e10cSrcweir 
5123cdf0e10cSrcweir 		if ( aPropertyName.equalsAscii( "MediaType" ) )
5124cdf0e10cSrcweir 			return uno::makeAny( m_pImpl->m_aMediaType );
5125cdf0e10cSrcweir 		else if ( aPropertyName.equalsAscii( "Version" ) )
5126cdf0e10cSrcweir 			return uno::makeAny( m_pImpl->m_aVersion );
5127cdf0e10cSrcweir 		else
5128cdf0e10cSrcweir 			return uno::makeAny( m_pImpl->m_bMTFallbackUsed );
5129cdf0e10cSrcweir 	}
5130cdf0e10cSrcweir 	else if ( aPropertyName.equalsAscii( "IsRoot" ) )
5131cdf0e10cSrcweir 	{
5132cdf0e10cSrcweir 		return uno::makeAny( m_pData->m_bIsRoot );
5133cdf0e10cSrcweir 	}
5134cdf0e10cSrcweir 	else if ( aPropertyName.equalsAscii( "OpenMode" ) )
5135cdf0e10cSrcweir 	{
5136cdf0e10cSrcweir 		return uno::makeAny( m_pImpl->m_nStorageMode );
5137cdf0e10cSrcweir 	}
5138cdf0e10cSrcweir 	else if ( m_pData->m_bIsRoot )
5139cdf0e10cSrcweir 	{
5140cdf0e10cSrcweir 		if ( aPropertyName.equalsAscii( "URL" )
5141cdf0e10cSrcweir 		  || aPropertyName.equalsAscii( "RepairPackage" ) )
5142cdf0e10cSrcweir 		{
5143cdf0e10cSrcweir 			for ( sal_Int32 aInd = 0; aInd < m_pImpl->m_xProperties.getLength(); aInd++ )
5144cdf0e10cSrcweir 			{
5145cdf0e10cSrcweir 				if ( m_pImpl->m_xProperties[aInd].Name.equals( aPropertyName ) )
5146cdf0e10cSrcweir 					return m_pImpl->m_xProperties[aInd].Value;
5147cdf0e10cSrcweir 			}
5148cdf0e10cSrcweir 
5149cdf0e10cSrcweir 			if ( aPropertyName.equalsAscii( "URL" ) )
5150cdf0e10cSrcweir 				return uno::makeAny( ::rtl::OUString() );
5151cdf0e10cSrcweir 
5152cdf0e10cSrcweir 			return uno::makeAny( sal_False ); // RepairPackage
5153cdf0e10cSrcweir 		}
5154cdf0e10cSrcweir         else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
5155cdf0e10cSrcweir           && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY )
5156cdf0e10cSrcweir             || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY )
5157cdf0e10cSrcweir             || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) ) )
5158cdf0e10cSrcweir 		{
5159cdf0e10cSrcweir 			try {
5160cdf0e10cSrcweir 				m_pImpl->ReadContents();
5161cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY );
5162cdf0e10cSrcweir 				if ( !xPackPropSet.is() )
5163cdf0e10cSrcweir 					throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5164cdf0e10cSrcweir 
5165cdf0e10cSrcweir 				return xPackPropSet->getPropertyValue( aPropertyName );
5166cdf0e10cSrcweir 			}
5167cdf0e10cSrcweir 			catch ( uno::RuntimeException& aRuntimeException )
5168cdf0e10cSrcweir             {
5169cdf0e10cSrcweir                 m_pImpl->AddLog( aRuntimeException.Message );
5170cdf0e10cSrcweir                 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5171cdf0e10cSrcweir                 throw;
5172cdf0e10cSrcweir 			}
5173cdf0e10cSrcweir 			catch ( uno::Exception& aException )
5174cdf0e10cSrcweir             {
5175cdf0e10cSrcweir                 m_pImpl->AddLog( aException.Message );
5176cdf0e10cSrcweir                 m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5177cdf0e10cSrcweir 
5178cdf0e10cSrcweir         		uno::Any aCaught( ::cppu::getCaughtException() );
5179cdf0e10cSrcweir 				throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ),
5180cdf0e10cSrcweir 													uno::Reference< uno::XInterface >(  static_cast< OWeakObject* >( this ),
5181cdf0e10cSrcweir 																						uno::UNO_QUERY ),
5182cdf0e10cSrcweir 													aCaught );
5183cdf0e10cSrcweir 			}
5184cdf0e10cSrcweir 		}
5185cdf0e10cSrcweir 	}
5186cdf0e10cSrcweir 
5187cdf0e10cSrcweir 	throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5188cdf0e10cSrcweir }
5189cdf0e10cSrcweir 
5190cdf0e10cSrcweir 
5191cdf0e10cSrcweir //-----------------------------------------------
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)5192cdf0e10cSrcweir void SAL_CALL OStorage::addPropertyChangeListener(
5193cdf0e10cSrcweir     const ::rtl::OUString& /*aPropertyName*/,
5194cdf0e10cSrcweir     const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
5195cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
5196cdf0e10cSrcweir 				lang::WrappedTargetException,
5197cdf0e10cSrcweir 				uno::RuntimeException )
5198cdf0e10cSrcweir {
5199cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5200cdf0e10cSrcweir 
5201cdf0e10cSrcweir 	if ( !m_pImpl )
5202cdf0e10cSrcweir     {
5203cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5204cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5205cdf0e10cSrcweir     }
5206cdf0e10cSrcweir 
5207cdf0e10cSrcweir 	//TODO:
5208cdf0e10cSrcweir }
5209cdf0e10cSrcweir 
5210cdf0e10cSrcweir 
5211cdf0e10cSrcweir //-----------------------------------------------
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)5212cdf0e10cSrcweir void SAL_CALL OStorage::removePropertyChangeListener(
5213cdf0e10cSrcweir     const ::rtl::OUString& /*aPropertyName*/,
5214cdf0e10cSrcweir     const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
5215cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
5216cdf0e10cSrcweir 				lang::WrappedTargetException,
5217cdf0e10cSrcweir 				uno::RuntimeException )
5218cdf0e10cSrcweir {
5219cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5220cdf0e10cSrcweir 
5221cdf0e10cSrcweir 	if ( !m_pImpl )
5222cdf0e10cSrcweir     {
5223cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5224cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5225cdf0e10cSrcweir     }
5226cdf0e10cSrcweir 
5227cdf0e10cSrcweir 	//TODO:
5228cdf0e10cSrcweir }
5229cdf0e10cSrcweir 
5230cdf0e10cSrcweir 
5231cdf0e10cSrcweir //-----------------------------------------------
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)5232cdf0e10cSrcweir void SAL_CALL OStorage::addVetoableChangeListener(
5233cdf0e10cSrcweir     const ::rtl::OUString& /*PropertyName*/,
5234cdf0e10cSrcweir     const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
5235cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
5236cdf0e10cSrcweir 				lang::WrappedTargetException,
5237cdf0e10cSrcweir 				uno::RuntimeException )
5238cdf0e10cSrcweir {
5239cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5240cdf0e10cSrcweir 
5241cdf0e10cSrcweir 	if ( !m_pImpl )
5242cdf0e10cSrcweir     {
5243cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5244cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5245cdf0e10cSrcweir     }
5246cdf0e10cSrcweir 
5247cdf0e10cSrcweir 	//TODO:
5248cdf0e10cSrcweir }
5249cdf0e10cSrcweir 
5250cdf0e10cSrcweir 
5251cdf0e10cSrcweir //-----------------------------------------------
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)5252cdf0e10cSrcweir void SAL_CALL OStorage::removeVetoableChangeListener(
5253cdf0e10cSrcweir     const ::rtl::OUString& /*PropertyName*/,
5254cdf0e10cSrcweir     const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
5255cdf0e10cSrcweir 		throw ( beans::UnknownPropertyException,
5256cdf0e10cSrcweir 				lang::WrappedTargetException,
5257cdf0e10cSrcweir 				uno::RuntimeException )
5258cdf0e10cSrcweir {
5259cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5260cdf0e10cSrcweir 
5261cdf0e10cSrcweir 	if ( !m_pImpl )
5262cdf0e10cSrcweir     {
5263cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5264cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5265cdf0e10cSrcweir     }
5266cdf0e10cSrcweir 
5267cdf0e10cSrcweir 	//TODO:
5268cdf0e10cSrcweir }
5269cdf0e10cSrcweir 
5270cdf0e10cSrcweir //____________________________________________________________________________________________________
5271cdf0e10cSrcweir //	XRelationshipAccess
5272cdf0e10cSrcweir //____________________________________________________________________________________________________
5273cdf0e10cSrcweir 
5274cdf0e10cSrcweir // TODO/LATER: the storage and stream implementations of this interface are very similar, they could use a helper class
5275cdf0e10cSrcweir 
5276cdf0e10cSrcweir //-----------------------------------------------
hasByID(const::rtl::OUString & sID)5277cdf0e10cSrcweir sal_Bool SAL_CALL OStorage::hasByID(  const ::rtl::OUString& sID )
5278cdf0e10cSrcweir 		throw ( io::IOException,
5279cdf0e10cSrcweir 				uno::RuntimeException )
5280cdf0e10cSrcweir {
5281cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5282cdf0e10cSrcweir 
5283cdf0e10cSrcweir 	if ( !m_pImpl )
5284cdf0e10cSrcweir     {
5285cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5286cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5287cdf0e10cSrcweir     }
5288cdf0e10cSrcweir 
5289cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5290cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5291cdf0e10cSrcweir 
5292cdf0e10cSrcweir 	try
5293cdf0e10cSrcweir 	{
5294cdf0e10cSrcweir 		getRelationshipByID( sID );
5295cdf0e10cSrcweir 		return sal_True;
5296cdf0e10cSrcweir 	}
5297cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
5298cdf0e10cSrcweir 	{
5299cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
5300cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
5301cdf0e10cSrcweir     }
5302cdf0e10cSrcweir 
5303cdf0e10cSrcweir 	return sal_False;
5304cdf0e10cSrcweir }
5305cdf0e10cSrcweir 
5306cdf0e10cSrcweir //-----------------------------------------------
getTargetByID(const::rtl::OUString & sID)5307cdf0e10cSrcweir ::rtl::OUString SAL_CALL OStorage::getTargetByID(  const ::rtl::OUString& sID  )
5308cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
5309cdf0e10cSrcweir 				io::IOException,
5310cdf0e10cSrcweir 				uno::RuntimeException )
5311cdf0e10cSrcweir {
5312cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5313cdf0e10cSrcweir 
5314cdf0e10cSrcweir 	if ( !m_pImpl )
5315cdf0e10cSrcweir     {
5316cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5317cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5318cdf0e10cSrcweir     }
5319cdf0e10cSrcweir 
5320cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5321cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5322cdf0e10cSrcweir 
5323cdf0e10cSrcweir 	uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5324cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5325cdf0e10cSrcweir 		if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) )
5326cdf0e10cSrcweir 			return aSeq[nInd].Second;
5327cdf0e10cSrcweir 
5328cdf0e10cSrcweir 	return ::rtl::OUString();
5329cdf0e10cSrcweir }
5330cdf0e10cSrcweir 
5331cdf0e10cSrcweir //-----------------------------------------------
getTypeByID(const::rtl::OUString & sID)5332cdf0e10cSrcweir ::rtl::OUString SAL_CALL OStorage::getTypeByID(  const ::rtl::OUString& sID  )
5333cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
5334cdf0e10cSrcweir 				io::IOException,
5335cdf0e10cSrcweir 				uno::RuntimeException )
5336cdf0e10cSrcweir {
5337cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5338cdf0e10cSrcweir 
5339cdf0e10cSrcweir 	if ( !m_pImpl )
5340cdf0e10cSrcweir     {
5341cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5342cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5343cdf0e10cSrcweir     }
5344cdf0e10cSrcweir 
5345cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5346cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5347cdf0e10cSrcweir 
5348cdf0e10cSrcweir 	uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
5349cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
5350cdf0e10cSrcweir 		if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) )
5351cdf0e10cSrcweir 			return aSeq[nInd].Second;
5352cdf0e10cSrcweir 
5353cdf0e10cSrcweir 	return ::rtl::OUString();
5354cdf0e10cSrcweir }
5355cdf0e10cSrcweir 
5356cdf0e10cSrcweir //-----------------------------------------------
getRelationshipByID(const::rtl::OUString & sID)5357cdf0e10cSrcweir uno::Sequence< beans::StringPair > SAL_CALL OStorage::getRelationshipByID(  const ::rtl::OUString& sID  )
5358cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
5359cdf0e10cSrcweir 				io::IOException,
5360cdf0e10cSrcweir 				uno::RuntimeException )
5361cdf0e10cSrcweir {
5362cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5363cdf0e10cSrcweir 
5364cdf0e10cSrcweir 	if ( !m_pImpl )
5365cdf0e10cSrcweir     {
5366cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5367cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5368cdf0e10cSrcweir     }
5369cdf0e10cSrcweir 
5370cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5371cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5372cdf0e10cSrcweir 
5373cdf0e10cSrcweir 	// TODO/LATER: in future the unification of the ID could be checked
5374cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5375cdf0e10cSrcweir 	for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5376cdf0e10cSrcweir 		for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5377cdf0e10cSrcweir 			if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) )
5378cdf0e10cSrcweir 			{
5379cdf0e10cSrcweir 				if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5380cdf0e10cSrcweir 					return aSeq[nInd1];
5381cdf0e10cSrcweir 				break;
5382cdf0e10cSrcweir 			}
5383cdf0e10cSrcweir 
5384cdf0e10cSrcweir 	throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5385cdf0e10cSrcweir }
5386cdf0e10cSrcweir 
5387cdf0e10cSrcweir //-----------------------------------------------
getRelationshipsByType(const::rtl::OUString & sType)5388cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getRelationshipsByType(  const ::rtl::OUString& sType  )
5389cdf0e10cSrcweir 		throw ( io::IOException,
5390cdf0e10cSrcweir 				uno::RuntimeException )
5391cdf0e10cSrcweir {
5392cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5393cdf0e10cSrcweir 
5394cdf0e10cSrcweir 	if ( !m_pImpl )
5395cdf0e10cSrcweir     {
5396cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5397cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5398cdf0e10cSrcweir     }
5399cdf0e10cSrcweir 
5400cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5401cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5402cdf0e10cSrcweir 
5403cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aResult;
5404cdf0e10cSrcweir 	sal_Int32 nEntriesNum = 0;
5405cdf0e10cSrcweir 
5406cdf0e10cSrcweir 	// TODO/LATER: in future the unification of the ID could be checked
5407cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5408cdf0e10cSrcweir 	for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5409cdf0e10cSrcweir 		for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5410cdf0e10cSrcweir 			if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) )
5411cdf0e10cSrcweir 			{
5412cdf0e10cSrcweir                 // the type is usually an URL, so the check should be case insensitive
5413cdf0e10cSrcweir 				if ( aSeq[nInd1][nInd2].Second.equalsIgnoreAsciiCase( sType ) )
5414cdf0e10cSrcweir 				{
5415cdf0e10cSrcweir 					aResult.realloc( ++nEntriesNum );
5416cdf0e10cSrcweir 					aResult[nEntriesNum-1] = aSeq[nInd1];
5417cdf0e10cSrcweir 				}
5418cdf0e10cSrcweir 				break;
5419cdf0e10cSrcweir 			}
5420cdf0e10cSrcweir 
5421cdf0e10cSrcweir 	return aResult;
5422cdf0e10cSrcweir }
5423cdf0e10cSrcweir 
5424cdf0e10cSrcweir //-----------------------------------------------
getAllRelationships()5425cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getAllRelationships()
5426cdf0e10cSrcweir 		throw (io::IOException, uno::RuntimeException)
5427cdf0e10cSrcweir {
5428cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5429cdf0e10cSrcweir 
5430cdf0e10cSrcweir 	if ( !m_pImpl )
5431cdf0e10cSrcweir     {
5432cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5433cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5434cdf0e10cSrcweir     }
5435cdf0e10cSrcweir 
5436cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5437cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5438cdf0e10cSrcweir 
5439cdf0e10cSrcweir 	return m_pImpl->GetAllRelationshipsIfAny();
5440cdf0e10cSrcweir }
5441cdf0e10cSrcweir 
5442cdf0e10cSrcweir //-----------------------------------------------
insertRelationshipByID(const::rtl::OUString & sID,const uno::Sequence<beans::StringPair> & aEntry,::sal_Bool bReplace)5443cdf0e10cSrcweir void SAL_CALL OStorage::insertRelationshipByID(  const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace  )
5444cdf0e10cSrcweir 		throw ( container::ElementExistException,
5445cdf0e10cSrcweir 				io::IOException,
5446cdf0e10cSrcweir 				uno::RuntimeException )
5447cdf0e10cSrcweir {
5448cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5449cdf0e10cSrcweir 
5450cdf0e10cSrcweir 	if ( !m_pImpl )
5451cdf0e10cSrcweir     {
5452cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5453cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5454cdf0e10cSrcweir     }
5455cdf0e10cSrcweir 
5456cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5457cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5458cdf0e10cSrcweir 
5459cdf0e10cSrcweir 	::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
5460cdf0e10cSrcweir 
5461cdf0e10cSrcweir 	sal_Int32 nIDInd = -1;
5462cdf0e10cSrcweir 
5463cdf0e10cSrcweir 	// TODO/LATER: in future the unification of the ID could be checked
5464cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5465cdf0e10cSrcweir 	for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5466cdf0e10cSrcweir 		for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5467cdf0e10cSrcweir 			if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) )
5468cdf0e10cSrcweir 			{
5469cdf0e10cSrcweir 				if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5470cdf0e10cSrcweir 					nIDInd = nInd1;
5471cdf0e10cSrcweir 
5472cdf0e10cSrcweir 				break;
5473cdf0e10cSrcweir 			}
5474cdf0e10cSrcweir 
5475cdf0e10cSrcweir 	if ( nIDInd == -1 || bReplace )
5476cdf0e10cSrcweir 	{
5477cdf0e10cSrcweir 		if ( nIDInd == -1 )
5478cdf0e10cSrcweir 		{
5479cdf0e10cSrcweir 			nIDInd = aSeq.getLength();
5480cdf0e10cSrcweir 			aSeq.realloc( nIDInd + 1 );
5481cdf0e10cSrcweir 		}
5482cdf0e10cSrcweir 
5483cdf0e10cSrcweir 		aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
5484cdf0e10cSrcweir 
5485cdf0e10cSrcweir 		aSeq[nIDInd][0].First = aIDTag;
5486cdf0e10cSrcweir 		aSeq[nIDInd][0].Second = sID;
5487cdf0e10cSrcweir 		sal_Int32 nIndTarget = 1;
5488cdf0e10cSrcweir 		for ( sal_Int32 nIndOrig = 0;
5489cdf0e10cSrcweir 			  nIndOrig < aEntry.getLength();
5490cdf0e10cSrcweir 			  nIndOrig++ )
5491cdf0e10cSrcweir 		{
5492cdf0e10cSrcweir 			if ( !aEntry[nIndOrig].First.equals( aIDTag ) )
5493cdf0e10cSrcweir 				aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
5494cdf0e10cSrcweir 		}
5495cdf0e10cSrcweir 
5496cdf0e10cSrcweir 		aSeq[nIDInd].realloc( nIndTarget );
5497cdf0e10cSrcweir 	}
5498cdf0e10cSrcweir 	else
5499cdf0e10cSrcweir 		throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5500cdf0e10cSrcweir 
5501cdf0e10cSrcweir 
5502cdf0e10cSrcweir 	m_pImpl->m_aRelInfo = aSeq;
5503cdf0e10cSrcweir 	m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5504cdf0e10cSrcweir 	m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5505cdf0e10cSrcweir }
5506cdf0e10cSrcweir 
5507cdf0e10cSrcweir //-----------------------------------------------
removeRelationshipByID(const::rtl::OUString & sID)5508cdf0e10cSrcweir void SAL_CALL OStorage::removeRelationshipByID(  const ::rtl::OUString& sID  )
5509cdf0e10cSrcweir 		throw ( container::NoSuchElementException,
5510cdf0e10cSrcweir 				io::IOException,
5511cdf0e10cSrcweir 				uno::RuntimeException )
5512cdf0e10cSrcweir {
5513cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5514cdf0e10cSrcweir 
5515cdf0e10cSrcweir 	if ( !m_pImpl )
5516cdf0e10cSrcweir     {
5517cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5518cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5519cdf0e10cSrcweir     }
5520cdf0e10cSrcweir 
5521cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5522cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5523cdf0e10cSrcweir 
5524cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5525cdf0e10cSrcweir 	for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
5526cdf0e10cSrcweir 		for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
5527cdf0e10cSrcweir 			if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) )
5528cdf0e10cSrcweir 			{
5529cdf0e10cSrcweir 				if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
5530cdf0e10cSrcweir 				{
5531cdf0e10cSrcweir 					sal_Int32 nLength = aSeq.getLength();
5532cdf0e10cSrcweir 					aSeq[nInd1] = aSeq[nLength-1];
5533cdf0e10cSrcweir 					aSeq.realloc( nLength - 1 );
5534cdf0e10cSrcweir 
5535cdf0e10cSrcweir 					m_pImpl->m_aRelInfo = aSeq;
5536cdf0e10cSrcweir 					m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5537cdf0e10cSrcweir 					m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5538cdf0e10cSrcweir 
5539cdf0e10cSrcweir 					// TODO/LATER: in future the unification of the ID could be checked
5540cdf0e10cSrcweir 					return;
5541cdf0e10cSrcweir 				}
5542cdf0e10cSrcweir 
5543cdf0e10cSrcweir 				break;
5544cdf0e10cSrcweir 			}
5545cdf0e10cSrcweir 
5546cdf0e10cSrcweir 	throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5547cdf0e10cSrcweir }
5548cdf0e10cSrcweir 
5549cdf0e10cSrcweir //-----------------------------------------------
insertRelationships(const uno::Sequence<uno::Sequence<beans::StringPair>> & aEntries,::sal_Bool bReplace)5550cdf0e10cSrcweir void SAL_CALL OStorage::insertRelationships(  const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace  )
5551cdf0e10cSrcweir 		throw ( container::ElementExistException,
5552cdf0e10cSrcweir 				io::IOException,
5553cdf0e10cSrcweir 				uno::RuntimeException )
5554cdf0e10cSrcweir {
5555cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5556cdf0e10cSrcweir 
5557cdf0e10cSrcweir 	if ( !m_pImpl )
5558cdf0e10cSrcweir     {
5559cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5560cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5561cdf0e10cSrcweir     }
5562cdf0e10cSrcweir 
5563cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5564cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5565cdf0e10cSrcweir 
5566cdf0e10cSrcweir 	::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
5567cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
5568cdf0e10cSrcweir 	uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() );
5569cdf0e10cSrcweir 	sal_Int32 nResultInd = 0;
5570cdf0e10cSrcweir 
5571cdf0e10cSrcweir 	for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ )
5572cdf0e10cSrcweir 		for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ )
5573cdf0e10cSrcweir 			if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) )
5574cdf0e10cSrcweir 			{
5575cdf0e10cSrcweir 				sal_Int32 nIndSourceSame = -1;
5576cdf0e10cSrcweir 
5577cdf0e10cSrcweir 				for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5578cdf0e10cSrcweir 					for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5579cdf0e10cSrcweir 					{
5580cdf0e10cSrcweir 						if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5581cdf0e10cSrcweir 						{
5582cdf0e10cSrcweir 							if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) )
5583cdf0e10cSrcweir 							{
5584cdf0e10cSrcweir 								if ( !bReplace )
5585cdf0e10cSrcweir 									throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5586cdf0e10cSrcweir 
5587cdf0e10cSrcweir 								nIndSourceSame = nIndSource1;
5588cdf0e10cSrcweir 							}
5589cdf0e10cSrcweir 
5590cdf0e10cSrcweir 							break;
5591cdf0e10cSrcweir 						}
5592cdf0e10cSrcweir 					}
5593cdf0e10cSrcweir 
5594cdf0e10cSrcweir 				if ( nIndSourceSame == -1 )
5595cdf0e10cSrcweir 				{
5596cdf0e10cSrcweir 					// no such element in the provided sequence
5597cdf0e10cSrcweir 					aResultSeq[nResultInd++] = aSeq[nIndTarget1];
5598cdf0e10cSrcweir 				}
5599cdf0e10cSrcweir 
5600cdf0e10cSrcweir 				break;
5601cdf0e10cSrcweir 			}
5602cdf0e10cSrcweir 
5603cdf0e10cSrcweir 	for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
5604cdf0e10cSrcweir 	{
5605cdf0e10cSrcweir 		aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() );
5606cdf0e10cSrcweir 		sal_Bool bHasID = sal_False;
5607cdf0e10cSrcweir 		sal_Int32 nResInd2 = 1;
5608cdf0e10cSrcweir 
5609cdf0e10cSrcweir 		for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
5610cdf0e10cSrcweir 			if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
5611cdf0e10cSrcweir 			{
5612cdf0e10cSrcweir 				aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2];
5613cdf0e10cSrcweir 				bHasID = sal_True;
5614cdf0e10cSrcweir 			}
5615cdf0e10cSrcweir 			else if ( nResInd2 < aResultSeq[nResultInd].getLength() )
5616cdf0e10cSrcweir 				aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2];
5617cdf0e10cSrcweir 			else
5618cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relation ( no ID )
5619cdf0e10cSrcweir 
5620cdf0e10cSrcweir 		if ( !bHasID )
5621cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relations
5622cdf0e10cSrcweir 
5623cdf0e10cSrcweir 		nResultInd++;
5624cdf0e10cSrcweir 	}
5625cdf0e10cSrcweir 
5626cdf0e10cSrcweir 	aResultSeq.realloc( nResultInd );
5627cdf0e10cSrcweir 	m_pImpl->m_aRelInfo = aResultSeq;
5628cdf0e10cSrcweir 	m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5629cdf0e10cSrcweir 	m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5630cdf0e10cSrcweir }
5631cdf0e10cSrcweir 
5632cdf0e10cSrcweir //-----------------------------------------------
clearRelationships()5633cdf0e10cSrcweir void SAL_CALL OStorage::clearRelationships()
5634cdf0e10cSrcweir 		throw ( io::IOException,
5635cdf0e10cSrcweir 				uno::RuntimeException )
5636cdf0e10cSrcweir {
5637cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5638cdf0e10cSrcweir 
5639cdf0e10cSrcweir 	if ( !m_pImpl )
5640cdf0e10cSrcweir     {
5641cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5642cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5643cdf0e10cSrcweir     }
5644cdf0e10cSrcweir 
5645cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
5646cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5647cdf0e10cSrcweir 
5648cdf0e10cSrcweir 	m_pImpl->m_aRelInfo.realloc( 0 );
5649cdf0e10cSrcweir 	m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
5650cdf0e10cSrcweir 	m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
5651cdf0e10cSrcweir }
5652cdf0e10cSrcweir 
5653cdf0e10cSrcweir //____________________________________________________________________________________________________
5654cdf0e10cSrcweir //	XOptimizedStorage
5655cdf0e10cSrcweir //____________________________________________________________________________________________________
5656cdf0e10cSrcweir //-----------------------------------------------
insertRawNonEncrStreamElementDirect(const::rtl::OUString &,const uno::Reference<io::XInputStream> &)5657cdf0e10cSrcweir void SAL_CALL OStorage::insertRawNonEncrStreamElementDirect(
5658cdf0e10cSrcweir 			const ::rtl::OUString& /*sStreamName*/,
5659cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& /*xInStream*/ )
5660cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
5661cdf0e10cSrcweir 				lang::IllegalArgumentException,
5662cdf0e10cSrcweir 				packages::NoRawFormatException,
5663cdf0e10cSrcweir 				container::ElementExistException,
5664cdf0e10cSrcweir 				io::IOException,
5665cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
5666cdf0e10cSrcweir 				uno::RuntimeException )
5667cdf0e10cSrcweir {
5668cdf0e10cSrcweir 	// not implemented currently because there is still no demand
5669cdf0e10cSrcweir 	// might need to be implemented if direct copying of compressed streams is used
5670cdf0e10cSrcweir 	throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5671cdf0e10cSrcweir }
5672cdf0e10cSrcweir 
5673cdf0e10cSrcweir //-----------------------------------------------
insertStreamElementDirect(const::rtl::OUString & aStreamName,const uno::Reference<io::XInputStream> & xInStream,const uno::Sequence<beans::PropertyValue> & aProps)5674cdf0e10cSrcweir void SAL_CALL OStorage::insertStreamElementDirect(
5675cdf0e10cSrcweir 			const ::rtl::OUString& aStreamName,
5676cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& xInStream,
5677cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& aProps )
5678cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
5679cdf0e10cSrcweir 				lang::IllegalArgumentException,
5680cdf0e10cSrcweir 				container::ElementExistException,
5681cdf0e10cSrcweir 				io::IOException,
5682cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
5683cdf0e10cSrcweir 				uno::RuntimeException )
5684cdf0e10cSrcweir {
5685cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertStreamElementDirect" );
5686cdf0e10cSrcweir 
5687cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5688cdf0e10cSrcweir 
5689cdf0e10cSrcweir 	if ( !m_pImpl )
5690cdf0e10cSrcweir     {
5691cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5692cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5693cdf0e10cSrcweir     }
5694cdf0e10cSrcweir 
5695cdf0e10cSrcweir 	if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
5696cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5697cdf0e10cSrcweir 
5698cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
5699cdf0e10cSrcweir 	  && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
5700cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name
5701cdf0e10cSrcweir 
5702cdf0e10cSrcweir 	if ( m_pData->m_bReadOnlyWrap )
5703cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied
5704cdf0e10cSrcweir 
5705cdf0e10cSrcweir 	try
5706cdf0e10cSrcweir 	{
5707cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName );
5708cdf0e10cSrcweir 
5709cdf0e10cSrcweir 		if ( pElement )
5710cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5711cdf0e10cSrcweir 
5712cdf0e10cSrcweir     	pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, sal_False );
5713cdf0e10cSrcweir 		OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
5714cdf0e10cSrcweir 
5715cdf0e10cSrcweir 		pElement->m_pStream->InsertStreamDirectly( xInStream, aProps );
5716cdf0e10cSrcweir 	}
5717cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
5718cdf0e10cSrcweir     {
5719cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
5720cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5721cdf0e10cSrcweir         throw;
5722cdf0e10cSrcweir 	}
5723cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
5724cdf0e10cSrcweir     {
5725cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
5726cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5727cdf0e10cSrcweir         throw;
5728cdf0e10cSrcweir 	}
5729cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
5730cdf0e10cSrcweir     {
5731cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
5732cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5733cdf0e10cSrcweir         throw;
5734cdf0e10cSrcweir 	}
5735cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5736cdf0e10cSrcweir     {
5737cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5738cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5739cdf0e10cSrcweir         throw;
5740cdf0e10cSrcweir 	}
5741cdf0e10cSrcweir 	catch( io::IOException& aIOException )
5742cdf0e10cSrcweir     {
5743cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
5744cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5745cdf0e10cSrcweir         throw;
5746cdf0e10cSrcweir 	}
5747cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
5748cdf0e10cSrcweir     {
5749cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
5750cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5751cdf0e10cSrcweir         throw;
5752cdf0e10cSrcweir 	}
5753cdf0e10cSrcweir 	catch( uno::Exception& aException )
5754cdf0e10cSrcweir 	{
5755cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
5756cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5757cdf0e10cSrcweir 
5758cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
5759cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert stream directly!" ) ),
5760cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
5761cdf0e10cSrcweir 												 aCaught );
5762cdf0e10cSrcweir 	}
5763cdf0e10cSrcweir }
5764cdf0e10cSrcweir 
5765cdf0e10cSrcweir //-----------------------------------------------
copyElementDirectlyTo(const::rtl::OUString & aElementName,const uno::Reference<embed::XOptimizedStorage> & xDest,const::rtl::OUString & aNewName)5766cdf0e10cSrcweir void SAL_CALL OStorage::copyElementDirectlyTo(
5767cdf0e10cSrcweir 			const ::rtl::OUString& aElementName,
5768cdf0e10cSrcweir 			const uno::Reference< embed::XOptimizedStorage >& xDest,
5769cdf0e10cSrcweir 			const ::rtl::OUString& aNewName )
5770cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
5771cdf0e10cSrcweir 				lang::IllegalArgumentException,
5772cdf0e10cSrcweir 				container::NoSuchElementException,
5773cdf0e10cSrcweir 				container::ElementExistException,
5774cdf0e10cSrcweir 				io::IOException,
5775cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
5776cdf0e10cSrcweir 				uno::RuntimeException )
5777cdf0e10cSrcweir {
5778cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementDirectlyTo" );
5779cdf0e10cSrcweir 
5780cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5781cdf0e10cSrcweir 
5782cdf0e10cSrcweir 	if ( !m_pImpl )
5783cdf0e10cSrcweir     {
5784cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5785cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5786cdf0e10cSrcweir     }
5787cdf0e10cSrcweir 
5788cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False )
5789cdf0e10cSrcweir 	  || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) )
5790cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
5791cdf0e10cSrcweir 
5792cdf0e10cSrcweir 	if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) )
5793cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
5794cdf0e10cSrcweir 
5795cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
5796cdf0e10cSrcweir 	  && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) )
5797cdf0e10cSrcweir 	    || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) )
5798cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable name
5799cdf0e10cSrcweir 
5800cdf0e10cSrcweir 	try
5801cdf0e10cSrcweir 	{
5802cdf0e10cSrcweir 		SotElement_Impl* pElement = m_pImpl->FindElement( aElementName );
5803cdf0e10cSrcweir 		if ( !pElement )
5804cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5805cdf0e10cSrcweir 
5806cdf0e10cSrcweir 		uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY );
5807cdf0e10cSrcweir 		if ( !xNameAccess.is() )
5808cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5809cdf0e10cSrcweir 
5810cdf0e10cSrcweir 		if ( xNameAccess->hasByName( aNewName ) )
5811cdf0e10cSrcweir 			throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5812cdf0e10cSrcweir 
5813cdf0e10cSrcweir 		// let the element be copied directly
5814cdf0e10cSrcweir 		uno::Reference< embed::XStorage > xStorDest( xDest, uno::UNO_QUERY_THROW );
5815cdf0e10cSrcweir 		m_pImpl->CopyStorageElement( pElement, xStorDest, aNewName, sal_True );
5816cdf0e10cSrcweir 	}
5817cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
5818cdf0e10cSrcweir     {
5819cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
5820cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5821cdf0e10cSrcweir         throw;
5822cdf0e10cSrcweir 	}
5823cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
5824cdf0e10cSrcweir     {
5825cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
5826cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5827cdf0e10cSrcweir         throw;
5828cdf0e10cSrcweir 	}
5829cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
5830cdf0e10cSrcweir     {
5831cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
5832cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5833cdf0e10cSrcweir         throw;
5834cdf0e10cSrcweir 	}
5835cdf0e10cSrcweir 	catch( container::ElementExistException& aElementExistException )
5836cdf0e10cSrcweir     {
5837cdf0e10cSrcweir         m_pImpl->AddLog( aElementExistException.Message );
5838cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5839cdf0e10cSrcweir         throw;
5840cdf0e10cSrcweir 	}
5841cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5842cdf0e10cSrcweir     {
5843cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5844cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5845cdf0e10cSrcweir         throw;
5846cdf0e10cSrcweir 	}
5847cdf0e10cSrcweir 	catch( io::IOException& aIOException )
5848cdf0e10cSrcweir     {
5849cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
5850cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5851cdf0e10cSrcweir         throw;
5852cdf0e10cSrcweir 	}
5853cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
5854cdf0e10cSrcweir     {
5855cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
5856cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5857cdf0e10cSrcweir         throw;
5858cdf0e10cSrcweir 	}
5859cdf0e10cSrcweir 	catch( uno::Exception& aException )
5860cdf0e10cSrcweir 	{
5861cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
5862cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5863cdf0e10cSrcweir 
5864cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
5865cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element direcly!" ) ),
5866cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
5867cdf0e10cSrcweir 												 aCaught );
5868cdf0e10cSrcweir 	}
5869cdf0e10cSrcweir }
5870cdf0e10cSrcweir 
5871cdf0e10cSrcweir //-----------------------------------------------
writeAndAttachToStream(const uno::Reference<io::XStream> & xStream)5872cdf0e10cSrcweir void SAL_CALL OStorage::writeAndAttachToStream( const uno::Reference< io::XStream >& xStream )
5873cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
5874cdf0e10cSrcweir 				lang::IllegalArgumentException,
5875cdf0e10cSrcweir 				io::IOException,
5876cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
5877cdf0e10cSrcweir 				uno::RuntimeException )
5878cdf0e10cSrcweir {
5879cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::writeAndAttachToStream" );
5880cdf0e10cSrcweir 
5881cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5882cdf0e10cSrcweir 
5883cdf0e10cSrcweir 	if ( !m_pImpl )
5884cdf0e10cSrcweir     {
5885cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5886cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5887cdf0e10cSrcweir     }
5888cdf0e10cSrcweir 
5889cdf0e10cSrcweir 	if ( !m_pData->m_bIsRoot )
5890cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5891cdf0e10cSrcweir 
5892cdf0e10cSrcweir 	if ( !m_pImpl->m_pSwitchStream )
5893cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5894cdf0e10cSrcweir 
5895cdf0e10cSrcweir 	try
5896cdf0e10cSrcweir 	{
5897cdf0e10cSrcweir 		m_pImpl->m_pSwitchStream->CopyAndSwitchPersistenceTo( xStream );
5898cdf0e10cSrcweir 	}
5899cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
5900cdf0e10cSrcweir     {
5901cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
5902cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5903cdf0e10cSrcweir         throw;
5904cdf0e10cSrcweir 	}
5905cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
5906cdf0e10cSrcweir     {
5907cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
5908cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5909cdf0e10cSrcweir         throw;
5910cdf0e10cSrcweir 	}
5911cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5912cdf0e10cSrcweir     {
5913cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
5914cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5915cdf0e10cSrcweir         throw;
5916cdf0e10cSrcweir 	}
5917cdf0e10cSrcweir 	catch( io::IOException& aIOException )
5918cdf0e10cSrcweir     {
5919cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
5920cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5921cdf0e10cSrcweir         throw;
5922cdf0e10cSrcweir 	}
5923cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
5924cdf0e10cSrcweir     {
5925cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
5926cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5927cdf0e10cSrcweir         throw;
5928cdf0e10cSrcweir 	}
5929cdf0e10cSrcweir 	catch( uno::Exception& aException )
5930cdf0e10cSrcweir 	{
5931cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
5932cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5933cdf0e10cSrcweir 
5934cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
5935cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't write and attach to stream!" ) ),
5936cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
5937cdf0e10cSrcweir 												 aCaught );
5938cdf0e10cSrcweir 	}
5939cdf0e10cSrcweir 
5940cdf0e10cSrcweir }
5941cdf0e10cSrcweir 
5942cdf0e10cSrcweir //-----------------------------------------------
attachToURL(const::rtl::OUString & sURL,sal_Bool bReadOnly)5943cdf0e10cSrcweir void SAL_CALL OStorage::attachToURL( const ::rtl::OUString& sURL,
5944cdf0e10cSrcweir 									sal_Bool bReadOnly )
5945cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
5946cdf0e10cSrcweir 				lang::IllegalArgumentException,
5947cdf0e10cSrcweir 				io::IOException,
5948cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
5949cdf0e10cSrcweir 				uno::RuntimeException )
5950cdf0e10cSrcweir {
5951cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::attachToURL" );
5952cdf0e10cSrcweir 
5953cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
5954cdf0e10cSrcweir 
5955cdf0e10cSrcweir 	if ( !m_pImpl )
5956cdf0e10cSrcweir     {
5957cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
5958cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5959cdf0e10cSrcweir     }
5960cdf0e10cSrcweir 
5961cdf0e10cSrcweir 	if ( !m_pData->m_bIsRoot )
5962cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
5963cdf0e10cSrcweir 
5964cdf0e10cSrcweir 	if ( !m_pImpl->m_pSwitchStream )
5965cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
5966cdf0e10cSrcweir 
5967cdf0e10cSrcweir 	uno::Reference < ucb::XSimpleFileAccess > xAccess(
5968cdf0e10cSrcweir 			m_pImpl->m_xFactory->createInstance (
5969cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
5970cdf0e10cSrcweir 			uno::UNO_QUERY_THROW );
5971cdf0e10cSrcweir 
5972cdf0e10cSrcweir 	try
5973cdf0e10cSrcweir 	{
5974cdf0e10cSrcweir 		if ( bReadOnly )
5975cdf0e10cSrcweir 		{
5976cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xInputStream = xAccess->openFileRead( sURL );
5977cdf0e10cSrcweir 			m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xInputStream );
5978cdf0e10cSrcweir 		}
5979cdf0e10cSrcweir 		else
5980cdf0e10cSrcweir 		{
5981cdf0e10cSrcweir 			uno::Reference< io::XStream > xStream = xAccess->openFileReadWrite( sURL );
5982cdf0e10cSrcweir 			m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xStream );
5983cdf0e10cSrcweir 		}
5984cdf0e10cSrcweir 	}
5985cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
5986cdf0e10cSrcweir     {
5987cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
5988cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5989cdf0e10cSrcweir         throw;
5990cdf0e10cSrcweir 	}
5991cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
5992cdf0e10cSrcweir     {
5993cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
5994cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
5995cdf0e10cSrcweir         throw;
5996cdf0e10cSrcweir 	}
5997cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
5998cdf0e10cSrcweir     {
5999cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
6000cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6001cdf0e10cSrcweir         throw;
6002cdf0e10cSrcweir 	}
6003cdf0e10cSrcweir 	catch( io::IOException& aIOException )
6004cdf0e10cSrcweir     {
6005cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
6006cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6007cdf0e10cSrcweir         throw;
6008cdf0e10cSrcweir 	}
6009cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
6010cdf0e10cSrcweir     {
6011cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
6012cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6013cdf0e10cSrcweir         throw;
6014cdf0e10cSrcweir 	}
6015cdf0e10cSrcweir 	catch( uno::Exception& aException )
6016cdf0e10cSrcweir 	{
6017cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
6018cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6019cdf0e10cSrcweir 
6020cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
6021cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't attach to URL!" ) ),
6022cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
6023cdf0e10cSrcweir 												 aCaught );
6024cdf0e10cSrcweir 	}
6025cdf0e10cSrcweir }
6026cdf0e10cSrcweir 
6027cdf0e10cSrcweir //-----------------------------------------------
getElementPropertyValue(const::rtl::OUString & aElementName,const::rtl::OUString & aPropertyName)6028cdf0e10cSrcweir uno::Any SAL_CALL OStorage::getElementPropertyValue( const ::rtl::OUString& aElementName, const ::rtl::OUString& aPropertyName )
6029cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6030cdf0e10cSrcweir 				lang::IllegalArgumentException,
6031cdf0e10cSrcweir 				container::NoSuchElementException,
6032cdf0e10cSrcweir 				io::IOException,
6033cdf0e10cSrcweir 				beans::UnknownPropertyException,
6034cdf0e10cSrcweir 				beans::PropertyVetoException,
6035cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6036cdf0e10cSrcweir 				uno::RuntimeException)
6037cdf0e10cSrcweir {
6038cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementPropertyValue" );
6039cdf0e10cSrcweir 
6040cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6041cdf0e10cSrcweir 
6042cdf0e10cSrcweir 	if ( !m_pImpl )
6043cdf0e10cSrcweir     {
6044cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6045cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6046cdf0e10cSrcweir     }
6047cdf0e10cSrcweir 
6048cdf0e10cSrcweir 	if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) )
6049cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6050cdf0e10cSrcweir 
6051cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
6052cdf0e10cSrcweir 	  && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
6053cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name
6054cdf0e10cSrcweir 
6055cdf0e10cSrcweir 	try
6056cdf0e10cSrcweir 	{
6057cdf0e10cSrcweir     	SotElement_Impl *pElement = m_pImpl->FindElement( aElementName );
6058cdf0e10cSrcweir     	if ( !pElement )
6059cdf0e10cSrcweir 			throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6060cdf0e10cSrcweir 
6061cdf0e10cSrcweir 		// TODO/LATER: Currently it is only implemented for MediaType property of substorages, might be changed in future
6062cdf0e10cSrcweir 		if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != embed::StorageFormats::PACKAGE || !aPropertyName.equalsAscii( "MediaType" ) )
6063cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6064cdf0e10cSrcweir 
6065cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
6066cdf0e10cSrcweir 			m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ );
6067cdf0e10cSrcweir 
6068cdf0e10cSrcweir 		if ( !pElement->m_pStorage )
6069cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error
6070cdf0e10cSrcweir 
6071cdf0e10cSrcweir 		pElement->m_pStorage->ReadContents();
6072cdf0e10cSrcweir 		return uno::makeAny( pElement->m_pStorage->m_aMediaType );
6073cdf0e10cSrcweir 	}
6074cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
6075cdf0e10cSrcweir     {
6076cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
6077cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6078cdf0e10cSrcweir         throw;
6079cdf0e10cSrcweir 	}
6080cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
6081cdf0e10cSrcweir     {
6082cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
6083cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6084cdf0e10cSrcweir         throw;
6085cdf0e10cSrcweir 	}
6086cdf0e10cSrcweir 	catch( container::NoSuchElementException& aNoSuchElementException )
6087cdf0e10cSrcweir     {
6088cdf0e10cSrcweir         m_pImpl->AddLog( aNoSuchElementException.Message );
6089cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6090cdf0e10cSrcweir         throw;
6091cdf0e10cSrcweir 	}
6092cdf0e10cSrcweir 	catch( beans::UnknownPropertyException& aUnknownPropertyException )
6093cdf0e10cSrcweir     {
6094cdf0e10cSrcweir         m_pImpl->AddLog( aUnknownPropertyException.Message );
6095cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6096cdf0e10cSrcweir         throw;
6097cdf0e10cSrcweir 	}
6098cdf0e10cSrcweir 	catch( beans::PropertyVetoException& aPropertyVetoException )
6099cdf0e10cSrcweir     {
6100cdf0e10cSrcweir         m_pImpl->AddLog( aPropertyVetoException.Message );
6101cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6102cdf0e10cSrcweir         throw;
6103cdf0e10cSrcweir 	}
6104cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
6105cdf0e10cSrcweir     {
6106cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
6107cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6108cdf0e10cSrcweir         throw;
6109cdf0e10cSrcweir 	}
6110cdf0e10cSrcweir 	catch( io::IOException& aIOException )
6111cdf0e10cSrcweir     {
6112cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
6113cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6114cdf0e10cSrcweir         throw;
6115cdf0e10cSrcweir 	}
6116cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
6117cdf0e10cSrcweir     {
6118cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
6119cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6120cdf0e10cSrcweir         throw;
6121cdf0e10cSrcweir 	}
6122cdf0e10cSrcweir 	catch( uno::Exception& aException )
6123cdf0e10cSrcweir 	{
6124cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
6125cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6126cdf0e10cSrcweir 
6127cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
6128cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get element property!" ) ),
6129cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
6130cdf0e10cSrcweir 												 aCaught );
6131cdf0e10cSrcweir 	}
6132cdf0e10cSrcweir }
6133cdf0e10cSrcweir 
6134cdf0e10cSrcweir //-----------------------------------------------
copyStreamElementData(const::rtl::OUString & aStreamName,const uno::Reference<io::XStream> & xTargetStream)6135cdf0e10cSrcweir void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamName, const uno::Reference< io::XStream >& xTargetStream )
6136cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6137cdf0e10cSrcweir 				lang::IllegalArgumentException,
6138cdf0e10cSrcweir 				packages::WrongPasswordException,
6139cdf0e10cSrcweir 				io::IOException,
6140cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6141cdf0e10cSrcweir 				uno::RuntimeException )
6142cdf0e10cSrcweir {
6143cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6144cdf0e10cSrcweir 
6145cdf0e10cSrcweir 	if ( !m_pImpl )
6146cdf0e10cSrcweir     {
6147cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6148cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6149cdf0e10cSrcweir     }
6150cdf0e10cSrcweir 
6151cdf0e10cSrcweir 	if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) )
6152cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6153cdf0e10cSrcweir 
6154cdf0e10cSrcweir 	if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML
6155cdf0e10cSrcweir 	  && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) )
6156cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name
6157cdf0e10cSrcweir 
6158cdf0e10cSrcweir 	if ( !xTargetStream.is() )
6159cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
6160cdf0e10cSrcweir 
6161cdf0e10cSrcweir 	try
6162cdf0e10cSrcweir 	{
6163cdf0e10cSrcweir 		uno::Reference< io::XStream > xNonconstRef = xTargetStream;
6164cdf0e10cSrcweir 		m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xNonconstRef );
6165cdf0e10cSrcweir 
6166cdf0e10cSrcweir 		OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" );
6167cdf0e10cSrcweir 		if ( xNonconstRef != xTargetStream )
6168cdf0e10cSrcweir 			throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // if the stream reference is set it must not be changed!
6169cdf0e10cSrcweir 	}
6170cdf0e10cSrcweir 	catch( embed::InvalidStorageException& aInvalidStorageException )
6171cdf0e10cSrcweir     {
6172cdf0e10cSrcweir         m_pImpl->AddLog( aInvalidStorageException.Message );
6173cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6174cdf0e10cSrcweir         throw;
6175cdf0e10cSrcweir 	}
6176cdf0e10cSrcweir 	catch( lang::IllegalArgumentException& aIllegalArgumentException )
6177cdf0e10cSrcweir     {
6178cdf0e10cSrcweir         m_pImpl->AddLog( aIllegalArgumentException.Message );
6179cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6180cdf0e10cSrcweir         throw;
6181cdf0e10cSrcweir 	}
6182cdf0e10cSrcweir 	catch( packages::WrongPasswordException& aWrongPasswordException )
6183cdf0e10cSrcweir     {
6184cdf0e10cSrcweir         m_pImpl->AddLog( aWrongPasswordException.Message );
6185cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6186cdf0e10cSrcweir         throw;
6187cdf0e10cSrcweir 	}
6188cdf0e10cSrcweir 	catch( io::IOException& aIOException )
6189cdf0e10cSrcweir     {
6190cdf0e10cSrcweir         m_pImpl->AddLog( aIOException.Message );
6191cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6192cdf0e10cSrcweir         throw;
6193cdf0e10cSrcweir 	}
6194cdf0e10cSrcweir 	catch( embed::StorageWrappedTargetException& aStorageWrappedTargetException )
6195cdf0e10cSrcweir     {
6196cdf0e10cSrcweir         m_pImpl->AddLog( aStorageWrappedTargetException.Message );
6197cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6198cdf0e10cSrcweir         throw;
6199cdf0e10cSrcweir 	}
6200cdf0e10cSrcweir 	catch( uno::RuntimeException& aRuntimeException )
6201cdf0e10cSrcweir     {
6202cdf0e10cSrcweir         m_pImpl->AddLog( aRuntimeException.Message );
6203cdf0e10cSrcweir         m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6204cdf0e10cSrcweir         throw;
6205cdf0e10cSrcweir 	}
6206cdf0e10cSrcweir 	catch( uno::Exception& aException )
6207cdf0e10cSrcweir 	{
6208cdf0e10cSrcweir       	m_pImpl->AddLog( aException.Message );
6209cdf0e10cSrcweir       	m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
6210cdf0e10cSrcweir 
6211cdf0e10cSrcweir       	uno::Any aCaught( ::cppu::getCaughtException() );
6212cdf0e10cSrcweir 		throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy stream data!" ) ),
6213cdf0e10cSrcweir 												 uno::Reference< io::XInputStream >(),
6214cdf0e10cSrcweir 												 aCaught );
6215cdf0e10cSrcweir 	}
6216cdf0e10cSrcweir 
6217cdf0e10cSrcweir 
6218cdf0e10cSrcweir }
6219cdf0e10cSrcweir 
6220cdf0e10cSrcweir //____________________________________________________________________________________________________
6221cdf0e10cSrcweir // XHierarchicalStorageAccess
6222cdf0e10cSrcweir //____________________________________________________________________________________________________
6223cdf0e10cSrcweir 
6224cdf0e10cSrcweir //-----------------------------------------------
openStreamElementByHierarchicalName(const::rtl::OUString & aStreamPath,::sal_Int32 nOpenMode)6225cdf0e10cSrcweir uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode )
6226cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6227cdf0e10cSrcweir 				lang::IllegalArgumentException,
6228cdf0e10cSrcweir 				packages::WrongPasswordException,
6229cdf0e10cSrcweir 				io::IOException,
6230cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6231cdf0e10cSrcweir 				uno::RuntimeException )
6232cdf0e10cSrcweir {
6233cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6234cdf0e10cSrcweir 
6235cdf0e10cSrcweir 	if ( !m_pImpl )
6236cdf0e10cSrcweir     {
6237cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6238cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6239cdf0e10cSrcweir     }
6240cdf0e10cSrcweir 
6241cdf0e10cSrcweir 	if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6242cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6243cdf0e10cSrcweir 
6244cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
6245cdf0e10cSrcweir 	  && ( nOpenMode & embed::ElementModes::WRITE ) )
6246cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6247cdf0e10cSrcweir 
6248cdf0e10cSrcweir 	OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6249cdf0e10cSrcweir 	OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6250cdf0e10cSrcweir 
6251cdf0e10cSrcweir 	uno::Reference< embed::XExtendedStorageStream > xResult;
6252cdf0e10cSrcweir 	if ( aListPath.size() == 1 )
6253cdf0e10cSrcweir 	{
6254cdf0e10cSrcweir 		// that must be a direct request for a stream
6255cdf0e10cSrcweir 		// the transacted version of the stream should be opened
6256cdf0e10cSrcweir 
6257cdf0e10cSrcweir     	SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_False );
6258cdf0e10cSrcweir 		OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
6259cdf0e10cSrcweir 
6260cdf0e10cSrcweir 		xResult = uno::Reference< embed::XExtendedStorageStream >(
6261cdf0e10cSrcweir 						pElement->m_pStream->GetStream( nOpenMode, sal_True ),
6262cdf0e10cSrcweir 						uno::UNO_QUERY_THROW );
6263cdf0e10cSrcweir 	}
6264cdf0e10cSrcweir 	else
6265cdf0e10cSrcweir 	{
6266cdf0e10cSrcweir 		// there are still storages in between
6267cdf0e10cSrcweir 		if ( !m_pData->m_rHierarchyHolder.is() )
6268cdf0e10cSrcweir 			m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6269cdf0e10cSrcweir 				uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6270cdf0e10cSrcweir 
6271cdf0e10cSrcweir 		xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
6272cdf0e10cSrcweir 												( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
6273cdf0e10cSrcweir 												aListPath,
6274cdf0e10cSrcweir 												nOpenMode );
6275cdf0e10cSrcweir 	}
6276cdf0e10cSrcweir 
6277cdf0e10cSrcweir 	if ( !xResult.is() )
6278cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6279cdf0e10cSrcweir 
6280cdf0e10cSrcweir 	return xResult;
6281cdf0e10cSrcweir }
6282cdf0e10cSrcweir 
6283cdf0e10cSrcweir //-----------------------------------------------
openEncryptedStreamElementByHierarchicalName(const::rtl::OUString & aStreamPath,::sal_Int32 nOpenMode,const::rtl::OUString & sPassword)6284cdf0e10cSrcweir uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword )
6285cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6286cdf0e10cSrcweir 				lang::IllegalArgumentException,
6287cdf0e10cSrcweir 				packages::NoEncryptionException,
6288cdf0e10cSrcweir 				packages::WrongPasswordException,
6289cdf0e10cSrcweir 				io::IOException,
6290cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6291cdf0e10cSrcweir 				uno::RuntimeException )
6292cdf0e10cSrcweir {
6293cdf0e10cSrcweir     return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) );
6294cdf0e10cSrcweir }
6295cdf0e10cSrcweir 
6296cdf0e10cSrcweir //-----------------------------------------------
removeStreamElementByHierarchicalName(const::rtl::OUString & aStreamPath)6297cdf0e10cSrcweir void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath )
6298cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6299cdf0e10cSrcweir 				lang::IllegalArgumentException,
6300cdf0e10cSrcweir 				container::NoSuchElementException,
6301cdf0e10cSrcweir 				io::IOException,
6302cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6303cdf0e10cSrcweir 				uno::RuntimeException )
6304cdf0e10cSrcweir {
6305cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6306cdf0e10cSrcweir 
6307cdf0e10cSrcweir 	if ( !m_pImpl )
6308cdf0e10cSrcweir     {
6309cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6310cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6311cdf0e10cSrcweir     }
6312cdf0e10cSrcweir 
6313cdf0e10cSrcweir 	if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6314cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6315cdf0e10cSrcweir 
6316cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) )
6317cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6318cdf0e10cSrcweir 
6319cdf0e10cSrcweir 	OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6320cdf0e10cSrcweir 	OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6321cdf0e10cSrcweir 
6322cdf0e10cSrcweir 	if ( !m_pData->m_rHierarchyHolder.is() )
6323cdf0e10cSrcweir 		m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6324cdf0e10cSrcweir 			uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6325cdf0e10cSrcweir 
6326cdf0e10cSrcweir 	m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );
6327cdf0e10cSrcweir }
6328cdf0e10cSrcweir 
6329cdf0e10cSrcweir //____________________________________________________________________________________________________
6330cdf0e10cSrcweir // XHierarchicalStorageAccess2
6331cdf0e10cSrcweir //____________________________________________________________________________________________________
6332cdf0e10cSrcweir 
openEncryptedStreamByHierarchicalName(const::rtl::OUString & aStreamPath,::sal_Int32 nOpenMode,const uno::Sequence<beans::NamedValue> & aEncryptionData)6333cdf0e10cSrcweir uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData )
6334cdf0e10cSrcweir 		throw ( embed::InvalidStorageException,
6335cdf0e10cSrcweir 				lang::IllegalArgumentException,
6336cdf0e10cSrcweir 				packages::NoEncryptionException,
6337cdf0e10cSrcweir 				packages::WrongPasswordException,
6338cdf0e10cSrcweir 				io::IOException,
6339cdf0e10cSrcweir 				embed::StorageWrappedTargetException,
6340cdf0e10cSrcweir 				uno::RuntimeException )
6341cdf0e10cSrcweir {
6342cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
6343cdf0e10cSrcweir 
6344cdf0e10cSrcweir 	if ( !m_pImpl )
6345cdf0e10cSrcweir     {
6346cdf0e10cSrcweir         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
6347cdf0e10cSrcweir         throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6348cdf0e10cSrcweir     }
6349cdf0e10cSrcweir 
6350cdf0e10cSrcweir 	if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE )
6351cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6352cdf0e10cSrcweir 
6353cdf0e10cSrcweir 	if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) )
6354cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 );
6355cdf0e10cSrcweir 
6356cdf0e10cSrcweir 	if ( !aEncryptionData.getLength() )
6357cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 );
6358cdf0e10cSrcweir 
6359cdf0e10cSrcweir 	if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE )
6360cdf0e10cSrcweir 	  && ( nOpenMode & embed::ElementModes::WRITE ) )
6361cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied
6362cdf0e10cSrcweir 
6363cdf0e10cSrcweir 	OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath );
6364cdf0e10cSrcweir 	OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
6365cdf0e10cSrcweir 
6366cdf0e10cSrcweir 	uno::Reference< embed::XExtendedStorageStream > xResult;
6367cdf0e10cSrcweir 	if ( aListPath.size() == 1 )
6368cdf0e10cSrcweir 	{
6369cdf0e10cSrcweir 		// that must be a direct request for a stream
6370cdf0e10cSrcweir 		// the transacted version of the stream should be opened
6371cdf0e10cSrcweir 
6372cdf0e10cSrcweir     	SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_True );
6373cdf0e10cSrcweir 		OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
6374cdf0e10cSrcweir 
6375cdf0e10cSrcweir 		xResult = uno::Reference< embed::XExtendedStorageStream >(
6376cdf0e10cSrcweir 						pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_True ),
6377cdf0e10cSrcweir 						uno::UNO_QUERY_THROW );
6378cdf0e10cSrcweir 	}
6379cdf0e10cSrcweir 	else
6380cdf0e10cSrcweir 	{
6381cdf0e10cSrcweir 		// there are still storages in between
6382cdf0e10cSrcweir 		if ( !m_pData->m_rHierarchyHolder.is() )
6383cdf0e10cSrcweir 			m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl(
6384cdf0e10cSrcweir 				uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
6385cdf0e10cSrcweir 
6386cdf0e10cSrcweir 		xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically(
6387cdf0e10cSrcweir 												( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
6388cdf0e10cSrcweir 												aListPath,
6389cdf0e10cSrcweir 												nOpenMode,
6390cdf0e10cSrcweir 												aEncryptionData );
6391cdf0e10cSrcweir 	}
6392cdf0e10cSrcweir 
6393cdf0e10cSrcweir 	if ( !xResult.is() )
6394cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
6395cdf0e10cSrcweir 
6396cdf0e10cSrcweir 	return xResult;
6397cdf0e10cSrcweir }
6398cdf0e10cSrcweir 
6399cdf0e10cSrcweir 
6400