1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/XComponentContext.hpp>
21 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
22 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
25 #include <com/sun/star/lang/XTypeProvider.hpp>
26 #include <com/sun/star/logging/DocumentIOLogRing.hpp>
27 #include <com/sun/star/io/TempFile.hpp>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <com/sun/star/io/IOException.hpp>
30 #include <com/sun/star/embed/ElementModes.hpp>
31 #include <com/sun/star/embed/StorageFormats.hpp>
32 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <cppuhelper/queryinterface.hxx>
35 #include <cppuhelper/exc_hlp.hxx>
36 #include <osl/diagnose.h>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/storagehelper.hxx>
40 #include <comphelper/ofopxmlhelper.hxx>
42 #include <rtl/digest.h>
43 #include <rtl/instance.hxx>
45 #include <PackageConstants.hxx>
46 #include <mutexholder.hxx>
48 #include "selfterminatefilestream.hxx"
49 #include "owriteablestream.hxx"
50 #include "oseekinstream.hxx"
51 #include "xstorage.hxx"
53 // since the copying uses 32000 blocks usually, it makes sense to have a smaller size
54 #define MAX_STORCACHE_SIZE 30000
56 using namespace ::com::sun::star
;
58 struct WSInternalData_Impl
60 SotMutexHolderRef m_rSharedMutexRef
;
61 ::std::unique_ptr
< ::cppu::OTypeCollection
> m_pTypeCollection
;
62 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer
; // list of listeners
63 sal_Int32 m_nStorageType
;
65 // the mutex reference MUST NOT be empty
66 WSInternalData_Impl( const SotMutexHolderRef
& rMutexRef
, sal_Int32 nStorageType
)
67 : m_rSharedMutexRef( rMutexRef
)
69 , m_aListenersContainer( rMutexRef
->GetMutex() )
70 , m_nStorageType( nStorageType
)
77 bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap
& aHash1
, const ::comphelper::SequenceAsHashMap
& aHash2
)
79 bool bResult
= ( aHash1
.size() && aHash1
.size() == aHash2
.size() );
80 for ( ::comphelper::SequenceAsHashMap::const_iterator aIter
= aHash1
.begin();
81 bResult
&& aIter
!= aHash1
.end();
84 uno::Sequence
< sal_Int8
> aKey1
;
85 bResult
= ( ( aIter
->second
>>= aKey1
) && aKey1
.getLength() );
88 uno::Sequence
< sal_Int8
> aKey2
= aHash2
.getUnpackedValueOrDefault( aIter
->first
, uno::Sequence
< sal_Int8
>() );
89 bResult
= ( aKey1
.getLength() == aKey2
.getLength() );
90 for ( sal_Int32 nInd
= 0; bResult
&& nInd
< aKey1
.getLength(); nInd
++ )
91 bResult
= ( aKey1
[nInd
] == aKey2
[nInd
] );
98 } // namespace package
103 void SetEncryptionKeyProperty_Impl( const uno::Reference
< beans::XPropertySet
>& xPropertySet
,
104 const uno::Sequence
< beans::NamedValue
>& aKey
)
106 SAL_WARN_IF( !xPropertySet
.is(), "package.xstor", "No property set is provided!" );
107 if ( !xPropertySet
.is() )
108 throw uno::RuntimeException();
111 xPropertySet
->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY
, uno::makeAny( aKey
) );
113 catch ( const uno::Exception
& rException
)
115 SAL_INFO("package.xstor", rException
.Message
);
116 SAL_INFO("package.xstor", "Can't set encryption");
117 SAL_WARN( "package.xstor", "Can't write encryption related properties!" );
118 throw io::IOException(); // TODO
122 uno::Any
GetEncryptionKeyProperty_Impl( const uno::Reference
< beans::XPropertySet
>& xPropertySet
)
124 SAL_WARN_IF( !xPropertySet
.is(), "package.xstor", "No property set is provided!" );
125 if ( !xPropertySet
.is() )
126 throw uno::RuntimeException();
129 return xPropertySet
->getPropertyValue(STORAGE_ENCRYPTION_KEYS_PROPERTY
);
131 catch ( const uno::Exception
& rException
)
133 SAL_INFO("package.xstor", rException
.Message
);
134 SAL_INFO("package.xstor", "Can't get encryption property");
136 SAL_WARN( "package.xstor", "Can't get encryption related properties!" );
137 throw io::IOException(); // TODO
141 bool SequencesEqual( const uno::Sequence
< sal_Int8
>& aSequence1
, const uno::Sequence
< sal_Int8
>& aSequence2
)
143 if ( aSequence1
.getLength() != aSequence2
.getLength() )
146 for ( sal_Int32 nInd
= 0; nInd
< aSequence1
.getLength(); nInd
++ )
147 if ( aSequence1
[nInd
] != aSequence2
[nInd
] )
153 bool SequencesEqual( const uno::Sequence
< beans::NamedValue
>& aSequence1
, const uno::Sequence
< beans::NamedValue
>& aSequence2
)
155 if ( aSequence1
.getLength() != aSequence2
.getLength() )
158 for ( sal_Int32 nInd
= 0; nInd
< aSequence1
.getLength(); nInd
++ )
160 bool bHasMember
= false;
161 uno::Sequence
< sal_Int8
> aMember1
;
162 sal_Int32 nMember1
= 0;
163 if ( ( aSequence1
[nInd
].Value
>>= aMember1
) )
165 for ( sal_Int32 nInd2
= 0; nInd2
< aSequence2
.getLength(); nInd2
++ )
167 if ( aSequence1
[nInd
].Name
.equals( aSequence2
[nInd2
].Name
) )
171 uno::Sequence
< sal_Int8
> aMember2
;
172 if ( !( aSequence2
[nInd2
].Value
>>= aMember2
) || !SequencesEqual( aMember1
, aMember2
) )
177 else if ( ( aSequence1
[nInd
].Value
>>= nMember1
) )
179 for ( sal_Int32 nInd2
= 0; nInd2
< aSequence2
.getLength(); nInd2
++ )
181 if ( aSequence1
[nInd
].Name
.equals( aSequence2
[nInd2
].Name
) )
185 sal_Int32 nMember2
= 0;
186 if ( !( aSequence2
[nInd2
].Value
>>= nMember2
) || nMember1
!= nMember2
)
201 bool KillFile( const OUString
& aURL
, const uno::Reference
< uno::XComponentContext
>& xContext
)
203 if ( !xContext
.is() )
210 uno::Reference
< ucb::XSimpleFileAccess3
> xAccess( ucb::SimpleFileAccess::create( xContext
) );
212 xAccess
->kill( aURL
);
215 catch( const uno::Exception
& rException
)
217 SAL_INFO("package.xstor", rException
.Message
);
218 SAL_INFO("package.xstor", "Quiet exception");
224 OUString
GetNewTempFileURL( const uno::Reference
< uno::XComponentContext
>& rContext
)
228 uno::Reference
< beans::XPropertySet
> xTempFile(
229 io::TempFile::create(rContext
),
230 uno::UNO_QUERY_THROW
);
233 xTempFile
->setPropertyValue( "RemoveFile", uno::makeAny( sal_False
) );
234 uno::Any aUrl
= xTempFile
->getPropertyValue( "Uri" );
237 catch ( const uno::Exception
& rException
)
239 SAL_INFO("package.xstor", rException
.Message
);
240 SAL_INFO("package.xstor", "Quiet exception");
243 if ( aTempURL
.isEmpty() )
244 throw uno::RuntimeException(); // TODO: can not create tempfile
249 uno::Reference
< io::XStream
> CreateMemoryStream( const uno::Reference
< uno::XComponentContext
>& rContext
)
251 return uno::Reference
< io::XStream
>(
252 rContext
->getServiceManager()->createInstanceWithContext("com.sun.star.comp.MemoryStream", rContext
),
253 uno::UNO_QUERY_THROW
);
256 } // anonymous namespace
258 OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl
* pParent
,
259 const uno::Reference
< packages::XDataSinkEncrSupport
>& xPackageStream
,
260 const uno::Reference
< lang::XSingleServiceFactory
>& xPackage
,
261 const uno::Reference
< uno::XComponentContext
>& rContext
,
262 bool bForceEncrypted
,
263 sal_Int32 nStorageType
,
264 bool bDefaultCompress
,
265 const uno::Reference
< io::XInputStream
>& xRelInfoStream
)
266 : m_pAntiImpl( NULL
)
267 , m_bHasDataToFlush( false )
268 , m_bFlushed( false )
269 , m_xPackageStream( xPackageStream
)
270 , m_xContext( rContext
)
271 , m_pParent( pParent
)
272 , m_bForceEncrypted( bForceEncrypted
)
273 , m_bUseCommonEncryption( !bForceEncrypted
&& nStorageType
== embed::StorageFormats::PACKAGE
)
274 , m_bHasCachedEncryptionData( false )
275 , m_bCompressedSetExplicit( !bDefaultCompress
)
276 , m_xPackage( xPackage
)
277 , m_bHasInsertedStreamOptimization( false )
278 , m_nStorageType( nStorageType
)
279 , m_xOrigRelInfoStream( xRelInfoStream
)
280 , m_bOrigRelInfoBroken( false )
281 , m_nRelInfoStatus( RELINFO_NO_INIT
)
284 SAL_WARN_IF( !xPackageStream
.is(), "package.xstor", "No package stream is provided!" );
285 SAL_WARN_IF( !xPackage
.is(), "package.xstor", "No package component is provided!" );
286 SAL_WARN_IF( !m_xContext
.is(), "package.xstor", "No package stream is provided!" );
287 OSL_ENSURE( pParent
, "No parent storage is provided!\n" );
288 OSL_ENSURE( m_nStorageType
== embed::StorageFormats::OFOPXML
|| !m_xOrigRelInfoStream
.is(), "The Relations info makes sense only for OFOPXML format!\n" );
291 OWriteStream_Impl::~OWriteStream_Impl()
295 if ( !m_aTempURL
.isEmpty() )
297 KillFile( m_aTempURL
, comphelper::getProcessComponentContext() );
304 void OWriteStream_Impl::CleanCacheStream()
306 if ( m_xCacheStream
.is() )
310 uno::Reference
< io::XInputStream
> xInputCache
= m_xCacheStream
->getInputStream();
311 if ( xInputCache
.is() )
312 xInputCache
->closeInput();
314 catch( const uno::Exception
& )
319 uno::Reference
< io::XOutputStream
> xOutputCache
= m_xCacheStream
->getOutputStream();
320 if ( xOutputCache
.is() )
321 xOutputCache
->closeOutput();
323 catch( const uno::Exception
& )
326 m_xCacheStream
= uno::Reference
< io::XStream
>();
327 m_xCacheSeek
= uno::Reference
< io::XSeekable
>();
331 void OWriteStream_Impl::AddLog( const OUString
& aMessage
)
333 if ( !m_xLogRing
.is() )
337 uno::Reference
< uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
338 m_xLogRing
= logging::DocumentIOLogRing::get(xContext
);
340 catch( const uno::Exception
& )
346 if ( m_xLogRing
.is() )
347 m_xLogRing
->logString( aMessage
);
350 void OWriteStream_Impl::InsertIntoPackageFolder( const OUString
& aName
,
351 const uno::Reference
< container::XNameContainer
>& xParentPackageFolder
)
353 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() );
355 SAL_WARN_IF( !m_bFlushed
, "package.xstor", "This method must not be called for nonflushed streams!" );
358 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "An inserted stream is incomplete!\n" );
359 uno::Reference
< lang::XUnoTunnel
> xTunnel( m_xPackageStream
, uno::UNO_QUERY
);
361 throw uno::RuntimeException(); // TODO
363 xParentPackageFolder
->insertByName( aName
, uno::makeAny( xTunnel
) );
366 m_bHasInsertedStreamOptimization
= false;
369 bool OWriteStream_Impl::IsEncrypted()
371 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
374 if ( m_bForceEncrypted
|| m_bHasCachedEncryptionData
)
377 if ( !m_aTempURL
.isEmpty() || m_xCacheStream
.is() )
380 GetStreamProperties();
382 // the following value can not be cached since it can change after root commit
383 bool bWasEncr
= false;
384 uno::Reference
< beans::XPropertySet
> xPropSet( m_xPackageStream
, uno::UNO_QUERY
);
387 uno::Any aValue
= xPropSet
->getPropertyValue("WasEncrypted");
388 if ( !( aValue
>>= bWasEncr
) )
390 SAL_WARN( "package.xstor", "The property WasEncrypted has wrong type!" );
394 bool bToBeEncr
= false;
395 for ( sal_Int32 nInd
= 0; nInd
< m_aProps
.getLength(); nInd
++ )
397 if ( m_aProps
[nInd
].Name
== "Encrypted" )
399 if ( !( m_aProps
[nInd
].Value
>>= bToBeEncr
) )
401 SAL_WARN( "package.xstor", "The property has wrong type!" );
406 // since a new key set to the package stream it should not be removed except the case when
407 // the stream becomes nonencrypted
408 uno::Sequence
< beans::NamedValue
> aKey
;
410 GetEncryptionKeyProperty_Impl( xPropSet
) >>= aKey
;
412 // If the properties must be investigated the stream is either
413 // was never changed or was changed, the parent was committed
414 // and the stream was closed.
415 // That means that if it is intended to use common storage key
416 // it is already has no encryption but is marked to be stored
417 // encrypted and the key is empty.
418 if ( !bWasEncr
&& bToBeEncr
&& !aKey
.getLength() )
420 // the stream is intended to use common storage password
421 m_bUseCommonEncryption
= true;
428 void OWriteStream_Impl::SetDecrypted()
430 SAL_WARN_IF( m_nStorageType
!= embed::StorageFormats::PACKAGE
, "package.xstor", "The encryption is supported only for package storages!" );
431 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
432 throw uno::RuntimeException();
434 GetStreamProperties();
436 // let the stream be modified
437 FillTempGetFileName();
438 m_bHasDataToFlush
= true;
441 m_bForceEncrypted
= false;
442 m_bHasCachedEncryptionData
= false;
443 m_aEncryptionData
.clear();
445 for ( sal_Int32 nInd
= 0; nInd
< m_aProps
.getLength(); nInd
++ )
447 if ( m_aProps
[nInd
].Name
== "Encrypted" )
448 m_aProps
[nInd
].Value
<<= false;
452 void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap
& aEncryptionData
)
454 SAL_WARN_IF( m_nStorageType
!= embed::StorageFormats::PACKAGE
, "package.xstor", "The encryption is supported only for package storages!" );
455 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
456 throw uno::RuntimeException();
458 if ( !aEncryptionData
.size() )
459 throw uno::RuntimeException();
461 GetStreamProperties();
463 // let the stream be modified
464 FillTempGetFileName();
465 m_bHasDataToFlush
= true;
467 // introduce encryption info
468 for ( sal_Int32 nInd
= 0; nInd
< m_aProps
.getLength(); nInd
++ )
470 if ( m_aProps
[nInd
].Name
== "Encrypted" )
471 m_aProps
[nInd
].Value
<<= true;
474 m_bUseCommonEncryption
= false; // very important to set it to false
476 m_bHasCachedEncryptionData
= true;
477 m_aEncryptionData
= aEncryptionData
;
480 void OWriteStream_Impl::DisposeWrappers()
482 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() );
486 m_pAntiImpl
->dispose();
488 catch ( const uno::RuntimeException
& rRuntimeException
)
490 AddLog( rRuntimeException
.Message
);
491 AddLog( "Quiet exception" );
498 if ( !m_aInputStreamsList
.empty() )
500 for ( InputStreamsList_Impl::iterator pStreamIter
= m_aInputStreamsList
.begin();
501 pStreamIter
!= m_aInputStreamsList
.end(); ++pStreamIter
)
503 if ( (*pStreamIter
) )
505 (*pStreamIter
)->InternalDispose();
506 (*pStreamIter
) = NULL
;
510 m_aInputStreamsList
.clear();
514 OUString
OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference
< io::XInputStream
>& xStream
)
516 if ( !m_aTempURL
.getLength() )
518 OUString aTempURL
= GetNewTempFileURL( m_xContext
);
521 if ( !aTempURL
.isEmpty() && xStream
.is() )
523 uno::Reference
< ucb::XSimpleFileAccess3
> xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
525 uno::Reference
< io::XOutputStream
> xTempOutStream
= xTempAccess
->openFileWrite( aTempURL
);
526 if ( xTempOutStream
.is() )
528 // the current position of the original stream should be still OK, copy further
529 ::comphelper::OStorageHelper::CopyInputToOutput( xStream
, xTempOutStream
);
530 xTempOutStream
->closeOutput();
531 xTempOutStream
= uno::Reference
< io::XOutputStream
>();
534 throw io::IOException(); // TODO:
537 catch( const packages::WrongPasswordException
& rWrongPasswordException
)
539 AddLog( rWrongPasswordException
.Message
);
542 KillFile( aTempURL
, comphelper::getProcessComponentContext() );
545 catch( const uno::Exception
& rException
)
547 AddLog( rException
.Message
);
550 KillFile( aTempURL
, comphelper::getProcessComponentContext() );
554 if ( !aTempURL
.isEmpty() )
557 m_aTempURL
= aTempURL
;
563 OUString
OWriteStream_Impl::FillTempGetFileName()
565 // should try to create cache first, if the amount of contents is too big, the temp file should be taken
566 if ( !m_xCacheStream
.is() && m_aTempURL
.isEmpty() )
568 uno::Reference
< io::XInputStream
> xOrigStream
= m_xPackageStream
->getDataStream();
569 if ( !xOrigStream
.is() )
571 // in case of new inserted package stream it is possible that input stream still was not set
572 uno::Reference
< io::XStream
> xCacheStream
= CreateMemoryStream( m_xContext
);
573 SAL_WARN_IF( !xCacheStream
.is(), "package.xstor", "If the stream can not be created an exception must be thrown!" );
574 m_xCacheSeek
.set( xCacheStream
, uno::UNO_QUERY_THROW
);
575 m_xCacheStream
= xCacheStream
;
580 uno::Sequence
< sal_Int8
> aData( MAX_STORCACHE_SIZE
+ 1 );
581 nRead
= xOrigStream
->readBytes( aData
, MAX_STORCACHE_SIZE
+ 1 );
582 if ( aData
.getLength() > nRead
)
583 aData
.realloc( nRead
);
585 if ( nRead
<= MAX_STORCACHE_SIZE
)
587 uno::Reference
< io::XStream
> xCacheStream
= CreateMemoryStream( m_xContext
);
588 SAL_WARN_IF( !xCacheStream
.is(), "package.xstor", "If the stream can not be created an exception must be thrown!" );
592 uno::Reference
< io::XOutputStream
> xOutStream( xCacheStream
->getOutputStream(), uno::UNO_SET_THROW
);
593 xOutStream
->writeBytes( aData
);
595 m_xCacheSeek
.set( xCacheStream
, uno::UNO_QUERY_THROW
);
596 m_xCacheStream
= xCacheStream
;
597 m_xCacheSeek
->seek( 0 );
599 else if ( m_aTempURL
.isEmpty() )
601 m_aTempURL
= GetNewTempFileURL( m_xContext
);
604 if ( !m_aTempURL
.isEmpty() )
606 uno::Reference
< ucb::XSimpleFileAccess3
> xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
608 uno::Reference
< io::XOutputStream
> xTempOutStream
= xTempAccess
->openFileWrite( m_aTempURL
);
609 if ( xTempOutStream
.is() )
611 // copy stream contents to the file
612 xTempOutStream
->writeBytes( aData
);
614 // the current position of the original stream should be still OK, copy further
615 ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream
, xTempOutStream
);
616 xTempOutStream
->closeOutput();
617 xTempOutStream
= uno::Reference
< io::XOutputStream
>();
620 throw io::IOException(); // TODO:
623 catch( const packages::WrongPasswordException
& )
625 KillFile( m_aTempURL
, comphelper::getProcessComponentContext() );
630 catch( const uno::Exception
& )
632 KillFile( m_aTempURL
, comphelper::getProcessComponentContext() );
642 uno::Reference
< io::XStream
> OWriteStream_Impl::GetTempFileAsStream()
644 uno::Reference
< io::XStream
> xTempStream
;
646 if ( !m_xCacheStream
.is() )
648 if ( m_aTempURL
.isEmpty() )
649 m_aTempURL
= FillTempGetFileName();
651 if ( !m_aTempURL
.isEmpty() )
653 // the temporary file is not used if the cache is used
654 uno::Reference
< ucb::XSimpleFileAccess3
> xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
658 xTempStream
= xTempAccess
->openFileReadWrite( m_aTempURL
);
660 catch( const uno::Exception
& rException
)
662 AddLog( rException
.Message
);
663 AddLog( "Quiet exception" );
668 if ( m_xCacheStream
.is() )
669 xTempStream
= m_xCacheStream
;
671 // the method must always return a stream
672 // in case the stream can not be open
673 // an exception should be thrown
674 if ( !xTempStream
.is() )
675 throw io::IOException(); //TODO:
680 uno::Reference
< io::XInputStream
> OWriteStream_Impl::GetTempFileAsInputStream()
682 uno::Reference
< io::XInputStream
> xInputStream
;
684 if ( !m_xCacheStream
.is() )
686 if ( m_aTempURL
.isEmpty() )
687 m_aTempURL
= FillTempGetFileName();
689 if ( !m_aTempURL
.isEmpty() )
691 // the temporary file is not used if the cache is used
692 uno::Reference
< ucb::XSimpleFileAccess3
> xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
696 xInputStream
= xTempAccess
->openFileRead( m_aTempURL
);
698 catch( const uno::Exception
& rException
)
700 AddLog( rException
.Message
);
701 AddLog( "Quiet exception" );
706 if ( m_xCacheStream
.is() )
707 xInputStream
= m_xCacheStream
->getInputStream();
709 // the method must always return a stream
710 // in case the stream can not be open
711 // an exception should be thrown
712 if ( !xInputStream
.is() )
713 throw io::IOException(); // TODO:
718 void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference
< io::XInputStream
>& xInStream
,
719 const uno::Sequence
< beans::PropertyValue
>& aProps
)
721 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
723 // this call can be made only during parent storage commit
724 // the parent storage is responsible for the correct handling
725 // of deleted and renamed contents
727 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
729 if ( m_bHasDataToFlush
)
730 throw io::IOException();
732 OSL_ENSURE( m_aTempURL
.isEmpty() && !m_xCacheStream
.is(), "The temporary must not exist!\n" );
734 // use new file as current persistent representation
735 // the new file will be removed after it's stream is closed
736 m_xPackageStream
->setDataStream( xInStream
);
738 // copy properties to the package stream
739 uno::Reference
< beans::XPropertySet
> xPropertySet( m_xPackageStream
, uno::UNO_QUERY
);
740 if ( !xPropertySet
.is() )
741 throw uno::RuntimeException();
743 // The storage-package communication has a problem
744 // the storage caches properties, thus if the package changes one of them itself
745 // the storage does not know about it
747 // Depending from MediaType value the package can change the compressed property itself
748 // Thus if Compressed property is provided it must be set as the latest one
749 bool bCompressedIsSet
= false;
750 bool bCompressed
= false;
751 OUString
aComprPropName( "Compressed" );
752 OUString
aMedTypePropName( "MediaType" );
753 for ( sal_Int32 nInd
= 0; nInd
< aProps
.getLength(); nInd
++ )
755 if ( aProps
[nInd
].Name
.equals( aComprPropName
) )
757 bCompressedIsSet
= true;
758 aProps
[nInd
].Value
>>= bCompressed
;
760 else if ( ( m_nStorageType
== embed::StorageFormats::OFOPXML
|| m_nStorageType
== embed::StorageFormats::PACKAGE
)
761 && aProps
[nInd
].Name
.equals( aMedTypePropName
) )
763 xPropertySet
->setPropertyValue( aProps
[nInd
].Name
, aProps
[nInd
].Value
);
765 else if ( m_nStorageType
== embed::StorageFormats::PACKAGE
&& aProps
[nInd
].Name
== "UseCommonStoragePasswordEncryption" )
766 aProps
[nInd
].Value
>>= m_bUseCommonEncryption
;
768 throw lang::IllegalArgumentException();
770 // if there are cached properties update them
771 if ( aProps
[nInd
].Name
.equals( aMedTypePropName
) || aProps
[nInd
].Name
.equals( aComprPropName
) )
772 for ( sal_Int32 nMemInd
= 0; nMemInd
< m_aProps
.getLength(); nMemInd
++ )
774 if ( aProps
[nInd
].Name
.equals( m_aProps
[nMemInd
].Name
) )
775 m_aProps
[nMemInd
].Value
= aProps
[nInd
].Value
;
779 if ( bCompressedIsSet
)
781 xPropertySet
->setPropertyValue( aComprPropName
, uno::makeAny( bCompressed
) );
782 m_bCompressedSetExplicit
= true;
785 if ( m_bUseCommonEncryption
)
787 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
788 throw uno::RuntimeException();
790 // set to be encrypted but do not use encryption key
791 xPropertySet
->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY
,
792 uno::makeAny( uno::Sequence
< beans::NamedValue
>() ) );
793 xPropertySet
->setPropertyValue( "Encrypted", uno::makeAny( true ) );
796 // the stream should be free soon, after package is stored
797 m_bHasDataToFlush
= false;
798 m_bFlushed
= true; // will allow to use transaction on stream level if will need it
799 m_bHasInsertedStreamOptimization
= true;
802 void OWriteStream_Impl::Commit()
804 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
806 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
808 if ( !m_bHasDataToFlush
)
811 uno::Reference
< packages::XDataSinkEncrSupport
> xNewPackageStream
;
812 uno::Sequence
< uno::Any
> aSeq( 1 );
813 aSeq
[0] <<= sal_False
;
815 if ( m_xCacheStream
.is() )
818 m_pAntiImpl
->DeInit();
820 uno::Reference
< io::XInputStream
> xInStream( m_xCacheStream
->getInputStream(), uno::UNO_SET_THROW
);
822 xNewPackageStream
= uno::Reference
< packages::XDataSinkEncrSupport
>(
823 m_xPackage
->createInstanceWithArguments( aSeq
),
824 uno::UNO_QUERY_THROW
);
826 xNewPackageStream
->setDataStream( xInStream
);
828 m_xCacheStream
= uno::Reference
< io::XStream
>();
829 m_xCacheSeek
= uno::Reference
< io::XSeekable
>();
832 else if ( !m_aTempURL
.isEmpty() )
835 m_pAntiImpl
->DeInit();
837 uno::Reference
< io::XInputStream
> xInStream
;
840 xInStream
.set( static_cast< io::XInputStream
* >( new OSelfTerminateFileStream( m_xContext
, m_aTempURL
) ), uno::UNO_QUERY
);
842 catch( const uno::Exception
& )
846 if ( !xInStream
.is() )
847 throw io::IOException();
849 xNewPackageStream
= uno::Reference
< packages::XDataSinkEncrSupport
>(
850 m_xPackage
->createInstanceWithArguments( aSeq
),
851 uno::UNO_QUERY_THROW
);
853 // TODO/NEW: Let the temporary file be removed after commit
854 xNewPackageStream
->setDataStream( xInStream
);
857 else // if ( m_bHasInsertedStreamOptimization )
859 // if the optimization is used the stream can be accessed directly
860 xNewPackageStream
= m_xPackageStream
;
863 // copy properties to the package stream
864 uno::Reference
< beans::XPropertySet
> xPropertySet( xNewPackageStream
, uno::UNO_QUERY
);
865 if ( !xPropertySet
.is() )
866 throw uno::RuntimeException();
868 for ( sal_Int32 nInd
= 0; nInd
< m_aProps
.getLength(); nInd
++ )
870 if ( m_aProps
[nInd
].Name
== "Size" )
872 if ( m_pAntiImpl
&& !m_bHasInsertedStreamOptimization
&& m_pAntiImpl
->m_xSeekable
.is() )
874 m_aProps
[nInd
].Value
<<= m_pAntiImpl
->m_xSeekable
->getLength();
875 xPropertySet
->setPropertyValue( m_aProps
[nInd
].Name
, m_aProps
[nInd
].Value
);
879 xPropertySet
->setPropertyValue( m_aProps
[nInd
].Name
, m_aProps
[nInd
].Value
);
882 if ( m_bUseCommonEncryption
)
884 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
885 throw uno::RuntimeException();
887 // set to be encrypted but do not use encryption key
888 xPropertySet
->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY
,
889 uno::makeAny( uno::Sequence
< beans::NamedValue
>() ) );
890 xPropertySet
->setPropertyValue( "Encrypted",
891 uno::makeAny( true ) );
893 else if ( m_bHasCachedEncryptionData
)
895 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
896 throw uno::RuntimeException();
898 xPropertySet
->setPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY
,
899 uno::makeAny( m_aEncryptionData
.getAsConstNamedValueList() ) );
902 // the stream should be free soon, after package is stored
903 m_xPackageStream
= xNewPackageStream
;
904 m_bHasDataToFlush
= false;
905 m_bFlushed
= true; // will allow to use transaction on stream level if will need it
908 void OWriteStream_Impl::Revert()
910 // can be called only from parent storage
911 // means complete reload of the stream
913 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
915 if ( !m_bHasDataToFlush
)
916 return; // nothing to do
918 OSL_ENSURE( !m_aTempURL
.isEmpty() || m_xCacheStream
.is(), "The temporary must exist!\n" );
920 if ( m_xCacheStream
.is() )
922 m_xCacheStream
= uno::Reference
< io::XStream
>();
923 m_xCacheSeek
= uno::Reference
< io::XSeekable
>();
926 if ( !m_aTempURL
.isEmpty() )
928 KillFile( m_aTempURL
, comphelper::getProcessComponentContext() );
932 m_aProps
.realloc( 0 );
934 m_bHasDataToFlush
= false;
936 m_bUseCommonEncryption
= true;
937 m_bHasCachedEncryptionData
= false;
938 m_aEncryptionData
.clear();
940 if ( m_nStorageType
== embed::StorageFormats::OFOPXML
)
942 // currently the relations storage is changed only on commit
943 m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
944 m_aNewRelInfo
= uno::Sequence
< uno::Sequence
< beans::StringPair
> >();
945 if ( m_xOrigRelInfoStream
.is() )
947 // the original stream is still here, that means that it was not parsed
948 m_aOrigRelInfo
= uno::Sequence
< uno::Sequence
< beans::StringPair
> >();
949 m_nRelInfoStatus
= RELINFO_NO_INIT
;
953 // the original stream was already parsed
954 if ( !m_bOrigRelInfoBroken
)
955 m_nRelInfoStatus
= RELINFO_READ
;
957 m_nRelInfoStatus
= RELINFO_BROKEN
;
962 uno::Sequence
< beans::PropertyValue
> OWriteStream_Impl::GetStreamProperties()
964 if ( !m_aProps
.getLength() )
965 m_aProps
= ReadPackageStreamProperties();
970 uno::Sequence
< beans::PropertyValue
> OWriteStream_Impl::InsertOwnProps(
971 const uno::Sequence
< beans::PropertyValue
>& aProps
,
972 bool bUseCommonEncryption
)
974 uno::Sequence
< beans::PropertyValue
> aResult( aProps
);
975 sal_Int32 nLen
= aResult
.getLength();
977 if ( m_nStorageType
== embed::StorageFormats::PACKAGE
)
979 for ( sal_Int32 nInd
= 0; nInd
< nLen
; nInd
++ )
980 if ( aResult
[nInd
].Name
== "UseCommonStoragePasswordEncryption" )
982 aResult
[nInd
].Value
<<= bUseCommonEncryption
;
986 aResult
.realloc( ++nLen
);
987 aResult
[nLen
- 1].Name
= "UseCommonStoragePasswordEncryption";
988 aResult
[nLen
- 1].Value
<<= bUseCommonEncryption
;
990 else if ( m_nStorageType
== embed::StorageFormats::OFOPXML
)
992 ReadRelInfoIfNecessary();
995 if ( m_nRelInfoStatus
== RELINFO_READ
)
996 aValue
<<= m_aOrigRelInfo
;
997 else if ( m_nRelInfoStatus
== RELINFO_CHANGED_STREAM_READ
|| m_nRelInfoStatus
== RELINFO_CHANGED
)
998 aValue
<<= m_aNewRelInfo
;
999 else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1000 throw io::IOException( "Wrong relinfo stream!" );
1002 for ( sal_Int32 nInd
= 0; nInd
< nLen
; nInd
++ )
1003 if ( aResult
[nInd
].Name
== "RelationsInfo" )
1005 aResult
[nInd
].Value
= aValue
;
1009 aResult
.realloc( ++nLen
);
1010 aResult
[nLen
- 1].Name
= "RelationsInfo";
1011 aResult
[nLen
- 1].Value
= aValue
;
1017 bool OWriteStream_Impl::IsTransacted()
1019 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1020 return ( m_pAntiImpl
&& m_pAntiImpl
->m_bTransacted
);
1023 void OWriteStream_Impl::ReadRelInfoIfNecessary()
1025 if ( m_nStorageType
!= embed::StorageFormats::OFOPXML
)
1028 if ( m_nRelInfoStatus
== RELINFO_NO_INIT
)
1032 // Init from original stream
1033 if ( m_xOrigRelInfoStream
.is() )
1034 m_aOrigRelInfo
= ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
1035 m_xOrigRelInfoStream
,
1039 // in case of success the stream must be thrown away, that means that the OrigRelInfo is initialized
1040 // the reason for this is that the original stream might not be seekable ( at the same time the new
1041 // provided stream must be seekable ), so it must be read only once
1042 m_xOrigRelInfoStream
= uno::Reference
< io::XInputStream
>();
1043 m_nRelInfoStatus
= RELINFO_READ
;
1045 catch( const uno::Exception
& rException
)
1047 AddLog( rException
.Message
);
1048 AddLog( "Quiet exception" );
1050 m_nRelInfoStatus
= RELINFO_BROKEN
;
1051 m_bOrigRelInfoBroken
= true;
1054 else if ( m_nRelInfoStatus
== RELINFO_CHANGED_STREAM
)
1056 // Init from the new stream
1059 if ( m_xNewRelInfoStream
.is() )
1060 m_aNewRelInfo
= ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
1061 m_xNewRelInfoStream
,
1065 m_nRelInfoStatus
= RELINFO_CHANGED_STREAM_READ
;
1067 catch( const uno::Exception
& )
1069 m_nRelInfoStatus
= RELINFO_CHANGED_BROKEN
;
1074 uno::Sequence
< beans::PropertyValue
> OWriteStream_Impl::ReadPackageStreamProperties()
1076 sal_Int32 nPropNum
= 0;
1077 if ( m_nStorageType
== embed::StorageFormats::ZIP
)
1079 else if ( m_nStorageType
== embed::StorageFormats::OFOPXML
)
1081 else if ( m_nStorageType
== embed::StorageFormats::PACKAGE
)
1083 uno::Sequence
< beans::PropertyValue
> aResult( nPropNum
);
1085 // The "Compressed" property must be set after "MediaType" property,
1086 // since the setting of the last one can change the value of the first one
1088 if ( m_nStorageType
== embed::StorageFormats::OFOPXML
|| m_nStorageType
== embed::StorageFormats::PACKAGE
)
1090 aResult
[0].Name
= "MediaType";
1091 aResult
[1].Name
= "Compressed";
1092 aResult
[2].Name
= "Size";
1094 if ( m_nStorageType
== embed::StorageFormats::PACKAGE
)
1095 aResult
[3].Name
= "Encrypted";
1099 aResult
[0].Name
= "Compressed";
1100 aResult
[1].Name
= "Size";
1103 // TODO: may be also raw stream should be marked
1105 uno::Reference
< beans::XPropertySet
> xPropSet( m_xPackageStream
, uno::UNO_QUERY
);
1106 if ( xPropSet
.is() )
1108 for ( sal_Int32 nInd
= 0; nInd
< aResult
.getLength(); nInd
++ )
1111 aResult
[nInd
].Value
= xPropSet
->getPropertyValue( aResult
[nInd
].Name
);
1113 catch( const uno::Exception
& rException
)
1115 AddLog( rException
.Message
);
1116 AddLog( "Quiet exception" );
1118 SAL_WARN( "package.xstor", "A property can't be retrieved!" );
1124 SAL_WARN( "package.xstor", "Can not get properties from a package stream!" );
1125 throw uno::RuntimeException();
1131 void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference
< io::XStream
>& xDestStream
,
1132 const ::comphelper::SequenceAsHashMap
& aEncryptionData
)
1134 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1136 SAL_WARN_IF( m_bUseCommonEncryption
, "package.xstor", "The stream can not be encrypted!" );
1138 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
)
1139 throw packages::NoEncryptionException();
1143 m_pAntiImpl
->CopyToStreamInternally_Impl( xDestStream
);
1147 uno::Reference
< io::XStream
> xOwnStream
= GetStream( embed::ElementModes::READ
, aEncryptionData
, false );
1148 if ( !xOwnStream
.is() )
1149 throw io::IOException(); // TODO
1151 OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream
, xDestStream
, m_nStorageType
, GetAllRelationshipsIfAny() );
1154 uno::Reference
< embed::XEncryptionProtectedSource2
> xEncr( xDestStream
, uno::UNO_QUERY
);
1156 xEncr
->setEncryptionData( aEncryptionData
.getAsConstNamedValueList() );
1159 uno::Sequence
< uno::Sequence
< beans::StringPair
> > OWriteStream_Impl::GetAllRelationshipsIfAny()
1161 if ( m_nStorageType
!= embed::StorageFormats::OFOPXML
)
1162 return uno::Sequence
< uno::Sequence
< beans::StringPair
> >();
1164 ReadRelInfoIfNecessary();
1166 if ( m_nRelInfoStatus
== RELINFO_READ
)
1167 return m_aOrigRelInfo
;
1168 else if ( m_nRelInfoStatus
== RELINFO_CHANGED_STREAM_READ
|| m_nRelInfoStatus
== RELINFO_CHANGED
)
1169 return m_aNewRelInfo
;
1170 else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1171 throw io::IOException( "Wrong relinfo stream!" );
1174 void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference
< io::XStream
>& xDestStream
)
1176 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1180 m_pAntiImpl
->CopyToStreamInternally_Impl( xDestStream
);
1184 uno::Reference
< io::XStream
> xOwnStream
= GetStream( embed::ElementModes::READ
, false );
1185 if ( !xOwnStream
.is() )
1186 throw io::IOException(); // TODO
1188 OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream
, xDestStream
, m_nStorageType
, GetAllRelationshipsIfAny() );
1192 uno::Reference
< io::XStream
> OWriteStream_Impl::GetStream( sal_Int32 nStreamMode
, const ::comphelper::SequenceAsHashMap
& aEncryptionData
, bool bHierarchyAccess
)
1194 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1196 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
1199 throw io::IOException(); // TODO:
1201 if ( !IsEncrypted() )
1202 throw packages::NoEncryptionException();
1204 uno::Reference
< io::XStream
> xResultStream
;
1206 uno::Reference
< beans::XPropertySet
> xPropertySet( m_xPackageStream
, uno::UNO_QUERY
);
1207 if ( !xPropertySet
.is() )
1208 throw uno::RuntimeException();
1210 if ( m_bHasCachedEncryptionData
)
1212 if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData
, aEncryptionData
) )
1213 throw packages::WrongPasswordException();
1215 // the correct key must be set already
1216 xResultStream
= GetStream_Impl( nStreamMode
, bHierarchyAccess
);
1220 SetEncryptionKeyProperty_Impl( xPropertySet
, aEncryptionData
.getAsConstNamedValueList() );
1223 xResultStream
= GetStream_Impl( nStreamMode
, bHierarchyAccess
);
1225 m_bUseCommonEncryption
= false; // very important to set it to false
1226 m_bHasCachedEncryptionData
= true;
1227 m_aEncryptionData
= aEncryptionData
;
1229 catch( const packages::WrongPasswordException
& rWrongPasswordException
)
1231 SetEncryptionKeyProperty_Impl( xPropertySet
, uno::Sequence
< beans::NamedValue
>() );
1232 AddLog( rWrongPasswordException
.Message
);
1233 AddLog( "Rethrow" );
1236 catch ( const uno::Exception
& rException
)
1238 AddLog( rException
.Message
);
1239 AddLog( "Quiet exception" );
1241 SAL_WARN( "package.xstor", "Can't write encryption related properties!" );
1242 SetEncryptionKeyProperty_Impl( xPropertySet
, uno::Sequence
< beans::NamedValue
>() );
1243 throw io::IOException(); // TODO:
1247 SAL_WARN_IF( !xResultStream
.is(), "package.xstor", "In case stream can not be retrieved an exception must be thrown!" );
1249 return xResultStream
;
1252 uno::Reference
< io::XStream
> OWriteStream_Impl::GetStream( sal_Int32 nStreamMode
, bool bHierarchyAccess
)
1254 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1256 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
1259 throw io::IOException(); // TODO:
1261 uno::Reference
< io::XStream
> xResultStream
;
1263 if ( IsEncrypted() )
1265 ::comphelper::SequenceAsHashMap aGlobalEncryptionData
;
1268 aGlobalEncryptionData
= GetCommonRootEncryptionData();
1270 catch( const packages::NoEncryptionException
& rNoEncryptionException
)
1272 AddLog( rNoEncryptionException
.Message
);
1273 AddLog( "Rethrow" );
1275 throw packages::WrongPasswordException();
1278 xResultStream
= GetStream( nStreamMode
, aGlobalEncryptionData
, bHierarchyAccess
);
1281 xResultStream
= GetStream_Impl( nStreamMode
, bHierarchyAccess
);
1283 return xResultStream
;
1286 uno::Reference
< io::XStream
> OWriteStream_Impl::GetStream_Impl( sal_Int32 nStreamMode
, bool bHierarchyAccess
)
1288 // private method, no mutex is used
1289 GetStreamProperties();
1291 // TODO/LATER: this info might be read later, on demand in future
1292 ReadRelInfoIfNecessary();
1294 if ( ( nStreamMode
& embed::ElementModes::READWRITE
) == embed::ElementModes::READ
)
1296 uno::Reference
< io::XInputStream
> xInStream
;
1297 if ( m_xCacheStream
.is() || !m_aTempURL
.isEmpty() )
1298 xInStream
= GetTempFileAsInputStream(); //TODO:
1300 xInStream
= m_xPackageStream
->getDataStream();
1302 // The stream does not exist in the storage
1303 if ( !xInStream
.is() )
1304 throw io::IOException();
1306 OInputCompStream
* pStream
= new OInputCompStream( *this, xInStream
, InsertOwnProps( m_aProps
, m_bUseCommonEncryption
), m_nStorageType
);
1307 uno::Reference
< io::XStream
> xCompStream(
1308 static_cast< ::cppu::OWeakObject
* >( pStream
),
1310 SAL_WARN_IF( !xCompStream
.is(), "package.xstor", "OInputCompStream MUST provide XStream interfaces!" );
1312 m_aInputStreamsList
.push_back( pStream
);
1315 else if ( ( nStreamMode
& embed::ElementModes::READWRITE
) == embed::ElementModes::SEEKABLEREAD
)
1317 if ( !m_xCacheStream
.is() && m_aTempURL
.isEmpty() && !( m_xPackageStream
->getDataStream().is() ) )
1319 // The stream does not exist in the storage
1320 throw io::IOException();
1323 uno::Reference
< io::XInputStream
> xInStream
;
1325 xInStream
= GetTempFileAsInputStream(); //TODO:
1327 if ( !xInStream
.is() )
1328 throw io::IOException();
1330 OInputSeekStream
* pStream
= new OInputSeekStream( *this, xInStream
, InsertOwnProps( m_aProps
, m_bUseCommonEncryption
), m_nStorageType
);
1331 uno::Reference
< io::XStream
> xSeekStream(
1332 static_cast< ::cppu::OWeakObject
* >( pStream
),
1334 SAL_WARN_IF( !xSeekStream
.is(), "package.xstor", "OInputSeekStream MUST provide XStream interfaces!" );
1336 m_aInputStreamsList
.push_back( pStream
);
1339 else if ( ( nStreamMode
& embed::ElementModes::WRITE
) == embed::ElementModes::WRITE
)
1341 if ( !m_aInputStreamsList
.empty() )
1342 throw io::IOException(); // TODO:
1344 uno::Reference
< io::XStream
> xStream
;
1345 if ( ( nStreamMode
& embed::ElementModes::TRUNCATE
) == embed::ElementModes::TRUNCATE
)
1347 if ( !m_aTempURL
.isEmpty() )
1349 KillFile( m_aTempURL
, comphelper::getProcessComponentContext() );
1352 if ( m_xCacheStream
.is() )
1355 m_bHasDataToFlush
= true;
1357 // this call is triggered by the parent and it will recognize the change of the state
1359 m_pParent
->m_bIsModified
= true;
1361 xStream
= CreateMemoryStream( m_xContext
);
1362 m_xCacheSeek
.set( xStream
, uno::UNO_QUERY_THROW
);
1363 m_xCacheStream
= xStream
;
1365 else if ( !m_bHasInsertedStreamOptimization
)
1367 if ( m_aTempURL
.isEmpty() && !m_xCacheStream
.is() && !( m_xPackageStream
->getDataStream().is() ) )
1369 // The stream does not exist in the storage
1370 m_bHasDataToFlush
= true;
1372 // this call is triggered by the parent and it will recognize the change of the state
1374 m_pParent
->m_bIsModified
= true;
1375 xStream
= GetTempFileAsStream();
1378 // if the stream exists the temporary file is created on demand
1379 // xStream = GetTempFileAsStream();
1382 if ( !xStream
.is() )
1383 m_pAntiImpl
= new OWriteStream( this, bHierarchyAccess
);
1385 m_pAntiImpl
= new OWriteStream( this, xStream
, bHierarchyAccess
);
1387 uno::Reference
< io::XStream
> xWriteStream
=
1388 uno::Reference
< io::XStream
>( static_cast< ::cppu::OWeakObject
* >( m_pAntiImpl
),
1391 SAL_WARN_IF( !xWriteStream
.is(), "package.xstor", "OWriteStream MUST implement XStream && XComponent interfaces!" );
1393 return xWriteStream
;
1396 throw lang::IllegalArgumentException(); // TODO
1399 uno::Reference
< io::XInputStream
> OWriteStream_Impl::GetPlainRawInStream()
1401 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1403 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
1405 // this method is used only internally, this stream object should not go outside of this implementation
1406 // if ( m_pAntiImpl )
1407 // throw io::IOException(); // TODO:
1409 return m_xPackageStream
->getPlainRawStream();
1412 uno::Reference
< io::XInputStream
> OWriteStream_Impl::GetRawInStream()
1414 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1416 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "No package stream is set!" );
1419 throw io::IOException(); // TODO:
1421 SAL_WARN_IF( !IsEncrypted(), "package.xstor", "Impossible to get raw representation for nonencrypted stream!" );
1422 if ( !IsEncrypted() )
1423 throw packages::NoEncryptionException();
1425 return m_xPackageStream
->getRawStream();
1428 ::comphelper::SequenceAsHashMap
OWriteStream_Impl::GetCommonRootEncryptionData()
1429 throw ( packages::NoEncryptionException
)
1431 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() ) ;
1433 if ( m_nStorageType
!= embed::StorageFormats::PACKAGE
|| !m_pParent
)
1434 throw packages::NoEncryptionException();
1436 return m_pParent
->GetCommonRootEncryptionData();
1439 void OWriteStream_Impl::InputStreamDisposed( OInputCompStream
* pStream
)
1441 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() );
1442 m_aInputStreamsList
.remove( pStream
);
1445 void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference
< io::XInputStream
>& xDataToCopy
, const uno::Sequence
< beans::PropertyValue
>& aProps
, bool, uno::Reference
< io::XStream
>& xTargetStream
)
1447 uno::Reference
< io::XStream
> xTempFile
;
1448 if ( !xTargetStream
.is() )
1449 xTempFile
= uno::Reference
< io::XStream
>(
1450 io::TempFile::create(m_xContext
),
1453 xTempFile
= xTargetStream
;
1455 uno::Reference
< io::XSeekable
> xTempSeek( xTempFile
, uno::UNO_QUERY
);
1456 if ( !xTempSeek
.is() )
1457 throw uno::RuntimeException(); // TODO
1459 uno::Reference
< io::XOutputStream
> xTempOut
= xTempFile
->getOutputStream();
1460 if ( !xTempOut
.is() )
1461 throw uno::RuntimeException();
1463 if ( xDataToCopy
.is() )
1464 ::comphelper::OStorageHelper::CopyInputToOutput( xDataToCopy
, xTempOut
);
1466 xTempOut
->closeOutput();
1467 xTempSeek
->seek( 0 );
1469 uno::Reference
< io::XInputStream
> xInStream
= xTempFile
->getInputStream();
1470 if ( !xInStream
.is() )
1471 throw io::IOException();
1473 // TODO: remember last state of m_bUseCommonEncryption
1474 if ( !xTargetStream
.is() )
1475 xTargetStream
= uno::Reference
< io::XStream
> (
1476 static_cast< ::cppu::OWeakObject
* >(
1477 new OInputSeekStream( xInStream
, InsertOwnProps( aProps
, m_bUseCommonEncryption
), m_nStorageType
) ),
1478 uno::UNO_QUERY_THROW
);
1481 void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference
< io::XStream
>& xTargetStream
)
1483 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() );
1485 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "The source stream for copying is incomplete!" );
1486 if ( !m_xPackageStream
.is() )
1487 throw uno::RuntimeException();
1489 uno::Reference
< io::XInputStream
> xDataToCopy
;
1490 if ( IsEncrypted() )
1492 // an encrypted stream must contain input stream
1493 ::comphelper::SequenceAsHashMap aGlobalEncryptionData
;
1496 aGlobalEncryptionData
= GetCommonRootEncryptionData();
1498 catch( const packages::NoEncryptionException
& rNoEncryptionException
)
1500 AddLog( rNoEncryptionException
.Message
);
1501 AddLog( "No Element" );
1503 throw packages::WrongPasswordException();
1506 GetCopyOfLastCommit( xTargetStream
, aGlobalEncryptionData
);
1510 xDataToCopy
= m_xPackageStream
->getDataStream();
1512 // in case of new inserted package stream it is possible that input stream still was not set
1513 GetStreamProperties();
1515 CreateReadonlyCopyBasedOnData( xDataToCopy
, m_aProps
, m_bUseCommonEncryption
, xTargetStream
);
1519 void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference
< io::XStream
>& xTargetStream
, const ::comphelper::SequenceAsHashMap
& aEncryptionData
)
1521 ::osl::MutexGuard
aGuard( m_rMutexRef
->GetMutex() );
1523 SAL_WARN_IF( !m_xPackageStream
.is(), "package.xstor", "The source stream for copying is incomplete!" );
1524 if ( !m_xPackageStream
.is() )
1525 throw uno::RuntimeException();
1527 if ( !IsEncrypted() )
1528 throw packages::NoEncryptionException();
1530 uno::Reference
< io::XInputStream
> xDataToCopy
;
1532 if ( m_bHasCachedEncryptionData
)
1534 // TODO: introduce last committed cashed password information and use it here
1535 // that means "use common pass" also should be remembered on flash
1536 uno::Sequence
< beans::NamedValue
> aKey
= aEncryptionData
.getAsConstNamedValueList();
1538 uno::Reference
< beans::XPropertySet
> xProps( m_xPackageStream
, uno::UNO_QUERY
);
1540 throw uno::RuntimeException();
1543 xProps
->getPropertyValue( "Encrypted" ) >>= bEncr
;
1545 throw packages::NoEncryptionException();
1547 uno::Sequence
< beans::NamedValue
> aPackKey
;
1548 xProps
->getPropertyValue( STORAGE_ENCRYPTION_KEYS_PROPERTY
) >>= aPackKey
;
1549 if ( !SequencesEqual( aKey
, aPackKey
) )
1550 throw packages::WrongPasswordException();
1552 // the correct key must be set already
1553 xDataToCopy
= m_xPackageStream
->getDataStream();
1557 uno::Reference
< beans::XPropertySet
> xPropertySet( m_xPackageStream
, uno::UNO_QUERY
);
1558 SetEncryptionKeyProperty_Impl( xPropertySet
, aEncryptionData
.getAsConstNamedValueList() );
1561 xDataToCopy
= m_xPackageStream
->getDataStream();
1563 if ( !xDataToCopy
.is() )
1565 SAL_WARN( "package.xstor", "Encrypted ZipStream must already have input stream inside!" );
1566 SetEncryptionKeyProperty_Impl( xPropertySet
, uno::Sequence
< beans::NamedValue
>() );
1569 catch( const uno::Exception
& rException
)
1571 SAL_WARN( "package.xstor", "Can't open encrypted stream!" );
1572 SetEncryptionKeyProperty_Impl( xPropertySet
, uno::Sequence
< beans::NamedValue
>() );
1573 AddLog( rException
.Message
);
1574 AddLog( "Rethrow" );
1578 SetEncryptionKeyProperty_Impl( xPropertySet
, uno::Sequence
< beans::NamedValue
>() );
1581 // in case of new inserted package stream it is possible that input stream still was not set
1582 GetStreamProperties();
1584 CreateReadonlyCopyBasedOnData( xDataToCopy
, m_aProps
, m_bUseCommonEncryption
, xTargetStream
);
1587 void OWriteStream_Impl::CommitStreamRelInfo( const uno::Reference
< embed::XStorage
>& xRelStorage
, const OUString
& aOrigStreamName
, const OUString
& aNewStreamName
)
1589 // at this point of time the old stream must be already cleaned
1590 OSL_ENSURE( m_nStorageType
== embed::StorageFormats::OFOPXML
, "The method should be used only with OFOPXML format!\n" );
1592 if ( m_nStorageType
== embed::StorageFormats::OFOPXML
)
1594 OSL_ENSURE( !aOrigStreamName
.isEmpty() && !aNewStreamName
.isEmpty() && xRelStorage
.is(),
1595 "Wrong relation persistence information is provided!\n" );
1597 if ( !xRelStorage
.is() || aOrigStreamName
.isEmpty() || aNewStreamName
.isEmpty() )
1598 throw uno::RuntimeException();
1600 if ( m_nRelInfoStatus
== RELINFO_BROKEN
|| m_nRelInfoStatus
== RELINFO_CHANGED_BROKEN
)
1601 throw io::IOException(); // TODO:
1603 OUString aOrigRelStreamName
= aOrigStreamName
;
1604 aOrigRelStreamName
+= ".rels";
1606 OUString aNewRelStreamName
= aNewStreamName
;
1607 aNewRelStreamName
+= ".rels";
1609 bool bRenamed
= !aOrigRelStreamName
.equals( aNewRelStreamName
);
1610 if ( m_nRelInfoStatus
== RELINFO_CHANGED
1611 || m_nRelInfoStatus
== RELINFO_CHANGED_STREAM_READ
1612 || m_nRelInfoStatus
== RELINFO_CHANGED_STREAM
)
1614 if ( bRenamed
&& xRelStorage
->hasByName( aOrigRelStreamName
) )
1615 xRelStorage
->removeElement( aOrigRelStreamName
);
1617 if ( m_nRelInfoStatus
== RELINFO_CHANGED
)
1619 if ( m_aNewRelInfo
.getLength() )
1621 uno::Reference
< io::XStream
> xRelsStream
=
1622 xRelStorage
->openStreamElement( aNewRelStreamName
,
1623 embed::ElementModes::TRUNCATE
| embed::ElementModes::READWRITE
);
1625 uno::Reference
< io::XOutputStream
> xOutStream
= xRelsStream
->getOutputStream();
1626 if ( !xOutStream
.is() )
1627 throw uno::RuntimeException();
1629 ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream
, m_aNewRelInfo
, m_xContext
);
1631 // set the mediatype
1632 uno::Reference
< beans::XPropertySet
> xPropSet( xRelsStream
, uno::UNO_QUERY_THROW
);
1633 xPropSet
->setPropertyValue(
1635 uno::makeAny( OUString("application/vnd.openxmlformats-package.relationships+xml" ) ) );
1637 m_nRelInfoStatus
= RELINFO_READ
;
1640 else if ( m_nRelInfoStatus
== RELINFO_CHANGED_STREAM_READ
1641 || m_nRelInfoStatus
== RELINFO_CHANGED_STREAM
)
1643 uno::Reference
< io::XStream
> xRelsStream
=
1644 xRelStorage
->openStreamElement( aNewRelStreamName
,
1645 embed::ElementModes::TRUNCATE
| embed::ElementModes::READWRITE
);
1647 uno::Reference
< io::XOutputStream
> xOutputStream
= xRelsStream
->getOutputStream();
1648 if ( !xOutputStream
.is() )
1649 throw uno::RuntimeException();
1651 uno::Reference
< io::XSeekable
> xSeek( m_xNewRelInfoStream
, uno::UNO_QUERY_THROW
);
1653 ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream
, xOutputStream
);
1656 // set the mediatype
1657 uno::Reference
< beans::XPropertySet
> xPropSet( xRelsStream
, uno::UNO_QUERY_THROW
);
1658 xPropSet
->setPropertyValue("MediaType",
1659 uno::makeAny( OUString("application/vnd.openxmlformats-package.relationships+xml" ) ) );
1661 if ( m_nRelInfoStatus
== RELINFO_CHANGED_STREAM
)
1662 m_nRelInfoStatus
= RELINFO_NO_INIT
;
1665 // the information is already parsed and the stream is stored, no need in temporary stream any more
1666 m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
1667 m_nRelInfoStatus
= RELINFO_READ
;
1671 // the original stream makes no sense after this step
1672 m_xOrigRelInfoStream
= m_xNewRelInfoStream
;
1673 m_aOrigRelInfo
= m_aNewRelInfo
;
1674 m_bOrigRelInfoBroken
= false;
1675 m_aNewRelInfo
= uno::Sequence
< uno::Sequence
< beans::StringPair
> >();
1676 m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
1680 // the stream is not changed but it might be renamed
1681 if ( bRenamed
&& xRelStorage
->hasByName( aOrigRelStreamName
) )
1682 xRelStorage
->renameElement( aOrigRelStreamName
, aNewRelStreamName
);
1687 // OWriteStream implementation
1689 OWriteStream::OWriteStream( OWriteStream_Impl
* pImpl
, bool bTransacted
)
1691 , m_bInStreamDisconnected( false )
1692 , m_bInitOnDemand( true )
1693 , m_nInitPosition( 0 )
1694 , m_bTransacted( bTransacted
)
1696 OSL_ENSURE( pImpl
, "No base implementation!\n" );
1697 OSL_ENSURE( m_pImpl
->m_rMutexRef
.Is(), "No mutex!\n" );
1699 if ( !m_pImpl
|| !m_pImpl
->m_rMutexRef
.Is() )
1700 throw uno::RuntimeException(); // just a disaster
1702 m_pData
.reset(new WSInternalData_Impl(pImpl
->m_rMutexRef
, m_pImpl
->m_nStorageType
));
1705 OWriteStream::OWriteStream( OWriteStream_Impl
* pImpl
, uno::Reference
< io::XStream
> xStream
, bool bTransacted
)
1707 , m_bInStreamDisconnected( false )
1708 , m_bInitOnDemand( false )
1709 , m_nInitPosition( 0 )
1710 , m_bTransacted( bTransacted
)
1712 OSL_ENSURE( pImpl
&& xStream
.is(), "No base implementation!\n" );
1713 OSL_ENSURE( m_pImpl
->m_rMutexRef
.Is(), "No mutex!\n" );
1715 if ( !m_pImpl
|| !m_pImpl
->m_rMutexRef
.Is() )
1716 throw uno::RuntimeException(); // just a disaster
1718 m_pData
.reset(new WSInternalData_Impl(pImpl
->m_rMutexRef
, m_pImpl
->m_nStorageType
));
1722 m_xInStream
= xStream
->getInputStream();
1723 m_xOutStream
= xStream
->getOutputStream();
1724 m_xSeekable
= uno::Reference
< io::XSeekable
>( xStream
, uno::UNO_QUERY
);
1725 OSL_ENSURE( m_xInStream
.is() && m_xOutStream
.is() && m_xSeekable
.is(), "Stream implementation is incomplete!\n" );
1729 OWriteStream::~OWriteStream()
1731 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
1738 catch( const uno::RuntimeException
& rRuntimeException
)
1740 m_pImpl
->AddLog( rRuntimeException
.Message
);
1741 m_pImpl
->AddLog( "Quiet exception" );
1746 void OWriteStream::DeInit()
1749 return; // do nothing
1751 if ( m_xSeekable
.is() )
1752 m_nInitPosition
= m_xSeekable
->getPosition();
1754 m_xInStream
= uno::Reference
< io::XInputStream
>();
1755 m_xOutStream
= uno::Reference
< io::XOutputStream
>();
1756 m_xSeekable
= uno::Reference
< io::XSeekable
>();
1757 m_bInitOnDemand
= true;
1760 void OWriteStream::CheckInitOnDemand()
1764 SAL_INFO("package.xstor", "Disposed!");
1765 throw lang::DisposedException();
1768 if ( m_bInitOnDemand
)
1770 SAL_INFO( "package.xstor", "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" );
1771 uno::Reference
< io::XStream
> xStream
= m_pImpl
->GetTempFileAsStream();
1774 m_xInStream
.set( xStream
->getInputStream(), uno::UNO_SET_THROW
);
1775 m_xOutStream
.set( xStream
->getOutputStream(), uno::UNO_SET_THROW
);
1776 m_xSeekable
.set( xStream
, uno::UNO_QUERY_THROW
);
1777 m_xSeekable
->seek( m_nInitPosition
);
1779 m_nInitPosition
= 0;
1780 m_bInitOnDemand
= false;
1785 void OWriteStream::CopyToStreamInternally_Impl( const uno::Reference
< io::XStream
>& xDest
)
1787 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
1789 CheckInitOnDemand();
1791 if ( !m_xInStream
.is() )
1792 throw uno::RuntimeException();
1794 if ( !m_xSeekable
.is() )
1795 throw uno::RuntimeException();
1797 uno::Reference
< beans::XPropertySet
> xDestProps( xDest
, uno::UNO_QUERY
);
1798 if ( !xDestProps
.is() )
1799 throw uno::RuntimeException(); //TODO
1801 uno::Reference
< io::XOutputStream
> xDestOutStream
= xDest
->getOutputStream();
1802 if ( !xDestOutStream
.is() )
1803 throw io::IOException(); // TODO
1805 sal_Int64 nCurPos
= m_xSeekable
->getPosition();
1806 m_xSeekable
->seek( 0 );
1808 uno::Exception eThrown
;
1809 bool bThrown
= false;
1811 ::comphelper::OStorageHelper::CopyInputToOutput( m_xInStream
, xDestOutStream
);
1813 catch ( const uno::Exception
& e
)
1819 // position-related section below is critical
1820 // if it fails the stream will become invalid
1822 m_xSeekable
->seek( nCurPos
);
1824 catch ( const uno::Exception
& rException
)
1826 m_pImpl
->AddLog( rException
.Message
);
1827 m_pImpl
->AddLog( "Quiet exception" );
1829 // TODO: set the stoream in invalid state or dispose
1830 SAL_WARN( "package.xstor", "The stream become invalid during copiing!" );
1831 throw uno::RuntimeException();
1837 // now the properties can be copied
1838 // the order of the properties setting is not important for StorageStream API
1839 OUString
aPropName ("Compressed");
1840 xDestProps
->setPropertyValue( aPropName
, getPropertyValue( aPropName
) );
1841 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
|| m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
)
1843 aPropName
= "MediaType";
1844 xDestProps
->setPropertyValue( aPropName
, getPropertyValue( aPropName
) );
1846 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
)
1848 aPropName
= "UseCommonStoragePasswordEncryption";
1849 xDestProps
->setPropertyValue( aPropName
, getPropertyValue( aPropName
) );
1854 void OWriteStream::ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard
& aGuard
)
1856 if ( m_pImpl
->m_pParent
)
1858 if ( m_pImpl
->m_pParent
->HasModifiedListener() )
1860 uno::Reference
< util::XModifiable
> xParentModif( (util::XModifiable
*)(m_pImpl
->m_pParent
->m_pAntiImpl
) );
1862 xParentModif
->setModified( sal_True
);
1865 m_pImpl
->m_pParent
->m_bIsModified
= true;
1869 uno::Any SAL_CALL
OWriteStream::queryInterface( const uno::Type
& rType
)
1870 throw( uno::RuntimeException
, std::exception
)
1874 // common interfaces
1875 aReturn
<<= ::cppu::queryInterface
1877 , static_cast<lang::XTypeProvider
*> ( this )
1878 , static_cast<io::XInputStream
*> ( this )
1879 , static_cast<io::XOutputStream
*> ( this )
1880 , static_cast<io::XStream
*> ( this )
1881 , static_cast<embed::XExtendedStorageStream
*> ( this )
1882 , static_cast<io::XSeekable
*> ( this )
1883 , static_cast<io::XTruncate
*> ( this )
1884 , static_cast<lang::XComponent
*> ( this )
1885 , static_cast<beans::XPropertySet
*> ( this ) );
1887 if ( aReturn
.hasValue() )
1890 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
)
1892 aReturn
<<= ::cppu::queryInterface
1894 , static_cast<embed::XEncryptionProtectedSource2
*> ( this )
1895 , static_cast<embed::XEncryptionProtectedSource
*> ( this ) );
1897 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
)
1899 aReturn
<<= ::cppu::queryInterface
1901 , static_cast<embed::XRelationshipAccess
*> ( this ) );
1904 if ( aReturn
.hasValue() )
1907 if ( m_bTransacted
)
1909 aReturn
<<= ::cppu::queryInterface
1911 , static_cast<embed::XTransactedObject
*> ( this )
1912 , static_cast<embed::XTransactionBroadcaster
*> ( this ) );
1914 if ( aReturn
.hasValue() )
1918 return OWeakObject::queryInterface( rType
);
1921 void SAL_CALL
OWriteStream::acquire() throw()
1923 OWeakObject::acquire();
1926 void SAL_CALL
OWriteStream::release() throw()
1928 OWeakObject::release();
1931 uno::Sequence
< uno::Type
> SAL_CALL
OWriteStream::getTypes()
1932 throw( uno::RuntimeException
, std::exception
)
1934 if (! m_pData
->m_pTypeCollection
)
1936 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
1938 if (! m_pData
->m_pTypeCollection
)
1940 if ( m_bTransacted
)
1942 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
)
1944 ::cppu::OTypeCollection aTmpCollection
1945 ( cppu::UnoType
<lang::XTypeProvider
>::get()
1946 , cppu::UnoType
<io::XInputStream
>::get()
1947 , cppu::UnoType
<io::XOutputStream
>::get()
1948 , cppu::UnoType
<io::XStream
>::get()
1949 , cppu::UnoType
<io::XSeekable
>::get()
1950 , cppu::UnoType
<io::XTruncate
>::get()
1951 , cppu::UnoType
<lang::XComponent
>::get()
1952 , cppu::UnoType
<embed::XEncryptionProtectedSource2
>::get()
1953 , cppu::UnoType
<embed::XEncryptionProtectedSource
>::get()
1954 , cppu::UnoType
<embed::XExtendedStorageStream
>::get()
1955 , cppu::UnoType
<embed::XTransactedObject
>::get()
1956 , cppu::UnoType
<embed::XTransactionBroadcaster
>::get());
1958 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
1959 ( cppu::UnoType
<beans::XPropertySet
>::get()
1960 , aTmpCollection
.getTypes()));
1962 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
)
1964 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
1965 ( cppu::UnoType
<lang::XTypeProvider
>::get()
1966 , cppu::UnoType
<io::XInputStream
>::get()
1967 , cppu::UnoType
<io::XOutputStream
>::get()
1968 , cppu::UnoType
<io::XStream
>::get()
1969 , cppu::UnoType
<io::XSeekable
>::get()
1970 , cppu::UnoType
<io::XTruncate
>::get()
1971 , cppu::UnoType
<lang::XComponent
>::get()
1972 , cppu::UnoType
<embed::XRelationshipAccess
>::get()
1973 , cppu::UnoType
<embed::XExtendedStorageStream
>::get()
1974 , cppu::UnoType
<embed::XTransactedObject
>::get()
1975 , cppu::UnoType
<embed::XTransactionBroadcaster
>::get()
1976 , cppu::UnoType
<beans::XPropertySet
>::get()));
1978 else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
1980 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
1981 ( cppu::UnoType
<lang::XTypeProvider
>::get()
1982 , cppu::UnoType
<io::XInputStream
>::get()
1983 , cppu::UnoType
<io::XOutputStream
>::get()
1984 , cppu::UnoType
<io::XStream
>::get()
1985 , cppu::UnoType
<io::XSeekable
>::get()
1986 , cppu::UnoType
<io::XTruncate
>::get()
1987 , cppu::UnoType
<lang::XComponent
>::get()
1988 , cppu::UnoType
<embed::XExtendedStorageStream
>::get()
1989 , cppu::UnoType
<embed::XTransactedObject
>::get()
1990 , cppu::UnoType
<embed::XTransactionBroadcaster
>::get()
1991 , cppu::UnoType
<beans::XPropertySet
>::get()));
1996 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
)
1998 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
1999 ( cppu::UnoType
<lang::XTypeProvider
>::get()
2000 , cppu::UnoType
<io::XInputStream
>::get()
2001 , cppu::UnoType
<io::XOutputStream
>::get()
2002 , cppu::UnoType
<io::XStream
>::get()
2003 , cppu::UnoType
<io::XSeekable
>::get()
2004 , cppu::UnoType
<io::XTruncate
>::get()
2005 , cppu::UnoType
<lang::XComponent
>::get()
2006 , cppu::UnoType
<embed::XEncryptionProtectedSource2
>::get()
2007 , cppu::UnoType
<embed::XEncryptionProtectedSource
>::get()
2008 , cppu::UnoType
<beans::XPropertySet
>::get()));
2010 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
)
2012 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
2013 ( cppu::UnoType
<lang::XTypeProvider
>::get()
2014 , cppu::UnoType
<io::XInputStream
>::get()
2015 , cppu::UnoType
<io::XOutputStream
>::get()
2016 , cppu::UnoType
<io::XStream
>::get()
2017 , cppu::UnoType
<io::XSeekable
>::get()
2018 , cppu::UnoType
<io::XTruncate
>::get()
2019 , cppu::UnoType
<lang::XComponent
>::get()
2020 , cppu::UnoType
<embed::XRelationshipAccess
>::get()
2021 , cppu::UnoType
<beans::XPropertySet
>::get()));
2023 else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
2025 m_pData
->m_pTypeCollection
.reset(new ::cppu::OTypeCollection
2026 ( cppu::UnoType
<lang::XTypeProvider
>::get()
2027 , cppu::UnoType
<io::XInputStream
>::get()
2028 , cppu::UnoType
<io::XOutputStream
>::get()
2029 , cppu::UnoType
<io::XStream
>::get()
2030 , cppu::UnoType
<io::XSeekable
>::get()
2031 , cppu::UnoType
<io::XTruncate
>::get()
2032 , cppu::UnoType
<lang::XComponent
>::get()
2033 , cppu::UnoType
<beans::XPropertySet
>::get()));
2039 return m_pData
->m_pTypeCollection
->getTypes() ;
2042 namespace { struct lcl_ImplId
: public rtl::Static
< ::cppu::OImplementationId
, lcl_ImplId
> {}; }
2044 uno::Sequence
< sal_Int8
> SAL_CALL
OWriteStream::getImplementationId()
2045 throw( uno::RuntimeException
, std::exception
)
2047 return css::uno::Sequence
<sal_Int8
>();
2050 sal_Int32 SAL_CALL
OWriteStream::readBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nBytesToRead
)
2051 throw ( io::NotConnectedException
,
2052 io::BufferSizeExceededException
,
2054 uno::RuntimeException
, std::exception
)
2056 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2058 CheckInitOnDemand();
2062 SAL_INFO("package.xstor", "Disposed!");
2063 throw lang::DisposedException();
2066 if ( !m_xInStream
.is() )
2067 throw io::NotConnectedException();
2069 return m_xInStream
->readBytes( aData
, nBytesToRead
);
2072 sal_Int32 SAL_CALL
OWriteStream::readSomeBytes( uno::Sequence
< sal_Int8
>& aData
, sal_Int32 nMaxBytesToRead
)
2073 throw ( io::NotConnectedException
,
2074 io::BufferSizeExceededException
,
2076 uno::RuntimeException
, std::exception
)
2078 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2080 CheckInitOnDemand();
2084 SAL_INFO("package.xstor", "Disposed!");
2085 throw lang::DisposedException();
2088 if ( !m_xInStream
.is() )
2089 throw io::NotConnectedException();
2091 return m_xInStream
->readSomeBytes( aData
, nMaxBytesToRead
);
2094 void SAL_CALL
OWriteStream::skipBytes( sal_Int32 nBytesToSkip
)
2095 throw ( io::NotConnectedException
,
2096 io::BufferSizeExceededException
,
2098 uno::RuntimeException
, std::exception
)
2100 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2102 CheckInitOnDemand();
2106 SAL_INFO("package.xstor", "Disposed!");
2107 throw lang::DisposedException();
2110 if ( !m_xInStream
.is() )
2111 throw io::NotConnectedException();
2113 m_xInStream
->skipBytes( nBytesToSkip
);
2116 sal_Int32 SAL_CALL
OWriteStream::available( )
2117 throw ( io::NotConnectedException
,
2119 uno::RuntimeException
, std::exception
)
2121 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2123 CheckInitOnDemand();
2127 SAL_INFO("package.xstor", "Disposed!");
2128 throw lang::DisposedException();
2131 if ( !m_xInStream
.is() )
2132 throw io::NotConnectedException();
2134 return m_xInStream
->available();
2138 void SAL_CALL
OWriteStream::closeInput( )
2139 throw ( io::NotConnectedException
,
2141 uno::RuntimeException
, std::exception
)
2143 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2147 SAL_INFO("package.xstor", "Disposed!");
2148 throw lang::DisposedException();
2151 if ( !m_bInitOnDemand
&& ( m_bInStreamDisconnected
|| !m_xInStream
.is() ) )
2152 throw io::NotConnectedException();
2154 // the input part of the stream stays open for internal purposes ( to allow reading during copiing )
2155 // since it can not be reopened until output part is closed, it will be closed with output part.
2156 m_bInStreamDisconnected
= true;
2157 // m_xInStream->closeInput();
2158 // m_xInStream = uno::Reference< io::XInputStream >();
2160 if ( !m_xOutStream
.is() )
2164 uno::Reference
< io::XInputStream
> SAL_CALL
OWriteStream::getInputStream()
2165 throw ( uno::RuntimeException
, std::exception
)
2167 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2171 SAL_INFO("package.xstor", "Disposed!");
2172 throw lang::DisposedException();
2175 if ( !m_bInitOnDemand
&& ( m_bInStreamDisconnected
|| !m_xInStream
.is() ) )
2176 return uno::Reference
< io::XInputStream
>();
2178 return uno::Reference
< io::XInputStream
>( static_cast< io::XInputStream
* >( this ), uno::UNO_QUERY
);
2181 uno::Reference
< io::XOutputStream
> SAL_CALL
OWriteStream::getOutputStream()
2182 throw ( uno::RuntimeException
, std::exception
)
2184 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2188 CheckInitOnDemand();
2190 catch( const io::IOException
& r
)
2192 throw lang::WrappedTargetRuntimeException("OWriteStream::getOutputStream: Could not create backing temp file",
2193 static_cast < OWeakObject
* > ( this ), makeAny ( r
) );
2198 SAL_INFO("package.xstor", "Disposed!");
2199 throw lang::DisposedException();
2202 if ( !m_xOutStream
.is() )
2203 return uno::Reference
< io::XOutputStream
>();
2205 return uno::Reference
< io::XOutputStream
>( static_cast< io::XOutputStream
* >( this ), uno::UNO_QUERY
);
2208 void SAL_CALL
OWriteStream::writeBytes( const uno::Sequence
< sal_Int8
>& aData
)
2209 throw ( io::NotConnectedException
,
2210 io::BufferSizeExceededException
,
2212 uno::RuntimeException
, std::exception
)
2214 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2216 // the write method makes initialization itself, since it depends from the aData length
2217 // NO CheckInitOnDemand()!
2221 SAL_INFO("package.xstor", "Disposed!");
2222 throw lang::DisposedException();
2225 if ( !m_bInitOnDemand
)
2227 if ( !m_xOutStream
.is() || !m_xSeekable
.is())
2228 throw io::NotConnectedException();
2230 if ( m_pImpl
->m_xCacheStream
.is() )
2232 // check whether the cache should be turned off
2233 sal_Int64 nPos
= m_xSeekable
->getPosition();
2234 if ( nPos
+ aData
.getLength() > MAX_STORCACHE_SIZE
)
2236 // disconnect the cache and copy the data to the temporary file
2237 m_xSeekable
->seek( 0 );
2239 // it is enough to copy the cached stream, the cache should already contain everything
2240 if ( !m_pImpl
->GetFilledTempFileIfNo( m_xInStream
).isEmpty() )
2243 // the last position is known and it is differs from the current stream position
2244 m_nInitPosition
= nPos
;
2250 if ( m_bInitOnDemand
)
2252 SAL_INFO( "package.xstor", "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" );
2253 uno::Reference
< io::XStream
> xStream
= m_pImpl
->GetTempFileAsStream();
2256 m_xInStream
.set( xStream
->getInputStream(), uno::UNO_SET_THROW
);
2257 m_xOutStream
.set( xStream
->getOutputStream(), uno::UNO_SET_THROW
);
2258 m_xSeekable
.set( xStream
, uno::UNO_QUERY_THROW
);
2259 m_xSeekable
->seek( m_nInitPosition
);
2261 m_nInitPosition
= 0;
2262 m_bInitOnDemand
= false;
2266 if ( !m_xOutStream
.is() )
2267 throw io::NotConnectedException();
2269 m_xOutStream
->writeBytes( aData
);
2270 m_pImpl
->m_bHasDataToFlush
= true;
2272 ModifyParentUnlockMutex_Impl( aGuard
);
2275 void SAL_CALL
OWriteStream::flush()
2276 throw ( io::NotConnectedException
,
2277 io::BufferSizeExceededException
,
2279 uno::RuntimeException
, std::exception
)
2281 // In case stream is flushed its current version becomes visible
2282 // to the parent storage. Usually parent storage flushes the stream
2283 // during own commit but a user can explicitly flush the stream
2284 // so the changes will be available through cloning functionality.
2286 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2290 SAL_INFO("package.xstor", "Disposed!");
2291 throw lang::DisposedException();
2294 if ( !m_bInitOnDemand
)
2296 if ( !m_xOutStream
.is() )
2297 throw io::NotConnectedException();
2299 m_xOutStream
->flush();
2304 void OWriteStream::CloseOutput_Impl()
2306 // all the checks must be done in calling method
2308 m_xOutStream
->closeOutput();
2309 m_xOutStream
= uno::Reference
< io::XOutputStream
>();
2311 if ( !m_bInitOnDemand
)
2313 // after the stream is disposed it can be committed
2314 // so transport correct size property
2315 if ( !m_xSeekable
.is() )
2316 throw uno::RuntimeException();
2318 for ( sal_Int32 nInd
= 0; nInd
< m_pImpl
->m_aProps
.getLength(); nInd
++ )
2320 if ( m_pImpl
->m_aProps
[nInd
].Name
== "Size" )
2321 m_pImpl
->m_aProps
[nInd
].Value
<<= m_xSeekable
->getLength();
2326 void SAL_CALL
OWriteStream::closeOutput()
2327 throw ( io::NotConnectedException
,
2328 io::BufferSizeExceededException
,
2330 uno::RuntimeException
, std::exception
)
2332 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2334 CheckInitOnDemand();
2338 SAL_INFO("package.xstor", "Disposed!");
2339 throw lang::DisposedException();
2342 if ( !m_xOutStream
.is() )
2343 throw io::NotConnectedException();
2347 if ( m_bInStreamDisconnected
|| !m_xInStream
.is() )
2351 void SAL_CALL
OWriteStream::seek( sal_Int64 location
)
2352 throw ( lang::IllegalArgumentException
,
2354 uno::RuntimeException
, std::exception
)
2356 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2358 CheckInitOnDemand();
2362 SAL_INFO("package.xstor", "Disposed!");
2363 throw lang::DisposedException();
2366 if ( !m_xSeekable
.is() )
2367 throw uno::RuntimeException();
2369 m_xSeekable
->seek( location
);
2372 sal_Int64 SAL_CALL
OWriteStream::getPosition()
2373 throw ( io::IOException
,
2374 uno::RuntimeException
, std::exception
)
2376 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2378 CheckInitOnDemand();
2382 SAL_INFO("package.xstor", "Disposed!");
2383 throw lang::DisposedException();
2386 if ( !m_xSeekable
.is() )
2387 throw uno::RuntimeException();
2389 return m_xSeekable
->getPosition();
2392 sal_Int64 SAL_CALL
OWriteStream::getLength()
2393 throw ( io::IOException
,
2394 uno::RuntimeException
, std::exception
)
2396 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2398 CheckInitOnDemand();
2402 SAL_INFO("package.xstor", "Disposed!");
2403 throw lang::DisposedException();
2406 if ( !m_xSeekable
.is() )
2407 throw uno::RuntimeException();
2409 return m_xSeekable
->getLength();
2412 void SAL_CALL
OWriteStream::truncate()
2413 throw ( io::IOException
,
2414 uno::RuntimeException
, std::exception
)
2416 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2418 CheckInitOnDemand();
2422 SAL_INFO("package.xstor", "Disposed!");
2423 throw lang::DisposedException();
2426 if ( !m_xOutStream
.is() )
2427 throw uno::RuntimeException();
2429 uno::Reference
< io::XTruncate
> xTruncate( m_xOutStream
, uno::UNO_QUERY
);
2431 if ( !xTruncate
.is() )
2433 SAL_WARN( "package.xstor", "The output stream must support XTruncate interface!" );
2434 throw uno::RuntimeException();
2437 xTruncate
->truncate();
2439 m_pImpl
->m_bHasDataToFlush
= true;
2441 ModifyParentUnlockMutex_Impl( aGuard
);
2444 void SAL_CALL
OWriteStream::dispose()
2445 throw ( uno::RuntimeException
, std::exception
)
2447 // should be an internal method since it can be called only from parent storage
2449 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2453 SAL_INFO("package.xstor", "Disposed!");
2454 throw lang::DisposedException();
2457 if ( m_xOutStream
.is() )
2460 if ( m_xInStream
.is() )
2462 m_xInStream
->closeInput();
2463 m_xInStream
= uno::Reference
< io::XInputStream
>();
2466 m_xSeekable
= uno::Reference
< io::XSeekable
>();
2468 m_pImpl
->m_pAntiImpl
= NULL
;
2470 if ( !m_bInitOnDemand
)
2474 if ( !m_bTransacted
)
2480 // throw away all the changes
2484 catch( const uno::Exception
& rException
)
2486 m_pImpl
->AddLog( rException
.Message
);
2487 m_pImpl
->AddLog( "Rethrow" );
2489 uno::Any
aCaught( ::cppu::getCaughtException() );
2490 throw lang::WrappedTargetRuntimeException("Can not commit/revert the storage!",
2491 static_cast< OWeakObject
* >( this ),
2499 // the listener might try to get rid of parent storage, and the storage would delete this object;
2500 // for now the listener is just notified at the end of the method to workaround the problem
2501 // in future a more elegant way should be found
2503 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >(this) );
2504 m_pData
->m_aListenersContainer
.disposeAndClear( aSource
);
2507 void SAL_CALL
OWriteStream::addEventListener(
2508 const uno::Reference
< lang::XEventListener
>& xListener
)
2509 throw ( uno::RuntimeException
, std::exception
)
2511 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2515 SAL_INFO("package.xstor", "Disposed!");
2516 throw lang::DisposedException();
2519 m_pData
->m_aListenersContainer
.addInterface( cppu::UnoType
<lang::XEventListener
>::get(),
2523 void SAL_CALL
OWriteStream::removeEventListener(
2524 const uno::Reference
< lang::XEventListener
>& xListener
)
2525 throw ( uno::RuntimeException
, std::exception
)
2527 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2531 SAL_INFO("package.xstor", "Disposed!");
2532 throw lang::DisposedException();
2535 m_pData
->m_aListenersContainer
.removeInterface( cppu::UnoType
<lang::XEventListener
>::get(),
2539 void SAL_CALL
OWriteStream::setEncryptionPassword( const OUString
& aPass
)
2540 throw ( uno::RuntimeException
,
2541 io::IOException
, std::exception
)
2543 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2545 CheckInitOnDemand();
2549 SAL_INFO("package.xstor", "Disposed!");
2550 throw lang::DisposedException();
2553 OSL_ENSURE( m_pImpl
->m_xPackageStream
.is(), "No package stream is set!\n" );
2555 m_pImpl
->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass
) );
2557 ModifyParentUnlockMutex_Impl( aGuard
);
2560 void SAL_CALL
OWriteStream::removeEncryption()
2561 throw ( uno::RuntimeException
,
2562 io::IOException
, std::exception
)
2564 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2566 CheckInitOnDemand();
2570 SAL_INFO("package.xstor", "Disposed!");
2571 throw lang::DisposedException();
2574 OSL_ENSURE( m_pImpl
->m_xPackageStream
.is(), "No package stream is set!\n" );
2576 m_pImpl
->SetDecrypted();
2578 ModifyParentUnlockMutex_Impl( aGuard
);
2581 void SAL_CALL
OWriteStream::setEncryptionData( const uno::Sequence
< beans::NamedValue
>& aEncryptionData
)
2582 throw (io::IOException
, uno::RuntimeException
, std::exception
)
2584 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2586 CheckInitOnDemand();
2590 SAL_INFO("package.xstor", "Disposed!");
2591 throw lang::DisposedException();
2594 OSL_ENSURE( m_pImpl
->m_xPackageStream
.is(), "No package stream is set!\n" );
2596 m_pImpl
->SetEncrypted( aEncryptionData
);
2598 ModifyParentUnlockMutex_Impl( aGuard
);
2601 sal_Bool SAL_CALL
OWriteStream::hasEncryptionData()
2602 throw (uno::RuntimeException
, std::exception
)
2604 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2613 bRet
= m_pImpl
->IsEncrypted();
2615 if (!bRet
&& m_pImpl
->m_bUseCommonEncryption
&& m_pImpl
->m_pParent
)
2616 bRet
= m_pImpl
->m_pParent
->m_bHasCommonEncryptionData
;
2618 catch( const uno::RuntimeException
& rRuntimeException
)
2620 m_pImpl
->AddLog( rRuntimeException
.Message
);
2621 m_pImpl
->AddLog( "Rethrow" );
2624 catch( const uno::Exception
& rException
)
2626 m_pImpl
->AddLog( rException
.Message
);
2627 m_pImpl
->AddLog( "Rethrow" );
2629 uno::Any
aCaught( ::cppu::getCaughtException() );
2630 throw lang::WrappedTargetRuntimeException( "Problems on hasEncryptionData!",
2631 static_cast< ::cppu::OWeakObject
* >( this ),
2638 sal_Bool SAL_CALL
OWriteStream::hasByID( const OUString
& sID
)
2639 throw ( io::IOException
,
2640 uno::RuntimeException
, std::exception
)
2642 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2646 SAL_INFO("package.xstor", "Disposed!");
2647 throw lang::DisposedException();
2650 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2651 throw uno::RuntimeException();
2655 getRelationshipByID( sID
);
2658 catch( const container::NoSuchElementException
& rNoSuchElementException
)
2660 m_pImpl
->AddLog( rNoSuchElementException
.Message
);
2661 m_pImpl
->AddLog( "No Element" );
2667 OUString SAL_CALL
OWriteStream::getTargetByID( const OUString
& sID
)
2668 throw ( container::NoSuchElementException
,
2670 uno::RuntimeException
, std::exception
)
2672 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2676 SAL_INFO("package.xstor", "Disposed!");
2677 throw lang::DisposedException();
2680 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2681 throw uno::RuntimeException();
2683 uno::Sequence
< beans::StringPair
> aSeq
= getRelationshipByID( sID
);
2684 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
2685 if ( aSeq
[nInd
].First
== "Target" )
2686 return aSeq
[nInd
].Second
;
2691 OUString SAL_CALL
OWriteStream::getTypeByID( const OUString
& sID
)
2692 throw ( container::NoSuchElementException
,
2694 uno::RuntimeException
, std::exception
)
2696 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2700 SAL_INFO("package.xstor", "Disposed!");
2701 throw lang::DisposedException();
2704 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2705 throw uno::RuntimeException();
2707 uno::Sequence
< beans::StringPair
> aSeq
= getRelationshipByID( sID
);
2708 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
2709 if ( aSeq
[nInd
].First
== "Type" )
2710 return aSeq
[nInd
].Second
;
2715 uno::Sequence
< beans::StringPair
> SAL_CALL
OWriteStream::getRelationshipByID( const OUString
& sID
)
2716 throw ( container::NoSuchElementException
,
2718 uno::RuntimeException
, std::exception
)
2720 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2724 SAL_INFO("package.xstor", "Disposed!");
2725 throw lang::DisposedException();
2728 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2729 throw uno::RuntimeException();
2731 // TODO/LATER: in future the unification of the ID could be checked
2732 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aSeq
= getAllRelationships();
2733 for ( sal_Int32 nInd1
= 0; nInd1
< aSeq
.getLength(); nInd1
++ )
2734 for ( sal_Int32 nInd2
= 0; nInd2
< aSeq
[nInd1
].getLength(); nInd2
++ )
2735 if ( aSeq
[nInd1
][nInd2
].First
== "Id" )
2737 if ( aSeq
[nInd1
][nInd2
].Second
.equals( sID
) )
2742 throw container::NoSuchElementException();
2745 uno::Sequence
< uno::Sequence
< beans::StringPair
> > SAL_CALL
OWriteStream::getRelationshipsByType( const OUString
& sType
)
2746 throw ( io::IOException
,
2747 uno::RuntimeException
, std::exception
)
2749 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2753 SAL_INFO("package.xstor", "Disposed!");
2754 throw lang::DisposedException();
2757 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2758 throw uno::RuntimeException();
2760 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aResult
;
2761 sal_Int32 nEntriesNum
= 0;
2763 // TODO/LATER: in future the unification of the ID could be checked
2764 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aSeq
= getAllRelationships();
2765 for ( sal_Int32 nInd1
= 0; nInd1
< aSeq
.getLength(); nInd1
++ )
2766 for ( sal_Int32 nInd2
= 0; nInd2
< aSeq
[nInd1
].getLength(); nInd2
++ )
2767 if ( aSeq
[nInd1
][nInd2
].First
== "Type" )
2769 if ( aSeq
[nInd1
][nInd2
].Second
.equals( sType
) )
2771 aResult
.realloc( nEntriesNum
);
2772 aResult
[nEntriesNum
-1] = aSeq
[nInd1
];
2780 uno::Sequence
< uno::Sequence
< beans::StringPair
> > SAL_CALL
OWriteStream::getAllRelationships()
2781 throw (io::IOException
, uno::RuntimeException
, std::exception
)
2783 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2787 SAL_INFO("package.xstor", "Disposed!");
2788 throw lang::DisposedException();
2791 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2792 throw uno::RuntimeException();
2794 return m_pImpl
->GetAllRelationshipsIfAny();
2797 void SAL_CALL
OWriteStream::insertRelationshipByID( const OUString
& sID
, const uno::Sequence
< beans::StringPair
>& aEntry
, sal_Bool bReplace
)
2798 throw ( container::ElementExistException
,
2800 uno::RuntimeException
, std::exception
)
2802 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2806 SAL_INFO("package.xstor", "Disposed!");
2807 throw lang::DisposedException();
2810 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2811 throw uno::RuntimeException();
2813 OUString
aIDTag( "Id" );
2815 sal_Int32 nIDInd
= -1;
2817 // TODO/LATER: in future the unification of the ID could be checked
2818 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aSeq
= getAllRelationships();
2819 for ( sal_Int32 nInd1
= 0; nInd1
< aSeq
.getLength(); nInd1
++ )
2820 for ( sal_Int32 nInd2
= 0; nInd2
< aSeq
[nInd1
].getLength(); nInd2
++ )
2821 if ( aSeq
[nInd1
][nInd2
].First
.equals( aIDTag
) )
2823 if ( aSeq
[nInd1
][nInd2
].Second
.equals( sID
) )
2829 if ( nIDInd
== -1 || bReplace
)
2833 nIDInd
= aSeq
.getLength();
2834 aSeq
.realloc( nIDInd
+ 1 );
2837 aSeq
[nIDInd
].realloc( aEntry
.getLength() + 1 );
2839 aSeq
[nIDInd
][0].First
= aIDTag
;
2840 aSeq
[nIDInd
][0].Second
= sID
;
2841 sal_Int32 nIndTarget
= 1;
2842 for ( sal_Int32 nIndOrig
= 0;
2843 nIndOrig
< aEntry
.getLength();
2846 if ( !aEntry
[nIndOrig
].First
.equals( aIDTag
) )
2847 aSeq
[nIDInd
][nIndTarget
++] = aEntry
[nIndOrig
];
2850 aSeq
[nIDInd
].realloc( nIndTarget
);
2853 throw container::ElementExistException(); // TODO
2855 m_pImpl
->m_aNewRelInfo
= aSeq
;
2856 m_pImpl
->m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
2857 m_pImpl
->m_nRelInfoStatus
= RELINFO_CHANGED
;
2860 void SAL_CALL
OWriteStream::removeRelationshipByID( const OUString
& sID
)
2861 throw ( container::NoSuchElementException
,
2863 uno::RuntimeException
, std::exception
)
2865 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2869 SAL_INFO("package.xstor", "Disposed!");
2870 throw lang::DisposedException();
2873 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2874 throw uno::RuntimeException();
2876 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aSeq
= getAllRelationships();
2877 for ( sal_Int32 nInd1
= 0; nInd1
< aSeq
.getLength(); nInd1
++ )
2878 for ( sal_Int32 nInd2
= 0; nInd2
< aSeq
[nInd1
].getLength(); nInd2
++ )
2879 if ( aSeq
[nInd1
][nInd2
].First
== "Id" )
2881 if ( aSeq
[nInd1
][nInd2
].Second
.equals( sID
) )
2883 sal_Int32 nLength
= aSeq
.getLength();
2884 aSeq
[nInd1
] = aSeq
[nLength
-1];
2885 aSeq
.realloc( nLength
- 1 );
2887 m_pImpl
->m_aNewRelInfo
= aSeq
;
2888 m_pImpl
->m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
2889 m_pImpl
->m_nRelInfoStatus
= RELINFO_CHANGED
;
2891 // TODO/LATER: in future the unification of the ID could be checked
2898 throw container::NoSuchElementException();
2901 void SAL_CALL
OWriteStream::insertRelationships( const uno::Sequence
< uno::Sequence
< beans::StringPair
> >& aEntries
, sal_Bool bReplace
)
2902 throw ( container::ElementExistException
,
2904 uno::RuntimeException
, std::exception
)
2906 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2910 SAL_INFO("package.xstor", "Disposed!");
2911 throw lang::DisposedException();
2914 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2915 throw uno::RuntimeException();
2917 OUString
aIDTag( "Id" );
2918 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aSeq
= getAllRelationships();
2919 uno::Sequence
< uno::Sequence
< beans::StringPair
> > aResultSeq( aSeq
.getLength() + aEntries
.getLength() );
2920 sal_Int32 nResultInd
= 0;
2922 for ( sal_Int32 nIndTarget1
= 0; nIndTarget1
< aSeq
.getLength(); nIndTarget1
++ )
2923 for ( sal_Int32 nIndTarget2
= 0; nIndTarget2
< aSeq
[nIndTarget1
].getLength(); nIndTarget2
++ )
2924 if ( aSeq
[nIndTarget1
][nIndTarget2
].First
.equals( aIDTag
) )
2926 sal_Int32 nIndSourceSame
= -1;
2928 for ( sal_Int32 nIndSource1
= 0; nIndSource1
< aEntries
.getLength(); nIndSource1
++ )
2929 for ( sal_Int32 nIndSource2
= 0; nIndSource2
< aEntries
[nIndSource1
].getLength(); nIndSource2
++ )
2931 if ( aEntries
[nIndSource1
][nIndSource2
].First
.equals( aIDTag
) )
2933 if ( aEntries
[nIndSource1
][nIndSource2
].Second
.equals( aSeq
[nIndTarget1
][nIndTarget2
].Second
) )
2936 throw container::ElementExistException();
2938 nIndSourceSame
= nIndSource1
;
2945 if ( nIndSourceSame
== -1 )
2947 // no such element in the provided sequence
2948 aResultSeq
[nResultInd
++] = aSeq
[nIndTarget1
];
2954 for ( sal_Int32 nIndSource1
= 0; nIndSource1
< aEntries
.getLength(); nIndSource1
++ )
2956 aResultSeq
[nResultInd
].realloc( aEntries
[nIndSource1
].getLength() );
2957 bool bHasID
= false;
2958 sal_Int32 nResInd2
= 1;
2960 for ( sal_Int32 nIndSource2
= 0; nIndSource2
< aEntries
[nIndSource1
].getLength(); nIndSource2
++ )
2961 if ( aEntries
[nIndSource1
][nIndSource2
].First
.equals( aIDTag
) )
2963 aResultSeq
[nResultInd
][0] = aEntries
[nIndSource1
][nIndSource2
];
2966 else if ( nResInd2
< aResultSeq
[nResultInd
].getLength() )
2967 aResultSeq
[nResultInd
][nResInd2
++] = aEntries
[nIndSource1
][nIndSource2
];
2969 throw io::IOException(); // TODO: illegal relation ( no ID )
2972 throw io::IOException(); // TODO: illegal relations
2977 aResultSeq
.realloc( nResultInd
);
2978 m_pImpl
->m_aNewRelInfo
= aResultSeq
;
2979 m_pImpl
->m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
2980 m_pImpl
->m_nRelInfoStatus
= RELINFO_CHANGED
;
2983 void SAL_CALL
OWriteStream::clearRelationships()
2984 throw ( io::IOException
,
2985 uno::RuntimeException
, std::exception
)
2987 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
2991 SAL_INFO("package.xstor", "Disposed!");
2992 throw lang::DisposedException();
2995 if ( m_pData
->m_nStorageType
!= embed::StorageFormats::OFOPXML
)
2996 throw uno::RuntimeException();
2998 m_pImpl
->m_aNewRelInfo
.realloc( 0 );
2999 m_pImpl
->m_xNewRelInfoStream
= uno::Reference
< io::XInputStream
>();
3000 m_pImpl
->m_nRelInfoStatus
= RELINFO_CHANGED
;
3003 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
OWriteStream::getPropertySetInfo()
3004 throw ( uno::RuntimeException
, std::exception
)
3006 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3009 return uno::Reference
< beans::XPropertySetInfo
>();
3012 void SAL_CALL
OWriteStream::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
)
3013 throw ( beans::UnknownPropertyException
,
3014 beans::PropertyVetoException
,
3015 lang::IllegalArgumentException
,
3016 lang::WrappedTargetException
,
3017 uno::RuntimeException
, std::exception
)
3019 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3023 SAL_INFO("package.xstor", "Disposed!");
3024 throw lang::DisposedException();
3027 m_pImpl
->GetStreamProperties();
3028 OUString
aCompressedString( "Compressed" );
3029 OUString
aMediaTypeString( "MediaType" );
3030 if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
&& aPropertyName
.equals( aMediaTypeString
) )
3032 // if the "Compressed" property is not set explicitly, the MediaType can change the default value
3033 bool bCompressedValueFromType
= true;
3037 if ( !m_pImpl
->m_bCompressedSetExplicit
)
3039 if ( aType
== "image/jpeg" || aType
== "image/png" || aType
== "image/gif" )
3040 bCompressedValueFromType
= false;
3043 for ( sal_Int32 nInd
= 0; nInd
< m_pImpl
->m_aProps
.getLength(); nInd
++ )
3045 if ( aPropertyName
.equals( m_pImpl
->m_aProps
[nInd
].Name
) )
3046 m_pImpl
->m_aProps
[nInd
].Value
= aValue
;
3047 else if ( !m_pImpl
->m_bCompressedSetExplicit
&& aCompressedString
.equals( m_pImpl
->m_aProps
[nInd
].Name
) )
3048 m_pImpl
->m_aProps
[nInd
].Value
<<= bCompressedValueFromType
;
3051 else if ( aPropertyName
.equals( aCompressedString
) )
3053 // if the "Compressed" property is not set explicitly, the MediaType can change the default value
3054 m_pImpl
->m_bCompressedSetExplicit
= true;
3055 for ( sal_Int32 nInd
= 0; nInd
< m_pImpl
->m_aProps
.getLength(); nInd
++ )
3057 if ( aPropertyName
.equals( m_pImpl
->m_aProps
[nInd
].Name
) )
3058 m_pImpl
->m_aProps
[nInd
].Value
= aValue
;
3061 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
3062 && aPropertyName
== "UseCommonStoragePasswordEncryption" )
3064 bool bUseCommonEncryption
= false;
3065 if ( aValue
>>= bUseCommonEncryption
)
3067 if ( m_bInitOnDemand
&& m_pImpl
->m_bHasInsertedStreamOptimization
)
3069 // the data stream is provided to the packagestream directly
3070 m_pImpl
->m_bUseCommonEncryption
= bUseCommonEncryption
;
3072 else if ( bUseCommonEncryption
)
3074 if ( !m_pImpl
->m_bUseCommonEncryption
)
3076 m_pImpl
->SetDecrypted();
3077 m_pImpl
->m_bUseCommonEncryption
= true;
3081 m_pImpl
->m_bUseCommonEncryption
= false;
3084 throw lang::IllegalArgumentException(); //TODO
3086 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
&& aPropertyName
.equals( aMediaTypeString
) )
3088 for ( sal_Int32 nInd
= 0; nInd
< m_pImpl
->m_aProps
.getLength(); nInd
++ )
3090 if ( aPropertyName
.equals( m_pImpl
->m_aProps
[nInd
].Name
) )
3091 m_pImpl
->m_aProps
[nInd
].Value
= aValue
;
3094 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
&& aPropertyName
== "RelationsInfoStream" )
3096 uno::Reference
< io::XInputStream
> xInRelStream
;
3097 if ( ( aValue
>>= xInRelStream
) && xInRelStream
.is() )
3099 uno::Reference
< io::XSeekable
> xSeek( xInRelStream
, uno::UNO_QUERY
);
3102 // currently this is an internal property that is used for optimization
3103 // and the stream must support XSeekable interface
3104 // TODO/LATER: in future it can be changed if property is used from outside
3105 throw lang::IllegalArgumentException(); // TODO
3108 m_pImpl
->m_xNewRelInfoStream
= xInRelStream
;
3109 m_pImpl
->m_aNewRelInfo
= uno::Sequence
< uno::Sequence
< beans::StringPair
> >();
3110 m_pImpl
->m_nRelInfoStatus
= RELINFO_CHANGED_STREAM
;
3113 throw lang::IllegalArgumentException(); // TODO
3115 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
&& aPropertyName
== "RelationsInfo" )
3117 if ( aValue
>>= m_pImpl
->m_aNewRelInfo
)
3121 throw lang::IllegalArgumentException(); // TODO
3123 else if ( aPropertyName
== "Size" )
3124 throw beans::PropertyVetoException(); // TODO
3125 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
3126 && ( aPropertyName
== "IsEncrypted" || aPropertyName
== "Encrypted" ) )
3127 throw beans::PropertyVetoException(); // TODO
3128 else if ( aPropertyName
== "RelId" )
3130 aValue
>>= m_pImpl
->m_nRelId
;
3133 throw beans::UnknownPropertyException(); // TODO
3135 m_pImpl
->m_bHasDataToFlush
= true;
3136 ModifyParentUnlockMutex_Impl( aGuard
);
3139 uno::Any SAL_CALL
OWriteStream::getPropertyValue( const OUString
& aProp
)
3140 throw ( beans::UnknownPropertyException
,
3141 lang::WrappedTargetException
,
3142 uno::RuntimeException
, std::exception
)
3144 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3148 SAL_INFO("package.xstor", "Disposed!");
3149 throw lang::DisposedException();
3152 if ( aProp
== "RelId" )
3154 return uno::makeAny( m_pImpl
->GetNewRelId() );
3157 OUString aPropertyName
;
3158 if ( aProp
== "IsEncrypted" )
3159 aPropertyName
= "Encrypted";
3161 aPropertyName
= aProp
;
3163 if ( ( ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
|| m_pData
->m_nStorageType
== embed::StorageFormats::OFOPXML
)
3164 && aPropertyName
== "MediaType" )
3165 || ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
&& aPropertyName
== "Encrypted" )
3166 || aPropertyName
== "Compressed" )
3168 m_pImpl
->GetStreamProperties();
3170 for ( sal_Int32 nInd
= 0; nInd
< m_pImpl
->m_aProps
.getLength(); nInd
++ )
3172 if ( aPropertyName
.equals( m_pImpl
->m_aProps
[nInd
].Name
) )
3173 return m_pImpl
->m_aProps
[nInd
].Value
;
3176 else if ( m_pData
->m_nStorageType
== embed::StorageFormats::PACKAGE
3177 && aPropertyName
== "UseCommonStoragePasswordEncryption" )
3178 return uno::makeAny( m_pImpl
->m_bUseCommonEncryption
);
3179 else if ( aPropertyName
== "Size" )
3181 bool bThrow
= false;
3184 CheckInitOnDemand();
3186 catch (const io::IOException
&)
3190 if (bThrow
|| !m_xSeekable
.is())
3191 throw uno::RuntimeException();
3193 return uno::makeAny( m_xSeekable
->getLength() );
3196 throw beans::UnknownPropertyException(); // TODO
3199 void SAL_CALL
OWriteStream::addPropertyChangeListener(
3200 const OUString
& /*aPropertyName*/,
3201 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
3202 throw ( beans::UnknownPropertyException
,
3203 lang::WrappedTargetException
,
3204 uno::RuntimeException
, std::exception
)
3206 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3210 SAL_INFO("package.xstor", "Disposed!");
3211 throw lang::DisposedException();
3217 void SAL_CALL
OWriteStream::removePropertyChangeListener(
3218 const OUString
& /*aPropertyName*/,
3219 const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
3220 throw ( beans::UnknownPropertyException
,
3221 lang::WrappedTargetException
,
3222 uno::RuntimeException
, std::exception
)
3224 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3228 SAL_INFO("package.xstor", "Disposed!");
3229 throw lang::DisposedException();
3235 void SAL_CALL
OWriteStream::addVetoableChangeListener(
3236 const OUString
& /*PropertyName*/,
3237 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
3238 throw ( beans::UnknownPropertyException
,
3239 lang::WrappedTargetException
,
3240 uno::RuntimeException
, std::exception
)
3242 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3246 SAL_INFO("package.xstor", "Disposed!");
3247 throw lang::DisposedException();
3253 void SAL_CALL
OWriteStream::removeVetoableChangeListener(
3254 const OUString
& /*PropertyName*/,
3255 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
3256 throw ( beans::UnknownPropertyException
,
3257 lang::WrappedTargetException
,
3258 uno::RuntimeException
, std::exception
)
3260 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3264 SAL_INFO("package.xstor", "Disposed!");
3265 throw lang::DisposedException();
3271 // XTransactedObject
3273 void OWriteStream::BroadcastTransaction( sal_Int8 nMessage
)
3281 // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
3284 SAL_INFO("package.xstor", "Disposed!");
3285 throw lang::DisposedException();
3288 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >(this) );
3290 ::cppu::OInterfaceContainerHelper
* pContainer
=
3291 m_pData
->m_aListenersContainer
.getContainer(
3292 cppu::UnoType
<embed::XTransactionListener
>::get());
3295 ::cppu::OInterfaceIteratorHelper
pIterator( *pContainer
);
3296 while ( pIterator
.hasMoreElements( ) )
3298 OSL_ENSURE( nMessage
>= 1 && nMessage
<= 4, "Wrong internal notification code is used!\n" );
3302 case STOR_MESS_PRECOMMIT
:
3303 static_cast<embed::XTransactionListener
*>( pIterator
.next( ) )->preCommit( aSource
);
3305 case STOR_MESS_COMMITED
:
3306 static_cast<embed::XTransactionListener
*>( pIterator
.next( ) )->commited( aSource
);
3308 case STOR_MESS_PREREVERT
:
3309 static_cast<embed::XTransactionListener
*>( pIterator
.next( ) )->preRevert( aSource
);
3311 case STOR_MESS_REVERTED
:
3312 static_cast< embed::XTransactionListener
*>( pIterator
.next( ) )->reverted( aSource
);
3318 void SAL_CALL
OWriteStream::commit()
3319 throw ( io::IOException
,
3320 embed::StorageWrappedTargetException
,
3321 uno::RuntimeException
, std::exception
)
3323 SAL_INFO( "package.xstor", "package (mv76033) OWriteStream::commit" );
3327 SAL_INFO("package.xstor", "Disposed!");
3328 throw lang::DisposedException();
3331 if ( !m_bTransacted
)
3332 throw uno::RuntimeException();
3335 BroadcastTransaction( STOR_MESS_PRECOMMIT
);
3337 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3341 SAL_INFO("package.xstor", "Disposed!");
3342 throw lang::DisposedException();
3347 // when the storage is committed the parent is modified
3348 ModifyParentUnlockMutex_Impl( aGuard
);
3350 catch( const io::IOException
& rIOException
)
3352 m_pImpl
->AddLog( rIOException
.Message
);
3353 m_pImpl
->AddLog( "Rethrow" );
3356 catch( const embed::StorageWrappedTargetException
& rStorageWrappedTargetException
)
3358 m_pImpl
->AddLog( rStorageWrappedTargetException
.Message
);
3359 m_pImpl
->AddLog( "Rethrow" );
3362 catch( const uno::RuntimeException
& rRuntimeException
)
3364 m_pImpl
->AddLog( rRuntimeException
.Message
);
3365 m_pImpl
->AddLog( "Rethrow" );
3368 catch( const uno::Exception
& rException
)
3370 m_pImpl
->AddLog( rException
.Message
);
3371 m_pImpl
->AddLog( "Rethrow" );
3373 uno::Any
aCaught( ::cppu::getCaughtException() );
3374 throw embed::StorageWrappedTargetException( "Problems on commit!",
3375 static_cast< ::cppu::OWeakObject
* >( this ),
3379 BroadcastTransaction( STOR_MESS_COMMITED
);
3382 void SAL_CALL
OWriteStream::revert()
3383 throw ( io::IOException
,
3384 embed::StorageWrappedTargetException
,
3385 uno::RuntimeException
, std::exception
)
3387 SAL_INFO( "package.xstor", "package (mv76033) OWriteStream::revert" );
3389 // the method removes all the changes done after last commit
3393 SAL_INFO("package.xstor", "Disposed!");
3394 throw lang::DisposedException();
3397 if ( !m_bTransacted
)
3398 throw uno::RuntimeException();
3400 BroadcastTransaction( STOR_MESS_PREREVERT
);
3402 ::osl::ResettableMutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3406 SAL_INFO("package.xstor", "Disposed!");
3407 throw lang::DisposedException();
3413 catch( const io::IOException
& rIOException
)
3415 m_pImpl
->AddLog( rIOException
.Message
);
3416 m_pImpl
->AddLog( "Rethrow" );
3419 catch( const embed::StorageWrappedTargetException
& rStorageWrappedTargetException
)
3421 m_pImpl
->AddLog( rStorageWrappedTargetException
.Message
);
3422 m_pImpl
->AddLog( "Rethrow" );
3425 catch( const uno::RuntimeException
& rRuntimeException
)
3427 m_pImpl
->AddLog( rRuntimeException
.Message
);
3428 m_pImpl
->AddLog( "Rethrow" );
3431 catch( const uno::Exception
& rException
)
3433 m_pImpl
->AddLog( rException
.Message
);
3434 m_pImpl
->AddLog( "Rethrow" );
3436 uno::Any
aCaught( ::cppu::getCaughtException() );
3437 throw embed::StorageWrappedTargetException( "Problems on revert!",
3438 static_cast< ::cppu::OWeakObject
* >( this ),
3444 BroadcastTransaction( STOR_MESS_REVERTED
);
3447 // XTransactionBroadcaster
3449 void SAL_CALL
OWriteStream::addTransactionListener( const uno::Reference
< embed::XTransactionListener
>& aListener
)
3450 throw ( uno::RuntimeException
, std::exception
)
3452 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3456 SAL_INFO("package.xstor", "Disposed!");
3457 throw lang::DisposedException();
3460 if ( !m_bTransacted
)
3461 throw uno::RuntimeException();
3463 m_pData
->m_aListenersContainer
.addInterface( cppu::UnoType
<embed::XTransactionListener
>::get(),
3467 void SAL_CALL
OWriteStream::removeTransactionListener( const uno::Reference
< embed::XTransactionListener
>& aListener
)
3468 throw ( uno::RuntimeException
, std::exception
)
3470 ::osl::MutexGuard
aGuard( m_pData
->m_rSharedMutexRef
->GetMutex() );
3474 SAL_INFO("package.xstor", "Disposed!");
3475 throw lang::DisposedException();
3478 if ( !m_bTransacted
)
3479 throw uno::RuntimeException();
3481 m_pData
->m_aListenersContainer
.removeInterface( cppu::UnoType
<embed::XTransactionListener
>::get(),
3485 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */