LCOV - code coverage report
Current view: top level - libreoffice/sot/source/unoolestorage - xolesimplestorage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 178 380 46.8 %
Date: 2012-12-17 Functions: 17 29 58.6 %
Legend: Lines: hit not hit

          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          54 : 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          54 : , m_bNoTemporaryCopy( sal_False )
      52             : {
      53             :     OSL_ENSURE( m_xFactory.is(), "No factory is provided on creation!\n" );
      54          54 :     if ( !m_xFactory.is() )
      55           0 :         throw uno::RuntimeException();
      56          54 : }
      57             : 
      58             : // --------------------------------------------------------------------------------
      59         162 : OLESimpleStorage::~OLESimpleStorage()
      60             : {
      61             :     try {
      62          54 :         m_refCount++;
      63          54 :         dispose();
      64           0 :     } catch( uno::Exception& )
      65             :     {}
      66             : 
      67          54 :     if ( m_pListenersContainer )
      68             :     {
      69           0 :         delete m_pListenersContainer;
      70           0 :         m_pListenersContainer = NULL;
      71             :     }
      72         108 : }
      73             : 
      74             : //-------------------------------------------------------------------------
      75           6 : uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::impl_staticGetSupportedServiceNames()
      76             : {
      77           6 :     uno::Sequence< ::rtl::OUString > aRet(1);
      78           6 :     aRet[0] = ::rtl::OUString("com.sun.star.embed.OLESimpleStorage");
      79           6 :     return aRet;
      80             : }
      81             : 
      82             : //-------------------------------------------------------------------------
      83          12 : ::rtl::OUString SAL_CALL OLESimpleStorage::impl_staticGetImplementationName()
      84             : {
      85          12 :     return ::rtl::OUString("com.sun.star.comp.embed.OLESimpleStorage");
      86             : }
      87             : 
      88             : //-------------------------------------------------------------------------
      89          54 : uno::Reference< uno::XInterface > SAL_CALL OLESimpleStorage::impl_staticCreateSelfInstance(
      90             :             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
      91             : {
      92          54 :     return uno::Reference< uno::XInterface >( *new OLESimpleStorage( xServiceManager ) );
      93             : }
      94             : 
      95             : //-------------------------------------------------------------------------
      96          20 : void OLESimpleStorage::UpdateOriginal_Impl()
      97             : {
      98          20 :     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          20 : }
     120             : 
     121             : //-------------------------------------------------------------------------
     122         288 : void OLESimpleStorage::InsertInputStreamToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInputStream )
     123             :     throw ( uno::Exception )
     124             : {
     125         288 :     if ( !pStorage || aName.isEmpty() || !xInputStream.is() )
     126           0 :         throw uno::RuntimeException();
     127             : 
     128         288 :     if ( pStorage->IsContained( aName ) )
     129           0 :         throw container::ElementExistException(); // TODO:
     130             : 
     131         288 :     BaseStorageStream* pNewStream = pStorage->OpenStream( aName );
     132         288 :     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         288 :         uno::Sequence< sal_Int8 > aData( nBytesCount );
     143         288 :         sal_Int32 nRead = 0;
     144         288 :         do
     145             :         {
     146         288 :             nRead = xInputStream->readBytes( aData, nBytesCount );
     147         288 :             if ( nRead < nBytesCount )
     148         288 :                 aData.realloc( nRead );
     149             : 
     150         288 :             sal_Int32 nWritten = pNewStream->Write( aData.getArray(), nRead );
     151         288 :             if ( nWritten < nRead )
     152           0 :                 throw io::IOException();
     153         288 :         } 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         288 :     DELETEZ( pNewStream );
     164         288 : }
     165             : 
     166             : //-------------------------------------------------------------------------
     167          10 : void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, ::rtl::OUString aName, const uno::Reference< container::XNameAccess >& xNameAccess )
     168             :     throw ( uno::Exception )
     169             : {
     170          10 :     if ( !pStorage || aName.isEmpty() || !xNameAccess.is() )
     171           0 :         throw uno::RuntimeException();
     172             : 
     173          10 :     if ( pStorage->IsContained( aName ) )
     174           0 :         throw container::ElementExistException(); // TODO:
     175             : 
     176          10 :     BaseStorage* pNewStorage = pStorage->OpenStorage( aName );
     177          10 :     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          10 :         uno::Sequence< ::rtl::OUString > aElements = xNameAccess->getElementNames();
     188         144 :         for ( sal_Int32 nInd = 0; nInd < aElements.getLength(); nInd++ )
     189             :         {
     190         134 :             uno::Reference< io::XInputStream > xInputStream;
     191         134 :             uno::Reference< container::XNameAccess > xSubNameAccess;
     192         134 :             uno::Any aAny = xNameAccess->getByName( aElements[nInd] );
     193         134 :             if ( aAny >>= xInputStream )
     194         134 :                 InsertInputStreamToStorage_Impl( pNewStorage, aElements[nInd], xInputStream );
     195           0 :             else if ( aAny >>= xSubNameAccess )
     196           0 :                 InsertNameAccessToStorage_Impl( pNewStorage, aElements[nInd], xSubNameAccess );
     197         144 :         }
     198             :     }
     199           0 :     catch( uno::Exception& )
     200             :     {
     201           0 :         DELETEZ( pNewStorage );
     202           0 :         pStorage->Remove( aName );
     203             : 
     204           0 :         throw;
     205             :     }
     206             : 
     207          10 :     DELETEZ( pNewStorage );
     208          10 : }
     209             : 
     210             : //____________________________________________________________________________________________________
     211             : //  XInitialization
     212             : //____________________________________________________________________________________________________
     213             : 
     214          54 : void SAL_CALL OLESimpleStorage::initialize( const uno::Sequence< uno::Any >& aArguments )
     215             :         throw ( uno::Exception,
     216             :                 uno::RuntimeException)
     217             : {
     218          54 :     if ( m_pStream || m_pStorage )
     219           0 :         throw io::IOException(); // TODO: already initilized
     220             : 
     221          54 :     sal_Int32 nArgNum = aArguments.getLength();
     222             :     OSL_ENSURE( nArgNum >= 1 && nArgNum <= 2, "Wrong parameter number" );
     223             : 
     224          54 :     if ( nArgNum < 1 || nArgNum > 2 )
     225           0 :         throw lang::IllegalArgumentException(); // TODO:
     226             : 
     227          54 :     uno::Reference< io::XStream > xStream;
     228          54 :     uno::Reference< io::XInputStream > xInputStream;
     229          54 :     if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) )
     230           0 :         throw lang::IllegalArgumentException(); // TODO:
     231             : 
     232          54 :     if ( nArgNum == 2 )
     233             :     {
     234          54 :         if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) )
     235           0 :             throw lang::IllegalArgumentException(); // TODO:
     236             :     }
     237             : 
     238          54 :     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          54 :         if ( xInputStream.is() )
     244             :         {
     245             :             // the stream must be seekable for direct access
     246          12 :             uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
     247          12 :             m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, sal_False );
     248             :         }
     249          42 :         else if ( xStream.is() )
     250             :         {
     251             :             // the stream must be seekable for direct access
     252          42 :             uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW );
     253          42 :             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          54 :     if ( !m_pStream || m_pStream->GetError() )
     307           0 :         throw io::IOException(); // TODO
     308             : 
     309          54 :     m_pStorage = new Storage( *m_pStream, sal_False );
     310          54 : }
     311             : 
     312             : 
     313             : //____________________________________________________________________________________________________
     314             : //  XNameContainer
     315             : //____________________________________________________________________________________________________
     316             : 
     317             : // --------------------------------------------------------------------------------
     318         164 : 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         164 :     ::osl::MutexGuard aGuard( m_aMutex );
     325             : 
     326         164 :     if ( m_bDisposed )
     327           0 :         throw lang::DisposedException();
     328             : 
     329         164 :       if ( !m_pStorage )
     330           0 :         throw uno::RuntimeException();
     331             : 
     332         164 :     uno::Reference< io::XStream > xStream;
     333         164 :     uno::Reference< io::XInputStream > xInputStream;
     334         164 :     uno::Reference< container::XNameAccess > xNameAccess;
     335             : 
     336             :     try
     337             :     {
     338         164 :         if ( !m_bNoTemporaryCopy && !m_xStream.is() )
     339           0 :             throw io::IOException(); // TODO
     340             : 
     341         164 :         if ( aElement >>= xStream )
     342         154 :             xInputStream = xStream->getInputStream();
     343          10 :         else if ( !( aElement >>= xInputStream ) && !( aElement >>= xNameAccess ) )
     344           0 :             throw lang::IllegalArgumentException(); // TODO:
     345             : 
     346         164 :         if ( xInputStream.is() )
     347         154 :             InsertInputStreamToStorage_Impl( m_pStorage, aName, xInputStream );
     348          10 :         else if ( xNameAccess.is() )
     349          10 :             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         164 :     }
     367         164 : }
     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         564 : uno::Any SAL_CALL OLESimpleStorage::getByName( const ::rtl::OUString& aName )
     428             :         throw ( container::NoSuchElementException,
     429             :                 lang::WrappedTargetException,
     430             :                 uno::RuntimeException )
     431             : {
     432         564 :     ::osl::MutexGuard aGuard( m_aMutex );
     433             : 
     434         564 :     if ( m_bDisposed )
     435           0 :         throw lang::DisposedException();
     436             : 
     437         564 :       if ( !m_pStorage )
     438           0 :         throw uno::RuntimeException();
     439             : 
     440         564 :     if ( !m_pStorage->IsContained( aName ) )
     441          10 :         throw container::NoSuchElementException(); // TODO:
     442             : 
     443         554 :     uno::Any aResult;
     444             : 
     445             :     uno::Reference< io::XStream > xTempFile(
     446             :         io::TempFile::create(comphelper::getComponentContext(m_xFactory)),
     447         554 :         uno::UNO_QUERY );
     448         554 :     uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW );
     449         554 :     uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream();
     450         554 :     uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream();
     451         554 :     if ( !xOutputStream.is() || !xInputStream.is() )
     452           0 :         throw uno::RuntimeException();
     453             : 
     454         554 :     if ( m_pStorage->IsStorage( aName ) )
     455             :     {
     456          22 :         BaseStorage* pStrg = m_pStorage->OpenStorage( aName );
     457          22 :         m_pStorage->ResetError();
     458          22 :         if ( !pStrg )
     459           0 :             throw io::IOException();
     460             : 
     461          22 :         SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, sal_False ); // do not close the original stream
     462          22 :         if ( !pStream )
     463           0 :             throw uno::RuntimeException();
     464             : 
     465          22 :         BaseStorage* pNewStor = new Storage( *pStream, sal_False );
     466             :         sal_Bool bSuccess =
     467          22 :             ( pStrg->CopyTo( pNewStor ) && pNewStor->Commit() && !pNewStor->GetError() && !pStrg->GetError() );
     468             : 
     469          22 :         DELETEZ( pNewStor );
     470          22 :         DELETEZ( pStrg );
     471          22 :         DELETEZ( pStream );
     472             : 
     473          22 :         if ( !bSuccess )
     474           0 :             throw uno::RuntimeException();
     475             : 
     476          22 :         uno::Sequence< uno::Any > aArgs( 2 );
     477          22 :         aArgs[0] <<= xInputStream; // allow readonly access only
     478          22 :         aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
     479             : 
     480             :         uno::Reference< container::XNameContainer > xResultNameContainer(
     481          22 :             m_xFactory->createInstanceWithArguments(
     482             :                     ::rtl::OUString("com.sun.star.embed.OLESimpleStorage"),
     483          22 :                     aArgs ),
     484          22 :             uno::UNO_QUERY_THROW );
     485             : 
     486          22 :         aResult <<= xResultNameContainer;
     487             :     }
     488             :     else
     489             :     {
     490         532 :         BaseStorageStream* pStream = m_pStorage->OpenStream( aName, STREAM_READ | STREAM_SHARE_DENYALL | STREAM_NOCREATE );
     491         532 :         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         532 :             uno::Sequence< sal_Int8 > aData( nBytesCount );
     501         532 :             sal_Int32 nSize = nBytesCount;
     502         532 :             sal_Int32 nRead = 0;
     503        1596 :             while( 0 != ( nRead = pStream->Read( aData.getArray(), nSize ) ) )
     504             :             {
     505         532 :                 if ( nRead < nSize )
     506             :                 {
     507         532 :                     nSize = nRead;
     508         532 :                     aData.realloc( nSize );
     509             :                 }
     510             : 
     511         532 :                 xOutputStream->writeBytes( aData );
     512             :             }
     513             : 
     514         532 :             if ( pStream->GetError() )
     515           0 :                 throw io::IOException(); // TODO
     516             : 
     517         532 :             xOutputStream->closeOutput();
     518         532 :             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         532 :         DELETEZ( pStream );
     532             : 
     533         532 :         aResult <<= xInputStream;
     534             :     }
     535             : 
     536         554 :     return aResult;
     537             : }
     538             : 
     539             : // --------------------------------------------------------------------------------
     540          40 : uno::Sequence< ::rtl::OUString > SAL_CALL OLESimpleStorage::getElementNames()
     541             :         throw ( uno::RuntimeException )
     542             : {
     543          40 :     ::osl::MutexGuard aGuard( m_aMutex );
     544             : 
     545          40 :     if ( m_bDisposed )
     546           0 :         throw lang::DisposedException();
     547             : 
     548          40 :       if ( !m_pStorage )
     549           0 :         throw uno::RuntimeException();
     550             : 
     551          40 :     SvStorageInfoList aList;
     552          40 :     m_pStorage->FillInfoList( &aList );
     553             : 
     554          40 :     if ( m_pStorage->GetError() )
     555             :     {
     556           0 :         m_pStorage->ResetError();
     557           0 :         throw uno::RuntimeException(); // TODO:
     558             :     }
     559             : 
     560          40 :     uno::Sequence< ::rtl::OUString > aSeq( aList.size() );
     561         368 :     for ( sal_uInt32 nInd = 0; nInd < aList.size(); nInd++ )
     562         328 :         aSeq[nInd] = aList[nInd].GetName();
     563             : 
     564          40 :     return aSeq;
     565             : }
     566             : 
     567             : // --------------------------------------------------------------------------------
     568         164 : sal_Bool SAL_CALL OLESimpleStorage::hasByName( const ::rtl::OUString& aName )
     569             :         throw ( uno::RuntimeException )
     570             : {
     571         164 :     ::osl::MutexGuard aGuard( m_aMutex );
     572             : 
     573         164 :     if ( m_bDisposed )
     574           0 :         throw lang::DisposedException();
     575             : 
     576         164 :      if ( !m_pStorage )
     577           0 :         throw uno::RuntimeException();
     578             : 
     579         164 :     sal_Bool bResult = m_pStorage->IsContained( aName );
     580             : 
     581         164 :     if ( m_pStorage->GetError() )
     582             :     {
     583           0 :         m_pStorage->ResetError();
     584           0 :         throw uno::RuntimeException(); // TODO:
     585             :     }
     586             : 
     587         164 :     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         194 : sal_Bool SAL_CALL OLESimpleStorage::hasElements()
     604             :         throw ( uno::RuntimeException )
     605             : {
     606         194 :     ::osl::MutexGuard aGuard( m_aMutex );
     607             : 
     608         194 :     if ( m_bDisposed )
     609           0 :         throw lang::DisposedException();
     610             : 
     611         194 :       if ( !m_pStorage )
     612           0 :         throw uno::RuntimeException();
     613             : 
     614         194 :     SvStorageInfoList aList;
     615         194 :     m_pStorage->FillInfoList( &aList );
     616             : 
     617         194 :     if ( m_pStorage->GetError() )
     618             :     {
     619           0 :         m_pStorage->ResetError();
     620           0 :         throw uno::RuntimeException(); // TODO:
     621             :     }
     622             : 
     623         194 :     return ( aList.size() != 0 );
     624             : }
     625             : 
     626             : //____________________________________________________________________________________________________
     627             : //  XComponent
     628             : //____________________________________________________________________________________________________
     629             : 
     630             : // --------------------------------------------------------------------------------
     631          54 : void SAL_CALL OLESimpleStorage::dispose()
     632             :         throw ( uno::RuntimeException )
     633             : {
     634          54 :     ::osl::MutexGuard aGuard( m_aMutex );
     635             : 
     636          54 :     if ( m_bDisposed )
     637           0 :         throw lang::DisposedException();
     638             : 
     639          54 :     if ( m_pListenersContainer )
     640             :     {
     641           0 :            lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
     642           0 :         m_pListenersContainer->disposeAndClear( aSource );
     643             :     }
     644             : 
     645          54 :     DELETEZ( m_pStorage );
     646          54 :     DELETEZ( m_pStream );
     647             : 
     648          54 :     m_xStream = uno::Reference< io::XStream >();
     649          54 :     m_xTempStream = uno::Reference< io::XStream >();
     650             : 
     651          54 :     m_bDisposed = sal_True;
     652          54 : }
     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          20 : 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          20 :     ::osl::MutexGuard aGuard( m_aMutex );
     695             : 
     696          20 :     if ( m_bDisposed )
     697           0 :         throw lang::DisposedException();
     698             : 
     699          20 :      if ( !m_pStorage )
     700           0 :         throw uno::RuntimeException();
     701             : 
     702          20 :     if ( !m_bNoTemporaryCopy && !m_xStream.is() )
     703           0 :         throw io::IOException(); // TODO
     704             : 
     705          20 :     if ( !m_pStorage->Commit() || m_pStorage->GetError() )
     706             :     {
     707           0 :         m_pStorage->ResetError();
     708           0 :         throw io::IOException(); // TODO
     709             :     }
     710             : 
     711          20 :     UpdateOriginal_Impl();
     712          20 : }
     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: */

Generated by: LCOV version 1.10