LCOV - code coverage report
Current view: top level - svl/source/fsstor - fsstorage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 151 651 23.2 %
Date: 2014-11-03 Functions: 17 47 36.2 %
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/beans/PropertyValue.hpp>
      21             : #include <com/sun/star/embed/ElementModes.hpp>
      22             : #include <com/sun/star/embed/XTransactedObject.hpp>
      23             : #include <com/sun/star/ucb/NameClash.hpp>
      24             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      25             : #include <com/sun/star/ucb/XProgressHandler.hpp>
      26             : #include <com/sun/star/ucb/XContentAccess.hpp>
      27             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      28             : 
      29             : #include <com/sun/star/ucb/InteractiveIOException.hpp>
      30             : #include <com/sun/star/ucb/IOErrorCode.hpp>
      31             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      32             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      33             : #include <com/sun/star/container/XNamed.hpp>
      34             : #include <com/sun/star/util/XChangesBatch.hpp>
      35             : #include <com/sun/star/util/XCloneable.hpp>
      36             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      37             : #include <com/sun/star/lang/XComponent.hpp>
      38             : #include <com/sun/star/lang/DisposedException.hpp>
      39             : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
      40             : #include <com/sun/star/io/IOException.hpp>
      41             : #include <com/sun/star/io/XTruncate.hpp>
      42             : #include <com/sun/star/io/TempFile.hpp>
      43             : #include <com/sun/star/sdbc/XResultSet.hpp>
      44             : #include <com/sun/star/sdbc/XRow.hpp>
      45             : 
      46             : 
      47             : #include <comphelper/processfactory.hxx>
      48             : #include <comphelper/storagehelper.hxx>
      49             : #include <cppuhelper/typeprovider.hxx>
      50             : #include <cppuhelper/exc_hlp.hxx>
      51             : 
      52             : #include <tools/urlobj.hxx>
      53             : #include <unotools/ucbhelper.hxx>
      54             : #include <unotools/ucbstreamhelper.hxx>
      55             : #include <unotools/streamwrap.hxx>
      56             : #include <ucbhelper/fileidentifierconverter.hxx>
      57             : #include <ucbhelper/content.hxx>
      58             : 
      59             : #include "fsstorage.hxx"
      60             : #include "oinputstreamcontainer.hxx"
      61             : #include "ostreamcontainer.hxx"
      62             : 
      63             : using namespace ::com::sun::star;
      64             : 
      65             : 
      66             : // TODO: move to a standard helper
      67           0 : bool isLocalFile_Impl( const OUString& aURL )
      68             : {
      69           0 :     OUString aSystemPath;
      70             : 
      71             :     try
      72             :     {
      73           0 :         aSystemPath = ::ucbhelper::getSystemPathFromFileURL(
      74             :             ucb::UniversalContentBroker::create(
      75             :                 comphelper::getProcessComponentContext() ),
      76           0 :             aURL );
      77             :     }
      78           0 :     catch ( uno::Exception& )
      79             :     {
      80             :     }
      81             : 
      82           0 :     return ( !aSystemPath.isEmpty() );
      83             : }
      84             : 
      85             : 
      86             : 
      87             : struct FSStorage_Impl
      88             : {
      89             :     OUString m_aURL;
      90             : 
      91             :     ::ucbhelper::Content* m_pContent;
      92             :     sal_Int32 m_nMode;
      93             : 
      94             :     ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
      95             :     ::cppu::OTypeCollection* m_pTypeCollection;
      96             : 
      97             :     uno::Reference< uno::XComponentContext > m_xContext;
      98             : 
      99             : 
     100        3204 :     FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< uno::XComponentContext > xContext )
     101        3204 :     : m_aURL( aContent.getURL() )
     102        3204 :     , m_pContent( new ::ucbhelper::Content( aContent ) )
     103             :     , m_nMode( nMode )
     104             :     , m_pListenersContainer( NULL )
     105             :     , m_pTypeCollection( NULL )
     106        6408 :     , m_xContext( xContext )
     107             :     {
     108             :         OSL_ENSURE( !m_aURL.isEmpty(), "The URL must not be empty" );
     109        3204 :     }
     110             : 
     111             :     ~FSStorage_Impl();
     112             : };
     113             : 
     114             : 
     115        6204 : FSStorage_Impl::~FSStorage_Impl()
     116             : {
     117        3102 :     if ( m_pListenersContainer )
     118           0 :         delete m_pListenersContainer;
     119        3102 :     if ( m_pTypeCollection )
     120           0 :         delete m_pTypeCollection;
     121        3102 :     if ( m_pContent )
     122        3102 :         delete m_pContent;
     123        3102 : }
     124             : 
     125        3204 : FSStorage::FSStorage( const ::ucbhelper::Content& aContent,
     126             :                     sal_Int32 nMode,
     127             :                     uno::Reference< uno::XComponentContext > xContext )
     128        3204 : : m_pImpl( new FSStorage_Impl( aContent, nMode, xContext ) )
     129             : {
     130             :     // TODO: use properties
     131        3204 :     if ( !xContext.is() )
     132           0 :         throw uno::RuntimeException();
     133             : 
     134        3204 :     GetContent();
     135        3204 : }
     136             : 
     137        9306 : FSStorage::~FSStorage()
     138             : {
     139             :     {
     140        3102 :         ::osl::MutexGuard aGuard( m_aMutex );
     141        3102 :         m_refCount++; // to call dispose
     142             :         try {
     143        3102 :             dispose();
     144             :         }
     145           0 :         catch( uno::RuntimeException& )
     146        3102 :         {}
     147             :     }
     148        6204 : }
     149             : 
     150         674 : bool FSStorage::MakeFolderNoUI( const OUString& rFolder )
     151             : {
     152         674 :     INetURLObject aURL( rFolder );
     153        1348 :     OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     154         674 :     aURL.removeSegment();
     155        1348 :     ::ucbhelper::Content aParent;
     156        1348 :     ::ucbhelper::Content aResultContent;
     157             : 
     158        1348 :        if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ),
     159             :                                  uno::Reference< ucb::XCommandEnvironment >(),
     160             :                                  comphelper::getProcessComponentContext(),
     161        1348 :                                  aParent ) )
     162         674 :         return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, false );
     163             : 
     164         674 :     return false;
     165             : }
     166             : 
     167      186672 : ::ucbhelper::Content* FSStorage::GetContent()
     168             : {
     169      186672 :     ::osl::MutexGuard aGuard( m_aMutex );
     170      186672 :     if ( !m_pImpl->m_pContent )
     171             :     {
     172           0 :         uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     173             : 
     174             :         try
     175             :         {
     176           0 :             m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv, comphelper::getProcessComponentContext() );
     177             :         }
     178           0 :         catch( uno::Exception& )
     179             :         {
     180           0 :         }
     181             :     }
     182             : 
     183      186672 :     return m_pImpl->m_pContent;
     184             : }
     185             : 
     186           0 : void FSStorage::CopyStreamToSubStream( const OUString& aSourceURL,
     187             :                                         const uno::Reference< embed::XStorage >& xDest,
     188             :                                         const OUString& aNewEntryName )
     189             : {
     190           0 :     if ( !xDest.is() )
     191           0 :         throw uno::RuntimeException();
     192             : 
     193           0 :     uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     194           0 :     ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() );
     195           0 :     uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream();
     196             : 
     197           0 :     if ( !xSourceInput.is() )
     198           0 :         throw io::IOException(); // TODO: error handling
     199             : 
     200           0 :     uno::Reference< io::XStream > xSubStream = xDest->openStreamElement(
     201             :                                                 aNewEntryName,
     202           0 :                                                 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
     203           0 :     if ( !xSubStream.is() )
     204           0 :         throw uno::RuntimeException();
     205             : 
     206           0 :     uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream();
     207           0 :     if ( !xDestOutput.is() )
     208           0 :         throw uno::RuntimeException();
     209             : 
     210           0 :     ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput );
     211           0 :     xDestOutput->closeOutput();
     212           0 : }
     213             : 
     214           0 : void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest )
     215             : {
     216           0 :     if ( !pContent )
     217           0 :         throw uno::RuntimeException();
     218             : 
     219             :     // get list of contents of the Content
     220             :     // create cursor for access to children
     221           0 :     uno::Sequence< OUString > aProps( 2 );
     222           0 :     OUString* pProps = aProps.getArray();
     223           0 :     pProps[0] = "TargetURL";
     224           0 :     pProps[1] = "IsFolder";
     225           0 :     ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
     226             : 
     227             :     try
     228             :     {
     229           0 :         uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude );
     230           0 :         uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
     231           0 :         uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
     232           0 :         if ( xResultSet.is() )
     233             :         {
     234             :             // go through the list: insert files as streams, insert folders as substorages using recursion
     235           0 :             while ( xResultSet->next() )
     236             :             {
     237           0 :                 OUString aSourceURL( xRow->getString( 1 ) );
     238           0 :                 bool bIsFolder( xRow->getBoolean(2) );
     239             : 
     240             :                 // TODO/LATER: not sure whether the entry name must be encoded
     241             :                 OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT,
     242             :                                                                                     true,
     243           0 :                                                                                     INetURLObject::NO_DECODE ) );
     244           0 :                 if ( bIsFolder )
     245             :                 {
     246           0 :                     uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName,
     247           0 :                                                                                                 embed::ElementModes::READWRITE );
     248           0 :                     if ( !xSubStorage.is() )
     249           0 :                         throw uno::RuntimeException();
     250             : 
     251           0 :                     uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     252           0 :                     ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() );
     253           0 :                     CopyContentToStorage_Impl( &aSourceContent, xSubStorage );
     254             :                 }
     255             :                 else
     256             :                 {
     257           0 :                     CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName );
     258             :                 }
     259           0 :             }
     260             :         }
     261             : 
     262           0 :         uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY );
     263           0 :         if ( xTransact.is() )
     264           0 :             xTransact->commit();
     265             :     }
     266           0 :     catch( ucb::InteractiveIOException& r )
     267             :     {
     268           0 :         if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
     269             :             OSL_FAIL( "The folder does not exist!\n" );
     270             :         else
     271           0 :             throw;
     272           0 :     }
     273           0 : }
     274             : 
     275             : //  XInterface
     276             : 
     277        7039 : uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType )
     278             :         throw( uno::RuntimeException, std::exception )
     279             : {
     280        7039 :     uno::Any aReturn;
     281       14078 :     aReturn <<= ::cppu::queryInterface
     282             :                 (   rType
     283             :                 ,   static_cast<lang::XTypeProvider*> ( this )
     284             :                 ,   static_cast<embed::XStorage*> ( this )
     285             :                 ,   static_cast<embed::XHierarchicalStorageAccess*> ( this )
     286             :                 ,   static_cast<container::XNameAccess*> ( this )
     287             :                 ,   static_cast<container::XElementAccess*> ( this )
     288             :                 ,   static_cast<lang::XComponent*> ( this )
     289        7039 :                 ,   static_cast<beans::XPropertySet*> ( this ) );
     290             : 
     291        7039 :     if ( aReturn.hasValue() )
     292        5024 :         return aReturn ;
     293             : 
     294        2015 :     return OWeakObject::queryInterface( rType );
     295             : }
     296             : 
     297      137260 : void SAL_CALL FSStorage::acquire() throw()
     298             : {
     299      137260 :     OWeakObject::acquire();
     300      137260 : }
     301             : 
     302      137078 : void SAL_CALL FSStorage::release() throw()
     303             : {
     304      137078 :     OWeakObject::release();
     305      137078 : }
     306             : 
     307             : //  XTypeProvider
     308             : 
     309           0 : uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes()
     310             :         throw( uno::RuntimeException, std::exception )
     311             : {
     312           0 :     if ( m_pImpl->m_pTypeCollection == NULL )
     313             :     {
     314           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     315             : 
     316           0 :         if ( m_pImpl->m_pTypeCollection == NULL )
     317             :         {
     318             :             m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection
     319             :                                 (   cppu::UnoType<lang::XTypeProvider>::get()
     320             :                                 ,   cppu::UnoType<embed::XStorage>::get()
     321             :                                 ,   cppu::UnoType<embed::XHierarchicalStorageAccess>::get()
     322           0 :                                 ,   cppu::UnoType<beans::XPropertySet>::get());
     323           0 :         }
     324             :     }
     325             : 
     326           0 :     return m_pImpl->m_pTypeCollection->getTypes() ;
     327             : }
     328             : 
     329           0 : uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId()
     330             :         throw( uno::RuntimeException, std::exception )
     331             : {
     332           0 :     return css::uno::Sequence<sal_Int8>();
     333             : }
     334             : 
     335             : //  XStorage
     336             : 
     337           0 : void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
     338             :         throw ( embed::InvalidStorageException,
     339             :                 io::IOException,
     340             :                 lang::IllegalArgumentException,
     341             :                 embed::StorageWrappedTargetException,
     342             :                 uno::RuntimeException, std::exception )
     343             : {
     344           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     345             : 
     346           0 :     if ( !m_pImpl )
     347           0 :         throw lang::DisposedException();
     348             : 
     349           0 :     if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
     350           0 :         throw lang::IllegalArgumentException(); // TODO:
     351             : 
     352           0 :     if ( !GetContent() )
     353           0 :         throw io::IOException(); // TODO: error handling
     354             : 
     355             :     try
     356             :     {
     357           0 :         CopyContentToStorage_Impl( GetContent(), xDest );
     358             :     }
     359           0 :     catch( embed::InvalidStorageException& )
     360             :     {
     361           0 :         throw;
     362             :     }
     363           0 :     catch( lang::IllegalArgumentException& )
     364             :     {
     365           0 :         throw;
     366             :     }
     367           0 :     catch( embed::StorageWrappedTargetException& )
     368             :     {
     369           0 :         throw;
     370             :     }
     371           0 :     catch( io::IOException& )
     372             :     {
     373           0 :         throw;
     374             :     }
     375           0 :     catch( uno::RuntimeException& )
     376             :     {
     377           0 :         throw;
     378             :     }
     379           0 :     catch( uno::Exception& )
     380             :     {
     381           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     382             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     383             :                                                  uno::Reference< io::XInputStream >(),
     384           0 :                                                  aCaught );
     385           0 :     }
     386           0 : }
     387             : 
     388         536 : uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement(
     389             :     const OUString& aStreamName, sal_Int32 nOpenMode )
     390             :         throw ( embed::InvalidStorageException,
     391             :                 lang::IllegalArgumentException,
     392             :                 packages::WrongPasswordException,
     393             :                 io::IOException,
     394             :                 embed::StorageWrappedTargetException,
     395             :                 uno::RuntimeException, std::exception )
     396             : {
     397         536 :     ::osl::MutexGuard aGuard( m_aMutex );
     398             : 
     399         536 :     if ( !m_pImpl )
     400           0 :         throw lang::DisposedException();
     401             : 
     402         536 :     if ( !GetContent() )
     403           0 :         throw io::IOException(); // TODO: error handling
     404             : 
     405             :     // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
     406        1072 :     INetURLObject aFileURL( m_pImpl->m_aURL );
     407         536 :     aFileURL.Append( aStreamName );
     408             : 
     409         536 :     if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     410           0 :         throw io::IOException();
     411             : 
     412        2144 :     if ( ( nOpenMode & embed::ElementModes::NOCREATE )
     413        1608 :       && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     414           0 :         throw io::IOException(); // TODO:
     415             : 
     416        1072 :     uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
     417         536 :     uno::Reference< io::XStream > xResult;
     418             :     try
     419             :     {
     420         536 :         if ( nOpenMode & embed::ElementModes::WRITE )
     421             :         {
     422           0 :             if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     423             :             {
     424             :                 uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
     425           0 :                     ucb::SimpleFileAccess::create( m_pImpl->m_xContext ) );
     426           0 :                 xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
     427             :             }
     428             :             else
     429             :             {
     430             :                 // TODO: test whether it really works for http and fwp
     431             :                 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
     432           0 :                                                                           STREAM_STD_WRITE );
     433           0 :                 if ( pStream )
     434             :                 {
     435           0 :                     if ( !pStream->GetError() )
     436           0 :                         xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
     437             :                     else
     438           0 :                         delete pStream;
     439             :                 }
     440             :             }
     441             : 
     442           0 :             if ( !xResult.is() )
     443           0 :                 throw io::IOException();
     444             : 
     445           0 :             if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
     446             :             {
     447           0 :                 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
     448           0 :                 xTrunc->truncate();
     449             :             }
     450             :         }
     451             :         else
     452             :         {
     453        1608 :             if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
     454        2144 :               || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     455         108 :                 throw io::IOException(); // TODO: access denied
     456             : 
     457         428 :             ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
     458         856 :             uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
     459         856 :             xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
     460             :         }
     461             :     }
     462           0 :     catch( embed::InvalidStorageException& )
     463             :     {
     464           0 :         throw;
     465             :     }
     466           0 :     catch( lang::IllegalArgumentException& )
     467             :     {
     468           0 :         throw;
     469             :     }
     470           0 :     catch( packages::WrongPasswordException& )
     471             :     {
     472           0 :         throw;
     473             :     }
     474           0 :     catch( embed::StorageWrappedTargetException& )
     475             :     {
     476           0 :         throw;
     477             :     }
     478         216 :     catch( io::IOException& )
     479             :     {
     480         108 :         throw;
     481             :     }
     482           0 :     catch( uno::RuntimeException& )
     483             :     {
     484           0 :         throw;
     485             :     }
     486           0 :     catch( uno::Exception& )
     487             :     {
     488           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     489             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     490             :                                                  uno::Reference< io::XInputStream >(),
     491           0 :                                                  aCaught );
     492             :     }
     493             : 
     494         964 :     return xResult;
     495             : }
     496             : 
     497           0 : uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement(
     498             :     const OUString&, sal_Int32, const OUString& )
     499             :         throw ( embed::InvalidStorageException,
     500             :                 lang::IllegalArgumentException,
     501             :                 packages::NoEncryptionException,
     502             :                 packages::WrongPasswordException,
     503             :                 io::IOException,
     504             :                 embed::StorageWrappedTargetException,
     505             :                 uno::RuntimeException, std::exception )
     506             : {
     507           0 :     throw packages::NoEncryptionException();
     508             : }
     509             : 
     510        2914 : uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement(
     511             :             const OUString& aStorName, sal_Int32 nStorageMode )
     512             :         throw ( embed::InvalidStorageException,
     513             :                 lang::IllegalArgumentException,
     514             :                 io::IOException,
     515             :                 embed::StorageWrappedTargetException,
     516             :                 uno::RuntimeException, std::exception )
     517             : {
     518        2914 :     ::osl::MutexGuard aGuard( m_aMutex );
     519             : 
     520        2914 :     if ( !m_pImpl )
     521           0 :         throw lang::DisposedException();
     522             : 
     523        2914 :     if ( !GetContent() )
     524           0 :         throw io::IOException(); // TODO: error handling
     525             : 
     526        2914 :     if ( ( nStorageMode & embed::ElementModes::WRITE )
     527        1350 :       && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) )
     528           0 :           throw io::IOException(); // TODO: error handling
     529             : 
     530             :     // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
     531        5828 :     INetURLObject aFolderURL( m_pImpl->m_aURL );
     532        2914 :     aFolderURL.Append( aStorName );
     533             : 
     534        2914 :     bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
     535        2914 :     if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     536           0 :         throw io::IOException(); // TODO:
     537             : 
     538        2914 :     if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists )
     539          14 :         throw io::IOException(); // TODO:
     540             : 
     541        5800 :     uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
     542        2900 :     uno::Reference< embed::XStorage > xResult;
     543             :     try
     544             :     {
     545        2900 :         if ( nStorageMode & embed::ElementModes::WRITE )
     546             :         {
     547        1350 :             if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists )
     548             :             {
     549           0 :                 ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
     550             :                 bFolderExists =
     551           0 :                     MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); // TODO: not atomic :(
     552             :             }
     553        1350 :             else if ( !bFolderExists )
     554             :             {
     555             :                 bFolderExists =
     556         516 :                     MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); // TODO: not atomic :(
     557             :             }
     558             :         }
     559        1550 :         else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
     560           0 :             throw io::IOException(); // TODO: access denied
     561             : 
     562        2900 :         if ( !bFolderExists )
     563          12 :             throw io::IOException(); // there is no such folder
     564             : 
     565        2888 :         ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
     566        5776 :         xResult = uno::Reference< embed::XStorage >(
     567             :                             static_cast< OWeakObject* >( new FSStorage( aResultContent,
     568             :                                                                         nStorageMode,
     569        5776 :                                                                         m_pImpl->m_xContext ) ),
     570        5776 :                             uno::UNO_QUERY );
     571             :     }
     572           0 :     catch( embed::InvalidStorageException& )
     573             :     {
     574           0 :         throw;
     575             :     }
     576           0 :     catch( lang::IllegalArgumentException& )
     577             :     {
     578           0 :         throw;
     579             :     }
     580           0 :     catch( embed::StorageWrappedTargetException& )
     581             :     {
     582           0 :         throw;
     583             :     }
     584          24 :     catch( io::IOException& )
     585             :     {
     586          12 :         throw;
     587             :     }
     588           0 :     catch( uno::RuntimeException& )
     589             :     {
     590           0 :         throw;
     591             :     }
     592           0 :     catch( uno::Exception& )
     593             :     {
     594           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     595             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     596             :                                                  uno::Reference< io::XInputStream >(),
     597           0 :                                                  aCaught );
     598             :     }
     599             : 
     600        5802 :     return xResult;
     601             : }
     602             : 
     603           0 : uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const OUString& aStreamName )
     604             :         throw ( embed::InvalidStorageException,
     605             :                 lang::IllegalArgumentException,
     606             :                 packages::WrongPasswordException,
     607             :                 io::IOException,
     608             :                 embed::StorageWrappedTargetException,
     609             :                 uno::RuntimeException, std::exception )
     610             : {
     611           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     612             : 
     613           0 :     if ( !m_pImpl )
     614           0 :         throw lang::DisposedException();
     615             : 
     616           0 :     if ( !GetContent() )
     617           0 :         throw io::IOException(); // TODO: error handling
     618             : 
     619             :     // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
     620           0 :     INetURLObject aFileURL( m_pImpl->m_aURL );
     621           0 :     aFileURL.Append( aStreamName );
     622             : 
     623           0 :     uno::Reference < io::XStream > xTempResult;
     624             :     try
     625             :     {
     626           0 :         uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     627           0 :         ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
     628           0 :         uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
     629             : 
     630           0 :         xTempResult = io::TempFile::create(m_pImpl->m_xContext);
     631           0 :         uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream();
     632           0 :         uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream();
     633             : 
     634           0 :         if ( !xTempOut.is() || !xTempIn.is() )
     635           0 :             throw io::IOException();
     636             : 
     637           0 :         ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
     638           0 :         xTempOut->closeOutput();
     639             :     }
     640           0 :     catch( embed::InvalidStorageException& )
     641             :     {
     642           0 :         throw;
     643             :     }
     644           0 :     catch( lang::IllegalArgumentException& )
     645             :     {
     646           0 :         throw;
     647             :     }
     648           0 :     catch( packages::WrongPasswordException& )
     649             :     {
     650           0 :         throw;
     651             :     }
     652           0 :     catch( io::IOException& )
     653             :     {
     654           0 :         throw;
     655             :     }
     656           0 :     catch( embed::StorageWrappedTargetException& )
     657             :     {
     658           0 :         throw;
     659             :     }
     660           0 :     catch( uno::RuntimeException& )
     661             :     {
     662           0 :         throw;
     663             :     }
     664           0 :     catch( uno::Exception& )
     665             :     {
     666           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     667             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     668             :                                                  uno::Reference< io::XInputStream >(),
     669           0 :                                                  aCaught );
     670             :     }
     671             : 
     672           0 :     return xTempResult;
     673             : }
     674             : 
     675           0 : uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement(
     676             :     const OUString&,
     677             :     const OUString& )
     678             :         throw ( embed::InvalidStorageException,
     679             :                 lang::IllegalArgumentException,
     680             :                 packages::NoEncryptionException,
     681             :                 packages::WrongPasswordException,
     682             :                 io::IOException,
     683             :                 embed::StorageWrappedTargetException,
     684             :                 uno::RuntimeException, std::exception )
     685             : {
     686           0 :     throw packages::NoEncryptionException();
     687             : }
     688             : 
     689           0 : void SAL_CALL FSStorage::copyLastCommitTo(
     690             :             const uno::Reference< embed::XStorage >& xTargetStorage )
     691             :         throw ( embed::InvalidStorageException,
     692             :                 lang::IllegalArgumentException,
     693             :                 io::IOException,
     694             :                 embed::StorageWrappedTargetException,
     695             :                 uno::RuntimeException, std::exception )
     696             : {
     697           0 :     copyToStorage( xTargetStorage );
     698           0 : }
     699             : 
     700           0 : void SAL_CALL FSStorage::copyStorageElementLastCommitTo(
     701             :             const OUString& aStorName,
     702             :             const uno::Reference< embed::XStorage >& xTargetStorage )
     703             :         throw ( embed::InvalidStorageException,
     704             :                 lang::IllegalArgumentException,
     705             :                 io::IOException,
     706             :                 embed::StorageWrappedTargetException,
     707             :                 uno::RuntimeException, std::exception )
     708             : {
     709           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     710             : 
     711           0 :     if ( !m_pImpl )
     712           0 :         throw lang::DisposedException();
     713             : 
     714           0 :     uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ),
     715           0 :                                                     uno::UNO_QUERY_THROW );
     716           0 :     xSourceStor->copyToStorage( xTargetStorage );
     717           0 : }
     718             : 
     719           0 : sal_Bool SAL_CALL FSStorage::isStreamElement( const OUString& aElementName )
     720             :         throw ( embed::InvalidStorageException,
     721             :                 lang::IllegalArgumentException,
     722             :                 container::NoSuchElementException,
     723             :                 uno::RuntimeException, std::exception )
     724             : {
     725           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     726             : 
     727           0 :     if ( !m_pImpl )
     728           0 :         throw lang::DisposedException();
     729             : 
     730           0 :     if ( !GetContent() )
     731           0 :         throw embed::InvalidStorageException(); // TODO: error handling
     732             : 
     733           0 :     INetURLObject aURL( m_pImpl->m_aURL );
     734           0 :     aURL.Append( aElementName );
     735             : 
     736           0 :     return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     737             : }
     738             : 
     739           0 : sal_Bool SAL_CALL FSStorage::isStorageElement( const OUString& aElementName )
     740             :         throw ( embed::InvalidStorageException,
     741             :                 lang::IllegalArgumentException,
     742             :                 container::NoSuchElementException,
     743             :                 uno::RuntimeException, std::exception )
     744             : {
     745           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     746             : 
     747           0 :     if ( !m_pImpl )
     748           0 :         throw lang::DisposedException();
     749             : 
     750           0 :     if ( !GetContent() )
     751           0 :         throw embed::InvalidStorageException(); // TODO: error handling
     752             : 
     753           0 :     INetURLObject aURL( m_pImpl->m_aURL );
     754           0 :     aURL.Append( aElementName );
     755             : 
     756           0 :     return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     757             : }
     758             : 
     759           0 : void SAL_CALL FSStorage::removeElement( const OUString& aElementName )
     760             :         throw ( embed::InvalidStorageException,
     761             :                 lang::IllegalArgumentException,
     762             :                 container::NoSuchElementException,
     763             :                 io::IOException,
     764             :                 embed::StorageWrappedTargetException,
     765             :                 uno::RuntimeException, std::exception )
     766             : {
     767           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     768             : 
     769           0 :     if ( !m_pImpl )
     770           0 :         throw lang::DisposedException();
     771             : 
     772           0 :     if ( !GetContent() )
     773           0 :         throw io::IOException(); // TODO: error handling
     774             : 
     775           0 :     INetURLObject aURL( m_pImpl->m_aURL );
     776           0 :     aURL.Append( aElementName );
     777             : 
     778           0 :     if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
     779           0 :       && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     780           0 :         throw container::NoSuchElementException(); // TODO:
     781             : 
     782           0 :     ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     783           0 : }
     784             : 
     785           0 : void SAL_CALL FSStorage::renameElement( const OUString& aElementName, const OUString& aNewName )
     786             :         throw ( embed::InvalidStorageException,
     787             :                 lang::IllegalArgumentException,
     788             :                 container::NoSuchElementException,
     789             :                 container::ElementExistException,
     790             :                 io::IOException,
     791             :                 embed::StorageWrappedTargetException,
     792             :                 uno::RuntimeException, std::exception )
     793             : {
     794           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     795             : 
     796           0 :     if ( !m_pImpl )
     797           0 :         throw lang::DisposedException();
     798             : 
     799           0 :     if ( !GetContent() )
     800           0 :         throw io::IOException(); // TODO: error handling
     801             : 
     802           0 :     INetURLObject aOldURL( m_pImpl->m_aURL );
     803           0 :     aOldURL.Append( aElementName );
     804             : 
     805           0 :     INetURLObject aNewURL( m_pImpl->m_aURL );
     806           0 :     aNewURL.Append( aNewName );
     807             : 
     808           0 :     if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) )
     809           0 :       && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     810           0 :         throw container::NoSuchElementException(); // TODO:
     811             : 
     812           0 :     if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) )
     813           0 :       || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     814           0 :           throw container::ElementExistException(); // TODO:
     815             : 
     816             :     try
     817             :     {
     818           0 :         uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     819           0 :         ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
     820             : 
     821           0 :         if ( !GetContent()->transferContent( aSourceContent,
     822             :                                             ::ucbhelper::InsertOperation_MOVE,
     823             :                                             aNewName,
     824           0 :                                             ucb::NameClash::ERROR ) )
     825           0 :             throw io::IOException(); // TODO: error handling
     826             :     }
     827           0 :     catch( embed::InvalidStorageException& )
     828             :     {
     829           0 :         throw;
     830             :     }
     831           0 :     catch( lang::IllegalArgumentException& )
     832             :     {
     833           0 :         throw;
     834             :     }
     835           0 :     catch( container::NoSuchElementException& )
     836             :     {
     837           0 :         throw;
     838             :     }
     839           0 :     catch( container::ElementExistException& )
     840             :     {
     841           0 :         throw;
     842             :     }
     843           0 :     catch( io::IOException& )
     844             :     {
     845           0 :         throw;
     846             :     }
     847           0 :     catch( embed::StorageWrappedTargetException& )
     848             :     {
     849           0 :         throw;
     850             :     }
     851           0 :     catch( uno::RuntimeException& )
     852             :     {
     853           0 :         throw;
     854             :     }
     855           0 :     catch( uno::Exception& )
     856             :     {
     857           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     858             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     859             :                                                  uno::Reference< io::XInputStream >(),
     860           0 :                                                  aCaught );
     861           0 :     }
     862           0 : }
     863             : 
     864           0 : void SAL_CALL FSStorage::copyElementTo( const OUString& aElementName,
     865             :                                         const uno::Reference< embed::XStorage >& xDest,
     866             :                                         const OUString& aNewName )
     867             :         throw ( embed::InvalidStorageException,
     868             :                 lang::IllegalArgumentException,
     869             :                 container::NoSuchElementException,
     870             :                 container::ElementExistException,
     871             :                 io::IOException,
     872             :                 embed::StorageWrappedTargetException,
     873             :                 uno::RuntimeException, std::exception )
     874             : {
     875           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     876             : 
     877           0 :     if ( !m_pImpl )
     878           0 :         throw lang::DisposedException();
     879             : 
     880           0 :     if ( !xDest.is() )
     881           0 :         throw uno::RuntimeException();
     882             : 
     883           0 :     if ( !GetContent() )
     884           0 :         throw io::IOException(); // TODO: error handling
     885             : 
     886           0 :     INetURLObject aOwnURL( m_pImpl->m_aURL );
     887           0 :     aOwnURL.Append( aElementName );
     888             : 
     889           0 :     if ( xDest->hasByName( aNewName ) )
     890           0 :           throw container::ElementExistException(); // TODO:
     891             : 
     892             :     try
     893             :     {
     894           0 :         uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
     895           0 :         if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     896             :         {
     897           0 :             ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
     898             :             uno::Reference< embed::XStorage > xDestSubStor(
     899           0 :                                     xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ),
     900           0 :                                     uno::UNO_QUERY_THROW );
     901             : 
     902           0 :             CopyContentToStorage_Impl( &aSourceContent, xDestSubStor );
     903             :         }
     904           0 :         else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     905             :         {
     906           0 :             CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName );
     907             :         }
     908             :         else
     909           0 :             throw container::NoSuchElementException(); // TODO:
     910             :     }
     911           0 :     catch( embed::InvalidStorageException& )
     912             :     {
     913           0 :         throw;
     914             :     }
     915           0 :     catch( lang::IllegalArgumentException& )
     916             :     {
     917           0 :         throw;
     918             :     }
     919           0 :     catch( container::NoSuchElementException& )
     920             :     {
     921           0 :         throw;
     922             :     }
     923           0 :     catch( container::ElementExistException& )
     924             :     {
     925           0 :         throw;
     926             :     }
     927           0 :     catch( embed::StorageWrappedTargetException& )
     928             :     {
     929           0 :         throw;
     930             :     }
     931           0 :     catch( io::IOException& )
     932             :     {
     933           0 :         throw;
     934             :     }
     935           0 :     catch( uno::RuntimeException& )
     936             :     {
     937           0 :         throw;
     938             :     }
     939           0 :     catch( uno::Exception& )
     940             :     {
     941           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
     942             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
     943             :                                                  uno::Reference< io::XInputStream >(),
     944           0 :                                                  aCaught );
     945           0 :     }
     946           0 : }
     947             : 
     948           0 : void SAL_CALL FSStorage::moveElementTo( const OUString& aElementName,
     949             :                                         const uno::Reference< embed::XStorage >& xDest,
     950             :                                         const OUString& aNewName )
     951             :         throw ( embed::InvalidStorageException,
     952             :                 lang::IllegalArgumentException,
     953             :                 container::NoSuchElementException,
     954             :                 container::ElementExistException,
     955             :                 io::IOException,
     956             :                 embed::StorageWrappedTargetException,
     957             :                 uno::RuntimeException, std::exception )
     958             : {
     959           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     960           0 :     copyElementTo( aElementName, xDest, aNewName );
     961             : 
     962           0 :     INetURLObject aOwnURL( m_pImpl->m_aURL );
     963           0 :     aOwnURL.Append( aElementName );
     964           0 :     if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     965           0 :         throw io::IOException(); // TODO: error handling
     966           0 : }
     967             : 
     968             : //  XNameAccess
     969             : 
     970         592 : uno::Any SAL_CALL FSStorage::getByName( const OUString& aName )
     971             :         throw ( container::NoSuchElementException,
     972             :                 lang::WrappedTargetException,
     973             :                 uno::RuntimeException, std::exception )
     974             : {
     975         592 :     ::osl::MutexGuard aGuard( m_aMutex );
     976             : 
     977         592 :     if ( !m_pImpl )
     978           0 :         throw lang::DisposedException();
     979             : 
     980         592 :     if ( aName.isEmpty() )
     981           0 :         throw lang::IllegalArgumentException();
     982             : 
     983         592 :     uno::Any aResult;
     984             :     try
     985             :     {
     986         592 :         if ( !GetContent() )
     987           0 :             throw io::IOException(); // TODO: error handling
     988             : 
     989         592 :         INetURLObject aURL( m_pImpl->m_aURL );
     990         592 :         aURL.Append( aName );
     991             : 
     992             : 
     993         592 :         if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     994             :         {
     995         592 :             aResult <<= openStorageElement( aName, embed::ElementModes::READ );
     996             :         }
     997           0 :         else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
     998             :         {
     999           0 :             aResult <<= openStreamElement( aName, embed::ElementModes::READ );
    1000             :         }
    1001             :         else
    1002           0 :             throw container::NoSuchElementException(); // TODO:
    1003             :     }
    1004           0 :     catch (const container::NoSuchElementException&)
    1005             :     {
    1006           0 :         throw;
    1007             :     }
    1008           0 :     catch (const lang::WrappedTargetException&)
    1009             :     {
    1010           0 :         throw;
    1011             :     }
    1012           0 :     catch (const uno::RuntimeException&)
    1013             :     {
    1014           0 :         throw;
    1015             :     }
    1016           0 :     catch (const uno::Exception&)
    1017             :     {
    1018           0 :         uno::Any aCaught( ::cppu::getCaughtException() );
    1019             :         throw lang::WrappedTargetException( "Can not open element!",
    1020             :                                             static_cast< OWeakObject* >( this ),
    1021           0 :                                             aCaught );
    1022             :     }
    1023             : 
    1024         592 :     return aResult;
    1025             : }
    1026             : 
    1027             : 
    1028       89017 : uno::Sequence< OUString > SAL_CALL FSStorage::getElementNames()
    1029             :         throw ( uno::RuntimeException, std::exception )
    1030             : {
    1031       89017 :     ::osl::MutexGuard aGuard( m_aMutex );
    1032             : 
    1033       89017 :     if ( !m_pImpl )
    1034           0 :         throw lang::DisposedException();
    1035             : 
    1036       89017 :     uno::Sequence< OUString > aResult;
    1037             : 
    1038             :     try
    1039             :     {
    1040       89017 :         if ( !GetContent() )
    1041           0 :             throw io::IOException(); // TODO: error handling
    1042             : 
    1043       89017 :         uno::Sequence< OUString > aProps( 1 );
    1044       89017 :         aProps[0] = "Title";
    1045       89017 :         ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
    1046             : 
    1047       89017 :         sal_Int32 nSize = 0;
    1048      178034 :         uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
    1049      178034 :         uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
    1050      178034 :         uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
    1051       89017 :         if ( xResultSet.is() )
    1052             :         {
    1053             :             // go through the list
    1054      185874 :             while ( xResultSet->next() )
    1055             :             {
    1056        7840 :                 OUString aName( xRow->getString( 1 ) );
    1057        7840 :                 aResult.realloc( ++nSize );
    1058        7840 :                 aResult[nSize-1] = aName;
    1059        7840 :             }
    1060       89017 :         }
    1061             :     }
    1062           0 :     catch( const ucb::InteractiveIOException& r )
    1063             :     {
    1064           0 :         if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
    1065             :             OSL_FAIL( "The folder does not exist!\n" );
    1066             :         else
    1067             :         {
    1068           0 :             uno::Any aCaught( ::cppu::getCaughtException() );
    1069             :             throw lang::WrappedTargetRuntimeException( "Can not open storage!",
    1070             :                                             static_cast< OWeakObject* >( this ),
    1071           0 :                                             aCaught );
    1072             :         }
    1073             :     }
    1074           0 :     catch (const uno::RuntimeException&)
    1075             :     {
    1076           0 :         throw;
    1077             :     }
    1078           0 :     catch (const uno::Exception&)
    1079             :     {
    1080           0 :         uno::Any aCaught( ::cppu::getCaughtException() );
    1081             :         throw lang::WrappedTargetRuntimeException( "Can not open storage!",
    1082             :                                             static_cast< OWeakObject* >( this ),
    1083           0 :                                             aCaught );
    1084             :     }
    1085             : 
    1086       89017 :     return aResult;
    1087             : }
    1088             : 
    1089        1392 : sal_Bool SAL_CALL FSStorage::hasByName( const OUString& aName )
    1090             :         throw ( uno::RuntimeException, std::exception )
    1091             : {
    1092        1392 :     ::osl::MutexGuard aGuard( m_aMutex );
    1093             : 
    1094        1392 :     if ( !m_pImpl )
    1095           0 :         throw lang::DisposedException();
    1096             : 
    1097             :     try
    1098             :     {
    1099        1392 :         if ( !GetContent() )
    1100           0 :             throw io::IOException(); // TODO: error handling
    1101             : 
    1102        1392 :         if ( aName.isEmpty() )
    1103           0 :             throw lang::IllegalArgumentException();
    1104             :     }
    1105           0 :     catch( uno::RuntimeException& )
    1106             :     {
    1107           0 :         throw;
    1108             :     }
    1109           0 :     catch ( uno::Exception& )
    1110             :     {
    1111           0 :         uno::Any aCaught( ::cppu::getCaughtException() );
    1112             :         throw lang::WrappedTargetRuntimeException( "Can not open storage!",
    1113             :                                             static_cast< OWeakObject* >( this ),
    1114           0 :                                             aCaught );
    1115             :     }
    1116             : 
    1117        2784 :     INetURLObject aURL( m_pImpl->m_aURL );
    1118        1392 :     aURL.Append( aName );
    1119             : 
    1120        5568 :     return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
    1121        5568 :       || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
    1122             : }
    1123             : 
    1124           0 : uno::Type SAL_CALL FSStorage::getElementType()
    1125             :         throw ( uno::RuntimeException, std::exception )
    1126             : {
    1127           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1128             : 
    1129           0 :     if ( !m_pImpl )
    1130           0 :         throw lang::DisposedException();
    1131             : 
    1132             :     // it is a multitype container
    1133           0 :     return uno::Type();
    1134             : }
    1135             : 
    1136           0 : sal_Bool SAL_CALL FSStorage::hasElements()
    1137             :         throw ( uno::RuntimeException, std::exception )
    1138             : {
    1139           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1140             : 
    1141           0 :     if ( !m_pImpl )
    1142           0 :         throw lang::DisposedException();
    1143             : 
    1144             :     try
    1145             :     {
    1146           0 :         if ( !GetContent() )
    1147           0 :             throw io::IOException(); // TODO: error handling
    1148             : 
    1149           0 :         uno::Sequence< OUString > aProps( 1 );
    1150           0 :         aProps[0] = "TargetURL";
    1151           0 :         ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
    1152             : 
    1153           0 :         uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
    1154           0 :         return ( xResultSet.is() && xResultSet->next() );
    1155             :     }
    1156           0 :     catch (const uno::RuntimeException&)
    1157             :     {
    1158           0 :         throw;
    1159             :     }
    1160           0 :     catch (const uno::Exception&)
    1161             :     {
    1162           0 :         throw uno::RuntimeException();
    1163           0 :     }
    1164             : }
    1165             : 
    1166             : //  XDisposable
    1167        3102 : void SAL_CALL FSStorage::dispose()
    1168             :         throw ( uno::RuntimeException, std::exception )
    1169             : {
    1170        3102 :     ::osl::MutexGuard aGuard( m_aMutex );
    1171             : 
    1172        3102 :     if ( !m_pImpl )
    1173           0 :         throw lang::DisposedException();
    1174             : 
    1175        3102 :     if ( m_pImpl->m_pListenersContainer )
    1176             :     {
    1177           0 :         lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
    1178           0 :         m_pImpl->m_pListenersContainer->disposeAndClear( aSource );
    1179             :     }
    1180             : 
    1181        3102 :     delete m_pImpl;
    1182        3102 :     m_pImpl = NULL;
    1183        3102 : }
    1184             : 
    1185           0 : void SAL_CALL FSStorage::addEventListener(
    1186             :             const uno::Reference< lang::XEventListener >& xListener )
    1187             :         throw ( uno::RuntimeException, std::exception )
    1188             : {
    1189           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1190             : 
    1191           0 :     if ( !m_pImpl )
    1192           0 :         throw lang::DisposedException();
    1193             : 
    1194           0 :     if ( !m_pImpl->m_pListenersContainer )
    1195           0 :         m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
    1196             : 
    1197           0 :     m_pImpl->m_pListenersContainer->addInterface( xListener );
    1198           0 : }
    1199             : 
    1200           0 : void SAL_CALL FSStorage::removeEventListener(
    1201             :             const uno::Reference< lang::XEventListener >& xListener )
    1202             :         throw ( uno::RuntimeException, std::exception )
    1203             : {
    1204           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1205             : 
    1206           0 :     if ( !m_pImpl )
    1207           0 :         throw lang::DisposedException();
    1208             : 
    1209           0 :     if ( m_pImpl->m_pListenersContainer )
    1210           0 :         m_pImpl->m_pListenersContainer->removeInterface( xListener );
    1211           0 : }
    1212             : 
    1213             : //  XPropertySet
    1214             : 
    1215           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo()
    1216             :         throw ( uno::RuntimeException, std::exception )
    1217             : {
    1218           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1219             : 
    1220           0 :     if ( !m_pImpl )
    1221           0 :         throw lang::DisposedException();
    1222             : 
    1223             :     //TODO:
    1224           0 :     return uno::Reference< beans::XPropertySetInfo >();
    1225             : }
    1226             : 
    1227             : 
    1228           0 : void SAL_CALL FSStorage::setPropertyValue( const OUString& aPropertyName, const uno::Any& )
    1229             :         throw ( beans::UnknownPropertyException,
    1230             :                 beans::PropertyVetoException,
    1231             :                 lang::IllegalArgumentException,
    1232             :                 lang::WrappedTargetException,
    1233             :                 uno::RuntimeException, std::exception )
    1234             : {
    1235           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1236             : 
    1237           0 :     if ( !m_pImpl )
    1238           0 :         throw lang::DisposedException();
    1239             : 
    1240           0 :     if ( aPropertyName == "URL" || aPropertyName == "OpenMode" )
    1241           0 :         throw beans::PropertyVetoException(); // TODO
    1242             :     else
    1243           0 :         throw beans::UnknownPropertyException(); // TODO
    1244             : }
    1245             : 
    1246             : 
    1247         394 : uno::Any SAL_CALL FSStorage::getPropertyValue( const OUString& aPropertyName )
    1248             :         throw ( beans::UnknownPropertyException,
    1249             :                 lang::WrappedTargetException,
    1250             :                 uno::RuntimeException, std::exception )
    1251             : {
    1252         394 :     ::osl::MutexGuard aGuard( m_aMutex );
    1253             : 
    1254         394 :     if ( !m_pImpl )
    1255           0 :         throw lang::DisposedException();
    1256             : 
    1257         394 :     if ( aPropertyName == "URL" )
    1258           0 :         return uno::makeAny( m_pImpl->m_aURL );
    1259         394 :     else if ( aPropertyName == "OpenMode" )
    1260         394 :         return uno::makeAny( m_pImpl->m_nMode );
    1261             : 
    1262           0 :     throw beans::UnknownPropertyException(); // TODO
    1263             : }
    1264             : 
    1265             : 
    1266           0 : void SAL_CALL FSStorage::addPropertyChangeListener(
    1267             :             const OUString& /*aPropertyName*/,
    1268             :             const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
    1269             :         throw ( beans::UnknownPropertyException,
    1270             :                 lang::WrappedTargetException,
    1271             :                 uno::RuntimeException, std::exception )
    1272             : {
    1273           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1274             : 
    1275           0 :     if ( !m_pImpl )
    1276           0 :         throw lang::DisposedException();
    1277             : 
    1278             :     //TODO:
    1279           0 : }
    1280             : 
    1281             : 
    1282           0 : void SAL_CALL FSStorage::removePropertyChangeListener(
    1283             :             const OUString& /*aPropertyName*/,
    1284             :             const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
    1285             :         throw ( beans::UnknownPropertyException,
    1286             :                 lang::WrappedTargetException,
    1287             :                 uno::RuntimeException, std::exception )
    1288             : {
    1289           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1290             : 
    1291           0 :     if ( !m_pImpl )
    1292           0 :         throw lang::DisposedException();
    1293             : 
    1294             :     //TODO:
    1295           0 : }
    1296             : 
    1297             : 
    1298           0 : void SAL_CALL FSStorage::addVetoableChangeListener(
    1299             :             const OUString& /*PropertyName*/,
    1300             :             const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
    1301             :         throw ( beans::UnknownPropertyException,
    1302             :                 lang::WrappedTargetException,
    1303             :                 uno::RuntimeException, std::exception )
    1304             : {
    1305           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1306             : 
    1307           0 :     if ( !m_pImpl )
    1308           0 :         throw lang::DisposedException();
    1309             : 
    1310             :     //TODO:
    1311           0 : }
    1312             : 
    1313             : 
    1314           0 : void SAL_CALL FSStorage::removeVetoableChangeListener(
    1315             :             const OUString& /*PropertyName*/,
    1316             :             const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
    1317             :         throw ( beans::UnknownPropertyException,
    1318             :                 lang::WrappedTargetException,
    1319             :                 uno::RuntimeException, std::exception )
    1320             : {
    1321           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1322             : 
    1323           0 :     if ( !m_pImpl )
    1324           0 :         throw lang::DisposedException();
    1325             : 
    1326             :     //TODO:
    1327           0 : }
    1328             : 
    1329             : //  XHierarchicalStorageAccess
    1330           0 : uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const OUString& sStreamPath, ::sal_Int32 nOpenMode )
    1331             :         throw ( embed::InvalidStorageException,
    1332             :                 lang::IllegalArgumentException,
    1333             :                 packages::WrongPasswordException,
    1334             :                 io::IOException,
    1335             :                 embed::StorageWrappedTargetException,
    1336             :                 uno::RuntimeException, std::exception )
    1337             : {
    1338           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1339             : 
    1340           0 :     if ( !m_pImpl )
    1341           0 :         throw lang::DisposedException();
    1342             : 
    1343           0 :     if ( sStreamPath.toChar() == '/' )
    1344           0 :         throw lang::IllegalArgumentException();
    1345             : 
    1346           0 :     if ( !GetContent() )
    1347           0 :         throw io::IOException(); // TODO: error handling
    1348             : 
    1349           0 :     INetURLObject aBaseURL( m_pImpl->m_aURL );
    1350           0 :     if ( !aBaseURL.setFinalSlash() )
    1351           0 :         throw uno::RuntimeException();
    1352             : 
    1353             :     OUString aFileURL = INetURLObject::GetAbsURL(
    1354             :                 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
    1355           0 :                 sStreamPath );
    1356             : 
    1357           0 :     if ( ::utl::UCBContentHelper::IsFolder( aFileURL ) )
    1358           0 :         throw io::IOException();
    1359             : 
    1360           0 :     if ( ( nOpenMode & embed::ElementModes::NOCREATE )
    1361           0 :       && !::utl::UCBContentHelper::IsDocument( aFileURL ) )
    1362           0 :         throw io::IOException(); // TODO:
    1363             : 
    1364           0 :     uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
    1365           0 :     uno::Reference< io::XStream > xResult;
    1366             :     try
    1367             :     {
    1368           0 :         if ( nOpenMode & embed::ElementModes::WRITE )
    1369             :         {
    1370           0 :             if ( isLocalFile_Impl( aFileURL ) )
    1371             :             {
    1372             :                 uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
    1373           0 :                     ucb::SimpleFileAccess::create( m_pImpl->m_xContext ) );
    1374             :                 uno::Reference< io::XStream > xStream =
    1375           0 :                     xSimpleFileAccess->openFileReadWrite( aFileURL );
    1376             : 
    1377           0 :                 xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
    1378             :             }
    1379             :             else
    1380             :             {
    1381             :                 // TODO: test whether it really works for http and fwp
    1382             :                 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL,
    1383           0 :                                                                           STREAM_STD_WRITE );
    1384           0 :                 if ( pStream )
    1385             :                 {
    1386           0 :                     if ( !pStream->GetError() )
    1387             :                     {
    1388             :                         uno::Reference< io::XStream > xStream =
    1389           0 :                             uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
    1390           0 :                         xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
    1391             :                     }
    1392             :                     else
    1393           0 :                         delete pStream;
    1394             :                 }
    1395             :             }
    1396             : 
    1397           0 :             if ( !xResult.is() )
    1398           0 :                 throw io::IOException();
    1399             : 
    1400           0 :             if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
    1401             :             {
    1402           0 :                 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
    1403           0 :                 xTrunc->truncate();
    1404             :             }
    1405             :         }
    1406             :         else
    1407             :         {
    1408           0 :             if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
    1409           0 :               || !::utl::UCBContentHelper::IsDocument( aFileURL ) )
    1410           0 :                 throw io::IOException(); // TODO: access denied
    1411             : 
    1412           0 :             ::ucbhelper::Content aResultContent( aFileURL, xDummyEnv, comphelper::getProcessComponentContext() );
    1413           0 :             uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
    1414           0 :             xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
    1415             :         }
    1416             :     }
    1417           0 :     catch( embed::InvalidStorageException& )
    1418             :     {
    1419           0 :         throw;
    1420             :     }
    1421           0 :     catch( lang::IllegalArgumentException& )
    1422             :     {
    1423           0 :         throw;
    1424             :     }
    1425           0 :     catch( packages::WrongPasswordException& )
    1426             :     {
    1427           0 :         throw;
    1428             :     }
    1429           0 :     catch( embed::StorageWrappedTargetException& )
    1430             :     {
    1431           0 :         throw;
    1432             :     }
    1433           0 :     catch( io::IOException& )
    1434             :     {
    1435           0 :         throw;
    1436             :     }
    1437           0 :     catch( uno::RuntimeException& )
    1438             :     {
    1439           0 :         throw;
    1440             :     }
    1441           0 :     catch( uno::Exception& )
    1442             :     {
    1443           0 :           uno::Any aCaught( ::cppu::getCaughtException() );
    1444             :         throw embed::StorageWrappedTargetException("Can't copy raw stream",
    1445             :                                                  uno::Reference< io::XInputStream >(),
    1446           0 :                                                  aCaught );
    1447             :     }
    1448             : 
    1449           0 :     return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW );
    1450             : }
    1451             : 
    1452           0 : uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const OUString& /*sPassword*/ )
    1453             :         throw ( embed::InvalidStorageException,
    1454             :                 lang::IllegalArgumentException,
    1455             :                 packages::NoEncryptionException,
    1456             :                 packages::WrongPasswordException,
    1457             :                 io::IOException,
    1458             :                 embed::StorageWrappedTargetException,
    1459             :                 uno::RuntimeException, std::exception )
    1460             : {
    1461           0 :     throw packages::NoEncryptionException();
    1462             : }
    1463             : 
    1464           0 : void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const OUString& sStreamPath )
    1465             :         throw ( embed::InvalidStorageException,
    1466             :                 lang::IllegalArgumentException,
    1467             :                 container::NoSuchElementException,
    1468             :                 io::IOException,
    1469             :                 embed::StorageWrappedTargetException,
    1470             :                 uno::RuntimeException, std::exception )
    1471             : {
    1472           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1473             : 
    1474           0 :     if ( !m_pImpl )
    1475           0 :         throw lang::DisposedException();
    1476             : 
    1477           0 :     if ( !GetContent() )
    1478           0 :         throw io::IOException(); // TODO: error handling
    1479             : 
    1480             :     // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
    1481           0 :     INetURLObject aBaseURL( m_pImpl->m_aURL );
    1482           0 :     if ( !aBaseURL.setFinalSlash() )
    1483           0 :         throw uno::RuntimeException();
    1484             : 
    1485             :     OUString aFileURL = INetURLObject::GetAbsURL(
    1486             :                 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
    1487           0 :                 sStreamPath );
    1488             : 
    1489           0 :     if ( !::utl::UCBContentHelper::IsDocument( aFileURL ) )
    1490             :     {
    1491           0 :         if ( ::utl::UCBContentHelper::IsFolder( aFileURL ) )
    1492           0 :             throw lang::IllegalArgumentException();
    1493             :         else
    1494           0 :             throw container::NoSuchElementException(); // TODO:
    1495             :     }
    1496             : 
    1497           0 :     if ( !::utl::UCBContentHelper::Kill( aFileURL ) )
    1498           0 :         throw io::IOException(); // TODO: error handling
    1499           0 : }
    1500             : 
    1501             : 
    1502             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10