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