LCOV - code coverage report
Current view: top level - package/source/xstor - xstorage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1267 2919 43.4 %
Date: 2014-11-03 Functions: 91 129 70.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10