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