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/lang/DisposedException.hpp>
21 : : #include <com/sun/star/io/XStream.hpp>
22 : : #include <com/sun/star/io/XInputStream.hpp>
23 : : #include <com/sun/star/io/XSeekable.hpp>
24 : : #include <com/sun/star/io/XTruncate.hpp>
25 : :
26 : : #include <comphelper/storagehelper.hxx>
27 : :
28 : : #include <unotools/ucbstreamhelper.hxx>
29 : :
30 : : #include <cppuhelper/exc_hlp.hxx>
31 : :
32 : : #include <sot/storinfo.hxx>
33 : :
34 : : #include "xolesimplestorage.hxx"
35 : :
36 : :
37 : : using namespace ::com::sun::star;
38 : :
39 : : const sal_Int32 nBytesCount = 32000;
40 : :
41 : :
42 : : // --------------------------------------------------------------------------------
43 : 83 : OLESimpleStorage::OLESimpleStorage( uno::Reference< lang::XMultiServiceFactory > xFactory )
44 : : : m_bDisposed( sal_False )
45 : : , m_pStream( NULL )
46 : : , m_pStorage( NULL )
47 : : , m_pListenersContainer( NULL )
48 : : , m_xFactory( xFactory )
49 [ + - ]: 83 : , m_bNoTemporaryCopy( sal_False )
50 : : {
51 : : OSL_ENSURE( m_xFactory.is(), "No factory is provided on creation!\n" );
52 [ - + ]: 83 : if ( !m_xFactory.is() )
53 [ # # ]: 0 : throw uno::RuntimeException();
54 : 83 : }
55 : :
56 : : // --------------------------------------------------------------------------------
57 [ + - ]: 83 : OLESimpleStorage::~OLESimpleStorage()
58 : : {
59 : : try {
60 : 83 : m_refCount++;
61 [ + + ]: 83 : dispose();
62 [ + - ]: 2 : } catch( uno::Exception& )
63 : : {}
64 : :
65 [ - + ]: 83 : if ( m_pListenersContainer )
66 : : {
67 [ # # ][ # # ]: 0 : delete m_pListenersContainer;
68 : 0 : m_pListenersContainer = NULL;
69 : : }
70 [ - + ][ - + ]: 168 : }
71 : :
72 : : //-------------------------------------------------------------------------
73 : 12 : uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::impl_staticGetSupportedServiceNames()
74 : : {
75 : 12 : uno::Sequence< ::rtl::OUString > aRet(1);
76 [ + - ]: 12 : aRet[0] = ::rtl::OUString("com.sun.star.embed.OLESimpleStorage");
77 : 12 : return aRet;
78 : : }
79 : :
80 : : //-------------------------------------------------------------------------
81 : 24 : ::rtl::OUString SAL_CALL OLESimpleStorage::impl_staticGetImplementationName()
82 : : {
83 : 24 : return ::rtl::OUString("com.sun.star.comp.embed.OLESimpleStorage");
84 : : }
85 : :
86 : : //-------------------------------------------------------------------------
87 : 83 : uno::Reference< uno::XInterface > SAL_CALL OLESimpleStorage::impl_staticCreateSelfInstance(
88 : : const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
89 : : {
90 [ + - ][ + - ]: 83 : return uno::Reference< uno::XInterface >( *new OLESimpleStorage( xServiceManager ) );
91 : : }
92 : :
93 : : //-------------------------------------------------------------------------
94 : 28 : void OLESimpleStorage::UpdateOriginal_Impl()
95 : : {
96 [ - + ]: 28 : if ( !m_bNoTemporaryCopy )
97 : : {
98 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( m_xStream, uno::UNO_QUERY_THROW );
99 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
100 : :
101 [ # # ]: 0 : uno::Reference< io::XSeekable > xTempSeek( m_xTempStream, uno::UNO_QUERY_THROW );
102 [ # # ][ # # ]: 0 : sal_Int64 nPos = xTempSeek->getPosition();
103 [ # # ][ # # ]: 0 : xTempSeek->seek( 0 );
104 : :
105 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xTempInp = m_xTempStream->getInputStream();
106 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xOutputStream = m_xStream->getOutputStream();
107 [ # # ][ # # ]: 0 : if ( !xTempInp.is() || !xOutputStream.is() )
[ # # ]
108 [ # # ]: 0 : throw uno::RuntimeException();
109 : :
110 [ # # ]: 0 : uno::Reference< io::XTruncate > xTrunc( xOutputStream, uno::UNO_QUERY_THROW );
111 [ # # ][ # # ]: 0 : xTrunc->truncate();
112 : :
113 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xTempInp, xOutputStream );
114 [ # # ][ # # ]: 0 : xOutputStream->flush();
115 [ # # ][ # # ]: 0 : xTempSeek->seek( nPos );
116 : : }
117 : 28 : }
118 : :
119 : : //-------------------------------------------------------------------------
120 : 402 : void OLESimpleStorage::InsertInputStreamToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInputStream )
121 : : throw ( uno::Exception )
122 : : {
123 [ + - ][ + - ]: 402 : if ( !pStorage || aName.isEmpty() || !xInputStream.is() )
[ - + ][ - + ]
124 [ # # ]: 0 : throw uno::RuntimeException();
125 : :
126 [ + - ][ - + ]: 402 : if ( pStorage->IsContained( aName ) )
127 [ # # ]: 0 : throw container::ElementExistException(); // TODO:
128 : :
129 [ + - ]: 402 : BaseStorageStream* pNewStream = pStorage->OpenStream( aName );
130 [ + - ][ - + ]: 402 : if ( !pNewStream || pNewStream->GetError() || pStorage->GetError() )
[ - + ][ + - ]
131 : : {
132 [ # # ]: 0 : if ( pNewStream )
133 [ # # ]: 0 : DELETEZ( pNewStream );
134 : 0 : pStorage->ResetError();
135 [ # # ]: 0 : throw io::IOException(); // TODO
136 : : }
137 : :
138 : : try
139 : : {
140 [ + - ]: 402 : uno::Sequence< sal_Int8 > aData( nBytesCount );
141 : 402 : sal_Int32 nRead = 0;
142 [ - + ]: 402 : do
143 : : {
144 [ + - ][ + - ]: 402 : nRead = xInputStream->readBytes( aData, nBytesCount );
145 [ + - ]: 402 : if ( nRead < nBytesCount )
146 [ + - ]: 402 : aData.realloc( nRead );
147 : :
148 [ + - ][ + - ]: 402 : sal_Int32 nWritten = pNewStream->Write( aData.getArray(), nRead );
149 [ - + ]: 402 : if ( nWritten < nRead )
150 [ # # ]: 0 : throw io::IOException();
151 [ + - ]: 402 : } while( nRead == nBytesCount );
152 : : }
153 [ # # ]: 0 : catch( uno::Exception& )
154 : : {
155 [ # # # # ]: 0 : DELETEZ( pNewStream );
156 [ # # # # : 0 : pStorage->Remove( aName );
# # ]
157 : :
158 : 0 : throw;
159 : : }
160 : :
161 [ + - ]: 402 : DELETEZ( pNewStream );
162 : 402 : }
163 : :
164 : : //-------------------------------------------------------------------------
165 : 13 : void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< container::XNameAccess >& xNameAccess )
166 : : throw ( uno::Exception )
167 : : {
168 [ + - ][ + - ]: 13 : if ( !pStorage || aName.isEmpty() || !xNameAccess.is() )
[ - + ][ - + ]
169 [ # # ]: 0 : throw uno::RuntimeException();
170 : :
171 [ + - ][ - + ]: 13 : if ( pStorage->IsContained( aName ) )
172 [ # # ]: 0 : throw container::ElementExistException(); // TODO:
173 : :
174 [ + - ]: 13 : BaseStorage* pNewStorage = pStorage->OpenStorage( aName );
175 [ + - ][ - + ]: 13 : if ( !pNewStorage || pNewStorage->GetError() || pStorage->GetError() )
[ - + ][ + - ]
176 : : {
177 [ # # ]: 0 : if ( pNewStorage )
178 [ # # ]: 0 : DELETEZ( pNewStorage );
179 : 0 : pStorage->ResetError();
180 [ # # ]: 0 : throw io::IOException(); // TODO
181 : : }
182 : :
183 : : try
184 : : {
185 [ + - ][ + - ]: 13 : uno::Sequence< ::rtl::OUString > aElements = xNameAccess->getElementNames();
186 [ + + ]: 196 : for ( sal_Int32 nInd = 0; nInd < aElements.getLength(); nInd++ )
187 : : {
188 : 183 : uno::Reference< io::XInputStream > xInputStream;
189 : 183 : uno::Reference< container::XNameAccess > xSubNameAccess;
190 [ + - ][ + - ]: 183 : uno::Any aAny = xNameAccess->getByName( aElements[nInd] );
[ + - ]
191 [ + - ][ + - ]: 183 : if ( aAny >>= xInputStream )
192 [ + - ][ + - ]: 183 : InsertInputStreamToStorage_Impl( pNewStorage, aElements[nInd], xInputStream );
193 [ # # ][ # # ]: 0 : else if ( aAny >>= xSubNameAccess )
194 [ # # ][ # # ]: 0 : InsertNameAccessToStorage_Impl( pNewStorage, aElements[nInd], xSubNameAccess );
195 [ + - ]: 196 : }
196 : : }
197 [ # # ]: 0 : catch( uno::Exception& )
198 : : {
199 [ # # # # ]: 0 : DELETEZ( pNewStorage );
200 [ # # # # : 0 : pStorage->Remove( aName );
# # ]
201 : :
202 : 0 : throw;
203 : : }
204 : :
205 [ + - ]: 13 : DELETEZ( pNewStorage );
206 : 13 : }
207 : :
208 : : //____________________________________________________________________________________________________
209 : : // XInitialization
210 : : //____________________________________________________________________________________________________
211 : :
212 : 83 : void SAL_CALL OLESimpleStorage::initialize( const uno::Sequence< uno::Any >& aArguments )
213 : : throw ( uno::Exception,
214 : : uno::RuntimeException)
215 : : {
216 [ + - ][ - + ]: 83 : if ( m_pStream || m_pStorage )
217 [ # # ]: 0 : throw io::IOException(); // TODO: already initilized
218 : :
219 : 83 : sal_Int32 nArgNum = aArguments.getLength();
220 : : OSL_ENSURE( nArgNum >= 1 && nArgNum <= 2, "Wrong parameter number" );
221 : :
222 [ - + ][ + - ]: 83 : if ( nArgNum < 1 || nArgNum > 2 )
223 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
224 : :
225 : 83 : uno::Reference< io::XStream > xStream;
226 : 83 : uno::Reference< io::XInputStream > xInputStream;
227 [ + + ][ + - ]: 83 : if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) )
[ - + ][ - + ]
[ + - ]
228 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
229 : :
230 [ + - ]: 83 : if ( nArgNum == 2 )
231 : : {
232 [ - + ]: 83 : if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) )
233 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
234 : : }
235 : :
236 [ + - ]: 83 : if ( m_bNoTemporaryCopy )
237 : : {
238 : : // TODO: ???
239 : : // If the temporary stream is not created, the original stream must be wrapped
240 : : // since SvStream wrapper closes the stream is owns
241 [ + + ]: 83 : if ( xInputStream.is() )
242 : : {
243 : : // the stream must be seekable for direct access
244 [ + - ]: 16 : uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
245 [ + - ]: 16 : m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, sal_False );
246 : : }
247 [ + - ]: 67 : else if ( xStream.is() )
248 : : {
249 : : // the stream must be seekable for direct access
250 [ + - ]: 67 : uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
251 [ + - ]: 67 : m_pStream = ::utl::UcbStreamHelper::CreateStream( xStream, sal_False );
252 : : }
253 : : else
254 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
255 : : }
256 : : else
257 : : {
258 : : uno::Reference < io::XStream > xTempFile(
259 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString("com.sun.star.io.TempFile") ),
260 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
261 [ # # ]: 0 : uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
262 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream();
263 [ # # ]: 0 : if ( !xTempOut.is() )
264 [ # # ]: 0 : throw uno::RuntimeException();
265 : :
266 [ # # ]: 0 : if ( xInputStream.is() )
267 : : {
268 : : try
269 : : {
270 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
271 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
[ # # ]
272 : : }
273 [ # # ]: 0 : catch( uno::Exception& )
274 : : {}
275 : :
276 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut );
277 [ # # ][ # # ]: 0 : xTempOut->closeOutput();
278 [ # # ][ # # ]: 0 : xTempSeek->seek( 0 );
279 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream();
280 [ # # ]: 0 : m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempInput, sal_False );
281 : : }
282 [ # # ]: 0 : else if ( xStream.is() )
283 : : {
284 : : // not sure that the storage flashes the stream on commit
285 [ # # ]: 0 : m_xStream = xStream;
286 [ # # ]: 0 : m_xTempStream = xTempFile;
287 : :
288 [ # # ]: 0 : uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
289 [ # # ][ # # ]: 0 : xSeek->seek( 0 );
290 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xInpStream = xStream->getInputStream();
291 [ # # ][ # # ]: 0 : if ( !xInpStream.is() || !xStream->getOutputStream().is() )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
292 [ # # ]: 0 : throw uno::RuntimeException();
293 : :
294 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xInpStream, xTempOut );
295 [ # # ][ # # ]: 0 : xTempOut->flush();
296 [ # # ][ # # ]: 0 : xTempSeek->seek( 0 );
297 : :
298 [ # # ]: 0 : m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False );
299 : : }
300 : : else
301 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
302 : : }
303 : :
304 [ + - ][ - + ]: 83 : if ( !m_pStream || m_pStream->GetError() )
[ - + ]
305 [ # # ]: 0 : throw io::IOException(); // TODO
306 : :
307 [ + - ][ + - ]: 83 : m_pStorage = new Storage( *m_pStream, sal_False );
308 : 83 : }
309 : :
310 : :
311 : : //____________________________________________________________________________________________________
312 : : // XNameContainer
313 : : //____________________________________________________________________________________________________
314 : :
315 : : // --------------------------------------------------------------------------------
316 : 232 : void SAL_CALL OLESimpleStorage::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement )
317 : : throw ( lang::IllegalArgumentException,
318 : : container::ElementExistException,
319 : : lang::WrappedTargetException,
320 : : uno::RuntimeException)
321 : : {
322 [ + - ]: 232 : ::osl::MutexGuard aGuard( m_aMutex );
323 : :
324 [ - + ]: 232 : if ( m_bDisposed )
325 [ # # ]: 0 : throw lang::DisposedException();
326 : :
327 [ - + ]: 232 : if ( !m_pStorage )
328 [ # # ]: 0 : throw uno::RuntimeException();
329 : :
330 : 232 : uno::Reference< io::XStream > xStream;
331 : 232 : uno::Reference< io::XInputStream > xInputStream;
332 : 232 : uno::Reference< container::XNameAccess > xNameAccess;
333 : :
334 : : try
335 : : {
336 [ # # ][ - + ]: 232 : if ( !m_bNoTemporaryCopy && !m_xStream.is() )
[ - + ]
337 [ # # ]: 0 : throw io::IOException(); // TODO
338 : :
339 [ + - ][ + + ]: 232 : if ( aElement >>= xStream )
340 [ + - ][ + - ]: 219 : xInputStream = xStream->getInputStream();
[ + - ]
341 [ + - ][ + - ]: 13 : else if ( !( aElement >>= xInputStream ) && !( aElement >>= xNameAccess ) )
[ + - ][ - + ]
[ - + ]
342 [ # # ]: 0 : throw lang::IllegalArgumentException(); // TODO:
343 : :
344 [ + + ]: 232 : if ( xInputStream.is() )
345 [ + - ]: 219 : InsertInputStreamToStorage_Impl( m_pStorage, aName, xInputStream );
346 [ + - ]: 13 : else if ( xNameAccess.is() )
347 [ + - ]: 13 : InsertNameAccessToStorage_Impl( m_pStorage, aName, xNameAccess );
348 : : else
349 [ # # ]: 0 : throw uno::RuntimeException();
350 : : }
351 : 0 : catch( uno::RuntimeException& )
352 : : {
353 : 0 : throw;
354 : : }
355 : 0 : catch( container::ElementExistException& )
356 : : {
357 : 0 : throw;
358 : : }
359 [ # # # # ]: 0 : catch( const uno::Exception& e )
360 : : {
361 : : throw lang::WrappedTargetException( ::rtl::OUString( "Insert has failed!" ),
362 : : uno::Reference< uno::XInterface >(),
363 [ # # # # ]: 0 : uno::makeAny( e ) );
364 [ + - ]: 232 : }
365 : 232 : }
366 : :
367 : : // --------------------------------------------------------------------------------
368 : 0 : void SAL_CALL OLESimpleStorage::removeByName( const ::rtl::OUString& aName )
369 : : throw ( container::NoSuchElementException,
370 : : lang::WrappedTargetException,
371 : : uno::RuntimeException)
372 : : {
373 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
374 : :
375 [ # # ]: 0 : if ( m_bDisposed )
376 [ # # ]: 0 : throw lang::DisposedException();
377 : :
378 [ # # ]: 0 : if ( !m_pStorage )
379 [ # # ]: 0 : throw uno::RuntimeException();
380 : :
381 [ # # ][ # # ]: 0 : if ( !m_bNoTemporaryCopy && !m_xStream.is() )
[ # # ]
382 [ # # ]: 0 : throw lang::WrappedTargetException(); // io::IOException(); // TODO
383 : :
384 [ # # ][ # # ]: 0 : if ( !m_pStorage->IsContained( aName ) )
[ # # ][ # # ]
385 [ # # ]: 0 : throw container::NoSuchElementException(); // TODO:
386 : :
387 [ # # ][ # # ]: 0 : m_pStorage->Remove( aName );
[ # # ]
388 : :
389 [ # # ][ # # ]: 0 : if ( m_pStorage->GetError() )
390 : : {
391 [ # # ]: 0 : m_pStorage->ResetError();
392 [ # # ]: 0 : throw lang::WrappedTargetException(); // io::IOException(); // TODO
393 [ # # ]: 0 : }
394 : 0 : }
395 : :
396 : : // --------------------------------------------------------------------------------
397 : 0 : void SAL_CALL OLESimpleStorage::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
398 : : throw ( lang::IllegalArgumentException,
399 : : container::NoSuchElementException,
400 : : lang::WrappedTargetException,
401 : : uno::RuntimeException)
402 : : {
403 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
404 : :
405 [ # # ]: 0 : if ( m_bDisposed )
406 [ # # ]: 0 : throw lang::DisposedException();
407 : :
408 [ # # ]: 0 : removeByName( aName );
409 : :
410 : : try
411 : : {
412 [ # # ]: 0 : insertByName( aName, aElement );
413 : : }
414 [ # # ]: 0 : catch( container::ElementExistException& )
415 : : {
416 [ # # ]: 0 : uno::Any aCaught( ::cppu::getCaughtException() );
417 : :
418 : : throw lang::WrappedTargetException( ::rtl::OUString("Can't copy raw stream"),
419 : : uno::Reference< uno::XInterface >(),
420 [ # # ]: 0 : aCaught );
421 [ # # ]: 0 : }
422 : 0 : }
423 : :
424 : : // --------------------------------------------------------------------------------
425 : 770 : uno::Any SAL_CALL OLESimpleStorage::getByName( const ::rtl::OUString& aName )
426 : : throw ( container::NoSuchElementException,
427 : : lang::WrappedTargetException,
428 : : uno::RuntimeException )
429 : : {
430 [ + - ]: 770 : ::osl::MutexGuard aGuard( m_aMutex );
431 : :
432 [ - + ]: 770 : if ( m_bDisposed )
433 [ # # ]: 0 : throw lang::DisposedException();
434 : :
435 [ - + ]: 770 : if ( !m_pStorage )
436 [ # # ]: 0 : throw uno::RuntimeException();
437 : :
438 [ + - ][ + - ]: 770 : if ( !m_pStorage->IsContained( aName ) )
[ + - ][ + + ]
439 [ + - ]: 13 : throw container::NoSuchElementException(); // TODO:
440 : :
441 : 757 : uno::Any aResult;
442 : :
443 : : uno::Reference< io::XStream > xTempFile(
444 [ + - ]: 757 : m_xFactory->createInstance( ::rtl::OUString("com.sun.star.io.TempFile") ),
445 [ + - ][ + - ]: 757 : uno::UNO_QUERY );
446 [ + - ]: 757 : uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW );
447 [ + - ][ + - ]: 757 : uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream();
448 [ + - ][ + - ]: 757 : uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream();
449 [ + - ][ - + ]: 757 : if ( !xOutputStream.is() || !xInputStream.is() )
[ - + ]
450 [ # # ]: 0 : throw uno::RuntimeException();
451 : :
452 [ + - ][ + - ]: 757 : if ( m_pStorage->IsStorage( aName ) )
[ + - ][ + + ]
453 : : {
454 [ + - ][ + - ]: 29 : BaseStorage* pStrg = m_pStorage->OpenStorage( aName );
[ + - ]
455 [ + - ]: 29 : m_pStorage->ResetError();
456 [ - + ]: 29 : if ( !pStrg )
457 [ # # ]: 0 : throw io::IOException();
458 : :
459 [ + - ]: 29 : SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False ); // do not close the original stream
460 [ - + ]: 29 : if ( !pStream )
461 [ # # ]: 0 : throw uno::RuntimeException();
462 : :
463 [ + - ][ + - ]: 29 : BaseStorage* pNewStor = new Storage( *pStream, sal_False );
464 : : sal_Bool bSuccess =
465 [ + - ][ + - ]: 29 : ( pStrg->CopyTo( pNewStor ) && pNewStor->Commit() && !pNewStor->GetError() && !pStrg->GetError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
466 : :
467 [ + - ][ + - ]: 29 : DELETEZ( pNewStor );
468 [ + - ][ + - ]: 29 : DELETEZ( pStrg );
469 [ + - ][ + - ]: 29 : DELETEZ( pStream );
470 : :
471 [ - + ]: 29 : if ( !bSuccess )
472 [ # # ]: 0 : throw uno::RuntimeException();
473 : :
474 [ + - ]: 29 : uno::Sequence< uno::Any > aArgs( 2 );
475 [ + - ][ + - ]: 29 : aArgs[0] <<= xInputStream; // allow readonly access only
476 [ + - ][ + - ]: 29 : aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
477 : :
478 : : uno::Reference< container::XNameContainer > xResultNameContainer(
479 [ + - ]: 29 : m_xFactory->createInstanceWithArguments(
480 : : ::rtl::OUString("com.sun.star.embed.OLESimpleStorage"),
481 : 29 : aArgs ),
482 [ + - ][ + - ]: 29 : uno::UNO_QUERY_THROW );
483 : :
484 [ + - ][ + - ]: 29 : aResult <<= xResultNameContainer;
485 : : }
486 : : else
487 : : {
488 [ + - ][ + - ]: 728 : BaseStorageStream* pStream = m_pStorage->OpenStream( aName, STREAM_READ | STREAM_SHARE_DENYALL | STREAM_NOCREATE );
[ + - ]
489 [ + - ][ + - ]: 728 : if ( !pStream || pStream->GetError() || m_pStorage->GetError() )
[ + - ][ + - ]
[ - + ][ - + ]
490 : : {
491 [ # # ]: 0 : m_pStorage->ResetError();
492 [ # # ][ # # ]: 0 : DELETEZ( pStream );
493 [ # # ]: 0 : throw io::IOException(); // TODO
494 : : }
495 : :
496 : : try
497 : : {
498 [ + - ]: 728 : uno::Sequence< sal_Int8 > aData( nBytesCount );
499 : 728 : sal_Int32 nSize = nBytesCount;
500 : 728 : sal_Int32 nRead = 0;
501 [ + - ][ + - ]: 1456 : while( 0 != ( nRead = pStream->Read( aData.getArray(), nSize ) ) )
[ + + ]
502 : : {
503 [ + - ]: 728 : if ( nRead < nSize )
504 : : {
505 : 728 : nSize = nRead;
506 [ + - ]: 728 : aData.realloc( nSize );
507 : : }
508 : :
509 [ + - ][ + - ]: 728 : xOutputStream->writeBytes( aData );
510 : : }
511 : :
512 [ + - ][ - + ]: 728 : if ( pStream->GetError() )
513 [ # # ]: 0 : throw io::IOException(); // TODO
514 : :
515 [ + - ][ + - ]: 728 : xOutputStream->closeOutput();
516 [ + - ][ + - ]: 728 : xSeekable->seek( 0 );
[ + - ]
517 : : }
518 : 0 : catch( uno::RuntimeException& )
519 : : {
520 [ # # # # ]: 0 : DELETEZ( pStream );
521 : 0 : throw;
522 : : }
523 [ # # # ]: 0 : catch( uno::Exception& )
524 : : {
525 [ # # # # ]: 0 : DELETEZ( pStream );
526 [ # # ]: 0 : throw lang::WrappedTargetException(); // TODO:
527 : : }
528 : :
529 [ + - ][ + - ]: 728 : DELETEZ( pStream );
530 : :
531 [ + - ]: 728 : aResult <<= xInputStream;
532 : : }
533 : :
534 [ + - ]: 770 : return aResult;
535 : : }
536 : :
537 : : // --------------------------------------------------------------------------------
538 : 52 : uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getElementNames()
539 : : throw ( uno::RuntimeException )
540 : : {
541 [ + - ]: 52 : ::osl::MutexGuard aGuard( m_aMutex );
542 : :
543 [ - + ]: 52 : if ( m_bDisposed )
544 [ # # ]: 0 : throw lang::DisposedException();
545 : :
546 [ - + ]: 52 : if ( !m_pStorage )
547 [ # # ]: 0 : throw uno::RuntimeException();
548 : :
549 [ + - ]: 52 : SvStorageInfoList aList;
550 [ + - ]: 52 : m_pStorage->FillInfoList( &aList );
551 : :
552 [ + - ][ - + ]: 52 : if ( m_pStorage->GetError() )
553 : : {
554 [ # # ]: 0 : m_pStorage->ResetError();
555 [ # # ]: 0 : throw uno::RuntimeException(); // TODO:
556 : : }
557 : :
558 [ + - ]: 52 : uno::Sequence< ::rtl::OUString > aSeq( aList.size() );
559 [ + + ]: 496 : for ( sal_uInt32 nInd = 0; nInd < aList.size(); nInd++ )
560 [ + - ][ + - ]: 444 : aSeq[nInd] = aList[nInd].GetName();
561 : :
562 [ + - ]: 52 : return aSeq;
563 : : }
564 : :
565 : : // --------------------------------------------------------------------------------
566 : 242 : sal_Bool SAL_CALL OLESimpleStorage::hasByName( const ::rtl::OUString& aName )
567 : : throw ( uno::RuntimeException )
568 : : {
569 [ + - ]: 242 : ::osl::MutexGuard aGuard( m_aMutex );
570 : :
571 [ - + ]: 242 : if ( m_bDisposed )
572 [ # # ]: 0 : throw lang::DisposedException();
573 : :
574 [ - + ]: 242 : if ( !m_pStorage )
575 [ # # ]: 0 : throw uno::RuntimeException();
576 : :
577 [ + - ][ + - ]: 242 : sal_Bool bResult = m_pStorage->IsContained( aName );
[ + - ]
578 : :
579 [ + - ][ - + ]: 242 : if ( m_pStorage->GetError() )
580 : : {
581 [ # # ]: 0 : m_pStorage->ResetError();
582 [ # # ]: 0 : throw uno::RuntimeException(); // TODO:
583 : : }
584 : :
585 [ + - ]: 242 : return bResult;
586 : : }
587 : :
588 : : // --------------------------------------------------------------------------------
589 : 0 : uno::Type SAL_CALL OLESimpleStorage::getElementType()
590 : : throw ( uno::RuntimeException )
591 : : {
592 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
593 : :
594 [ # # ]: 0 : if ( m_bDisposed )
595 [ # # ]: 0 : throw lang::DisposedException();
596 : :
597 [ # # ][ # # ]: 0 : return getCppuType( (const uno::Reference< io::XInputStream >*)NULL );
598 : : }
599 : :
600 : : // --------------------------------------------------------------------------------
601 : 269 : sal_Bool SAL_CALL OLESimpleStorage::hasElements()
602 : : throw ( uno::RuntimeException )
603 : : {
604 [ + - ]: 269 : ::osl::MutexGuard aGuard( m_aMutex );
605 : :
606 [ - + ]: 269 : if ( m_bDisposed )
607 [ # # ]: 0 : throw lang::DisposedException();
608 : :
609 [ - + ]: 269 : if ( !m_pStorage )
610 [ # # ]: 0 : throw uno::RuntimeException();
611 : :
612 [ + - ]: 269 : SvStorageInfoList aList;
613 [ + - ]: 269 : m_pStorage->FillInfoList( &aList );
614 : :
615 [ + - ][ + + ]: 269 : if ( m_pStorage->GetError() )
616 : : {
617 [ + - ]: 8 : m_pStorage->ResetError();
618 [ + - ]: 8 : throw uno::RuntimeException(); // TODO:
619 : : }
620 : :
621 [ + - ]: 269 : return ( aList.size() != 0 );
622 : : }
623 : :
624 : : //____________________________________________________________________________________________________
625 : : // XComponent
626 : : //____________________________________________________________________________________________________
627 : :
628 : : // --------------------------------------------------------------------------------
629 : 85 : void SAL_CALL OLESimpleStorage::dispose()
630 : : throw ( uno::RuntimeException )
631 : : {
632 [ + - ]: 85 : ::osl::MutexGuard aGuard( m_aMutex );
633 : :
634 [ + + ]: 85 : if ( m_bDisposed )
635 [ + - ]: 2 : throw lang::DisposedException();
636 : :
637 [ - + ]: 83 : if ( m_pListenersContainer )
638 : : {
639 [ # # ][ # # ]: 0 : lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
640 [ # # ][ # # ]: 0 : m_pListenersContainer->disposeAndClear( aSource );
641 : : }
642 : :
643 [ + - ][ + - ]: 83 : DELETEZ( m_pStorage );
644 [ + - ][ + - ]: 83 : DELETEZ( m_pStream );
645 : :
646 [ + - ]: 83 : m_xStream = uno::Reference< io::XStream >();
647 [ + - ]: 83 : m_xTempStream = uno::Reference< io::XStream >();
648 : :
649 [ + - ]: 85 : m_bDisposed = sal_True;
650 : 83 : }
651 : :
652 : : // --------------------------------------------------------------------------------
653 : 0 : void SAL_CALL OLESimpleStorage::addEventListener(
654 : : const uno::Reference< lang::XEventListener >& xListener )
655 : : throw ( uno::RuntimeException )
656 : : {
657 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
658 : :
659 [ # # ]: 0 : if ( m_bDisposed )
660 [ # # ]: 0 : throw lang::DisposedException();
661 : :
662 [ # # ]: 0 : if ( !m_pListenersContainer )
663 [ # # ]: 0 : m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
664 : :
665 [ # # ][ # # ]: 0 : m_pListenersContainer->addInterface( xListener );
666 : 0 : }
667 : :
668 : : // --------------------------------------------------------------------------------
669 : 0 : void SAL_CALL OLESimpleStorage::removeEventListener(
670 : : const uno::Reference< lang::XEventListener >& xListener )
671 : : throw ( uno::RuntimeException )
672 : : {
673 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
674 : :
675 [ # # ]: 0 : if ( m_bDisposed )
676 [ # # ]: 0 : throw lang::DisposedException();
677 : :
678 [ # # ]: 0 : if ( m_pListenersContainer )
679 [ # # ][ # # ]: 0 : m_pListenersContainer->removeInterface( xListener );
680 : 0 : }
681 : :
682 : : //____________________________________________________________________________________________________
683 : : // XTransactedObject
684 : : //____________________________________________________________________________________________________
685 : :
686 : : // --------------------------------------------------------------------------------
687 : 28 : void SAL_CALL OLESimpleStorage::commit()
688 : : throw ( ::com::sun::star::io::IOException,
689 : : ::com::sun::star::lang::WrappedTargetException,
690 : : ::com::sun::star::uno::RuntimeException )
691 : : {
692 [ + - ]: 28 : ::osl::MutexGuard aGuard( m_aMutex );
693 : :
694 [ - + ]: 28 : if ( m_bDisposed )
695 [ # # ]: 0 : throw lang::DisposedException();
696 : :
697 [ - + ]: 28 : if ( !m_pStorage )
698 [ # # ]: 0 : throw uno::RuntimeException();
699 : :
700 [ - + ][ # # ]: 28 : if ( !m_bNoTemporaryCopy && !m_xStream.is() )
[ - + ]
701 [ # # ]: 0 : throw io::IOException(); // TODO
702 : :
703 [ + - ][ + - ]: 28 : if ( !m_pStorage->Commit() || m_pStorage->GetError() )
[ + - ][ - + ]
[ - + ]
704 : : {
705 [ # # ]: 0 : m_pStorage->ResetError();
706 [ # # ]: 0 : throw io::IOException(); // TODO
707 : : }
708 : :
709 [ + - ][ + - ]: 28 : UpdateOriginal_Impl();
710 : 28 : }
711 : :
712 : : // --------------------------------------------------------------------------------
713 : 0 : void SAL_CALL OLESimpleStorage::revert()
714 : : throw ( ::com::sun::star::io::IOException,
715 : : ::com::sun::star::lang::WrappedTargetException,
716 : : ::com::sun::star::uno::RuntimeException )
717 : : {
718 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
719 : :
720 [ # # ]: 0 : if ( m_bDisposed )
721 [ # # ]: 0 : throw lang::DisposedException();
722 : :
723 [ # # ]: 0 : if ( !m_pStorage )
724 [ # # ]: 0 : throw uno::RuntimeException();
725 : :
726 [ # # ][ # # ]: 0 : if ( !m_bNoTemporaryCopy && !m_xStream.is() )
[ # # ]
727 [ # # ]: 0 : throw io::IOException(); // TODO
728 : :
729 [ # # ][ # # ]: 0 : if ( !m_pStorage->Revert() || m_pStorage->GetError() )
[ # # ][ # # ]
[ # # ]
730 : : {
731 [ # # ]: 0 : m_pStorage->ResetError();
732 [ # # ]: 0 : throw io::IOException(); // TODO
733 : : }
734 : :
735 [ # # ][ # # ]: 0 : UpdateOriginal_Impl();
736 : 0 : }
737 : :
738 : : //____________________________________________________________________________________________________
739 : : // XClassifiedObject
740 : : //____________________________________________________________________________________________________
741 : :
742 : 0 : uno::Sequence< sal_Int8 > SAL_CALL OLESimpleStorage::getClassID()
743 : : throw ( uno::RuntimeException )
744 : : {
745 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
746 : :
747 [ # # ]: 0 : if ( m_bDisposed )
748 [ # # ]: 0 : throw lang::DisposedException();
749 : :
750 [ # # ]: 0 : if ( !m_pStorage )
751 [ # # ]: 0 : throw uno::RuntimeException();
752 : :
753 [ # # ][ # # ]: 0 : return m_pStorage->GetClassName().GetByteSequence();
[ # # ][ # # ]
754 : : }
755 : :
756 : 0 : ::rtl::OUString SAL_CALL OLESimpleStorage::getClassName()
757 : : throw ( uno::RuntimeException )
758 : : {
759 : 0 : return ::rtl::OUString();
760 : : }
761 : :
762 : 0 : void SAL_CALL OLESimpleStorage::setClassInfo( const uno::Sequence< sal_Int8 >& /*aClassID*/,
763 : : const ::rtl::OUString& /*sClassName*/ )
764 : : throw ( lang::NoSupportException,
765 : : uno::RuntimeException )
766 : : {
767 [ # # ]: 0 : throw lang::NoSupportException();
768 : : }
769 : :
770 : : //____________________________________________________________________________________________________
771 : : // XServiceInfo
772 : : //____________________________________________________________________________________________________
773 : :
774 : : // --------------------------------------------------------------------------------
775 : 0 : ::rtl::OUString SAL_CALL OLESimpleStorage::getImplementationName()
776 : : throw ( uno::RuntimeException )
777 : : {
778 : 0 : return impl_staticGetImplementationName();
779 : : }
780 : :
781 : : // --------------------------------------------------------------------------------
782 : 0 : ::sal_Bool SAL_CALL OLESimpleStorage::supportsService( const ::rtl::OUString& ServiceName )
783 : : throw ( uno::RuntimeException )
784 : : {
785 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
786 : :
787 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
788 [ # # ][ # # ]: 0 : if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
789 : 0 : return sal_True;
790 : :
791 [ # # ]: 0 : return sal_False;
792 : : }
793 : :
794 : : // --------------------------------------------------------------------------------
795 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getSupportedServiceNames()
796 : : throw ( uno::RuntimeException )
797 : : {
798 : 0 : return impl_staticGetSupportedServiceNames();
799 : : }
800 : :
801 : :
802 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|