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