Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <com/sun/star/uno/XComponentContext.hpp>
21 : : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
22 : : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
23 : : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
24 : : #include <com/sun/star/lang/DisposedException.hpp>
25 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
26 : : #include <com/sun/star/lang/XTypeProvider.hpp>
27 : : #include <com/sun/star/io/XInputStream.hpp>
28 : : #include <com/sun/star/io/IOException.hpp>
29 : : #include <com/sun/star/embed/ElementModes.hpp>
30 : : #include <com/sun/star/embed/StorageFormats.hpp>
31 : : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
32 : : #include <cppuhelper/typeprovider.hxx>
33 : : #include <cppuhelper/exc_hlp.hxx>
34 : : #include <osl/diagnose.h>
35 : :
36 : : #include <comphelper/processfactory.hxx>
37 : : #include <comphelper/componentcontext.hxx>
38 : : #include <comphelper/storagehelper.hxx>
39 : : #include <comphelper/ofopxmlhelper.hxx>
40 : :
41 : : #include <rtl/digest.h>
42 : : #include <rtl/logfile.hxx>
43 : : #include <rtl/instance.hxx>
44 : :
45 : : #include <PackageConstants.hxx>
46 : : #include <mutexholder.hxx>
47 : :
48 : : #include "selfterminatefilestream.hxx"
49 : : #include "owriteablestream.hxx"
50 : : #include "oseekinstream.hxx"
51 : : #include "xstorage.hxx"
52 : :
53 : : // since the copying uses 32000 blocks usually, it makes sense to have a smaller size
54 : : #define MAX_STORCACHE_SIZE 30000
55 : :
56 : :
57 : : using namespace ::com::sun::star;
58 : :
59 : : namespace package
60 : : {
61 : : //-----------------------------------------------
62 : 0 : bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 )
63 : : {
64 [ # # ][ # # ]: 0 : bool bResult = ( aHash1.size() && aHash1.size() == aHash2.size() );
65 [ # # ]: 0 : for ( ::comphelper::SequenceAsHashMap::const_iterator aIter = aHash1.begin();
[ # # # # ]
[ # # ]
66 [ # # ][ # # ]: 0 : bResult && aIter != aHash1.end();
[ # # ]
67 : : ++aIter )
68 : : {
69 [ # # ]: 0 : uno::Sequence< sal_Int8 > aKey1;
70 [ # # ][ # # ]: 0 : bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() );
[ # # ][ # # ]
71 [ # # ]: 0 : if ( bResult )
72 : : {
73 [ # # ][ # # ]: 0 : uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() );
[ # # ][ # # ]
74 : 0 : bResult = ( aKey1.getLength() == aKey2.getLength() );
75 [ # # ][ # # ]: 0 : for ( sal_Int32 nInd = 0; bResult && nInd < aKey1.getLength(); nInd++ )
[ # # ]
76 [ # # ][ # # ]: 0 : bResult = ( aKey1[nInd] == aKey2[nInd] );
[ # # ]
77 : : }
78 [ # # ]: 0 : }
79 : :
80 : 0 : return bResult;
81 : : }
82 : :
83 : : //-----------------------------------------------
84 : 852 : void StaticAddLog( const ::rtl::OUString& aMessage )
85 : : {
86 : : try
87 : : {
88 [ + - ][ + - ]: 852 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
89 [ + - ]: 852 : if ( aContext.is() )
90 : : {
91 [ + - ][ + - ]: 852 : uno::Reference< logging::XSimpleLogRing > xLogRing( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW );
92 [ + - ][ + - ]: 852 : xLogRing->logString( aMessage );
93 [ + - ][ # # ]: 852 : }
94 : : }
95 : 0 : catch( const uno::Exception& )
96 : : {
97 : : // No log
98 : : }
99 : 852 : }
100 : : } // namespace package
101 : :
102 : : // ================================================================
103 : : namespace
104 : : {
105 : : //-----------------------------------------------
106 : 24 : void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet,
107 : : const uno::Sequence< beans::NamedValue >& aKey )
108 : : {
109 : : OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" );
110 [ - + ]: 24 : if ( !xPropertySet.is() )
111 [ # # ]: 0 : throw uno::RuntimeException();
112 : :
113 : : try {
114 [ + - ][ + - ]: 24 : xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) );
[ + - ][ + - ]
115 : : }
116 [ # # ]: 0 : catch ( const uno::Exception& rException )
117 : : {
118 [ # # ]: 0 : ::package::StaticAddLog( rException.Message );
119 [ # # # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't set encryption") ) );
120 : : OSL_FAIL( "Can't write encryption related properties!\n" );
121 [ # # ]: 0 : throw io::IOException(); // TODO
122 : : }
123 : 24 : }
124 : :
125 : : //-----------------------------------------------
126 : 48 : uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet )
127 : : {
128 : : OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" );
129 [ - + ]: 48 : if ( !xPropertySet.is() )
130 [ # # ]: 0 : throw uno::RuntimeException();
131 : :
132 : : try {
133 [ + - ][ + - ]: 48 : return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) );
[ + - ]
134 : : }
135 [ # # ]: 0 : catch ( const uno::Exception& rException )
136 : : {
137 [ # # ]: 0 : ::package::StaticAddLog( rException.Message );
138 [ # # # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get encryption property" ) ) );
139 : :
140 : : OSL_FAIL( "Can't get encryption related properties!\n" );
141 [ # # ]: 0 : throw io::IOException(); // TODO
142 : : }
143 : : }
144 : :
145 : : //-----------------------------------------------
146 : 0 : bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 )
147 : : {
148 [ # # ]: 0 : if ( aSequence1.getLength() != aSequence2.getLength() )
149 : 0 : return false;
150 : :
151 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ )
152 [ # # ]: 0 : if ( aSequence1[nInd] != aSequence2[nInd] )
153 : 0 : return false;
154 : :
155 : 0 : return true;
156 : : }
157 : :
158 : : //-----------------------------------------------
159 : 0 : bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 )
160 : : {
161 [ # # ]: 0 : if ( aSequence1.getLength() != aSequence2.getLength() )
162 : 0 : return false;
163 : :
164 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ )
165 : : {
166 : 0 : bool bHasMember = false;
167 [ # # ]: 0 : uno::Sequence< sal_Int8 > aMember1;
168 : 0 : sal_Int32 nMember1 = 0;
169 [ # # ][ # # ]: 0 : if ( ( aSequence1[nInd].Value >>= aMember1 ) )
170 : : {
171 [ # # ]: 0 : for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ )
172 : : {
173 [ # # ]: 0 : if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) )
174 : : {
175 : 0 : bHasMember = true;
176 : :
177 [ # # ]: 0 : uno::Sequence< sal_Int8 > aMember2;
178 [ # # ][ # # ]: 0 : if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) )
[ # # ][ # # ]
[ # # ]
179 [ # # ][ # # ]: 0 : return false;
180 : : }
181 : : }
182 : : }
183 [ # # ]: 0 : else if ( ( aSequence1[nInd].Value >>= nMember1 ) )
184 : : {
185 [ # # ]: 0 : for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ )
186 : : {
187 [ # # ]: 0 : if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) )
188 : : {
189 : 0 : bHasMember = true;
190 : :
191 : 0 : sal_Int32 nMember2 = 0;
192 [ # # ][ # # ]: 0 : if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 )
[ # # ]
193 : 0 : return false;
194 : : }
195 : : }
196 : : }
197 : : else
198 : 0 : return false;
199 : :
200 [ # # ]: 0 : if ( !bHasMember )
201 : 0 : return false;
202 [ # # ][ # # ]: 0 : }
203 : :
204 : 0 : return true;
205 : : }
206 : :
207 : : //-----------------------------------------------
208 : 3 : sal_Bool KillFile( const ::rtl::OUString& aURL, const uno::Reference< uno::XComponentContext >& xContext )
209 : : {
210 [ - + ]: 3 : if ( !xContext.is() )
211 : 0 : return sal_False;
212 : :
213 : 3 : sal_Bool bRet = sal_False;
214 : :
215 : : try
216 : : {
217 [ + - ]: 3 : uno::Reference < ucb::XSimpleFileAccess2 > xAccess( ucb::SimpleFileAccess::create( xContext ) );
218 : :
219 [ + - ][ + - ]: 3 : xAccess->kill( aURL );
220 : 3 : bRet = sal_True;
221 : : }
222 [ # # ]: 0 : catch( const uno::Exception& rException )
223 : : {
224 [ # # ]: 0 : ::package::StaticAddLog( rException.Message );
225 [ # # # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) );
226 : : }
227 : :
228 : 3 : return bRet;
229 : : }
230 : :
231 : : const sal_Int32 n_ConstBufferSize = 32000;
232 : :
233 : : //-----------------------------------------------
234 : 83 : ::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory )
235 : : {
236 : 83 : ::rtl::OUString aTempURL;
237 : :
238 : : uno::Reference < beans::XPropertySet > xTempFile(
239 [ + - ]: 83 : xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ),
240 [ + - ][ + - ]: 83 : uno::UNO_QUERY );
[ + - ]
241 : :
242 [ - + ]: 83 : if ( !xTempFile.is() )
243 [ # # ]: 0 : throw uno::RuntimeException(); // TODO
244 : :
245 : : try {
246 [ + - ][ + - ]: 83 : xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile") ), uno::makeAny( sal_False ) );
[ + - ][ + - ]
247 [ + - ][ + - ]: 83 : uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri") ) );
[ + - ]
248 : 83 : aUrl >>= aTempURL;
249 : : }
250 [ # # # # ]: 0 : catch ( const uno::Exception& rException )
251 : : {
252 [ # # ]: 0 : ::package::StaticAddLog( rException.Message );
253 [ # # # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) );
254 : : }
255 : :
256 [ - + ]: 83 : if ( aTempURL.isEmpty() )
257 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: can not create tempfile
258 : :
259 : 83 : return aTempURL;
260 : : }
261 : :
262 : : //-----------------------------------------------
263 : 5473 : uno::Reference< io::XStream > CreateMemoryStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
264 : : {
265 [ - + ]: 5473 : if ( !xFactory.is() )
266 [ # # ]: 0 : throw uno::RuntimeException();
267 : :
268 [ + - ][ + - ]: 5473 : return uno::Reference< io::XStream >( xFactory->createInstance (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.MemoryStream") ) ), uno::UNO_QUERY_THROW);
269 : : }
270 : :
271 : : } // anonymous namespace
272 : : // ================================================================
273 : :
274 : : //-----------------------------------------------
275 : 8324 : OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent,
276 : : const uno::Reference< packages::XDataSinkEncrSupport >& xPackageStream,
277 : : const uno::Reference< lang::XSingleServiceFactory >& xPackage,
278 : : const uno::Reference< lang::XMultiServiceFactory >& xFactory,
279 : : sal_Bool bForceEncrypted,
280 : : sal_Int32 nStorageType,
281 : : sal_Bool bDefaultCompress,
282 : : const uno::Reference< io::XInputStream >& xRelInfoStream )
283 : : : m_pAntiImpl( NULL )
284 : : , m_bHasDataToFlush( sal_False )
285 : : , m_bFlushed( sal_False )
286 : : , m_xPackageStream( xPackageStream )
287 : : , m_xFactory( xFactory )
288 : : , m_pParent( pParent )
289 : : , m_bForceEncrypted( bForceEncrypted )
290 : : , m_bUseCommonEncryption( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE )
291 : : , m_bHasCachedEncryptionData( sal_False )
292 : 8324 : , m_bCompressedSetExplicit( !bDefaultCompress )
293 : : , m_xPackage( xPackage )
294 : : , m_bHasInsertedStreamOptimization( sal_False )
295 : : , m_nStorageType( nStorageType )
296 : : , m_xOrigRelInfoStream( xRelInfoStream )
297 : : , m_bOrigRelInfoBroken( sal_False )
298 : : , m_nRelInfoStatus( RELINFO_NO_INIT )
299 [ + - ][ + - ]: 8324 : , m_nRelId( 1 )
[ + - ][ + + ]
[ + - ][ + - ]
[ + - ]
300 : : {
301 : : OSL_ENSURE( xPackageStream.is(), "No package stream is provided!\n" );
302 : : OSL_ENSURE( xPackage.is(), "No package component is provided!\n" );
303 : : OSL_ENSURE( m_xFactory.is(), "No package stream is provided!\n" );
304 : : OSL_ENSURE( pParent, "No parent storage is provided!\n" );
305 : : OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML || !m_xOrigRelInfoStream.is(), "The Relations info makes sence only for OFOPXML format!\n" );
306 : 8324 : }
307 : :
308 : : //-----------------------------------------------
309 [ + - ][ + - ]: 7969 : OWriteStream_Impl::~OWriteStream_Impl()
[ + - ][ + - ]
310 : : {
311 [ + - ]: 7969 : DisposeWrappers();
312 : :
313 [ + + ]: 7969 : if ( !m_aTempURL.isEmpty() )
314 : : {
315 [ + - ][ + - ]: 3 : KillFile( m_aTempURL, comphelper::getProcessComponentContext() );
316 : 3 : m_aTempURL = ::rtl::OUString();
317 : : }
318 : :
319 [ + - ]: 7969 : CleanCacheStream();
320 : 7969 : }
321 : :
322 : : //-----------------------------------------------
323 : 8044 : void OWriteStream_Impl::CleanCacheStream()
324 : : {
325 [ + + ]: 8044 : if ( m_xCacheStream.is() )
326 : : {
327 : : try
328 : : {
329 [ + - ][ + - ]: 974 : uno::Reference< io::XInputStream > xInputCache = m_xCacheStream->getInputStream();
330 [ + - ]: 974 : if ( xInputCache.is() )
331 [ + - ][ + - ]: 974 : xInputCache->closeInput();
[ # # ]
332 : : }
333 : 0 : catch( const uno::Exception& )
334 : : {}
335 : :
336 : : try
337 : : {
338 [ + - ][ + - ]: 974 : uno::Reference< io::XOutputStream > xOutputCache = m_xCacheStream->getOutputStream();
339 [ + - ]: 974 : if ( xOutputCache.is() )
340 [ + - ][ + - ]: 974 : xOutputCache->closeOutput();
[ # # ]
341 : : }
342 : 0 : catch( const uno::Exception& )
343 : : {}
344 : :
345 [ + - ]: 974 : m_xCacheStream = uno::Reference< io::XStream >();
346 [ + - ]: 974 : m_xCacheSeek = uno::Reference< io::XSeekable >();
347 : : }
348 : 8044 : }
349 : :
350 : : //-----------------------------------------------
351 : 0 : void OWriteStream_Impl::AddLog( const ::rtl::OUString& aMessage )
352 : : {
353 [ # # ]: 0 : if ( !m_xLogRing.is() )
354 : : {
355 : : try
356 : : {
357 [ # # ][ # # ]: 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
358 [ # # ]: 0 : if ( aContext.is() )
359 [ # # ][ # # ]: 0 : m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
360 : : }
361 : 0 : catch( const uno::Exception& )
362 : : {
363 : : // No log
364 : : }
365 : : }
366 : :
367 [ # # ]: 0 : if ( m_xLogRing.is() )
368 : 0 : m_xLogRing->logString( aMessage );
369 : 0 : }
370 : :
371 : :
372 : : //-----------------------------------------------
373 : 3231 : void OWriteStream_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName,
374 : : const uno::Reference< container::XNameContainer >& xParentPackageFolder )
375 : : {
376 [ + - ]: 3231 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
377 : :
378 : : OSL_ENSURE( m_bFlushed, "This method must not be called for nonflushed streams!\n" );
379 [ + - ]: 3231 : if ( m_bFlushed )
380 : : {
381 : : OSL_ENSURE( m_xPackageStream.is(), "An inserted stream is incomplete!\n" );
382 [ + - ]: 3231 : uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageStream, uno::UNO_QUERY );
383 [ - + ]: 3231 : if ( !xTunnel.is() )
384 [ # # ]: 0 : throw uno::RuntimeException(); // TODO
385 : :
386 [ + - ][ + - ]: 3231 : xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) );
[ + - ]
387 : :
388 : 3231 : m_bFlushed = sal_False;
389 : 3231 : m_bHasInsertedStreamOptimization = sal_False;
390 [ + - ]: 3231 : }
391 : 3231 : }
392 : : //-----------------------------------------------
393 : 8510 : sal_Bool OWriteStream_Impl::IsEncrypted()
394 : : {
395 [ + + ]: 8510 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
396 : 3105 : return sal_False;
397 : :
398 [ + - ][ - + ]: 5405 : if ( m_bForceEncrypted || m_bHasCachedEncryptionData )
399 : 0 : return sal_True;
400 : :
401 [ + - ][ + + ]: 5405 : if ( !m_aTempURL.isEmpty() || m_xCacheStream.is() )
[ + + ]
402 : 36 : return sal_False;
403 : :
404 [ + - ][ + - ]: 5369 : GetStreamProperties();
405 : :
406 : : // the following value can not be cached since it can change after root commit
407 : 5369 : sal_Bool bWasEncr = sal_False;
408 [ + - ]: 5369 : uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY );
409 [ + - ]: 5369 : if ( xPropSet.is() )
410 : : {
411 [ + - ][ + - ]: 5369 : uno::Any aValue = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WasEncrypted") ) );
[ + - ]
412 : 5369 : if ( !( aValue >>= bWasEncr ) )
413 : : {
414 : : OSL_FAIL( "The property WasEncrypted has wrong type!\n" );
415 : 5369 : }
416 : : }
417 : :
418 : 5369 : sal_Bool bToBeEncr = sal_False;
419 [ + + ]: 26845 : for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ )
420 : : {
421 [ + - ][ + + ]: 21476 : if ( m_aProps[nInd].Name == "Encrypted" )
422 : : {
423 [ + - ]: 5369 : if ( !( m_aProps[nInd].Value >>= bToBeEncr ) )
424 : : {
425 : : OSL_FAIL( "The property has wrong type!\n" );
426 : : }
427 : : }
428 : : }
429 : :
430 : : // since a new key set to the package stream it should not be removed except the case when
431 : : // the stream becomes nonencrypted
432 [ + - ]: 5369 : uno::Sequence< beans::NamedValue > aKey;
433 [ + + ]: 5369 : if ( bToBeEncr )
434 [ + - ][ + - ]: 48 : GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey;
435 : :
436 : : // If the properties must be investigated the stream is either
437 : : // was never changed or was changed, the parent was commited
438 : : // and the stream was closed.
439 : : // That means that if it is intended to use common storage key
440 : : // it is already has no encryption but is marked to be stored
441 : : // encrypted and the key is empty.
442 [ + + ][ - + ]: 5369 : if ( !bWasEncr && bToBeEncr && !aKey.getLength() )
[ # # ][ - + ]
443 : : {
444 : : // the stream is intended to use common storage password
445 : 0 : m_bUseCommonEncryption = sal_True;
446 : 0 : return sal_False;
447 : : }
448 : : else
449 [ + - ]: 8510 : return bToBeEncr;
450 : : }
451 : :
452 : : //-----------------------------------------------
453 : 0 : void OWriteStream_Impl::SetDecrypted()
454 : : {
455 : : OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" );
456 [ # # ]: 0 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
457 [ # # ]: 0 : throw uno::RuntimeException();
458 : :
459 : 0 : GetStreamProperties();
460 : :
461 : : // let the stream be modified
462 : 0 : FillTempGetFileName();
463 : 0 : m_bHasDataToFlush = sal_True;
464 : :
465 : : // remove encryption
466 : 0 : m_bForceEncrypted = sal_False;
467 : 0 : m_bHasCachedEncryptionData = sal_False;
468 : 0 : m_aEncryptionData.clear();
469 : :
470 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ )
471 : : {
472 [ # # ]: 0 : if ( m_aProps[nInd].Name == "Encrypted" )
473 [ # # ][ # # ]: 0 : m_aProps[nInd].Value <<= sal_False;
474 : : }
475 : 0 : }
476 : :
477 : : //-----------------------------------------------
478 : 0 : void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData )
479 : : {
480 : : OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" );
481 [ # # ]: 0 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
482 [ # # ]: 0 : throw uno::RuntimeException();
483 : :
484 [ # # ]: 0 : if ( !aEncryptionData.size() )
485 [ # # ]: 0 : throw uno::RuntimeException();
486 : :
487 : 0 : GetStreamProperties();
488 : :
489 : : // let the stream be modified
490 : 0 : FillTempGetFileName();
491 : 0 : m_bHasDataToFlush = sal_True;
492 : :
493 : : // introduce encryption info
494 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ )
495 : : {
496 [ # # ]: 0 : if ( m_aProps[nInd].Name == "Encrypted" )
497 [ # # ][ # # ]: 0 : m_aProps[nInd].Value <<= sal_True;
498 : : }
499 : :
500 : 0 : m_bUseCommonEncryption = sal_False; // very important to set it to false
501 : :
502 : 0 : m_bHasCachedEncryptionData = sal_True;
503 : 0 : m_aEncryptionData = aEncryptionData;
504 : 0 : }
505 : :
506 : : //-----------------------------------------------
507 : 7969 : void OWriteStream_Impl::DisposeWrappers()
508 : : {
509 [ + - ]: 7969 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
510 [ + + ]: 7969 : if ( m_pAntiImpl )
511 : : {
512 : : try {
513 [ + - ]: 12 : m_pAntiImpl->dispose();
514 : : }
515 [ # # # # ]: 0 : catch ( const uno::RuntimeException& rRuntimeException )
516 : : {
517 [ # # ]: 0 : AddLog( rRuntimeException.Message );
518 [ # # # # ]: 0 : AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OSL_LOG_PREFIX "Quiet exception") ) );
519 : : }
520 : :
521 : 12 : m_pAntiImpl = NULL;
522 : : }
523 : 7969 : m_pParent = NULL;
524 : :
525 [ - + ]: 7969 : if ( !m_aInputStreamsList.empty() )
526 : : {
527 [ # # ]: 0 : for ( InputStreamsList_Impl::iterator pStreamIter = m_aInputStreamsList.begin();
528 : 0 : pStreamIter != m_aInputStreamsList.end(); ++pStreamIter )
529 : : {
530 [ # # ]: 0 : if ( (*pStreamIter) )
531 : : {
532 [ # # ]: 0 : (*pStreamIter)->InternalDispose();
533 : 0 : (*pStreamIter) = NULL;
534 : : }
535 : : }
536 : :
537 : 0 : m_aInputStreamsList.clear();
538 [ + - ]: 7969 : }
539 : 7969 : }
540 : :
541 : : //-----------------------------------------------
542 : 5636 : uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactory()
543 : : {
544 [ + - ]: 5636 : if ( m_xFactory.is() )
545 : 5636 : return m_xFactory;
546 : :
547 : 5636 : return ::comphelper::getProcessServiceFactory();
548 : : }
549 : :
550 : : //-----------------------------------------------
551 : 75 : ::rtl::OUString OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference< io::XInputStream >& xStream )
552 : : {
553 [ + - ]: 75 : if ( !m_aTempURL.getLength() )
554 : : {
555 [ + - ][ + - ]: 75 : ::rtl::OUString aTempURL = GetNewTempFileURL( GetServiceFactory() );
556 : :
557 : : try {
558 [ + - ][ + - ]: 75 : if ( !aTempURL.isEmpty() && xStream.is() )
[ + - ]
559 : : {
560 [ + - ][ + - ]: 75 : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
561 : :
562 [ + - ][ + - ]: 75 : uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aTempURL );
563 [ + - ]: 75 : if ( xTempOutStream.is() )
564 : : {
565 : : // the current position of the original stream should be still OK, copy further
566 [ + - ]: 75 : ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream );
567 [ + - ][ + - ]: 75 : xTempOutStream->closeOutput();
568 [ + - ]: 75 : xTempOutStream = uno::Reference< io::XOutputStream >();
569 : : }
570 : : else
571 [ # # ]: 75 : throw io::IOException(); // TODO:
572 : : }
573 : : }
574 : 0 : catch( const packages::WrongPasswordException& rWrongPasswordException )
575 : : {
576 [ # # ]: 0 : AddLog( rWrongPasswordException.Message );
577 [ # # # # ]: 0 : AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) );
578 : :
579 [ # # # # ]: 0 : KillFile( aTempURL, comphelper::getProcessComponentContext() );
580 : 0 : throw;
581 : : }
582 [ # # # ]: 0 : catch( const uno::Exception& rException )
583 : : {
584 [ # # ]: 0 : AddLog( rException.Message );
585 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) );
586 : :
587 [ # # # # ]: 0 : KillFile( aTempURL, comphelper::getProcessComponentContext() );
588 : 0 : throw;
589 : : }
590 : :
591 [ + - ]: 75 : if ( !aTempURL.isEmpty() )
592 [ + - ]: 75 : CleanCacheStream();
593 : :
594 : 75 : m_aTempURL = aTempURL;
595 : : }
596 : :
597 : 75 : return m_aTempURL;
598 : : }
599 : :
600 : : //-----------------------------------------------
601 : 2460 : ::rtl::OUString OWriteStream_Impl::FillTempGetFileName()
602 : : {
603 : : // should try to create cache first, if the amount of contents is too big, the temp file should be taken
604 [ + - ][ + - ]: 2460 : if ( !m_xCacheStream.is() && m_aTempURL.isEmpty() )
[ + - ]
605 : : {
606 [ + - ][ + - ]: 2460 : uno::Reference< io::XInputStream > xOrigStream = m_xPackageStream->getDataStream();
607 [ + + ]: 2460 : if ( !xOrigStream.is() )
608 : : {
609 : : // in case of new inserted package stream it is possible that input stream still was not set
610 [ + - ][ + - ]: 1492 : uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() );
611 : : OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" );
612 [ + - ]: 1492 : m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW );
613 [ + - ]: 1492 : m_xCacheStream = xCacheStream;
614 : : }
615 : : else
616 : : {
617 : 968 : sal_Int32 nRead = 0;
618 [ + - ]: 968 : uno::Sequence< sal_Int8 > aData( MAX_STORCACHE_SIZE + 1 );
619 [ + - ][ + - ]: 968 : nRead = xOrigStream->readBytes( aData, MAX_STORCACHE_SIZE + 1 );
620 [ - + ]: 968 : if ( aData.getLength() > nRead )
621 [ # # ]: 0 : aData.realloc( nRead );
622 : :
623 [ + + ]: 968 : if ( nRead <= MAX_STORCACHE_SIZE )
624 : : {
625 [ + - ][ + - ]: 960 : uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() );
626 : : OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" );
627 : :
628 [ + + ]: 960 : if ( nRead )
629 : : {
630 [ + - ][ + - ]: 917 : uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW );
[ + - ]
631 [ + - ][ + - ]: 917 : xOutStream->writeBytes( aData );
632 : : }
633 [ + - ]: 960 : m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW );
634 [ + - ]: 960 : m_xCacheStream = xCacheStream;
635 [ + - ][ + - ]: 960 : m_xCacheSeek->seek( 0 );
636 : : }
637 [ + - ]: 8 : else if ( m_aTempURL.isEmpty() )
638 : : {
639 [ + - ][ + - ]: 8 : m_aTempURL = GetNewTempFileURL( GetServiceFactory() );
640 : :
641 : : try {
642 [ + - ]: 8 : if ( !m_aTempURL.isEmpty() )
643 : : {
644 [ + - ][ + - ]: 8 : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
645 : :
646 [ + - ][ + - ]: 8 : uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL );
647 [ + - ]: 8 : if ( xTempOutStream.is() )
648 : : {
649 : : // copy stream contents to the file
650 [ + - ][ + - ]: 8 : xTempOutStream->writeBytes( aData );
651 : :
652 : : // the current position of the original stream should be still OK, copy further
653 [ + - ]: 8 : ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream );
654 [ + - ][ + - ]: 8 : xTempOutStream->closeOutput();
655 [ + - ]: 8 : xTempOutStream = uno::Reference< io::XOutputStream >();
656 : : }
657 : : else
658 [ # # ]: 8 : throw io::IOException(); // TODO:
659 : : }
660 : : }
661 : 0 : catch( const packages::WrongPasswordException& )
662 : : {
663 [ # # # # ]: 0 : KillFile( m_aTempURL, comphelper::getProcessComponentContext() );
664 : 0 : m_aTempURL = ::rtl::OUString();
665 : :
666 : 0 : throw;
667 : : }
668 [ # # # # : 0 : catch( const uno::Exception& )
# ]
669 : : {
670 [ # # # # ]: 0 : KillFile( m_aTempURL, comphelper::getProcessComponentContext() );
671 : 0 : m_aTempURL = ::rtl::OUString();
672 : : }
673 [ + - ]: 968 : }
674 : 2460 : }
675 : : }
676 : :
677 : 2460 : return m_aTempURL;
678 : : }
679 : :
680 : : //-----------------------------------------------
681 : 1676 : uno::Reference< io::XStream > OWriteStream_Impl::GetTempFileAsStream()
682 : : {
683 : 1676 : uno::Reference< io::XStream > xTempStream;
684 : :
685 [ + - ]: 1676 : if ( !m_xCacheStream.is() )
686 : : {
687 [ + + ]: 1676 : if ( m_aTempURL.isEmpty() )
688 [ + - ]: 1601 : m_aTempURL = FillTempGetFileName();
689 : :
690 [ + + ]: 1676 : if ( !m_aTempURL.isEmpty() )
691 : : {
692 : : // the temporary file is not used if the cache is used
693 [ + - ][ + - ]: 80 : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
694 : :
695 : : try
696 : : {
697 [ + - ][ + - ]: 80 : xTempStream = xTempAccess->openFileReadWrite( m_aTempURL );
[ + - ]
698 : : }
699 [ # # # # ]: 0 : catch( const uno::Exception& rException )
700 : : {
701 [ # # ]: 0 : AddLog( rException.Message );
702 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
703 : 80 : }
704 : : }
705 : : }
706 : :
707 [ + + ]: 1676 : if ( m_xCacheStream.is() )
708 [ + - ]: 1596 : xTempStream = m_xCacheStream;
709 : :
710 : : // the method must always return a stream
711 : : // in case the stream can not be open
712 : : // an exception should be thrown
713 [ - + ]: 1676 : if ( !xTempStream.is() )
714 [ # # ]: 0 : throw io::IOException(); //TODO:
715 : :
716 : 1676 : return xTempStream;
717 : : }
718 : :
719 : : //-----------------------------------------------
720 : 867 : uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream()
721 : : {
722 : 867 : uno::Reference< io::XInputStream > xInputStream;
723 : :
724 [ + + ]: 867 : if ( !m_xCacheStream.is() )
725 : : {
726 [ + - ]: 859 : if ( m_aTempURL.isEmpty() )
727 [ + - ]: 859 : m_aTempURL = FillTempGetFileName();
728 : :
729 [ + + ]: 859 : if ( !m_aTempURL.isEmpty() )
730 : : {
731 : : // the temporary file is not used if the cache is used
732 [ + - ][ + - ]: 3 : uno::Reference < ucb::XSimpleFileAccess2 > xTempAccess( ucb::SimpleFileAccess::create( ::comphelper::getProcessComponentContext() ) );
733 : :
734 : : try
735 : : {
736 [ + - ][ + - ]: 3 : xInputStream = xTempAccess->openFileRead( m_aTempURL );
[ + - ]
737 : : }
738 [ # # # # ]: 0 : catch( const uno::Exception& rException )
739 : : {
740 [ # # ]: 0 : AddLog( rException.Message );
741 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
742 : 3 : }
743 : : }
744 : : }
745 : :
746 [ + + ]: 867 : if ( m_xCacheStream.is() )
747 [ + - ][ + - ]: 864 : xInputStream = m_xCacheStream->getInputStream();
[ + - ]
748 : :
749 : : // the method must always return a stream
750 : : // in case the stream can not be open
751 : : // an exception should be thrown
752 [ - + ]: 867 : if ( !xInputStream.is() )
753 [ # # ]: 0 : throw io::IOException(); // TODO:
754 : :
755 : 867 : return xInputStream;
756 : : }
757 : :
758 : : // =================================================================================================
759 : :
760 : : //-----------------------------------------------
761 : 0 : void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputStream >& xInStream,
762 : : const uno::Sequence< beans::PropertyValue >& aProps )
763 : : {
764 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
765 : :
766 : : // this call can be made only during parent storage commit
767 : : // the parent storage is responsible for the correct handling
768 : : // of deleted and renamed contents
769 : :
770 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
771 : :
772 [ # # ]: 0 : if ( m_bHasDataToFlush )
773 [ # # ]: 0 : throw io::IOException();
774 : :
775 : : OSL_ENSURE( m_aTempURL.isEmpty() && !m_xCacheStream.is(), "The temporary must not exist!\n" );
776 : :
777 : : // use new file as current persistent representation
778 : : // the new file will be removed after it's stream is closed
779 [ # # ][ # # ]: 0 : m_xPackageStream->setDataStream( xInStream );
780 : :
781 : : // copy properties to the package stream
782 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY );
783 [ # # ]: 0 : if ( !xPropertySet.is() )
784 [ # # ]: 0 : throw uno::RuntimeException();
785 : :
786 : : // The storage-package communication has a problem
787 : : // the storage caches properties, thus if the package changes one of them itself
788 : : // the storage does not know about it
789 : :
790 : : // Depending from MediaType value the package can change the compressed property itself
791 : : // Thus if Compressed property is provided it must be set as the latest one
792 : 0 : sal_Bool bCompressedIsSet = sal_False;
793 : 0 : sal_Bool bCompressed = sal_False;
794 [ # # ]: 0 : ::rtl::OUString aComprPropName( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) );
795 [ # # ]: 0 : ::rtl::OUString aMedTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
796 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ )
797 : : {
798 [ # # ]: 0 : if ( aProps[nInd].Name.equals( aComprPropName ) )
799 : : {
800 : 0 : bCompressedIsSet = sal_True;
801 : 0 : aProps[nInd].Value >>= bCompressed;
802 : : }
803 [ # # ]: 0 : else if ( ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE )
[ # # # # ]
[ # # ]
804 : 0 : && aProps[nInd].Name.equals( aMedTypePropName ) )
805 : : {
806 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( aProps[nInd].Name, aProps[nInd].Value );
807 : : }
808 [ # # ][ # # ]: 0 : else if ( m_nStorageType == embed::StorageFormats::PACKAGE && aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) )
[ # # ]
809 : 0 : aProps[nInd].Value >>= m_bUseCommonEncryption;
810 : : else
811 [ # # ]: 0 : throw lang::IllegalArgumentException();
812 : :
813 : : // if there are cached properties update them
814 [ # # ][ # # ]: 0 : if ( aProps[nInd].Name.equals( aMedTypePropName ) || aProps[nInd].Name.equals( aComprPropName ) )
[ # # ]
815 [ # # ]: 0 : for ( sal_Int32 nMemInd = 0; nMemInd < m_aProps.getLength(); nMemInd++ )
816 : : {
817 [ # # ][ # # ]: 0 : if ( aProps[nInd].Name.equals( m_aProps[nMemInd].Name ) )
818 [ # # ]: 0 : m_aProps[nMemInd].Value = aProps[nInd].Value;
819 : : }
820 : : }
821 : :
822 [ # # ]: 0 : if ( bCompressedIsSet )
823 : : {
824 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( aComprPropName, uno::makeAny( (sal_Bool)bCompressed ) );
[ # # ]
825 : 0 : m_bCompressedSetExplicit = sal_True;
826 : : }
827 : :
828 [ # # ]: 0 : if ( m_bUseCommonEncryption )
829 : : {
830 [ # # ]: 0 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
831 [ # # ]: 0 : throw uno::RuntimeException();
832 : :
833 : : // set to be encrypted but do not use encryption key
834 [ # # ]: 0 : xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
835 [ # # ][ # # ]: 0 : uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
[ # # ][ # # ]
[ # # ]
836 [ # # ]: 0 : xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ),
837 [ # # ][ # # ]: 0 : uno::makeAny( sal_True ) );
[ # # ]
838 : : }
839 : :
840 : : // the stream should be free soon, after package is stored
841 : 0 : m_bHasDataToFlush = sal_False;
842 : 0 : m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it
843 [ # # ]: 0 : m_bHasInsertedStreamOptimization = sal_True;
844 : 0 : }
845 : :
846 : : //-----------------------------------------------
847 : 7786 : void OWriteStream_Impl::Commit()
848 : : {
849 [ + - ]: 7786 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
850 : :
851 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
852 : :
853 [ + + ]: 7786 : if ( !m_bHasDataToFlush )
854 : 7786 : return;
855 : :
856 : 4941 : uno::Reference< packages::XDataSinkEncrSupport > xNewPackageStream;
857 [ + - ]: 4941 : uno::Sequence< uno::Any > aSeq( 1 );
858 [ + - ][ + - ]: 4941 : aSeq[0] <<= sal_False;
859 : :
860 [ + + ]: 4941 : if ( m_xCacheStream.is() )
861 : : {
862 [ + + ]: 4499 : if ( m_pAntiImpl )
863 [ + - ]: 656 : m_pAntiImpl->DeInit();
864 : :
865 [ + - ][ + - ]: 4499 : uno::Reference< io::XInputStream > xInStream( m_xCacheStream->getInputStream(), uno::UNO_SET_THROW );
[ + - ]
866 : :
867 : : xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >(
868 [ + - ]: 4499 : m_xPackage->createInstanceWithArguments( aSeq ),
869 [ + - ][ + - ]: 4499 : uno::UNO_QUERY_THROW );
[ + - ]
870 : :
871 [ + - ][ + - ]: 4499 : xNewPackageStream->setDataStream( xInStream );
872 : :
873 [ + - ]: 4499 : m_xCacheStream = uno::Reference< io::XStream >();
874 [ + - ]: 4499 : m_xCacheSeek = uno::Reference< io::XSeekable >();
875 : :
876 : : }
877 [ + + ]: 442 : else if ( !m_aTempURL.isEmpty() )
878 : : {
879 [ + + ]: 80 : if ( m_pAntiImpl )
880 [ + - ]: 71 : m_pAntiImpl->DeInit();
881 : :
882 : 80 : uno::Reference< io::XInputStream > xInStream;
883 : : try
884 : : {
885 [ + - ][ + - ]: 80 : xInStream.set( static_cast< io::XInputStream* >( new OSelfTerminateFileStream( GetServiceFactory(), m_aTempURL ) ), uno::UNO_QUERY );
[ + - ][ # # ]
[ + - ]
886 : : }
887 [ # # ]: 0 : catch( const uno::Exception& )
888 : : {
889 : : }
890 : :
891 [ - + ]: 80 : if ( !xInStream.is() )
892 [ # # ]: 0 : throw io::IOException();
893 : :
894 : : xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >(
895 [ + - ]: 80 : m_xPackage->createInstanceWithArguments( aSeq ),
896 [ + - ][ + - ]: 80 : uno::UNO_QUERY_THROW );
[ + - ]
897 : :
898 : : // TODO/NEW: Let the temporary file be removed after commit
899 [ + - ][ + - ]: 80 : xNewPackageStream->setDataStream( xInStream );
900 : 80 : m_aTempURL = ::rtl::OUString();
901 : : }
902 : : else // if ( m_bHasInsertedStreamOptimization )
903 : : {
904 : : // if the optimization is used the stream can be accessed directly
905 [ + - ]: 362 : xNewPackageStream = m_xPackageStream;
906 : : }
907 : :
908 : : // copy properties to the package stream
909 [ + - ]: 4941 : uno::Reference< beans::XPropertySet > xPropertySet( xNewPackageStream, uno::UNO_QUERY );
910 [ - + ]: 4941 : if ( !xPropertySet.is() )
911 [ # # ]: 0 : throw uno::RuntimeException();
912 : :
913 [ + + ]: 24246 : for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ )
914 : : {
915 [ + - ][ + + ]: 19305 : if ( m_aProps[nInd].Name == "Size" )
916 : : {
917 [ + + ][ + - ]: 4941 : if ( m_pAntiImpl && !m_bHasInsertedStreamOptimization && m_pAntiImpl->m_xSeekable.is() )
[ - + ][ - + ]
918 : : {
919 [ # # ][ # # ]: 0 : m_aProps[nInd].Value <<= ((sal_Int32)m_pAntiImpl->m_xSeekable->getLength());
[ # # ][ # # ]
920 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value );
[ # # ][ # # ]
921 : : }
922 : : }
923 : : else
924 [ + - ][ + - ]: 14364 : xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value );
[ + - ][ + - ]
925 : : }
926 : :
927 [ + + ]: 4941 : if ( m_bUseCommonEncryption )
928 : : {
929 [ - + ]: 4476 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
930 [ # # ]: 0 : throw uno::RuntimeException();
931 : :
932 : : // set to be encrypted but do not use encryption key
933 [ + - ]: 4476 : xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
934 [ + - ][ + - ]: 4476 : uno::makeAny( uno::Sequence< beans::NamedValue >() ) );
[ + - ][ + - ]
[ + - ]
935 [ + - ]: 4476 : xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ),
936 [ + - ][ + - ]: 4476 : uno::makeAny( sal_True ) );
[ + - ]
937 : : }
938 [ - + ]: 465 : else if ( m_bHasCachedEncryptionData )
939 : : {
940 [ # # ]: 0 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
941 [ # # ]: 0 : throw uno::RuntimeException();
942 : :
943 [ # # ]: 0 : xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ),
944 [ # # ][ # # ]: 0 : uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) );
[ # # ][ # # ]
[ # # ]
945 : : }
946 : :
947 : : // the stream should be free soon, after package is stored
948 [ + - ]: 4941 : m_xPackageStream = xNewPackageStream;
949 : 4941 : m_bHasDataToFlush = sal_False;
950 [ + - ][ + - ]: 7786 : m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it
[ + + ]
951 : : }
952 : :
953 : : //-----------------------------------------------
954 : 0 : void OWriteStream_Impl::Revert()
955 : : {
956 : : // can be called only from parent storage
957 : : // means complete reload of the stream
958 : :
959 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
960 : :
961 [ # # ]: 0 : if ( !m_bHasDataToFlush )
962 : 0 : return; // nothing to do
963 : :
964 : : OSL_ENSURE( !m_aTempURL.isEmpty() || m_xCacheStream.is(), "The temporary must exist!\n" );
965 : :
966 [ # # ]: 0 : if ( m_xCacheStream.is() )
967 : : {
968 [ # # ]: 0 : m_xCacheStream = uno::Reference< io::XStream >();
969 [ # # ]: 0 : m_xCacheSeek = uno::Reference< io::XSeekable >();
970 : : }
971 : :
972 [ # # ]: 0 : if ( !m_aTempURL.isEmpty() )
973 : : {
974 [ # # ][ # # ]: 0 : KillFile( m_aTempURL, comphelper::getProcessComponentContext() );
975 : 0 : m_aTempURL = ::rtl::OUString();
976 : : }
977 : :
978 [ # # ]: 0 : m_aProps.realloc( 0 );
979 : :
980 : 0 : m_bHasDataToFlush = sal_False;
981 : :
982 : 0 : m_bUseCommonEncryption = sal_True;
983 : 0 : m_bHasCachedEncryptionData = sal_False;
984 [ # # ]: 0 : m_aEncryptionData.clear();
985 : :
986 [ # # ]: 0 : if ( m_nStorageType == embed::StorageFormats::OFOPXML )
987 : : {
988 : : // currently the relations storage is changed only on commit
989 [ # # ]: 0 : m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
990 [ # # ][ # # ]: 0 : m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
[ # # ]
991 [ # # ]: 0 : if ( m_xOrigRelInfoStream.is() )
992 : : {
993 : : // the original stream is still here, that means that it was not parsed
994 [ # # ][ # # ]: 0 : m_aOrigRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
[ # # ]
995 : 0 : m_nRelInfoStatus = RELINFO_NO_INIT;
996 : : }
997 : : else
998 : : {
999 : : // the original stream was aready parsed
1000 [ # # ]: 0 : if ( !m_bOrigRelInfoBroken )
1001 : 0 : m_nRelInfoStatus = RELINFO_READ;
1002 : : else
1003 : 0 : m_nRelInfoStatus = RELINFO_BROKEN;
1004 : : }
1005 [ # # ][ # # ]: 0 : }
1006 : : }
1007 : :
1008 : : //-----------------------------------------------
1009 : 20662 : uno::Sequence< beans::PropertyValue > OWriteStream_Impl::GetStreamProperties()
1010 : : {
1011 [ + + ]: 20662 : if ( !m_aProps.getLength() )
1012 [ + - ]: 8324 : m_aProps = ReadPackageStreamProperties();
1013 : :
1014 : 20662 : return m_aProps;
1015 : : }
1016 : :
1017 : : //-----------------------------------------------
1018 : 3845 : uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps(
1019 : : const uno::Sequence< beans::PropertyValue >& aProps,
1020 : : sal_Bool bUseCommonEncryption )
1021 : : {
1022 : 3845 : uno::Sequence< beans::PropertyValue > aResult( aProps );
1023 : 3845 : sal_Int32 nLen = aResult.getLength();
1024 : :
1025 [ + + ]: 3845 : if ( m_nStorageType == embed::StorageFormats::PACKAGE )
1026 : : {
1027 [ + + ]: 5995 : for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
1028 [ + - ][ - + ]: 4796 : if ( aResult[nInd].Name == "UseCommonStoragePasswordEncryption" )
1029 : : {
1030 [ # # ][ # # ]: 0 : aResult[nInd].Value <<= bUseCommonEncryption;
1031 : 0 : return aResult;
1032 : : }
1033 : :
1034 [ + - ]: 1199 : aResult.realloc( ++nLen );
1035 [ + - ][ + - ]: 1199 : aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") );
1036 [ + - ][ + - ]: 1199 : aResult[nLen - 1].Value <<= bUseCommonEncryption;
1037 : : }
1038 [ + + ]: 2646 : else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1039 : : {
1040 [ + - ]: 1889 : ReadRelInfoIfNecessary();
1041 : :
1042 : 1889 : uno::Any aValue;
1043 [ + - ]: 1889 : if ( m_nRelInfoStatus == RELINFO_READ )
1044 [ + - ]: 1889 : aValue <<= m_aOrigRelInfo;
1045 [ # # ][ # # ]: 0 : else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
1046 [ # # ]: 0 : aValue <<= m_aNewRelInfo;
1047 : : else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1048 : : throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ),
1049 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
1050 : :
1051 [ + + ]: 7556 : for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
1052 [ + - ][ - + ]: 5667 : if ( aResult[nInd].Name == "RelationsInfo" )
1053 : : {
1054 [ # # ]: 0 : aResult[nInd].Value = aValue;
1055 : : return aResult;
1056 : : }
1057 : :
1058 [ + - ]: 1889 : aResult.realloc( ++nLen );
1059 [ + - ][ + - ]: 1889 : aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RelationsInfo") );
1060 [ + - ][ + - ]: 1889 : aResult[nLen - 1].Value = aValue;
1061 : : }
1062 : :
1063 : 3845 : return aResult;
1064 : : }
1065 : :
1066 : : //-----------------------------------------------
1067 : 3231 : sal_Bool OWriteStream_Impl::IsTransacted()
1068 : : {
1069 [ + - ]: 3231 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1070 [ + + ][ - + ]: 3231 : return ( m_pAntiImpl && m_pAntiImpl->m_bTransacted );
[ + - ]
1071 : : }
1072 : :
1073 : 10464 : void OWriteStream_Impl::ReadRelInfoIfNecessary()
1074 : : {
1075 [ + + ]: 10464 : if ( m_nStorageType != embed::StorageFormats::OFOPXML )
1076 : 10464 : return;
1077 : :
1078 [ + + ]: 4411 : if ( m_nRelInfoStatus == RELINFO_NO_INIT )
1079 : : {
1080 : : try
1081 : : {
1082 : : // Init from original stream
1083 [ + + ]: 2348 : if ( m_xOrigRelInfoStream.is() )
1084 : : m_aOrigRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
1085 : : m_xOrigRelInfoStream,
1086 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ),
1087 [ + - ][ + - ]: 194 : m_xFactory );
[ + - ][ + - ]
1088 : :
1089 : : // in case of success the stream must be thrown away, that means that the OrigRelInfo is initialized
1090 : : // the reason for this is that the original stream might not be seekable ( at the same time the new
1091 : : // provided stream must be seekable ), so it must be read only once
1092 [ + - ]: 2348 : m_xOrigRelInfoStream = uno::Reference< io::XInputStream >();
1093 : 2348 : m_nRelInfoStatus = RELINFO_READ;
1094 : : }
1095 [ # # ]: 0 : catch( const uno::Exception& rException )
1096 : : {
1097 [ # # ]: 0 : AddLog( rException.Message );
1098 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
1099 : :
1100 : 0 : m_nRelInfoStatus = RELINFO_BROKEN;
1101 : 0 : m_bOrigRelInfoBroken = sal_True;
1102 : : }
1103 : : }
1104 [ - + ]: 2063 : else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1105 : : {
1106 : : // Init from the new stream
1107 : : try
1108 : : {
1109 [ # # ]: 0 : if ( m_xNewRelInfoStream.is() )
1110 : : m_aNewRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(
1111 : : m_xNewRelInfoStream,
1112 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ),
1113 [ # # ][ # # ]: 0 : m_xFactory );
[ # # ][ # # ]
[ # # ]
1114 : :
1115 : 0 : m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ;
1116 : : }
1117 : 0 : catch( const uno::Exception& )
1118 : : {
1119 : 0 : m_nRelInfoStatus = RELINFO_CHANGED_BROKEN;
1120 : : }
1121 : : }
1122 : : }
1123 : :
1124 : : //-----------------------------------------------
1125 : 8324 : uno::Sequence< beans::PropertyValue > OWriteStream_Impl::ReadPackageStreamProperties()
1126 : : {
1127 : 8324 : sal_Int32 nPropNum = 0;
1128 [ + + ]: 8324 : if ( m_nStorageType == embed::StorageFormats::ZIP )
1129 : 757 : nPropNum = 2;
1130 [ + + ]: 7567 : else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1131 : 2348 : nPropNum = 3;
1132 [ + - ]: 5219 : else if ( m_nStorageType == embed::StorageFormats::PACKAGE )
1133 : 5219 : nPropNum = 4;
1134 [ + - ]: 8324 : uno::Sequence< beans::PropertyValue > aResult( nPropNum );
1135 : :
1136 : : // The "Compressed" property must be set after "MediaType" property,
1137 : : // since the setting of the last one can change the value of the first one
1138 : :
1139 [ + + ][ + + ]: 8324 : if ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE )
1140 : : {
1141 [ + - ][ + - ]: 7567 : aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType") );
1142 [ + - ][ + - ]: 7567 : aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") );
1143 [ + - ][ + - ]: 7567 : aResult[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") );
1144 : :
1145 [ + + ]: 12786 : if ( m_nStorageType == embed::StorageFormats::PACKAGE )
1146 [ + - ][ + - ]: 5219 : aResult[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") );
1147 : : }
1148 : : else
1149 : : {
1150 [ + - ][ + - ]: 757 : aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") );
1151 [ + - ][ + - ]: 757 : aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") );
1152 : :
1153 : : }
1154 : :
1155 : : // TODO: may be also raw stream should be marked
1156 : :
1157 [ + - ]: 8324 : uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY );
1158 [ + - ]: 8324 : if ( xPropSet.is() )
1159 : : {
1160 [ + + ]: 37758 : for ( sal_Int32 nInd = 0; nInd < aResult.getLength(); nInd++ )
1161 : : {
1162 : : try {
1163 [ + - ][ + - ]: 29434 : aResult[nInd].Value = xPropSet->getPropertyValue( aResult[nInd].Name );
[ + - ][ + - ]
1164 : : }
1165 [ # # # # ]: 0 : catch( const uno::Exception& rException )
1166 : : {
1167 [ # # ]: 0 : AddLog( rException.Message );
1168 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
1169 : :
1170 : : OSL_FAIL( "A property can't be retrieved!\n" );
1171 : : }
1172 : : }
1173 : : }
1174 : : else
1175 : : {
1176 : : OSL_FAIL( "Can not get properties from a package stream!\n" );
1177 [ # # ]: 0 : throw uno::RuntimeException();
1178 : : }
1179 : :
1180 : 8324 : return aResult;
1181 : : }
1182 : :
1183 : : //-----------------------------------------------
1184 : 0 : void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream,
1185 : : const ::comphelper::SequenceAsHashMap& aEncryptionData )
1186 : : {
1187 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1188 : :
1189 : : OSL_ENSURE( !m_bUseCommonEncryption, "The stream can not be encrypted!" );
1190 : :
1191 [ # # ]: 0 : if ( m_nStorageType != embed::StorageFormats::PACKAGE )
1192 [ # # ]: 0 : throw packages::NoEncryptionException();
1193 : :
1194 [ # # ]: 0 : if ( m_pAntiImpl )
1195 : : {
1196 [ # # ]: 0 : m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream );
1197 : : }
1198 : : else
1199 : : {
1200 [ # # ]: 0 : uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aEncryptionData, sal_False );
1201 [ # # ]: 0 : if ( !xOwnStream.is() )
1202 [ # # ]: 0 : throw io::IOException(); // TODO
1203 : :
1204 [ # # ][ # # ]: 0 : OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
[ # # ]
1205 : : }
1206 : :
1207 [ # # ]: 0 : uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDestStream, uno::UNO_QUERY );
1208 [ # # ]: 0 : if ( xEncr.is() )
1209 [ # # ][ # # ]: 0 : xEncr->setEncryptionData( aEncryptionData.getAsConstNamedValueList() );
[ # # ][ # # ]
[ # # ]
1210 : 0 : }
1211 : :
1212 : : //-----------------------------------------------
1213 : 239 : uno::Sequence< uno::Sequence< beans::StringPair > > OWriteStream_Impl::GetAllRelationshipsIfAny()
1214 : : {
1215 [ + + ]: 239 : if ( m_nStorageType != embed::StorageFormats::OFOPXML )
1216 : 65 : return uno::Sequence< uno::Sequence< beans::StringPair > >();
1217 : :
1218 : 174 : ReadRelInfoIfNecessary();
1219 : :
1220 [ + + ]: 174 : if ( m_nRelInfoStatus == RELINFO_READ )
1221 : 57 : return m_aOrigRelInfo;
1222 [ + - ][ + - ]: 117 : else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED )
1223 : 117 : return m_aNewRelInfo;
1224 : : else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN
1225 : : throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ),
1226 [ # # ][ # # ]: 239 : uno::Reference< uno::XInterface >() );
1227 : : }
1228 : :
1229 : : //-----------------------------------------------
1230 : 65 : void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream )
1231 : : {
1232 [ + - ]: 65 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1233 : :
1234 [ - + ]: 65 : if ( m_pAntiImpl )
1235 : : {
1236 [ # # ]: 0 : m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream );
1237 : : }
1238 : : else
1239 : : {
1240 [ + - ]: 65 : uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, sal_False );
1241 [ - + ]: 65 : if ( !xOwnStream.is() )
1242 [ # # ]: 0 : throw io::IOException(); // TODO
1243 : :
1244 [ + - ][ + - ]: 65 : OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() );
[ + - ]
1245 [ + - ]: 65 : }
1246 : 65 : }
1247 : :
1248 : : //-----------------------------------------------
1249 : 24 : uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess )
1250 : : {
1251 [ + - ]: 24 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1252 : :
1253 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
1254 : :
1255 [ - + ]: 24 : if ( m_pAntiImpl )
1256 [ # # ]: 0 : throw io::IOException(); // TODO:
1257 : :
1258 [ + - ][ - + ]: 24 : if ( !IsEncrypted() )
1259 [ # # ]: 0 : throw packages::NoEncryptionException();
1260 : :
1261 : 24 : uno::Reference< io::XStream > xResultStream;
1262 : :
1263 [ + - ]: 24 : uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY );
1264 [ - + ]: 24 : if ( !xPropertySet.is() )
1265 [ # # ]: 0 : throw uno::RuntimeException();
1266 : :
1267 [ - + ]: 24 : if ( m_bHasCachedEncryptionData )
1268 : : {
1269 [ # # ][ # # ]: 0 : if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData, aEncryptionData ) )
1270 [ # # ]: 0 : throw packages::WrongPasswordException();
1271 : :
1272 : : // the correct key must be set already
1273 [ # # ][ # # ]: 0 : xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
1274 : : }
1275 : : else
1276 : : {
1277 [ + - ][ + - ]: 24 : SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() );
[ + - ]
1278 : :
1279 : : try {
1280 [ + - ][ + - ]: 24 : xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
1281 : :
1282 : 24 : m_bUseCommonEncryption = sal_False; // very important to set it to false
1283 : 24 : m_bHasCachedEncryptionData = sal_True;
1284 [ + - ]: 24 : m_aEncryptionData = aEncryptionData;
1285 : : }
1286 : 0 : catch( const packages::WrongPasswordException& rWrongPasswordException )
1287 : : {
1288 [ # # # # : 0 : SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
# # ]
1289 [ # # ]: 0 : AddLog( rWrongPasswordException.Message );
1290 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
1291 : 0 : throw;
1292 : : }
1293 [ # # # ]: 0 : catch ( const uno::Exception& rException )
1294 : : {
1295 [ # # ]: 0 : AddLog( rException.Message );
1296 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
1297 : :
1298 : : OSL_FAIL( "Can't write encryption related properties!\n" );
1299 [ # # # # : 0 : SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
# # ]
1300 [ # # ]: 0 : throw io::IOException(); // TODO:
1301 : : }
1302 : : }
1303 : :
1304 : : OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" );
1305 : :
1306 [ + - ]: 24 : return xResultStream;
1307 : : }
1308 : :
1309 : : //-----------------------------------------------
1310 : 8401 : uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess )
1311 : : {
1312 [ + - ]: 8401 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1313 : :
1314 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
1315 : :
1316 [ - + ]: 8401 : if ( m_pAntiImpl )
1317 [ # # ]: 0 : throw io::IOException(); // TODO:
1318 : :
1319 : 8401 : uno::Reference< io::XStream > xResultStream;
1320 : :
1321 [ + + ][ + - ]: 8401 : if ( IsEncrypted() )
1322 : : {
1323 [ + - ]: 24 : ::comphelper::SequenceAsHashMap aGlobalEncryptionData;
1324 : : try
1325 : : {
1326 [ + - ][ + - ]: 24 : aGlobalEncryptionData = GetCommonRootEncryptionData();
[ + - ]
1327 : : }
1328 [ # # ]: 0 : catch( const packages::NoEncryptionException& rNoEncryptionException )
1329 : : {
1330 [ # # ]: 0 : AddLog( rNoEncryptionException.Message );
1331 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
1332 : :
1333 [ # # ]: 0 : throw packages::WrongPasswordException();
1334 : : }
1335 : :
1336 [ + - ][ + - ]: 24 : xResultStream = GetStream( nStreamMode, aGlobalEncryptionData, bHierarchyAccess );
[ + - ]
1337 : : }
1338 : : else
1339 [ + - ][ + - ]: 8377 : xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess );
1340 : :
1341 [ + - ]: 8401 : return xResultStream;
1342 : : }
1343 : :
1344 : : //-----------------------------------------------
1345 : 8401 : uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess )
1346 : : {
1347 : : // private method, no mutex is used
1348 : 8401 : GetStreamProperties();
1349 : :
1350 : : // TODO/LATER: this info might be read later, on demand in future
1351 : 8401 : ReadRelInfoIfNecessary();
1352 : :
1353 [ + + ]: 8401 : if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::READ )
1354 : : {
1355 : 2986 : uno::Reference< io::XInputStream > xInStream;
1356 [ - + ][ + + ]: 2986 : if ( m_xCacheStream.is() || !m_aTempURL.isEmpty() )
[ + + ]
1357 [ + - ][ + - ]: 8 : xInStream = GetTempFileAsInputStream(); //TODO:
1358 : : else
1359 [ + - ][ + - ]: 2978 : xInStream = m_xPackageStream->getDataStream();
[ + - ]
1360 : :
1361 : : // The stream does not exist in the storage
1362 [ - + ]: 2986 : if ( !xInStream.is() )
1363 [ # # ]: 0 : throw io::IOException();
1364 : :
1365 [ + - ][ + - ]: 2986 : OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType );
[ + - ]
1366 : : uno::Reference< io::XStream > xCompStream(
1367 : : static_cast< ::cppu::OWeakObject* >( pStream ),
1368 [ + - ]: 2986 : uno::UNO_QUERY );
1369 : : OSL_ENSURE( xCompStream.is(),
1370 : : "OInputCompStream MUST provide XStream interfaces!\n" );
1371 : :
1372 [ + - ]: 2986 : m_aInputStreamsList.push_back( pStream );
1373 : 2986 : return xCompStream;
1374 : : }
1375 [ + + ]: 5415 : else if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::SEEKABLEREAD )
1376 : : {
1377 [ + - ][ + - ]: 859 : if ( !m_xCacheStream.is() && m_aTempURL.isEmpty() && !( m_xPackageStream->getDataStream().is() ) )
[ + - ][ + - ]
[ - + ][ + - ]
[ - + # # ]
1378 : : {
1379 : : // The stream does not exist in the storage
1380 [ # # ]: 0 : throw io::IOException();
1381 : : }
1382 : :
1383 : 859 : uno::Reference< io::XInputStream > xInStream;
1384 : :
1385 [ + - ][ + - ]: 859 : xInStream = GetTempFileAsInputStream(); //TODO:
1386 : :
1387 [ - + ]: 859 : if ( !xInStream.is() )
1388 [ # # ]: 0 : throw io::IOException();
1389 : :
1390 [ + - ][ + - ]: 859 : OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType );
[ + - ]
1391 : : uno::Reference< io::XStream > xSeekStream(
1392 : : static_cast< ::cppu::OWeakObject* >( pStream ),
1393 [ + - ]: 859 : uno::UNO_QUERY );
1394 : : OSL_ENSURE( xSeekStream.is(),
1395 : : "OInputSeekStream MUST provide XStream interfaces!\n" );
1396 : :
1397 [ + - ]: 859 : m_aInputStreamsList.push_back( pStream );
1398 : 859 : return xSeekStream;
1399 : : }
1400 [ + - ]: 4556 : else if ( ( nStreamMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE )
1401 : : {
1402 [ - + ]: 4556 : if ( !m_aInputStreamsList.empty() )
1403 [ # # ]: 0 : throw io::IOException(); // TODO:
1404 : :
1405 : 4556 : uno::Reference< io::XStream > xStream;
1406 [ + + ]: 4556 : if ( ( nStreamMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE )
1407 : : {
1408 [ - + ]: 3021 : if ( !m_aTempURL.isEmpty() )
1409 : : {
1410 [ # # ][ # # ]: 0 : KillFile( m_aTempURL, comphelper::getProcessComponentContext() );
1411 : 0 : m_aTempURL = ::rtl::OUString();
1412 : : }
1413 [ - + ]: 3021 : if ( m_xCacheStream.is() )
1414 [ # # ]: 0 : CleanCacheStream();
1415 : :
1416 : 3021 : m_bHasDataToFlush = sal_True;
1417 : :
1418 : : // this call is triggered by the parent and it will recognize the change of the state
1419 [ + - ]: 3021 : if ( m_pParent )
1420 : 3021 : m_pParent->m_bIsModified = sal_True;
1421 : :
1422 [ + - ][ + - ]: 3021 : xStream = CreateMemoryStream( GetServiceFactory() );
[ + - ]
1423 [ + - ]: 3021 : m_xCacheSeek.set( xStream, uno::UNO_QUERY_THROW );
1424 [ + - ]: 3021 : m_xCacheStream = xStream;
1425 : : }
1426 [ + - ]: 1535 : else if ( !m_bHasInsertedStreamOptimization )
1427 : : {
1428 [ + - ][ + - ]: 1535 : if ( m_aTempURL.isEmpty() && !m_xCacheStream.is() && !( m_xPackageStream->getDataStream().is() ) )
[ + - ][ + - ]
[ + + ][ + - ]
[ + + # # ]
1429 : : {
1430 : : // The stream does not exist in the storage
1431 : 1492 : m_bHasDataToFlush = sal_True;
1432 : :
1433 : : // this call is triggered by the parent and it will recognize the change of the state
1434 [ + - ]: 1492 : if ( m_pParent )
1435 : 1492 : m_pParent->m_bIsModified = sal_True;
1436 [ + - ][ + - ]: 1492 : xStream = GetTempFileAsStream();
1437 : : }
1438 : :
1439 : : // if the stream exists the temporary file is created on demand
1440 : : // xStream = GetTempFileAsStream();
1441 : : }
1442 : :
1443 [ + + ]: 4556 : if ( !xStream.is() )
1444 [ + - ]: 43 : m_pAntiImpl = new OWriteStream( this, bHierarchyAccess );
1445 : : else
1446 [ + - ]: 4513 : m_pAntiImpl = new OWriteStream( this, xStream, bHierarchyAccess );
1447 : :
1448 : : uno::Reference< io::XStream > xWriteStream =
1449 [ + - ]: 4556 : uno::Reference< io::XStream >( static_cast< ::cppu::OWeakObject* >( m_pAntiImpl ),
1450 [ + - ]: 4556 : uno::UNO_QUERY );
1451 : :
1452 : : OSL_ENSURE( xWriteStream.is(), "OWriteStream MUST implement XStream && XComponent interfaces!\n" );
1453 : :
1454 : 4556 : return xWriteStream;
1455 : : }
1456 : :
1457 [ # # ]: 8401 : throw lang::IllegalArgumentException(); // TODO
1458 : : }
1459 : :
1460 : : //-----------------------------------------------
1461 : 0 : uno::Reference< io::XInputStream > OWriteStream_Impl::GetPlainRawInStream()
1462 : : {
1463 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1464 : :
1465 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
1466 : :
1467 : : // this method is used only internally, this stream object should not go outside of this implementation
1468 : : // if ( m_pAntiImpl )
1469 : : // throw io::IOException(); // TODO:
1470 : :
1471 [ # # ][ # # ]: 0 : return m_xPackageStream->getPlainRawStream();
[ # # ]
1472 : : }
1473 : :
1474 : : //-----------------------------------------------
1475 : 0 : uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream()
1476 : : {
1477 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1478 : :
1479 : : OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" );
1480 : :
1481 [ # # ]: 0 : if ( m_pAntiImpl )
1482 [ # # ]: 0 : throw io::IOException(); // TODO:
1483 : :
1484 : : OSL_ENSURE( IsEncrypted(), "Impossible to get raw representation for nonencrypted stream!\n" );
1485 [ # # ][ # # ]: 0 : if ( !IsEncrypted() )
1486 [ # # ]: 0 : throw packages::NoEncryptionException();
1487 : :
1488 [ # # ][ # # ]: 0 : return m_xPackageStream->getRawStream();
[ # # ]
1489 : : }
1490 : :
1491 : : //-----------------------------------------------
1492 : 24 : ::comphelper::SequenceAsHashMap OWriteStream_Impl::GetCommonRootEncryptionData()
1493 : : throw ( packages::NoEncryptionException )
1494 : : {
1495 [ + - ]: 24 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
1496 : :
1497 [ + - ][ - + ]: 24 : if ( m_nStorageType != embed::StorageFormats::PACKAGE || !m_pParent )
1498 [ # # ]: 0 : throw packages::NoEncryptionException();
1499 : :
1500 [ + - ][ + - ]: 24 : return m_pParent->GetCommonRootEncryptionData();
1501 : : }
1502 : :
1503 : : //-----------------------------------------------
1504 : 3845 : void OWriteStream_Impl::InputStreamDisposed( OInputCompStream* pStream )
1505 : : {
1506 [ + - ]: 3845 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1507 [ + - ][ + - ]: 3845 : m_aInputStreamsList.remove( pStream );
1508 : 3845 : }
1509 : :
1510 : : //-----------------------------------------------
1511 : 0 : void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io::XInputStream >& xDataToCopy, const uno::Sequence< beans::PropertyValue >& aProps, sal_Bool, uno::Reference< io::XStream >& xTargetStream )
1512 : : {
1513 : 0 : uno::Reference < io::XStream > xTempFile;
1514 [ # # ]: 0 : if ( !xTargetStream.is() )
1515 : : xTempFile = uno::Reference < io::XStream >(
1516 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ),
1517 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ][ # # ]
1518 : : else
1519 [ # # ]: 0 : xTempFile = xTargetStream;
1520 : :
1521 [ # # ]: 0 : uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY );
1522 [ # # ]: 0 : if ( !xTempSeek.is() )
1523 [ # # ]: 0 : throw uno::RuntimeException(); // TODO
1524 : :
1525 [ # # ][ # # ]: 0 : uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream();
1526 [ # # ]: 0 : if ( !xTempOut.is() )
1527 [ # # ]: 0 : throw uno::RuntimeException();
1528 : :
1529 [ # # ]: 0 : if ( xDataToCopy.is() )
1530 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xDataToCopy, xTempOut );
1531 : :
1532 [ # # ][ # # ]: 0 : xTempOut->closeOutput();
1533 [ # # ][ # # ]: 0 : xTempSeek->seek( 0 );
1534 : :
1535 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xInStream = xTempFile->getInputStream();
1536 [ # # ]: 0 : if ( !xInStream.is() )
1537 [ # # ]: 0 : throw io::IOException();
1538 : :
1539 : : // TODO: remember last state of m_bUseCommonEncryption
1540 [ # # ]: 0 : if ( !xTargetStream.is() )
1541 : : xTargetStream = uno::Reference< io::XStream > (
1542 : : static_cast< ::cppu::OWeakObject* >(
1543 [ # # ]: 0 : new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonEncryption ), m_nStorageType ) ),
1544 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ][ # # ]
1545 : 0 : }
1546 : :
1547 : : //-----------------------------------------------
1548 : 0 : void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream )
1549 : : {
1550 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1551 : :
1552 : : OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" );
1553 [ # # ]: 0 : if ( !m_xPackageStream.is() )
1554 [ # # ]: 0 : throw uno::RuntimeException();
1555 : :
1556 : 0 : uno::Reference< io::XInputStream > xDataToCopy;
1557 [ # # ][ # # ]: 0 : if ( IsEncrypted() )
1558 : : {
1559 : : // an encrypted stream must contain input stream
1560 [ # # ]: 0 : ::comphelper::SequenceAsHashMap aGlobalEncryptionData;
1561 : : try
1562 : : {
1563 [ # # ][ # # ]: 0 : aGlobalEncryptionData = GetCommonRootEncryptionData();
[ # # ]
1564 : : }
1565 [ # # ]: 0 : catch( const packages::NoEncryptionException& rNoEncryptionException )
1566 : : {
1567 [ # # ]: 0 : AddLog( rNoEncryptionException.Message );
1568 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) );
1569 : :
1570 [ # # ]: 0 : throw packages::WrongPasswordException();
1571 : : }
1572 : :
1573 [ # # ][ # # ]: 0 : GetCopyOfLastCommit( xTargetStream, aGlobalEncryptionData );
1574 : : }
1575 : : else
1576 : : {
1577 [ # # ][ # # ]: 0 : xDataToCopy = m_xPackageStream->getDataStream();
[ # # ]
1578 : :
1579 : : // in case of new inserted package stream it is possible that input stream still was not set
1580 [ # # ][ # # ]: 0 : GetStreamProperties();
1581 : :
1582 [ # # ]: 0 : CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream );
1583 [ # # ]: 0 : }
1584 : 0 : }
1585 : :
1586 : : //-----------------------------------------------
1587 : 0 : void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::comphelper::SequenceAsHashMap& aEncryptionData )
1588 : : {
1589 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
1590 : :
1591 : : OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" );
1592 [ # # ]: 0 : if ( !m_xPackageStream.is() )
1593 [ # # ]: 0 : throw uno::RuntimeException();
1594 : :
1595 [ # # ][ # # ]: 0 : if ( !IsEncrypted() )
1596 [ # # ]: 0 : throw packages::NoEncryptionException();
1597 : :
1598 : 0 : uno::Reference< io::XInputStream > xDataToCopy;
1599 : :
1600 [ # # ]: 0 : if ( m_bHasCachedEncryptionData )
1601 : : {
1602 : : // TODO: introduce last commited cashed password information and use it here
1603 : : // that means "use common pass" also should be remembered on flash
1604 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList();
1605 : :
1606 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY );
1607 [ # # ]: 0 : if ( !xProps.is() )
1608 [ # # ]: 0 : throw uno::RuntimeException();
1609 : :
1610 : 0 : sal_Bool bEncr = sal_False;
1611 [ # # ][ # # ]: 0 : xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) ) >>= bEncr;
[ # # ]
1612 [ # # ]: 0 : if ( !bEncr )
1613 [ # # ]: 0 : throw packages::NoEncryptionException();
1614 : :
1615 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aPackKey;
1616 [ # # ][ # # ]: 0 : xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) >>= aPackKey;
[ # # ][ # # ]
1617 [ # # ][ # # ]: 0 : if ( !SequencesEqual( aKey, aPackKey ) )
1618 [ # # ]: 0 : throw packages::WrongPasswordException();
1619 : :
1620 : : // the correct key must be set already
1621 [ # # ][ # # ]: 0 : xDataToCopy = m_xPackageStream->getDataStream();
[ # # ][ # # ]
[ # # ]
1622 : : }
1623 : : else
1624 : : {
1625 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY );
1626 [ # # ][ # # ]: 0 : SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() );
[ # # ]
1627 : :
1628 : : try {
1629 [ # # ][ # # ]: 0 : xDataToCopy = m_xPackageStream->getDataStream();
[ # # ]
1630 : :
1631 [ # # ]: 0 : if ( !xDataToCopy.is() )
1632 : : {
1633 : : OSL_FAIL( "Encrypted ZipStream must already have input stream inside!\n" );
1634 [ # # ][ # # ]: 0 : SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
[ # # ]
1635 : : }
1636 : : }
1637 [ # # ]: 0 : catch( const uno::Exception& rException )
1638 : : {
1639 : : OSL_FAIL( "Can't open encrypted stream!\n" );
1640 [ # # # # : 0 : SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
# # ]
1641 [ # # ]: 0 : AddLog( rException.Message );
1642 [ # # # # ]: 0 : AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
1643 : 0 : throw;
1644 : : }
1645 : :
1646 [ # # ][ # # ]: 0 : SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() );
[ # # ]
1647 : : }
1648 : :
1649 : : // in case of new inserted package stream it is possible that input stream still was not set
1650 [ # # ][ # # ]: 0 : GetStreamProperties();
1651 : :
1652 [ # # ][ # # ]: 0 : CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream );
1653 : 0 : }
1654 : :
1655 : : //-----------------------------------------------
1656 : 459 : void OWriteStream_Impl::CommitStreamRelInfo( const uno::Reference< embed::XStorage >& xRelStorage, const ::rtl::OUString& aOrigStreamName, const ::rtl::OUString& aNewStreamName )
1657 : : {
1658 : : // at this point of time the old stream must be already cleaned
1659 : : OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML, "The method should be used only with OFOPXML format!\n" );
1660 : :
1661 [ + - ]: 459 : if ( m_nStorageType == embed::StorageFormats::OFOPXML )
1662 : : {
1663 : : OSL_ENSURE( !aOrigStreamName.isEmpty() && !aNewStreamName.isEmpty() && xRelStorage.is(),
1664 : : "Wrong relation persistence information is provided!\n" );
1665 : :
1666 [ + - ][ + - ]: 459 : if ( !xRelStorage.is() || aOrigStreamName.isEmpty() || aNewStreamName.isEmpty() )
[ - + ][ - + ]
1667 [ # # ]: 0 : throw uno::RuntimeException();
1668 : :
1669 [ + - ][ - + ]: 459 : if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN )
1670 [ # # ]: 0 : throw io::IOException(); // TODO:
1671 : :
1672 : 459 : ::rtl::OUString aOrigRelStreamName = aOrigStreamName;
1673 [ + - ]: 459 : aOrigRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1674 : :
1675 : 459 : ::rtl::OUString aNewRelStreamName = aNewStreamName;
1676 [ + - ]: 459 : aNewRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) );
1677 : :
1678 : 459 : sal_Bool bRenamed = !aOrigRelStreamName.equals( aNewRelStreamName );
1679 [ + - ][ - + ]: 459 : if ( m_nRelInfoStatus == RELINFO_CHANGED
[ + + ]
1680 : : || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1681 : : || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1682 : : {
1683 [ - + ][ # # ]: 57 : if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) )
[ # # ][ # # ]
[ - + ]
1684 [ # # ][ # # ]: 0 : xRelStorage->removeElement( aOrigRelStreamName );
1685 : :
1686 [ + - ]: 57 : if ( m_nRelInfoStatus == RELINFO_CHANGED )
1687 : : {
1688 [ + - ]: 57 : if ( m_aNewRelInfo.getLength() )
1689 : : {
1690 : : uno::Reference< io::XStream > xRelsStream =
1691 [ + - ]: 57 : xRelStorage->openStreamElement( aNewRelStreamName,
1692 [ + - ]: 57 : embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1693 : :
1694 [ + - ][ + - ]: 57 : uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream();
1695 [ - + ]: 57 : if ( !xOutStream.is() )
1696 [ # # ]: 0 : throw uno::RuntimeException();
1697 : :
1698 [ + - ]: 57 : ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aNewRelInfo, m_xFactory );
1699 : :
1700 : : // set the mediatype
1701 [ + - ]: 57 : uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1702 [ + - ]: 57 : xPropSet->setPropertyValue(
1703 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1704 : : uno::makeAny( ::rtl::OUString(
1705 [ + - ][ + - ]: 57 : RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
[ + - ][ + - ]
1706 : :
1707 : 57 : m_nRelInfoStatus = RELINFO_READ;
1708 : : }
1709 : : }
1710 [ # # ][ # # ]: 0 : else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ
1711 : : || m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1712 : : {
1713 : : uno::Reference< io::XStream > xRelsStream =
1714 [ # # ]: 0 : xRelStorage->openStreamElement( aNewRelStreamName,
1715 [ # # ]: 0 : embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE );
1716 : :
1717 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream();
1718 [ # # ]: 0 : if ( !xOutputStream.is() )
1719 [ # # ]: 0 : throw uno::RuntimeException();
1720 : :
1721 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW );
1722 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
1723 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream );
1724 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
1725 : :
1726 : : // set the mediatype
1727 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW );
1728 [ # # ]: 0 : xPropSet->setPropertyValue(
1729 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
1730 : : uno::makeAny( ::rtl::OUString(
1731 [ # # ][ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) );
[ # # ][ # # ]
1732 : :
1733 [ # # ]: 0 : if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM )
1734 : 0 : m_nRelInfoStatus = RELINFO_NO_INIT;
1735 : : else
1736 : : {
1737 : : // the information is already parsed and the stream is stored, no need in temporary stream any more
1738 [ # # ]: 0 : m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1739 : 0 : m_nRelInfoStatus = RELINFO_READ;
1740 : 0 : }
1741 : : }
1742 : :
1743 : : // the original stream makes no sence after this step
1744 [ + - ]: 57 : m_xOrigRelInfoStream = m_xNewRelInfoStream;
1745 [ + - ]: 57 : m_aOrigRelInfo = m_aNewRelInfo;
1746 : 57 : m_bOrigRelInfoBroken = sal_False;
1747 [ + - ][ + - ]: 57 : m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
[ + - ]
1748 [ + - ]: 57 : m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
1749 : : }
1750 : : else
1751 : : {
1752 : : // the stream is not changed but it might be renamed
1753 [ - + ][ # # ]: 402 : if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) )
[ # # ][ # # ]
[ - + ]
1754 [ # # ][ # # ]: 0 : xRelStorage->renameElement( aOrigRelStreamName, aNewRelStreamName );
1755 : 459 : }
1756 : : }
1757 : 459 : }
1758 : :
1759 : : //===============================================
1760 : : // OWriteStream implementation
1761 : : //===============================================
1762 : :
1763 : : //-----------------------------------------------
1764 : 43 : OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted )
1765 : : : m_pImpl( pImpl )
1766 : : , m_bInStreamDisconnected( sal_False )
1767 : : , m_bInitOnDemand( sal_True )
1768 : : , m_nInitPosition( 0 )
1769 : 43 : , m_bTransacted( bTransacted )
1770 : : {
1771 : : OSL_ENSURE( pImpl, "No base implementation!\n" );
1772 : : OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" );
1773 : :
1774 [ - + ][ - + ]: 43 : if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() )
[ + - ]
1775 [ # # ]: 0 : throw uno::RuntimeException(); // just a disaster
1776 : :
1777 [ + - ][ + - ]: 43 : m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType );
[ + - ]
1778 : 43 : }
1779 : :
1780 : : //-----------------------------------------------
1781 : 4513 : OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, uno::Reference< io::XStream > xStream, sal_Bool bTransacted )
1782 : : : m_pImpl( pImpl )
1783 : : , m_bInStreamDisconnected( sal_False )
1784 : : , m_bInitOnDemand( sal_False )
1785 : : , m_nInitPosition( 0 )
1786 : 4513 : , m_bTransacted( bTransacted )
1787 : : {
1788 : : OSL_ENSURE( pImpl && xStream.is(), "No base implementation!\n" );
1789 : : OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" );
1790 : :
1791 [ - + ][ - + ]: 4513 : if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() )
[ + - ]
1792 [ # # ]: 0 : throw uno::RuntimeException(); // just a disaster
1793 : :
1794 [ + - ][ + - ]: 4513 : m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType );
[ + - ]
1795 : :
1796 [ + - ]: 4513 : if ( xStream.is() )
1797 : : {
1798 [ + - ][ + - ]: 4513 : m_xInStream = xStream->getInputStream();
[ + - ]
1799 [ + - ][ + - ]: 4513 : m_xOutStream = xStream->getOutputStream();
[ + - ]
1800 [ + - ][ + - ]: 4513 : m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY );
1801 : : OSL_ENSURE( m_xInStream.is() && m_xOutStream.is() && m_xSeekable.is(), "Stream implementation is incomplete!\n" );
1802 : : }
1803 : 4513 : }
1804 : :
1805 : : //-----------------------------------------------
1806 [ + - ]: 4556 : OWriteStream::~OWriteStream()
1807 : : {
1808 : : {
1809 [ + - ]: 4556 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
1810 [ + + ]: 4556 : if ( m_pImpl )
1811 : : {
1812 : 4544 : m_refCount++;
1813 : : try {
1814 [ + - ]: 4544 : dispose();
1815 : : }
1816 [ # # # # ]: 0 : catch( const uno::RuntimeException& rRuntimeException )
1817 : : {
1818 [ # # ]: 0 : m_pImpl->AddLog( rRuntimeException.Message );
1819 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
1820 : : }
1821 [ + - ]: 4556 : }
1822 : : }
1823 : :
1824 [ + - ][ - + ]: 4556 : if ( m_pData && m_pData->m_pTypeCollection )
1825 [ # # ][ # # ]: 0 : delete m_pData->m_pTypeCollection;
1826 : :
1827 [ + - ]: 4556 : if ( m_pData )
1828 [ + - ][ + - ]: 4556 : delete m_pData;
1829 [ - + ]: 9112 : }
1830 : :
1831 : : //-----------------------------------------------
1832 : 802 : void OWriteStream::DeInit()
1833 : : {
1834 [ - + ]: 802 : if ( !m_pImpl )
1835 : 802 : return; // do nothing
1836 : :
1837 [ + - ]: 802 : if ( m_xSeekable.is() )
1838 : 802 : m_nInitPosition = m_xSeekable->getPosition();
1839 : :
1840 [ + - ]: 802 : m_xInStream = uno::Reference< io::XInputStream >();
1841 [ + - ]: 802 : m_xOutStream = uno::Reference< io::XOutputStream >();
1842 [ + - ]: 802 : m_xSeekable = uno::Reference< io::XSeekable >();
1843 : 802 : m_bInitOnDemand = sal_True;
1844 : : }
1845 : :
1846 : : //-----------------------------------------------
1847 : 9717 : void OWriteStream::CheckInitOnDemand()
1848 : : {
1849 [ - + ]: 9717 : if ( !m_pImpl )
1850 : : {
1851 [ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
1852 [ # # ]: 0 : throw lang::DisposedException();
1853 : : }
1854 : :
1855 [ + + ]: 9717 : if ( m_bInitOnDemand )
1856 : : {
1857 : : RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" );
1858 [ + - ]: 109 : uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream();
1859 [ + - ]: 109 : if ( xStream.is() )
1860 : : {
1861 [ + - ][ + - ]: 109 : m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW );
[ + - ]
1862 [ + - ][ + - ]: 109 : m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW );
[ + - ]
1863 [ + - ]: 109 : m_xSeekable.set( xStream, uno::UNO_QUERY_THROW );
1864 [ + - ][ + - ]: 109 : m_xSeekable->seek( m_nInitPosition );
1865 : :
1866 : 109 : m_nInitPosition = 0;
1867 : 109 : m_bInitOnDemand = sal_False;
1868 : 109 : }
1869 : : }
1870 : 9717 : }
1871 : :
1872 : : //-----------------------------------------------
1873 : 0 : void OWriteStream::CopyToStreamInternally_Impl( const uno::Reference< io::XStream >& xDest )
1874 : : {
1875 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
1876 : :
1877 [ # # ]: 0 : CheckInitOnDemand();
1878 : :
1879 [ # # ]: 0 : if ( !m_xInStream.is() )
1880 [ # # ]: 0 : throw uno::RuntimeException();
1881 : :
1882 [ # # ]: 0 : if ( !m_xSeekable.is() )
1883 [ # # ]: 0 : throw uno::RuntimeException();
1884 : :
1885 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY );
1886 [ # # ]: 0 : if ( !xDestProps.is() )
1887 [ # # ]: 0 : throw uno::RuntimeException(); //TODO
1888 : :
1889 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream();
1890 [ # # ]: 0 : if ( !xDestOutStream.is() )
1891 [ # # ]: 0 : throw io::IOException(); // TODO
1892 : :
1893 [ # # ][ # # ]: 0 : sal_Int64 nCurPos = m_xSeekable->getPosition();
1894 [ # # ][ # # ]: 0 : m_xSeekable->seek( 0 );
1895 : :
1896 [ # # ]: 0 : uno::Exception eThrown;
1897 : 0 : sal_Bool bThrown = sal_False;
1898 : : try {
1899 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( m_xInStream, xDestOutStream );
1900 : : }
1901 [ # # # # ]: 0 : catch ( const uno::Exception& e )
1902 : : {
1903 [ # # ]: 0 : eThrown = e;
1904 : 0 : bThrown = sal_True;
1905 : : }
1906 : :
1907 : : // position-related section below is critical
1908 : : // if it fails the stream will become invalid
1909 : : try {
1910 [ # # ][ # # ]: 0 : m_xSeekable->seek( nCurPos );
1911 : : }
1912 [ # # ]: 0 : catch ( const uno::Exception& rException )
1913 : : {
1914 [ # # ]: 0 : m_pImpl->AddLog( rException.Message );
1915 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) );
1916 : :
1917 : : // TODO: set the stoream in invalid state or dispose
1918 : : OSL_FAIL( "The stream become invalid during copiing!\n" );
1919 [ # # ]: 0 : throw uno::RuntimeException();
1920 : : }
1921 : :
1922 [ # # ]: 0 : if ( bThrown )
1923 [ # # ]: 0 : throw eThrown;
1924 : :
1925 : : // now the properties can be copied
1926 : : // the order of the properties setting is not important for StorageStream API
1927 [ # # ]: 0 : ::rtl::OUString aPropName (RTL_CONSTASCII_USTRINGPARAM("Compressed") );
1928 [ # # ][ # # ]: 0 : xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) );
[ # # ]
1929 [ # # ][ # # ]: 0 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
1930 : : {
1931 [ # # ]: 0 : aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType" ) );
1932 [ # # ][ # # ]: 0 : xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) );
[ # # ]
1933 : :
1934 [ # # ]: 0 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
1935 : : {
1936 [ # # ]: 0 : aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") );
1937 [ # # ][ # # ]: 0 : xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) );
[ # # ]
1938 : : }
1939 [ # # ][ # # ]: 0 : }
1940 : 0 : }
1941 : :
1942 : : //-----------------------------------------------
1943 : 81981 : void OWriteStream::ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard )
1944 : : {
1945 [ + - ]: 81981 : if ( m_pImpl->m_pParent )
1946 : : {
1947 [ + - ]: 81981 : if ( m_pImpl->m_pParent->m_pAntiImpl )
1948 : : {
1949 [ + - ][ + - ]: 81981 : uno::Reference< util::XModifiable > xParentModif( (util::XModifiable*)(m_pImpl->m_pParent->m_pAntiImpl) );
1950 [ + - ]: 81981 : aGuard.clear();
1951 [ + - ][ + - ]: 81981 : xParentModif->setModified( sal_True );
1952 : : }
1953 : : else
1954 : 0 : m_pImpl->m_pParent->m_bIsModified = sal_True;
1955 : : }
1956 : 81981 : }
1957 : :
1958 : : //-----------------------------------------------
1959 : 17611 : uno::Any SAL_CALL OWriteStream::queryInterface( const uno::Type& rType )
1960 : : throw( uno::RuntimeException )
1961 : : {
1962 : 17611 : uno::Any aReturn;
1963 : :
1964 : : // common interfaces
1965 : : aReturn <<= ::cppu::queryInterface
1966 : : ( rType
1967 : : , static_cast<lang::XTypeProvider*> ( this )
1968 : : , static_cast<io::XInputStream*> ( this )
1969 : : , static_cast<io::XOutputStream*> ( this )
1970 : : , static_cast<io::XStream*> ( this )
1971 : : , static_cast<embed::XExtendedStorageStream*> ( this )
1972 : : , static_cast<io::XSeekable*> ( this )
1973 : : , static_cast<io::XTruncate*> ( this )
1974 : : , static_cast<lang::XComponent*> ( this )
1975 [ + - ][ + - ]: 17611 : , static_cast<beans::XPropertySet*> ( this ) );
1976 : :
1977 [ + + ]: 17611 : if ( aReturn.hasValue() == sal_True )
1978 : 14441 : return aReturn ;
1979 : :
1980 [ + + ]: 3170 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
1981 : : {
1982 : : aReturn <<= ::cppu::queryInterface
1983 : : ( rType
1984 : : , static_cast<embed::XEncryptionProtectedSource2*> ( this )
1985 [ + - ][ + - ]: 2363 : , static_cast<embed::XEncryptionProtectedSource*> ( this ) );
1986 : : }
1987 [ + - ]: 807 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
1988 : : {
1989 : : aReturn <<= ::cppu::queryInterface
1990 : : ( rType
1991 [ + - ][ + - ]: 807 : , static_cast<embed::XRelationshipAccess*> ( this ) );
1992 : : }
1993 : :
1994 [ + + ]: 3170 : if ( aReturn.hasValue() == sal_True )
1995 : 194 : return aReturn ;
1996 : :
1997 [ - + ]: 2976 : if ( m_bTransacted )
1998 : : {
1999 : : aReturn <<= ::cppu::queryInterface
2000 : : ( rType
2001 : : , static_cast<embed::XTransactedObject*> ( this )
2002 [ # # ][ # # ]: 0 : , static_cast<embed::XTransactionBroadcaster*> ( this ) );
2003 : :
2004 [ # # ]: 0 : if ( aReturn.hasValue() == sal_True )
2005 : 0 : return aReturn ;
2006 : : }
2007 : :
2008 [ + - ]: 17611 : return OWeakObject::queryInterface( rType );
2009 : : }
2010 : :
2011 : : //-----------------------------------------------
2012 : 93132 : void SAL_CALL OWriteStream::acquire() throw()
2013 : : {
2014 : 93132 : OWeakObject::acquire();
2015 : 93132 : }
2016 : :
2017 : : //-----------------------------------------------
2018 : 93132 : void SAL_CALL OWriteStream::release() throw()
2019 : : {
2020 : 93132 : OWeakObject::release();
2021 : 93132 : }
2022 : :
2023 : : //-----------------------------------------------
2024 : 0 : uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes()
2025 : : throw( uno::RuntimeException )
2026 : : {
2027 [ # # ]: 0 : if ( m_pData->m_pTypeCollection == NULL )
2028 : : {
2029 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2030 : :
2031 [ # # ]: 0 : if ( m_pData->m_pTypeCollection == NULL )
2032 : : {
2033 [ # # ]: 0 : if ( m_bTransacted )
2034 : : {
2035 [ # # ]: 0 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2036 : : {
2037 : : ::cppu::OTypeCollection aTmpCollection
2038 [ # # ]: 0 : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2039 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2040 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2041 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2042 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2043 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2044 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2045 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
2046 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
2047 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL )
2048 [ # # ]: 0 : , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2049 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) );
[ # # ][ # # ]
2050 : :
2051 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2052 : : ( ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL )
2053 [ # # ][ # # ]: 0 : , aTmpCollection.getTypes() );
[ # # ][ # # ]
[ # # ]
2054 : : }
2055 [ # # ]: 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2056 : : {
2057 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2058 : : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2059 : : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2060 : : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2061 : : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2062 : : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2063 : : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2064 : : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2065 : : , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL )
2066 : : , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL )
2067 : : , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2068 : : , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2069 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2070 : : }
2071 : : else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
2072 : : {
2073 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2074 : : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2075 : : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2076 : : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2077 : : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2078 : : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2079 : : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2080 : : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2081 : : , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL )
2082 : : , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL )
2083 : : , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL )
2084 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2085 : : }
2086 : : }
2087 : : else
2088 : : {
2089 [ # # ]: 0 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE )
2090 : : {
2091 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2092 : : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2093 : : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2094 : : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2095 : : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2096 : : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2097 : : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2098 : : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2099 : : , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL )
2100 : : , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL )
2101 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2102 : : }
2103 [ # # ]: 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
2104 : : {
2105 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2106 : : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2107 : : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2108 : : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2109 : : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2110 : : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2111 : : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2112 : : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2113 : : , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL )
2114 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2115 : : }
2116 : : else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP )
2117 : : {
2118 : : m_pData->m_pTypeCollection = new ::cppu::OTypeCollection
2119 : : ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
2120 : : , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL )
2121 : : , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL )
2122 : : , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL )
2123 : : , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL )
2124 : : , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL )
2125 : : , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL )
2126 [ # # ][ # # ]: 0 : , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2127 : : }
2128 : : }
2129 [ # # ]: 0 : }
2130 : : }
2131 : :
2132 : 0 : return m_pData->m_pTypeCollection->getTypes() ;
2133 : : }
2134 : :
2135 : : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
2136 : :
2137 : : //-----------------------------------------------
2138 : 0 : uno::Sequence< sal_Int8 > SAL_CALL OWriteStream::getImplementationId()
2139 : : throw( uno::RuntimeException )
2140 : : {
2141 : 0 : ::cppu::OImplementationId &rId = lcl_ImplId::get();
2142 : 0 : return rId.getImplementationId();
2143 : : }
2144 : :
2145 : : //-----------------------------------------------
2146 : 41 : sal_Int32 SAL_CALL OWriteStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
2147 : : throw ( io::NotConnectedException,
2148 : : io::BufferSizeExceededException,
2149 : : io::IOException,
2150 : : uno::RuntimeException )
2151 : : {
2152 [ + - ]: 41 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2153 : :
2154 [ + - ]: 41 : CheckInitOnDemand();
2155 : :
2156 [ - + ]: 41 : if ( !m_pImpl )
2157 : : {
2158 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2159 [ # # ]: 0 : throw lang::DisposedException();
2160 : : }
2161 : :
2162 [ - + ]: 41 : if ( !m_xInStream.is() )
2163 [ # # ]: 0 : throw io::NotConnectedException();
2164 : :
2165 [ + - ][ + - ]: 41 : return m_xInStream->readBytes( aData, nBytesToRead );
[ + - ]
2166 : : }
2167 : :
2168 : : //-----------------------------------------------
2169 : 1141 : sal_Int32 SAL_CALL OWriteStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
2170 : : throw ( io::NotConnectedException,
2171 : : io::BufferSizeExceededException,
2172 : : io::IOException,
2173 : : uno::RuntimeException )
2174 : : {
2175 [ + - ]: 1141 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2176 : :
2177 [ + - ]: 1141 : CheckInitOnDemand();
2178 : :
2179 [ - + ]: 1141 : if ( !m_pImpl )
2180 : : {
2181 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2182 [ # # ]: 0 : throw lang::DisposedException();
2183 : : }
2184 : :
2185 [ - + ]: 1141 : if ( !m_xInStream.is() )
2186 [ # # ]: 0 : throw io::NotConnectedException();
2187 : :
2188 [ + - ][ + - ]: 1141 : return m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
[ + - ]
2189 : : }
2190 : :
2191 : : //-----------------------------------------------
2192 : 0 : void SAL_CALL OWriteStream::skipBytes( sal_Int32 nBytesToSkip )
2193 : : throw ( io::NotConnectedException,
2194 : : io::BufferSizeExceededException,
2195 : : io::IOException,
2196 : : uno::RuntimeException )
2197 : : {
2198 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2199 : :
2200 [ # # ]: 0 : CheckInitOnDemand();
2201 : :
2202 [ # # ]: 0 : if ( !m_pImpl )
2203 : : {
2204 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2205 [ # # ]: 0 : throw lang::DisposedException();
2206 : : }
2207 : :
2208 [ # # ]: 0 : if ( !m_xInStream.is() )
2209 [ # # ]: 0 : throw io::NotConnectedException();
2210 : :
2211 [ # # ][ # # ]: 0 : m_xInStream->skipBytes( nBytesToSkip );
[ # # ]
2212 : 0 : }
2213 : :
2214 : : //-----------------------------------------------
2215 : 0 : sal_Int32 SAL_CALL OWriteStream::available( )
2216 : : throw ( io::NotConnectedException,
2217 : : io::IOException,
2218 : : uno::RuntimeException )
2219 : : {
2220 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2221 : :
2222 [ # # ]: 0 : CheckInitOnDemand();
2223 : :
2224 [ # # ]: 0 : if ( !m_pImpl )
2225 : : {
2226 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2227 [ # # ]: 0 : throw lang::DisposedException();
2228 : : }
2229 : :
2230 [ # # ]: 0 : if ( !m_xInStream.is() )
2231 [ # # ]: 0 : throw io::NotConnectedException();
2232 : :
2233 [ # # ][ # # ]: 0 : return m_xInStream->available();
[ # # ]
2234 : :
2235 : : }
2236 : :
2237 : : //-----------------------------------------------
2238 : 0 : void SAL_CALL OWriteStream::closeInput( )
2239 : : throw ( io::NotConnectedException,
2240 : : io::IOException,
2241 : : uno::RuntimeException )
2242 : : {
2243 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2244 : :
2245 [ # # ]: 0 : if ( !m_pImpl )
2246 : : {
2247 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2248 [ # # ]: 0 : throw lang::DisposedException();
2249 : : }
2250 : :
2251 [ # # ][ # # ]: 0 : if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) )
[ # # ][ # # ]
2252 [ # # ]: 0 : throw io::NotConnectedException();
2253 : :
2254 : : // the input part of the stream stays open for internal purposes ( to allow reading during copiing )
2255 : : // since it can not be reopened until output part is closed, it will be closed with output part.
2256 : 0 : m_bInStreamDisconnected = sal_True;
2257 : : // m_xInStream->closeInput();
2258 : : // m_xInStream = uno::Reference< io::XInputStream >();
2259 : :
2260 [ # # ]: 0 : if ( !m_xOutStream.is() )
2261 [ # # ][ # # ]: 0 : dispose();
2262 : 0 : }
2263 : :
2264 : : //-----------------------------------------------
2265 : 1207 : uno::Reference< io::XInputStream > SAL_CALL OWriteStream::getInputStream()
2266 : : throw ( uno::RuntimeException )
2267 : : {
2268 [ + - ]: 1207 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2269 : :
2270 [ - + ]: 1207 : if ( !m_pImpl )
2271 : : {
2272 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2273 [ # # ]: 0 : throw lang::DisposedException();
2274 : : }
2275 : :
2276 [ + + ][ + - ]: 1207 : if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) )
[ - + ][ - + ]
2277 : 0 : return uno::Reference< io::XInputStream >();
2278 : :
2279 [ + - ][ + - ]: 1207 : return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY );
2280 : : }
2281 : :
2282 : : //-----------------------------------------------
2283 : 3167 : uno::Reference< io::XOutputStream > SAL_CALL OWriteStream::getOutputStream()
2284 : : throw ( uno::RuntimeException )
2285 : : {
2286 [ + - ]: 3167 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2287 : :
2288 [ + - ]: 3167 : CheckInitOnDemand();
2289 : :
2290 [ - + ]: 3167 : if ( !m_pImpl )
2291 : : {
2292 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2293 [ # # ]: 0 : throw lang::DisposedException();
2294 : : }
2295 : :
2296 [ - + ]: 3167 : if ( !m_xOutStream.is() )
2297 : 0 : return uno::Reference< io::XOutputStream >();
2298 : :
2299 [ + - ][ + - ]: 3167 : return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ), uno::UNO_QUERY );
2300 : : }
2301 : :
2302 : : //-----------------------------------------------
2303 : 75058 : void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData )
2304 : : throw ( io::NotConnectedException,
2305 : : io::BufferSizeExceededException,
2306 : : io::IOException,
2307 : : uno::RuntimeException )
2308 : : {
2309 [ + - ]: 75058 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2310 : :
2311 : : // the write method makes initialization itself, since it depends from the aData length
2312 : : // NO CheckInitOnDemand()!
2313 : :
2314 [ - + ]: 75058 : if ( !m_pImpl )
2315 : : {
2316 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2317 [ # # ]: 0 : throw lang::DisposedException();
2318 : : }
2319 : :
2320 [ + - ]: 75058 : if ( !m_bInitOnDemand )
2321 : : {
2322 [ + - ][ - + ]: 75058 : if ( !m_xOutStream.is() || !m_xSeekable.is())
[ - + ]
2323 [ # # ]: 0 : throw io::NotConnectedException();
2324 : :
2325 [ + + ]: 75058 : if ( m_pImpl->m_xCacheStream.is() )
2326 : : {
2327 : : // check whether the cache should be turned off
2328 [ + - ][ + - ]: 74203 : sal_Int64 nPos = m_xSeekable->getPosition();
2329 [ + + ]: 74203 : if ( nPos + aData.getLength() > MAX_STORCACHE_SIZE )
2330 : : {
2331 : : // disconnect the cache and copy the data to the temporary file
2332 [ + - ][ + - ]: 75 : m_xSeekable->seek( 0 );
2333 : :
2334 : : // it is enough to copy the cached stream, the cache should already contain everything
2335 [ + - ][ + - ]: 75 : if ( !m_pImpl->GetFilledTempFileIfNo( m_xInStream ).isEmpty() )
2336 : : {
2337 [ + - ]: 75 : DeInit();
2338 : : // the last position is known and it is differs from the current stream position
2339 : 75 : m_nInitPosition = nPos;
2340 : : }
2341 : : }
2342 : : }
2343 : : }
2344 : :
2345 [ + + ]: 75058 : if ( m_bInitOnDemand )
2346 : : {
2347 : : RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" );
2348 [ + - ]: 75 : uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream();
2349 [ + - ]: 75 : if ( xStream.is() )
2350 : : {
2351 [ + - ][ + - ]: 75 : m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW );
[ + - ]
2352 [ + - ][ + - ]: 75 : m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW );
[ + - ]
2353 [ + - ]: 75 : m_xSeekable.set( xStream, uno::UNO_QUERY_THROW );
2354 [ + - ][ + - ]: 75 : m_xSeekable->seek( m_nInitPosition );
2355 : :
2356 : 75 : m_nInitPosition = 0;
2357 : 75 : m_bInitOnDemand = sal_False;
2358 : 75 : }
2359 : : }
2360 : :
2361 : :
2362 [ - + ]: 75058 : if ( !m_xOutStream.is() )
2363 [ # # ]: 0 : throw io::NotConnectedException();
2364 : :
2365 [ + - ][ + - ]: 75058 : m_xOutStream->writeBytes( aData );
2366 : 75058 : m_pImpl->m_bHasDataToFlush = sal_True;
2367 : :
2368 [ + - ][ + - ]: 75058 : ModifyParentUnlockMutex_Impl( aGuard );
2369 : 75058 : }
2370 : :
2371 : : //-----------------------------------------------
2372 : 713 : void SAL_CALL OWriteStream::flush()
2373 : : throw ( io::NotConnectedException,
2374 : : io::BufferSizeExceededException,
2375 : : io::IOException,
2376 : : uno::RuntimeException )
2377 : : {
2378 : : // In case stream is flushed it's current version becomes visible
2379 : : // to the parent storage. Usually parent storage flushes the stream
2380 : : // during own commit but a user can explicitly flush the stream
2381 : : // so the changes will be available through cloning functionality.
2382 : :
2383 [ + - ]: 713 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2384 : :
2385 [ - + ]: 713 : if ( !m_pImpl )
2386 : : {
2387 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2388 [ # # ]: 0 : throw lang::DisposedException();
2389 : : }
2390 : :
2391 [ + + ]: 713 : if ( !m_bInitOnDemand )
2392 : : {
2393 [ - + ]: 660 : if ( !m_xOutStream.is() )
2394 [ # # ]: 0 : throw io::NotConnectedException();
2395 : :
2396 [ + - ][ + - ]: 660 : m_xOutStream->flush();
2397 [ + - ]: 660 : m_pImpl->Commit();
2398 [ + - ]: 713 : }
2399 : 713 : }
2400 : :
2401 : : //-----------------------------------------------
2402 : 3956 : void OWriteStream::CloseOutput_Impl()
2403 : : {
2404 : : // all the checks must be done in calling method
2405 : :
2406 : 3956 : m_xOutStream->closeOutput();
2407 [ + - ]: 3956 : m_xOutStream = uno::Reference< io::XOutputStream >();
2408 : :
2409 [ + - ]: 3956 : if ( !m_bInitOnDemand )
2410 : : {
2411 : : // after the stream is disposed it can be commited
2412 : : // so transport correct size property
2413 [ - + ]: 3956 : if ( !m_xSeekable.is() )
2414 [ # # ]: 0 : throw uno::RuntimeException();
2415 : :
2416 [ + + ]: 19321 : for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
2417 : : {
2418 [ + + ]: 15365 : if ( m_pImpl->m_aProps[nInd].Name == "Size" )
2419 [ + - ][ + - ]: 3956 : m_pImpl->m_aProps[nInd].Value <<= ((sal_Int32)m_xSeekable->getLength());
2420 : : }
2421 : : }
2422 : 3956 : }
2423 : :
2424 : : //-----------------------------------------------
2425 : 2373 : void SAL_CALL OWriteStream::closeOutput()
2426 : : throw ( io::NotConnectedException,
2427 : : io::BufferSizeExceededException,
2428 : : io::IOException,
2429 : : uno::RuntimeException )
2430 : : {
2431 [ + - ]: 2373 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2432 : :
2433 [ + - ]: 2373 : CheckInitOnDemand();
2434 : :
2435 [ - + ]: 2373 : if ( !m_pImpl )
2436 : : {
2437 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2438 [ # # ]: 0 : throw lang::DisposedException();
2439 : : }
2440 : :
2441 [ - + ]: 2373 : if ( !m_xOutStream.is() )
2442 [ # # ]: 0 : throw io::NotConnectedException();
2443 : :
2444 [ + - ]: 2373 : CloseOutput_Impl();
2445 : :
2446 [ + - ][ - + ]: 2373 : if ( m_bInStreamDisconnected || !m_xInStream.is() )
[ - + ]
2447 [ # # ][ + - ]: 2373 : dispose();
2448 : 2373 : }
2449 : :
2450 : : //-----------------------------------------------
2451 : 2359 : void SAL_CALL OWriteStream::seek( sal_Int64 location )
2452 : : throw ( lang::IllegalArgumentException,
2453 : : io::IOException,
2454 : : uno::RuntimeException )
2455 : : {
2456 [ + - ]: 2359 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2457 : :
2458 [ + - ]: 2359 : CheckInitOnDemand();
2459 : :
2460 [ - + ]: 2359 : if ( !m_pImpl )
2461 : : {
2462 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2463 [ # # ]: 0 : throw lang::DisposedException();
2464 : : }
2465 : :
2466 [ - + ]: 2359 : if ( !m_xSeekable.is() )
2467 [ # # ]: 0 : throw uno::RuntimeException();
2468 : :
2469 [ + - ][ + - ]: 2359 : m_xSeekable->seek( location );
[ + - ]
2470 : 2359 : }
2471 : :
2472 : : //-----------------------------------------------
2473 : 0 : sal_Int64 SAL_CALL OWriteStream::getPosition()
2474 : : throw ( io::IOException,
2475 : : uno::RuntimeException)
2476 : : {
2477 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2478 : :
2479 [ # # ]: 0 : CheckInitOnDemand();
2480 : :
2481 [ # # ]: 0 : if ( !m_pImpl )
2482 : : {
2483 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2484 [ # # ]: 0 : throw lang::DisposedException();
2485 : : }
2486 : :
2487 [ # # ]: 0 : if ( !m_xSeekable.is() )
2488 [ # # ]: 0 : throw uno::RuntimeException();
2489 : :
2490 [ # # ][ # # ]: 0 : return m_xSeekable->getPosition();
[ # # ]
2491 : : }
2492 : :
2493 : : //-----------------------------------------------
2494 : 605 : sal_Int64 SAL_CALL OWriteStream::getLength()
2495 : : throw ( io::IOException,
2496 : : uno::RuntimeException )
2497 : : {
2498 [ + - ]: 605 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2499 : :
2500 [ + - ]: 605 : CheckInitOnDemand();
2501 : :
2502 [ - + ]: 605 : if ( !m_pImpl )
2503 : : {
2504 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2505 [ # # ]: 0 : throw lang::DisposedException();
2506 : : }
2507 : :
2508 [ - + ]: 605 : if ( !m_xSeekable.is() )
2509 [ # # ]: 0 : throw uno::RuntimeException();
2510 : :
2511 [ + - ][ + - ]: 605 : return m_xSeekable->getLength();
[ + - ]
2512 : : }
2513 : :
2514 : : //-----------------------------------------------
2515 : 31 : void SAL_CALL OWriteStream::truncate()
2516 : : throw ( io::IOException,
2517 : : uno::RuntimeException )
2518 : : {
2519 [ + - ]: 31 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2520 : :
2521 [ + - ]: 31 : CheckInitOnDemand();
2522 : :
2523 [ - + ]: 31 : if ( !m_pImpl )
2524 : : {
2525 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2526 [ # # ]: 0 : throw lang::DisposedException();
2527 : : }
2528 : :
2529 [ - + ]: 31 : if ( !m_xOutStream.is() )
2530 [ # # ]: 0 : throw uno::RuntimeException();
2531 : :
2532 [ + - ]: 31 : uno::Reference< io::XTruncate > xTruncate( m_xOutStream, uno::UNO_QUERY );
2533 : :
2534 [ - + ]: 31 : if ( !xTruncate.is() )
2535 : : {
2536 : : OSL_FAIL( "The output stream must support XTruncate interface!\n" );
2537 [ # # ]: 0 : throw uno::RuntimeException();
2538 : : }
2539 : :
2540 [ + - ][ + - ]: 31 : xTruncate->truncate();
2541 : :
2542 : 31 : m_pImpl->m_bHasDataToFlush = sal_True;
2543 : :
2544 [ + - ][ + - ]: 31 : ModifyParentUnlockMutex_Impl( aGuard );
2545 : 31 : }
2546 : :
2547 : : //-----------------------------------------------
2548 : 4556 : void SAL_CALL OWriteStream::dispose()
2549 : : throw ( uno::RuntimeException )
2550 : : {
2551 : : // should be an internal method since it can be called only from parent storage
2552 : : {
2553 [ + - ]: 4556 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2554 : :
2555 [ - + ]: 4556 : if ( !m_pImpl )
2556 : : {
2557 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2558 [ # # ]: 0 : throw lang::DisposedException();
2559 : : }
2560 : :
2561 [ + + ]: 4556 : if ( m_xOutStream.is() )
2562 [ + - ]: 1583 : CloseOutput_Impl();
2563 : :
2564 [ + + ]: 4556 : if ( m_xInStream.is() )
2565 : : {
2566 [ + - ][ + - ]: 3895 : m_xInStream->closeInput();
2567 [ + - ]: 3895 : m_xInStream = uno::Reference< io::XInputStream >();
2568 : : }
2569 : :
2570 [ + - ]: 4556 : m_xSeekable = uno::Reference< io::XSeekable >();
2571 : :
2572 : 4556 : m_pImpl->m_pAntiImpl = NULL;
2573 : :
2574 [ + + ]: 4556 : if ( !m_bInitOnDemand )
2575 : : {
2576 : : try
2577 : : {
2578 [ + - ]: 3895 : if ( !m_bTransacted )
2579 : : {
2580 [ + - ]: 3895 : m_pImpl->Commit();
2581 : : }
2582 : : else
2583 : : {
2584 : : // throw away all the changes
2585 [ # # ]: 0 : m_pImpl->Revert();
2586 : : }
2587 : : }
2588 [ # # ]: 0 : catch( const uno::Exception& rException )
2589 : : {
2590 [ # # ]: 0 : m_pImpl->AddLog( rException.Message );
2591 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
2592 : :
2593 [ # # ]: 0 : uno::Any aCaught( ::cppu::getCaughtException() );
2594 : : throw lang::WrappedTargetRuntimeException(
2595 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not commit/revert the storage!\n") ),
2596 : : uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
2597 : : uno::UNO_QUERY ),
2598 [ # # # # : 0 : aCaught );
# # ]
2599 : : }
2600 : : }
2601 : :
2602 [ + - ]: 4556 : m_pImpl = NULL;
2603 : : }
2604 : :
2605 : : // the listener might try to get rid of parent storage, and the storage would delete this object;
2606 : : // for now the listener is just notified at the end of the method to workaround the problem
2607 : : // in future a more elegant way should be found
2608 : :
2609 [ + - ][ + - ]: 4556 : lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
2610 [ + - ][ + - ]: 4556 : m_pData->m_aListenersContainer.disposeAndClear( aSource );
2611 : 4556 : }
2612 : :
2613 : : //-----------------------------------------------
2614 : 0 : void SAL_CALL OWriteStream::addEventListener(
2615 : : const uno::Reference< lang::XEventListener >& xListener )
2616 : : throw ( uno::RuntimeException )
2617 : : {
2618 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2619 : :
2620 [ # # ]: 0 : if ( !m_pImpl )
2621 : : {
2622 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2623 [ # # ]: 0 : throw lang::DisposedException();
2624 : : }
2625 : :
2626 [ # # ]: 0 : m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0),
2627 [ # # ][ # # ]: 0 : xListener );
2628 : 0 : }
2629 : :
2630 : : //-----------------------------------------------
2631 : 0 : void SAL_CALL OWriteStream::removeEventListener(
2632 : : const uno::Reference< lang::XEventListener >& xListener )
2633 : : throw ( uno::RuntimeException )
2634 : : {
2635 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2636 : :
2637 [ # # ]: 0 : if ( !m_pImpl )
2638 : : {
2639 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2640 [ # # ]: 0 : throw lang::DisposedException();
2641 : : }
2642 : :
2643 [ # # ]: 0 : m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0),
2644 [ # # ][ # # ]: 0 : xListener );
2645 : 0 : }
2646 : :
2647 : : //-----------------------------------------------
2648 : 0 : void SAL_CALL OWriteStream::setEncryptionPassword( const ::rtl::OUString& aPass )
2649 : : throw ( uno::RuntimeException,
2650 : : io::IOException )
2651 : : {
2652 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2653 : :
2654 [ # # ]: 0 : CheckInitOnDemand();
2655 : :
2656 [ # # ]: 0 : if ( !m_pImpl )
2657 : : {
2658 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2659 [ # # ]: 0 : throw lang::DisposedException();
2660 : : }
2661 : :
2662 : : OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" );
2663 : :
2664 [ # # ][ # # ]: 0 : m_pImpl->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) );
[ # # ][ # # ]
[ # # ]
2665 : :
2666 [ # # ][ # # ]: 0 : ModifyParentUnlockMutex_Impl( aGuard );
2667 : 0 : }
2668 : :
2669 : : //-----------------------------------------------
2670 : 0 : void SAL_CALL OWriteStream::removeEncryption()
2671 : : throw ( uno::RuntimeException,
2672 : : io::IOException )
2673 : : {
2674 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2675 : :
2676 [ # # ]: 0 : CheckInitOnDemand();
2677 : :
2678 [ # # ]: 0 : if ( !m_pImpl )
2679 : : {
2680 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2681 [ # # ]: 0 : throw lang::DisposedException();
2682 : : }
2683 : :
2684 : : OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" );
2685 : :
2686 [ # # ]: 0 : m_pImpl->SetDecrypted();
2687 : :
2688 [ # # ][ # # ]: 0 : ModifyParentUnlockMutex_Impl( aGuard );
2689 : 0 : }
2690 : :
2691 : : //-----------------------------------------------
2692 : 0 : void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData )
2693 : : throw (io::IOException, uno::RuntimeException)
2694 : : {
2695 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2696 : :
2697 [ # # ]: 0 : CheckInitOnDemand();
2698 : :
2699 [ # # ]: 0 : if ( !m_pImpl )
2700 : : {
2701 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2702 [ # # ]: 0 : throw lang::DisposedException();
2703 : : }
2704 : :
2705 : : OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" );
2706 : :
2707 [ # # ][ # # ]: 0 : m_pImpl->SetEncrypted( aEncryptionData );
[ # # ]
2708 : :
2709 [ # # ][ # # ]: 0 : ModifyParentUnlockMutex_Impl( aGuard );
2710 : 0 : }
2711 : :
2712 : : //-----------------------------------------------
2713 : 20 : sal_Bool SAL_CALL OWriteStream::hasEncryptionData()
2714 : : throw (uno::RuntimeException)
2715 : : {
2716 [ + - ]: 20 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2717 : :
2718 [ - + ]: 20 : if (!m_pImpl)
2719 : 0 : return sal_False;
2720 : :
2721 [ + - ]: 20 : sal_Bool bRet = m_pImpl->IsEncrypted();
2722 : :
2723 [ + - ][ + - ]: 20 : if (!bRet && m_pImpl->m_bUseCommonEncryption && m_pImpl->m_pParent)
[ + - ]
2724 : 20 : bRet = m_pImpl->m_pParent->m_bHasCommonEncryptionData;
2725 : :
2726 [ + - ]: 20 : return bRet;
2727 : : }
2728 : :
2729 : : //-----------------------------------------------
2730 : 0 : sal_Bool SAL_CALL OWriteStream::hasByID( const ::rtl::OUString& sID )
2731 : : throw ( io::IOException,
2732 : : uno::RuntimeException )
2733 : : {
2734 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2735 : :
2736 [ # # ]: 0 : if ( !m_pImpl )
2737 : : {
2738 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2739 [ # # ]: 0 : throw lang::DisposedException();
2740 : : }
2741 : :
2742 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2743 [ # # ]: 0 : throw uno::RuntimeException();
2744 : :
2745 : : try
2746 : : {
2747 [ # # ][ # # ]: 0 : getRelationshipByID( sID );
2748 : 0 : return sal_True;
2749 : : }
2750 [ # # # # ]: 0 : catch( const container::NoSuchElementException& rNoSuchElementException )
2751 : : {
2752 [ # # ]: 0 : m_pImpl->AddLog( rNoSuchElementException.Message );
2753 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) );
2754 : : }
2755 : :
2756 [ # # ]: 0 : return sal_False;
2757 : : }
2758 : :
2759 : : //-----------------------------------------------
2760 : 0 : ::rtl::OUString SAL_CALL OWriteStream::getTargetByID( const ::rtl::OUString& sID )
2761 : : throw ( container::NoSuchElementException,
2762 : : io::IOException,
2763 : : uno::RuntimeException )
2764 : : {
2765 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2766 : :
2767 [ # # ]: 0 : if ( !m_pImpl )
2768 : : {
2769 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2770 [ # # ]: 0 : throw lang::DisposedException();
2771 : : }
2772 : :
2773 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2774 [ # # ]: 0 : throw uno::RuntimeException();
2775 : :
2776 [ # # ]: 0 : uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
2777 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
2778 [ # # ][ # # ]: 0 : if ( aSeq[nInd].First == "Target" )
2779 [ # # ]: 0 : return aSeq[nInd].Second;
2780 : :
2781 [ # # ][ # # ]: 0 : return ::rtl::OUString();
2782 : : }
2783 : :
2784 : : //-----------------------------------------------
2785 : 0 : ::rtl::OUString SAL_CALL OWriteStream::getTypeByID( const ::rtl::OUString& sID )
2786 : : throw ( container::NoSuchElementException,
2787 : : io::IOException,
2788 : : uno::RuntimeException )
2789 : : {
2790 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2791 : :
2792 [ # # ]: 0 : if ( !m_pImpl )
2793 : : {
2794 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2795 [ # # ]: 0 : throw lang::DisposedException();
2796 : : }
2797 : :
2798 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2799 [ # # ]: 0 : throw uno::RuntimeException();
2800 : :
2801 [ # # ]: 0 : uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID );
2802 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
2803 [ # # ][ # # ]: 0 : if ( aSeq[nInd].First == "Type" )
2804 [ # # ]: 0 : return aSeq[nInd].Second;
2805 : :
2806 [ # # ][ # # ]: 0 : return ::rtl::OUString();
2807 : : }
2808 : :
2809 : : //-----------------------------------------------
2810 : 0 : uno::Sequence< beans::StringPair > SAL_CALL OWriteStream::getRelationshipByID( const ::rtl::OUString& sID )
2811 : : throw ( container::NoSuchElementException,
2812 : : io::IOException,
2813 : : uno::RuntimeException )
2814 : : {
2815 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2816 : :
2817 [ # # ]: 0 : if ( !m_pImpl )
2818 : : {
2819 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2820 [ # # ]: 0 : throw lang::DisposedException();
2821 : : }
2822 : :
2823 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2824 [ # # ]: 0 : throw uno::RuntimeException();
2825 : :
2826 : : // TODO/LATER: in future the unification of the ID could be checked
2827 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
2828 [ # # ]: 0 : for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
2829 [ # # ][ # # ]: 0 : for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
2830 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].First == "Id" )
[ # # ]
2831 : : {
2832 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
[ # # ]
2833 [ # # ][ # # ]: 0 : return aSeq[nInd1];
2834 : 0 : break;
2835 : : }
2836 : :
2837 [ # # ][ # # ]: 0 : throw container::NoSuchElementException();
[ # # ]
2838 : : }
2839 : :
2840 : : //-----------------------------------------------
2841 : 0 : uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getRelationshipsByType( const ::rtl::OUString& sType )
2842 : : throw ( io::IOException,
2843 : : uno::RuntimeException )
2844 : : {
2845 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2846 : :
2847 [ # # ]: 0 : if ( !m_pImpl )
2848 : : {
2849 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2850 [ # # ]: 0 : throw lang::DisposedException();
2851 : : }
2852 : :
2853 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2854 [ # # ]: 0 : throw uno::RuntimeException();
2855 : :
2856 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aResult;
2857 : 0 : sal_Int32 nEntriesNum = 0;
2858 : :
2859 : : // TODO/LATER: in future the unification of the ID could be checked
2860 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
2861 [ # # ]: 0 : for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
2862 [ # # ][ # # ]: 0 : for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
2863 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].First == "Type" )
[ # # ]
2864 : : {
2865 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].Second.equals( sType ) )
[ # # ]
2866 : : {
2867 [ # # ]: 0 : aResult.realloc( nEntriesNum );
2868 [ # # ][ # # ]: 0 : aResult[nEntriesNum-1] = aSeq[nInd1];
[ # # ]
2869 : : }
2870 : 0 : break;
2871 : : }
2872 : :
2873 [ # # ][ # # ]: 0 : return aResult;
2874 : : }
2875 : :
2876 : : //-----------------------------------------------
2877 : 174 : uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getAllRelationships()
2878 : : throw (io::IOException, uno::RuntimeException)
2879 : : {
2880 [ + - ]: 174 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2881 : :
2882 [ - + ]: 174 : if ( !m_pImpl )
2883 : : {
2884 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2885 [ # # ]: 0 : throw lang::DisposedException();
2886 : : }
2887 : :
2888 [ - + ]: 174 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2889 [ # # ]: 0 : throw uno::RuntimeException();
2890 : :
2891 [ + - ][ + - ]: 174 : return m_pImpl->GetAllRelationshipsIfAny();
2892 : : }
2893 : :
2894 : : //-----------------------------------------------
2895 : 174 : void SAL_CALL OWriteStream::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace )
2896 : : throw ( container::ElementExistException,
2897 : : io::IOException,
2898 : : uno::RuntimeException )
2899 : : {
2900 [ + - ]: 174 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2901 : :
2902 [ - + ]: 174 : if ( !m_pImpl )
2903 : : {
2904 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2905 [ # # ]: 0 : throw lang::DisposedException();
2906 : : }
2907 : :
2908 [ - + ]: 174 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2909 [ # # ]: 0 : throw uno::RuntimeException();
2910 : :
2911 [ + - ]: 174 : ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
2912 : :
2913 : 174 : sal_Int32 nIDInd = -1;
2914 : :
2915 : : // TODO/LATER: in future the unification of the ID could be checked
2916 [ + - ]: 174 : uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
2917 [ + + ]: 354 : for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
2918 [ + - ][ + - ]: 180 : for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
2919 [ + - ][ + - ]: 180 : if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) )
[ + - ]
2920 : : {
2921 [ + - ][ + - ]: 180 : if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
[ - + ]
2922 : 0 : nIDInd = nInd1;
2923 : :
2924 : 180 : break;
2925 : : }
2926 : :
2927 [ - + ][ # # ]: 174 : if ( nIDInd == -1 || bReplace )
2928 : : {
2929 [ + - ]: 174 : if ( nIDInd == -1 )
2930 : : {
2931 : 174 : nIDInd = aSeq.getLength();
2932 [ + - ]: 174 : aSeq.realloc( nIDInd + 1 );
2933 : : }
2934 : :
2935 [ + - ][ + - ]: 174 : aSeq[nIDInd].realloc( aEntry.getLength() + 1 );
2936 : :
2937 [ + - ][ + - ]: 174 : aSeq[nIDInd][0].First = aIDTag;
2938 [ + - ][ + - ]: 174 : aSeq[nIDInd][0].Second = sID;
2939 : 174 : sal_Int32 nIndTarget = 1;
2940 [ + + ]: 1044 : for ( sal_Int32 nIndOrig = 0;
2941 : 522 : nIndOrig < aEntry.getLength();
2942 : : nIndOrig++ )
2943 : : {
2944 [ + - ]: 348 : if ( !aEntry[nIndOrig].First.equals( aIDTag ) )
2945 [ + - ][ + - ]: 348 : aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig];
2946 : : }
2947 : :
2948 [ + - ][ + - ]: 174 : aSeq[nIDInd].realloc( nIndTarget );
2949 : : }
2950 : : else
2951 [ # # ]: 0 : throw container::ElementExistException(); // TODO
2952 : :
2953 : :
2954 [ + - ]: 174 : m_pImpl->m_aNewRelInfo = aSeq;
2955 [ + - ]: 174 : m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
2956 [ + - ][ + - ]: 174 : m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
2957 : 174 : }
2958 : :
2959 : : //-----------------------------------------------
2960 : 0 : void SAL_CALL OWriteStream::removeRelationshipByID( const ::rtl::OUString& sID )
2961 : : throw ( container::NoSuchElementException,
2962 : : io::IOException,
2963 : : uno::RuntimeException )
2964 : : {
2965 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
2966 : :
2967 [ # # ]: 0 : if ( !m_pImpl )
2968 : : {
2969 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
2970 [ # # ]: 0 : throw lang::DisposedException();
2971 : : }
2972 : :
2973 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
2974 [ # # ]: 0 : throw uno::RuntimeException();
2975 : :
2976 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
2977 [ # # ]: 0 : for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ )
2978 [ # # ][ # # ]: 0 : for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ )
2979 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].First == "Id" )
[ # # ]
2980 : : {
2981 [ # # ][ # # ]: 0 : if ( aSeq[nInd1][nInd2].Second.equals( sID ) )
[ # # ]
2982 : : {
2983 : 0 : sal_Int32 nLength = aSeq.getLength();
2984 [ # # ][ # # ]: 0 : aSeq[nInd1] = aSeq[nLength-1];
[ # # ]
2985 [ # # ]: 0 : aSeq.realloc( nLength - 1 );
2986 : :
2987 [ # # ]: 0 : m_pImpl->m_aNewRelInfo = aSeq;
2988 [ # # ]: 0 : m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
2989 : 0 : m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
2990 : :
2991 : : // TODO/LATER: in future the unification of the ID could be checked
2992 : 0 : return;
2993 : : }
2994 : :
2995 : 0 : break;
2996 : : }
2997 : :
2998 [ # # ][ # # ]: 0 : throw container::NoSuchElementException();
[ # # ]
2999 : : }
3000 : :
3001 : : //-----------------------------------------------
3002 : 0 : void SAL_CALL OWriteStream::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace )
3003 : : throw ( container::ElementExistException,
3004 : : io::IOException,
3005 : : uno::RuntimeException )
3006 : : {
3007 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3008 : :
3009 [ # # ]: 0 : if ( !m_pImpl )
3010 : : {
3011 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3012 [ # # ]: 0 : throw lang::DisposedException();
3013 : : }
3014 : :
3015 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
3016 [ # # ]: 0 : throw uno::RuntimeException();
3017 : :
3018 [ # # ]: 0 : ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
3019 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships();
3020 [ # # ]: 0 : uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() );
3021 : 0 : sal_Int32 nResultInd = 0;
3022 : :
3023 [ # # ]: 0 : for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ )
3024 [ # # ][ # # ]: 0 : for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ )
3025 [ # # ][ # # ]: 0 : if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) )
[ # # ]
3026 : : {
3027 : 0 : sal_Int32 nIndSourceSame = -1;
3028 : :
3029 [ # # ]: 0 : for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
3030 [ # # ]: 0 : for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
3031 : : {
3032 [ # # ]: 0 : if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
3033 : : {
3034 [ # # ][ # # ]: 0 : if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) )
[ # # ]
3035 : : {
3036 [ # # ]: 0 : if ( !bReplace )
3037 [ # # ]: 0 : throw container::ElementExistException();
3038 : :
3039 : 0 : nIndSourceSame = nIndSource1;
3040 : : }
3041 : :
3042 : 0 : break;
3043 : : }
3044 : : }
3045 : :
3046 [ # # ]: 0 : if ( nIndSourceSame == -1 )
3047 : : {
3048 : : // no such element in the provided sequence
3049 [ # # ][ # # ]: 0 : aResultSeq[nResultInd++] = aSeq[nIndTarget1];
[ # # ]
3050 : : }
3051 : :
3052 : 0 : break;
3053 : : }
3054 : :
3055 [ # # ]: 0 : for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ )
3056 : : {
3057 [ # # ][ # # ]: 0 : aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() );
3058 : 0 : sal_Bool bHasID = sal_False;
3059 : 0 : sal_Int32 nResInd2 = 1;
3060 : :
3061 [ # # ]: 0 : for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ )
3062 [ # # ]: 0 : if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) )
3063 : : {
3064 [ # # ][ # # ]: 0 : aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2];
3065 : 0 : bHasID = sal_True;
3066 : : }
3067 [ # # ][ # # ]: 0 : else if ( nResInd2 < aResultSeq[nResultInd].getLength() )
3068 [ # # ][ # # ]: 0 : aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2];
3069 : : else
3070 [ # # ]: 0 : throw io::IOException(); // TODO: illegal relation ( no ID )
3071 : :
3072 [ # # ]: 0 : if ( !bHasID )
3073 [ # # ]: 0 : throw io::IOException(); // TODO: illegal relations
3074 : :
3075 : 0 : nResultInd++;
3076 : : }
3077 : :
3078 [ # # ]: 0 : aResultSeq.realloc( nResultInd );
3079 [ # # ]: 0 : m_pImpl->m_aNewRelInfo = aResultSeq;
3080 [ # # ]: 0 : m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
3081 [ # # ][ # # ]: 0 : m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
[ # # ]
3082 : 0 : }
3083 : :
3084 : : //-----------------------------------------------
3085 : 0 : void SAL_CALL OWriteStream::clearRelationships()
3086 : : throw ( io::IOException,
3087 : : uno::RuntimeException )
3088 : : {
3089 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3090 : :
3091 [ # # ]: 0 : if ( !m_pImpl )
3092 : : {
3093 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3094 [ # # ]: 0 : throw lang::DisposedException();
3095 : : }
3096 : :
3097 [ # # ]: 0 : if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML )
3098 [ # # ]: 0 : throw uno::RuntimeException();
3099 : :
3100 [ # # ]: 0 : m_pImpl->m_aNewRelInfo.realloc( 0 );
3101 [ # # ]: 0 : m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >();
3102 [ # # ]: 0 : m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED;
3103 : 0 : }
3104 : :
3105 : : //-----------------------------------------------
3106 : 519 : uno::Reference< beans::XPropertySetInfo > SAL_CALL OWriteStream::getPropertySetInfo()
3107 : : throw ( uno::RuntimeException )
3108 : : {
3109 [ + - ]: 519 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3110 : :
3111 : : //TODO:
3112 [ + - ]: 519 : return uno::Reference< beans::XPropertySetInfo >();
3113 : : }
3114 : :
3115 : : //-----------------------------------------------
3116 : 6892 : void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue )
3117 : : throw ( beans::UnknownPropertyException,
3118 : : beans::PropertyVetoException,
3119 : : lang::IllegalArgumentException,
3120 : : lang::WrappedTargetException,
3121 : : uno::RuntimeException )
3122 : : {
3123 [ + - ]: 6892 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3124 : :
3125 [ - + ]: 6892 : if ( !m_pImpl )
3126 : : {
3127 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3128 [ # # ]: 0 : throw lang::DisposedException();
3129 : : }
3130 : :
3131 [ + - ][ + - ]: 6892 : m_pImpl->GetStreamProperties();
3132 [ + - ]: 6892 : ::rtl::OUString aCompressedString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) );
3133 [ + - ]: 6892 : ::rtl::OUString aMediaTypeString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) );
3134 [ + + ][ + + ]: 6892 : if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equals( aMediaTypeString ) )
[ + + ]
3135 : : {
3136 : : // if the "Compressed" property is not set explicitly, the MediaType can change the default value
3137 : 2934 : sal_Bool bCompressedValueFromType = sal_True;
3138 : 2934 : ::rtl::OUString aType;
3139 : 2934 : aValue >>= aType;
3140 : :
3141 [ + + ]: 2934 : if ( !m_pImpl->m_bCompressedSetExplicit )
3142 : : {
3143 [ + - ][ + + ]: 2831 : if ( aType == "image/jpeg" || aType == "image/png" || aType == "image/gif" )
[ - + ][ + + ]
3144 : 31 : bCompressedValueFromType = sal_False;
3145 : : }
3146 : :
3147 [ + + ]: 14670 : for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
3148 : : {
3149 [ + - ][ + + ]: 11736 : if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
3150 [ + - ]: 2934 : m_pImpl->m_aProps[nInd].Value = aValue;
3151 [ + + ][ + - ]: 8802 : else if ( !m_pImpl->m_bCompressedSetExplicit && aCompressedString.equals( m_pImpl->m_aProps[nInd].Name ) )
[ + + ][ + + ]
3152 [ + - ][ + - ]: 2831 : m_pImpl->m_aProps[nInd].Value <<= bCompressedValueFromType;
3153 : 2934 : }
3154 : : }
3155 [ + + ]: 3958 : else if ( aPropertyName.equals( aCompressedString ) )
3156 : : {
3157 : : // if the "Compressed" property is not set explicitly, the MediaType can change the default value
3158 : 1023 : m_pImpl->m_bCompressedSetExplicit = sal_True;
3159 [ + + ]: 5115 : for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
3160 : : {
3161 [ + - ][ + + ]: 4092 : if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
3162 [ + - ]: 1023 : m_pImpl->m_aProps[nInd].Value = aValue;
3163 : : }
3164 : : }
3165 [ + + + - ]: 5411 : else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
[ + + ]
3166 : 2476 : && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) )
3167 : : {
3168 : 2476 : sal_Bool bUseCommonEncryption = sal_False;
3169 [ + - ]: 2476 : if ( aValue >>= bUseCommonEncryption )
3170 : : {
3171 [ + + ][ - + ]: 2476 : if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization )
3172 : : {
3173 : : // the data stream is provided to the packagestream directly
3174 : 0 : m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption;
3175 : : }
3176 [ + + ]: 2476 : else if ( bUseCommonEncryption )
3177 : : {
3178 [ - + ]: 2470 : if ( !m_pImpl->m_bUseCommonEncryption )
3179 : : {
3180 [ # # ]: 0 : m_pImpl->SetDecrypted();
3181 : 0 : m_pImpl->m_bUseCommonEncryption = sal_True;
3182 : : }
3183 : : }
3184 : : else
3185 : 2476 : m_pImpl->m_bUseCommonEncryption = sal_False;
3186 : : }
3187 : : else
3188 [ # # ]: 0 : throw lang::IllegalArgumentException(); //TODO
3189 : : }
3190 [ + - ][ + - ]: 459 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equals( aMediaTypeString ) )
[ + - ]
3191 : : {
3192 [ + + ]: 1836 : for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
3193 : : {
3194 [ + - ][ + + ]: 1377 : if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
3195 [ + - ]: 459 : m_pImpl->m_aProps[nInd].Value = aValue;
3196 : : }
3197 : : }
3198 [ # # ][ # # ]: 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfoStream" ) ) )
[ # # ]
3199 : : {
3200 : 0 : uno::Reference< io::XInputStream > xInRelStream;
3201 [ # # ][ # # ]: 0 : if ( ( aValue >>= xInRelStream ) && xInRelStream.is() )
[ # # ][ # # ]
3202 : : {
3203 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY );
3204 [ # # ]: 0 : if ( !xSeek.is() )
3205 : : {
3206 : : // currently this is an internal property that is used for optimization
3207 : : // and the stream must support XSeekable interface
3208 : : // TODO/LATER: in future it can be changed if property is used from outside
3209 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO
3210 : : }
3211 : :
3212 [ # # ]: 0 : m_pImpl->m_xNewRelInfoStream = xInRelStream;
3213 [ # # ][ # # ]: 0 : m_pImpl->m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >();
[ # # ]
3214 : 0 : m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM;
3215 : : }
3216 : : else
3217 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO
3218 : : }
3219 [ # # ][ # # ]: 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) )
[ # # ]
3220 : : {
3221 [ # # ][ # # ]: 0 : if ( aValue >>= m_pImpl->m_aNewRelInfo )
3222 : : {
3223 : : }
3224 : : else
3225 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO
3226 : : }
3227 [ # # ]: 0 : else if ( aPropertyName == "Size" )
3228 [ # # ]: 0 : throw beans::PropertyVetoException(); // TODO
3229 [ # # # # : 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
# # ][ # # ]
3230 : 0 : && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) )
3231 [ # # ]: 0 : throw beans::PropertyVetoException(); // TODO
3232 : : else
3233 [ # # ]: 0 : throw beans::UnknownPropertyException(); // TODO
3234 : :
3235 : 6892 : m_pImpl->m_bHasDataToFlush = sal_True;
3236 [ + - ][ + - ]: 6892 : ModifyParentUnlockMutex_Impl( aGuard );
3237 : 6892 : }
3238 : :
3239 : :
3240 : : //-----------------------------------------------
3241 : 174 : uno::Any SAL_CALL OWriteStream::getPropertyValue( const ::rtl::OUString& aProp )
3242 : : throw ( beans::UnknownPropertyException,
3243 : : lang::WrappedTargetException,
3244 : : uno::RuntimeException )
3245 : : {
3246 [ + - ]: 174 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3247 : :
3248 [ - + ]: 174 : if ( !m_pImpl )
3249 : : {
3250 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3251 [ # # ]: 0 : throw lang::DisposedException();
3252 : : }
3253 : :
3254 [ + - ]: 174 : if ( aProp == "RelId" )
3255 : : {
3256 [ + - ]: 174 : return uno::makeAny( m_pImpl->GetNewRelId() );
3257 : : }
3258 : :
3259 : 0 : ::rtl::OUString aPropertyName;
3260 [ # # ]: 0 : if ( aProp == "IsEncrypted" )
3261 [ # # ]: 0 : aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) );
3262 : : else
3263 : 0 : aPropertyName = aProp;
3264 : :
3265 [ # # ]: 0 : if ( ( ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML )
[ # # # # ]
[ # # # #
# # ][ # # ]
3266 : 0 : && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
3267 : 0 : || ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) )
3268 : 0 : || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Compressed" ) ) )
3269 : : {
3270 [ # # ][ # # ]: 0 : m_pImpl->GetStreamProperties();
3271 : :
3272 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ )
3273 : : {
3274 [ # # ][ # # ]: 0 : if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) )
3275 [ # # ]: 0 : return m_pImpl->m_aProps[nInd].Value;
3276 : : }
3277 : : }
3278 [ # # # # ]: 0 : else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE
[ # # ]
3279 : 0 : && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) )
3280 [ # # ]: 0 : return uno::makeAny( m_pImpl->m_bUseCommonEncryption );
3281 [ # # ]: 0 : else if ( aPropertyName == "Size" )
3282 : : {
3283 [ # # ]: 0 : CheckInitOnDemand();
3284 : :
3285 [ # # ]: 0 : if ( !m_xSeekable.is() )
3286 [ # # ]: 0 : throw uno::RuntimeException();
3287 : :
3288 [ # # ][ # # ]: 0 : return uno::makeAny( (sal_Int32)m_xSeekable->getLength() );
[ # # ]
3289 : : }
3290 : :
3291 [ # # ][ + - ]: 174 : throw beans::UnknownPropertyException(); // TODO
3292 : : }
3293 : :
3294 : :
3295 : : //-----------------------------------------------
3296 : 0 : void SAL_CALL OWriteStream::addPropertyChangeListener(
3297 : : const ::rtl::OUString& /*aPropertyName*/,
3298 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
3299 : : throw ( beans::UnknownPropertyException,
3300 : : lang::WrappedTargetException,
3301 : : uno::RuntimeException )
3302 : : {
3303 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3304 : :
3305 [ # # ]: 0 : if ( !m_pImpl )
3306 : : {
3307 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3308 [ # # ]: 0 : throw lang::DisposedException();
3309 [ # # ]: 0 : }
3310 : :
3311 : : //TODO:
3312 : 0 : }
3313 : :
3314 : :
3315 : : //-----------------------------------------------
3316 : 0 : void SAL_CALL OWriteStream::removePropertyChangeListener(
3317 : : const ::rtl::OUString& /*aPropertyName*/,
3318 : : const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
3319 : : throw ( beans::UnknownPropertyException,
3320 : : lang::WrappedTargetException,
3321 : : uno::RuntimeException )
3322 : : {
3323 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3324 : :
3325 [ # # ]: 0 : if ( !m_pImpl )
3326 : : {
3327 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3328 [ # # ]: 0 : throw lang::DisposedException();
3329 [ # # ]: 0 : }
3330 : :
3331 : : //TODO:
3332 : 0 : }
3333 : :
3334 : :
3335 : : //-----------------------------------------------
3336 : 0 : void SAL_CALL OWriteStream::addVetoableChangeListener(
3337 : : const ::rtl::OUString& /*PropertyName*/,
3338 : : const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3339 : : throw ( beans::UnknownPropertyException,
3340 : : lang::WrappedTargetException,
3341 : : uno::RuntimeException )
3342 : : {
3343 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3344 : :
3345 [ # # ]: 0 : if ( !m_pImpl )
3346 : : {
3347 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3348 [ # # ]: 0 : throw lang::DisposedException();
3349 [ # # ]: 0 : }
3350 : :
3351 : : //TODO:
3352 : 0 : }
3353 : :
3354 : :
3355 : : //-----------------------------------------------
3356 : 0 : void SAL_CALL OWriteStream::removeVetoableChangeListener(
3357 : : const ::rtl::OUString& /*PropertyName*/,
3358 : : const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
3359 : : throw ( beans::UnknownPropertyException,
3360 : : lang::WrappedTargetException,
3361 : : uno::RuntimeException )
3362 : : {
3363 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3364 : :
3365 [ # # ]: 0 : if ( !m_pImpl )
3366 : : {
3367 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3368 [ # # ]: 0 : throw lang::DisposedException();
3369 [ # # ]: 0 : }
3370 : :
3371 : : //TODO:
3372 : 0 : }
3373 : :
3374 : : //____________________________________________________________________________________________________
3375 : : // XTransactedObject
3376 : : //____________________________________________________________________________________________________
3377 : :
3378 : : //-----------------------------------------------
3379 : 0 : void OWriteStream::BroadcastTransaction( sal_Int8 nMessage )
3380 : : /*
3381 : : 1 - preCommit
3382 : : 2 - commited
3383 : : 3 - preRevert
3384 : : 4 - reverted
3385 : : */
3386 : : {
3387 : : // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed
3388 [ # # ]: 0 : if ( !m_pImpl )
3389 : : {
3390 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3391 [ # # ]: 0 : throw lang::DisposedException();
3392 : : }
3393 : :
3394 [ # # ][ # # ]: 0 : lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
3395 : :
3396 : : ::cppu::OInterfaceContainerHelper* pContainer =
3397 : : m_pData->m_aListenersContainer.getContainer(
3398 [ # # ][ # # ]: 0 : ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) );
3399 [ # # ]: 0 : if ( pContainer )
3400 : : {
3401 [ # # ]: 0 : ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
3402 [ # # ]: 0 : while ( pIterator.hasMoreElements( ) )
3403 : : {
3404 : : OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" );
3405 : :
3406 [ # # # # : 0 : switch( nMessage )
# ]
3407 : : {
3408 : : case STOR_MESS_PRECOMMIT:
3409 [ # # ][ # # ]: 0 : ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource );
3410 : 0 : break;
3411 : : case STOR_MESS_COMMITED:
3412 [ # # ][ # # ]: 0 : ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource );
3413 : 0 : break;
3414 : : case STOR_MESS_PREREVERT:
3415 [ # # ][ # # ]: 0 : ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource );
3416 : 0 : break;
3417 : : case STOR_MESS_REVERTED:
3418 [ # # ][ # # ]: 0 : ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource );
3419 : 0 : break;
3420 : : }
3421 [ # # ]: 0 : }
3422 [ # # ]: 0 : }
3423 : 0 : }
3424 : : //-----------------------------------------------
3425 : 0 : void SAL_CALL OWriteStream::commit()
3426 : : throw ( io::IOException,
3427 : : embed::StorageWrappedTargetException,
3428 : : uno::RuntimeException )
3429 : : {
3430 : : RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::commit" );
3431 : :
3432 [ # # ]: 0 : if ( !m_pImpl )
3433 : : {
3434 [ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3435 [ # # ]: 0 : throw lang::DisposedException();
3436 : : }
3437 : :
3438 [ # # ]: 0 : if ( !m_bTransacted )
3439 [ # # ]: 0 : throw uno::RuntimeException();
3440 : :
3441 : : try {
3442 [ # # ]: 0 : BroadcastTransaction( STOR_MESS_PRECOMMIT );
3443 : :
3444 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3445 : :
3446 [ # # ]: 0 : if ( !m_pImpl )
3447 : : {
3448 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3449 [ # # ]: 0 : throw lang::DisposedException();
3450 : : }
3451 : :
3452 [ # # ]: 0 : m_pImpl->Commit();
3453 : :
3454 : : // when the storage is commited the parent is modified
3455 [ # # ][ # # ]: 0 : ModifyParentUnlockMutex_Impl( aGuard );
3456 : : }
3457 : 0 : catch( const io::IOException& rIOException )
3458 : : {
3459 [ # # ]: 0 : m_pImpl->AddLog( rIOException.Message );
3460 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3461 : 0 : throw;
3462 : : }
3463 : 0 : catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3464 : : {
3465 [ # # ]: 0 : m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3466 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3467 : 0 : throw;
3468 : : }
3469 : 0 : catch( const uno::RuntimeException& rRuntimeException )
3470 : : {
3471 [ # # ]: 0 : m_pImpl->AddLog( rRuntimeException.Message );
3472 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3473 : 0 : throw;
3474 : : }
3475 [ # # # # : 0 : catch( const uno::Exception& rException )
# ]
3476 : : {
3477 [ # # ]: 0 : m_pImpl->AddLog( rException.Message );
3478 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3479 : :
3480 [ # # ]: 0 : uno::Any aCaught( ::cppu::getCaughtException() );
3481 : : throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on commit!") ),
3482 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
3483 [ # # # # : 0 : aCaught );
# # ]
3484 : : }
3485 : :
3486 : 0 : BroadcastTransaction( STOR_MESS_COMMITED );
3487 : 0 : }
3488 : :
3489 : : //-----------------------------------------------
3490 : 0 : void SAL_CALL OWriteStream::revert()
3491 : : throw ( io::IOException,
3492 : : embed::StorageWrappedTargetException,
3493 : : uno::RuntimeException )
3494 : : {
3495 : : RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::revert" );
3496 : :
3497 : : // the method removes all the changes done after last commit
3498 : :
3499 [ # # ]: 0 : if ( !m_pImpl )
3500 : : {
3501 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3502 [ # # ]: 0 : throw lang::DisposedException();
3503 : : }
3504 : :
3505 [ # # ]: 0 : if ( !m_bTransacted )
3506 [ # # ]: 0 : throw uno::RuntimeException();
3507 : :
3508 [ # # ]: 0 : BroadcastTransaction( STOR_MESS_PREREVERT );
3509 : :
3510 [ # # ]: 0 : ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3511 : :
3512 [ # # ]: 0 : if ( !m_pImpl )
3513 : : {
3514 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3515 [ # # ]: 0 : throw lang::DisposedException();
3516 : : }
3517 : :
3518 : : try {
3519 [ # # ]: 0 : m_pImpl->Revert();
3520 : : }
3521 : 0 : catch( const io::IOException& rIOException )
3522 : : {
3523 [ # # ]: 0 : m_pImpl->AddLog( rIOException.Message );
3524 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3525 : 0 : throw;
3526 : : }
3527 : 0 : catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException )
3528 : : {
3529 [ # # ]: 0 : m_pImpl->AddLog( rStorageWrappedTargetException.Message );
3530 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3531 : 0 : throw;
3532 : : }
3533 : 0 : catch( const uno::RuntimeException& rRuntimeException )
3534 : : {
3535 [ # # ]: 0 : m_pImpl->AddLog( rRuntimeException.Message );
3536 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3537 : 0 : throw;
3538 : : }
3539 [ # # # # : 0 : catch( const uno::Exception& rException )
# ]
3540 : : {
3541 [ # # ]: 0 : m_pImpl->AddLog( rException.Message );
3542 [ # # # # ]: 0 : m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) );
3543 : :
3544 [ # # ]: 0 : uno::Any aCaught( ::cppu::getCaughtException() );
3545 : : throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on revert!") ),
3546 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
3547 [ # # # # : 0 : aCaught );
# # ]
3548 : : }
3549 : :
3550 [ # # ]: 0 : aGuard.clear();
3551 : :
3552 [ # # ][ # # ]: 0 : BroadcastTransaction( STOR_MESS_REVERTED );
3553 : 0 : }
3554 : :
3555 : : //____________________________________________________________________________________________________
3556 : : // XTransactionBroadcaster
3557 : : //____________________________________________________________________________________________________
3558 : :
3559 : : //-----------------------------------------------
3560 : 0 : void SAL_CALL OWriteStream::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
3561 : : throw ( uno::RuntimeException )
3562 : : {
3563 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3564 : :
3565 [ # # ]: 0 : if ( !m_pImpl )
3566 : : {
3567 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3568 [ # # ]: 0 : throw lang::DisposedException();
3569 : : }
3570 : :
3571 [ # # ]: 0 : if ( !m_bTransacted )
3572 [ # # ]: 0 : throw uno::RuntimeException();
3573 : :
3574 [ # # ]: 0 : m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
3575 [ # # ][ # # ]: 0 : aListener );
3576 : 0 : }
3577 : :
3578 : : //-----------------------------------------------
3579 : 0 : void SAL_CALL OWriteStream::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener )
3580 : : throw ( uno::RuntimeException )
3581 : : {
3582 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() );
3583 : :
3584 [ # # ]: 0 : if ( !m_pImpl )
3585 : : {
3586 [ # # ][ # # ]: 0 : ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
3587 [ # # ]: 0 : throw lang::DisposedException();
3588 : : }
3589 : :
3590 [ # # ]: 0 : if ( !m_bTransacted )
3591 [ # # ]: 0 : throw uno::RuntimeException();
3592 : :
3593 [ # # ]: 0 : m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0),
3594 [ # # ][ # # ]: 0 : aListener );
3595 : 0 : }
3596 : :
3597 : :
3598 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|