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