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