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