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

Generated by: LCOV version 1.10