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