diff options
Diffstat (limited to 'svl/source/fsstor')
-rw-r--r-- | svl/source/fsstor/fsfactory.cxx | 270 | ||||
-rw-r--r-- | svl/source/fsstor/fsstorage.component | 35 | ||||
-rw-r--r-- | svl/source/fsstor/fsstorage.cxx | 1612 | ||||
-rw-r--r-- | svl/source/fsstor/fsstorage.hxx | 339 | ||||
-rw-r--r-- | svl/source/fsstor/oinputstreamcontainer.cxx | 349 | ||||
-rw-r--r-- | svl/source/fsstor/oinputstreamcontainer.hxx | 98 | ||||
-rw-r--r-- | svl/source/fsstor/ostreamcontainer.cxx | 569 | ||||
-rw-r--r-- | svl/source/fsstor/ostreamcontainer.hxx | 127 |
8 files changed, 3399 insertions, 0 deletions
diff --git a/svl/source/fsstor/fsfactory.cxx b/svl/source/fsstor/fsfactory.cxx new file mode 100644 index 000000000000..a641a5d80c04 --- /dev/null +++ b/svl/source/fsstor/fsfactory.cxx @@ -0,0 +1,270 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include "fsfactory.hxx" +#include "cppuhelper/factory.hxx" +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/io/XSeekable.hpp> + + +#include <ucbhelper/fileidentifierconverter.hxx> +#include <ucbhelper/contentbroker.hxx> +#include <ucbhelper/content.hxx> + +#include <unotools/tempfile.hxx> +#include <unotools/ucbhelper.hxx> + +#include "fsstorage.hxx" + + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------- +uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames() +{ + uno::Sequence< ::rtl::OUString > aRet(2); + aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.FileSystemStorageFactory")); + aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.FileSystemStorageFactory")); + return aRet; +} + +//------------------------------------------------------------------------- +::rtl::OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName() +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.FileSystemStorageFactory")); +} + +//------------------------------------------------------------------------- +uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance( + const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) +{ + return uno::Reference< uno::XInterface >( *new FSStorageFactory( xServiceManager ) ); +} + +//------------------------------------------------------------------------- +uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance() + throw ( uno::Exception, + uno::RuntimeException ) +{ + ::rtl::OUString aTempURL; + + aTempURL = ::utl::TempFile( NULL, sal_True ).GetURL(); + + if ( !aTempURL.getLength() ) + throw uno::RuntimeException(); // TODO: can not create tempfile + + ::ucbhelper::Content aResultContent( + aTempURL, uno::Reference< ucb::XCommandEnvironment >() ); + + return uno::Reference< uno::XInterface >( + static_cast< OWeakObject* >( + new FSStorage( aResultContent, + embed::ElementModes::READWRITE, + uno::Sequence< beans::PropertyValue >(), + m_xFactory ) ), + uno::UNO_QUERY ); +} + +//------------------------------------------------------------------------- +uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments( + const uno::Sequence< uno::Any >& aArguments ) + throw ( uno::Exception, + uno::RuntimeException ) +{ + // The request for storage can be done with up to three arguments + + // The first argument specifies a source for the storage + // it must be URL. + // The second value is a mode the storage should be open in. + // And the third value is a media descriptor. + + sal_Int32 nArgNum = aArguments.getLength(); + OSL_ENSURE( nArgNum < 4, "Wrong parameter number" ); + + if ( !nArgNum ) + return createInstance(); + + // first try to retrieve storage open mode if any + // by default the storage will be open in readonly mode + sal_Int32 nStorageMode = embed::ElementModes::READ; + if ( nArgNum >= 2 ) + { + if( !( aArguments[1] >>= nStorageMode ) ) + { + OSL_FAIL( "Wrong second argument!\n" ); + throw uno::Exception(); // TODO: Illegal argument + } + // it's allways possible to read written storage in this implementation + nStorageMode |= embed::ElementModes::READ; + } + + // retrieve storage source URL + ::rtl::OUString aURL; + + if ( aArguments[0] >>= aURL ) + { + if ( !aURL.getLength() ) + { + OSL_FAIL( "Empty URL is provided!\n" ); + throw uno::Exception(); // TODO: illegal argument + } + } + else + { + OSL_FAIL( "Wrong first argument!\n" ); + throw uno::Exception(); // TODO: Illegal argument + } + + // retrieve mediadescriptor and set storage properties + uno::Sequence< beans::PropertyValue > aDescr; + uno::Sequence< beans::PropertyValue > aPropsToSet; + + if ( nArgNum >= 3 ) + { + if( aArguments[2] >>= aDescr ) + { + aPropsToSet.realloc(1); + aPropsToSet[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")); + aPropsToSet[0].Value <<= aURL; + + for ( sal_Int32 nInd = 0, nNumArgs = 1; nInd < aDescr.getLength(); nInd++ ) + { + if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) ) + { + aPropsToSet.realloc( ++nNumArgs ); + aPropsToSet[nNumArgs-1].Name = aDescr[nInd].Name; + aPropsToSet[nNumArgs-1].Value = aDescr[nInd].Value; + break; + } + else + OSL_FAIL( "Unacceptable property, will be ignored!\n" ); + } + } + else + { + OSL_FAIL( "Wrong third argument!\n" ); + throw uno::Exception(); // TODO: Illegal argument + } + } + + // allow to use other ucp's + // if ( !isLocalNotFile_Impl( aURL ) ) + if ( aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.pkg", 16 ) + || aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.zip", 16 ) + || ::utl::UCBContentHelper::IsDocument( aURL ) ) + { + OSL_FAIL( "File system storages can be based only on file URLs!\n" ); // ??? + throw uno::Exception(); // TODO: illegal argument + } + + if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) ) + FSStorage::MakeFolderNoUI( aURL, sal_False ); + else if ( !::utl::UCBContentHelper::IsFolder( aURL ) ) + throw io::IOException(); // there is no such folder + + ::ucbhelper::Content aResultContent( + aURL, uno::Reference< ucb::XCommandEnvironment >() ); + + // create storage based on source + return uno::Reference< uno::XInterface >( + static_cast< OWeakObject* >( new FSStorage( aResultContent, + nStorageMode, + aPropsToSet, + m_xFactory ) ), + uno::UNO_QUERY ); +} + +//------------------------------------------------------------------------- +::rtl::OUString SAL_CALL FSStorageFactory::getImplementationName() + throw ( uno::RuntimeException ) +{ + return impl_staticGetImplementationName(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL FSStorageFactory::supportsService( const ::rtl::OUString& ServiceName ) + throw ( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); + + for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) + if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) + return sal_True; + + return sal_False; +} + +//------------------------------------------------------------------------- +uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames() + throw ( uno::RuntimeException ) +{ + return impl_staticGetSupportedServiceNames(); +} + +//------------------------------------------------------------------------- + +extern "C" +{ +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment ( + const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory ( + const sal_Char * pImplementationName, void * pServiceManager, void * /* pRegistryKey */) +{ + void * pResult = 0; + if (pServiceManager) + { + uno::Reference< lang::XSingleServiceFactory > xFactory; + if (FSStorageFactory::impl_staticGetImplementationName().compareToAscii (pImplementationName) == 0) + { + xFactory = cppu::createOneInstanceFactory ( + reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager), + FSStorageFactory::impl_staticGetImplementationName(), + FSStorageFactory::impl_staticCreateSelfInstance, + FSStorageFactory::impl_staticGetSupportedServiceNames() ); + } + if (xFactory.is()) + { + xFactory->acquire(); + pResult = xFactory.get(); + } + } + return pResult; +} + +} // extern "C" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/fsstorage.component b/svl/source/fsstor/fsstorage.component new file mode 100644 index 000000000000..3ef0be825972 --- /dev/null +++ b/svl/source/fsstor/fsstorage.component @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.embed.FileSystemStorageFactory"> + <service name="com.sun.star.comp.embed.FileSystemStorageFactory"/> + <service name="com.sun.star.embed.FileSystemStorageFactory"/> + </implementation> +</component> diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx new file mode 100644 index 000000000000..2a6e2caca288 --- /dev/null +++ b/svl/source/fsstor/fsstorage.cxx @@ -0,0 +1,1612 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/ucb/XProgressHandler.hpp> +#include <com/sun/star/ucb/XContentAccess.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> + +#include <com/sun/star/ucb/InteractiveIOException.hpp> +#include <com/sun/star/ucb/IOErrorCode.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <com/sun/star/io/IOException.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> + + +#include <comphelper/processfactory.hxx> +#include <comphelper/storagehelper.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/exc_hlp.hxx> + +#include <tools/urlobj.hxx> +#include <unotools/ucbhelper.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/streamwrap.hxx> +#include <ucbhelper/fileidentifierconverter.hxx> +#include <ucbhelper/contentbroker.hxx> +#include <ucbhelper/content.hxx> + +#include "fsstorage.hxx" +#include "oinputstreamcontainer.hxx" +#include "ostreamcontainer.hxx" + +using namespace ::com::sun::star; + +//========================================================= + +// TODO: move to a standard helper +sal_Bool isLocalFile_Impl( ::rtl::OUString aURL ) +{ + ::rtl::OUString aSystemPath; + ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); + if ( !pBroker ) + throw uno::RuntimeException(); + + uno::Reference< ucb::XContentProviderManager > xManager = + pBroker->getContentProviderManagerInterface(); + try + { + aSystemPath = ::ucbhelper::getSystemPathFromFileURL( xManager, aURL ); + } + catch ( uno::Exception& ) + { + } + + return ( aSystemPath.getLength() != 0 ); +} + + +//========================================================= + +struct FSStorage_Impl +{ + ::rtl::OUString m_aURL; + + ::ucbhelper::Content* m_pContent; + sal_Int32 m_nMode; + + ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners + ::cppu::OTypeCollection* m_pTypeCollection; + + uno::Reference< lang::XMultiServiceFactory > m_xFactory; + + + FSStorage_Impl( const ::rtl::OUString& aURL, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory ) + : m_aURL( aURL ) + , m_pContent( NULL ) + , m_nMode( nMode ) + , m_pListenersContainer( NULL ) + , m_pTypeCollection( NULL ) + , m_xFactory( xFactory ) + { + OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" ); + } + + FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory ) + : m_aURL( aContent.getURL() ) + , m_pContent( new ::ucbhelper::Content( aContent ) ) + , m_nMode( nMode ) + , m_pListenersContainer( NULL ) + , m_pTypeCollection( NULL ) + , m_xFactory( xFactory ) + { + OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" ); + } + + ~FSStorage_Impl(); +}; + +//========================================================= + +FSStorage_Impl::~FSStorage_Impl() +{ + if ( m_pListenersContainer ) + delete m_pListenersContainer; + if ( m_pTypeCollection ) + delete m_pTypeCollection; + if ( m_pContent ) + delete m_pContent; +} + +//===================================================== +// FSStorage implementation +//===================================================== + +//----------------------------------------------- +FSStorage::FSStorage( const ::ucbhelper::Content& aContent, + sal_Int32 nMode, + uno::Sequence< beans::PropertyValue >, + uno::Reference< lang::XMultiServiceFactory > xFactory ) +: m_pImpl( new FSStorage_Impl( aContent, nMode, xFactory ) ) +{ + // TODO: use properties + if ( !xFactory.is() ) + throw uno::RuntimeException(); + + GetContent(); +} + +//----------------------------------------------- +FSStorage::~FSStorage() +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + m_refCount++; // to call dispose + try { + dispose(); + } + catch( uno::RuntimeException& ) + {} + } +} + +//----------------------------------------------- +sal_Bool FSStorage::MakeFolderNoUI( const String& rFolder, sal_Bool ) +{ + INetURLObject aURL( rFolder ); + ::rtl::OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); + aURL.removeSegment(); + ::ucbhelper::Content aParent; + ::ucbhelper::Content aResultContent; + + if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), + uno::Reference< ucb::XCommandEnvironment >(), + aParent ) ) + return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False ); + + return sal_False; +} + +//----------------------------------------------- +::ucbhelper::Content* FSStorage::GetContent() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pImpl->m_pContent ) + { + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + + try + { + m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv ); + } + catch( uno::Exception& ) + { + } + } + + return m_pImpl->m_pContent; +} + +//----------------------------------------------- +void FSStorage::CopyStreamToSubStream( const ::rtl::OUString& aSourceURL, + const uno::Reference< embed::XStorage >& xDest, + const ::rtl::OUString& aNewEntryName ) +{ + if ( !xDest.is() ) + throw uno::RuntimeException(); + + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); + uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream(); + + if ( !xSourceInput.is() ) + throw io::IOException(); // TODO: error handling + + uno::Reference< io::XStream > xSubStream = xDest->openStreamElement( + aNewEntryName, + embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); + if ( !xSubStream.is() ) + throw uno::RuntimeException(); + + uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream(); + if ( !xDestOutput.is() ) + throw uno::RuntimeException(); + + ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput ); + xDestOutput->closeOutput(); +} + +//----------------------------------------------- +void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest ) +{ + if ( !pContent ) + throw uno::RuntimeException(); + + // get list of contents of the Content + // create cursor for access to children + uno::Sequence< ::rtl::OUString > aProps( 2 ); + ::rtl::OUString* pProps = aProps.getArray(); + pProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); + pProps[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder")); + ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; + + try + { + uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude ); + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); + if ( xResultSet.is() ) + { + // go through the list: insert files as streams, insert folders as substorages using recursion + while ( xResultSet->next() ) + { + ::rtl::OUString aSourceURL( xRow->getString( 1 ) ); + sal_Bool bIsFolder( xRow->getBoolean(2) ); + + // TODO/LATER: not sure whether the entry name must be encoded + ::rtl::OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT, + true, + INetURLObject::NO_DECODE ) ); + if ( bIsFolder ) + { + uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName, + embed::ElementModes::READWRITE ); + if ( !xSubStorage.is() ) + throw uno::RuntimeException(); + + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); + CopyContentToStorage_Impl( &aSourceContent, xSubStorage ); + } + else + { + CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName ); + } + } + } + + uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY ); + if ( xTransact.is() ) + xTransact->commit(); + } + catch( ucb::InteractiveIOException& r ) + { + if ( r.Code == ucb::IOErrorCode_NOT_EXISTING ) + OSL_FAIL( "The folder does not exist!\n" ); + else + throw; + } +} + +//____________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________ + +//----------------------------------------------- +uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aReturn; + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<lang::XTypeProvider*> ( this ) + , static_cast<embed::XStorage*> ( this ) + , static_cast<embed::XHierarchicalStorageAccess*> ( this ) + , static_cast<container::XNameAccess*> ( this ) + , static_cast<container::XElementAccess*> ( this ) + , static_cast<lang::XComponent*> ( this ) + , static_cast<beans::XPropertySet*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + + return OWeakObject::queryInterface( rType ); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::acquire() throw() +{ + OWeakObject::acquire(); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::release() throw() +{ + OWeakObject::release(); +} + +//____________________________________________________________________________________________________ +// XTypeProvider +//____________________________________________________________________________________________________ + +//----------------------------------------------- +uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes() + throw( uno::RuntimeException ) +{ + if ( m_pImpl->m_pTypeCollection == NULL ) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pImpl->m_pTypeCollection == NULL ) + { + m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XHierarchicalStorageAccess >* )NULL ) + , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); + } + } + + return m_pImpl->m_pTypeCollection->getTypes() ; +} + +//----------------------------------------------- +uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId() + throw( uno::RuntimeException ) +{ + static ::cppu::OImplementationId* pID = NULL ; + + if ( pID == NULL ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; + + if ( pID == NULL ) + { + static ::cppu::OImplementationId aID( sal_False ) ; + pID = &aID ; + } + } + + return pID->getImplementationId() ; + +} + +//____________________________________________________________________________________________________ +// XStorage +//____________________________________________________________________________________________________ + +//----------------------------------------------- +void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest ) + throw ( embed::InvalidStorageException, + io::IOException, + lang::IllegalArgumentException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) ) + throw lang::IllegalArgumentException(); // TODO: + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + try + { + CopyContentToStorage_Impl( GetContent(), xDest ); + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } +} + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement( + const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked + INetURLObject aFileURL( m_pImpl->m_aURL ); + aFileURL.Append( aStreamName ); + + if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); + + if ( ( nOpenMode & embed::ElementModes::NOCREATE ) + && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: + + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any + uno::Reference< io::XStream > xResult; + try + { + if ( nOpenMode & embed::ElementModes::WRITE ) + { + if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( + m_pImpl->m_xFactory->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), + uno::UNO_QUERY_THROW ); + xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ); + } + else + { + // TODO: test whether it really works for http and fwp + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), + STREAM_STD_WRITE ); + if ( pStream ) + { + if ( !pStream->GetError() ) + xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) ); + else + delete pStream; + } + } + + if ( !xResult.is() ) + throw io::IOException(); + + if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) ) + { + uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW ); + xTrunc->truncate(); + } + } + else + { + if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) + || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: access denied + + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); + xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); + } + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( packages::WrongPasswordException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } + + return xResult; +} + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement( + const ::rtl::OUString&, sal_Int32, const ::rtl::OUString& ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + throw packages::NoEncryptionException(); +} + +//----------------------------------------------- +uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement( + const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + if ( ( nStorageMode & embed::ElementModes::WRITE ) + && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) ) + throw io::IOException(); // TODO: error handling + + // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked + INetURLObject aFolderURL( m_pImpl->m_aURL ); + aFolderURL.Append( aStorName ); + + sal_Bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); + if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: + + if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists ) + throw io::IOException(); // TODO: + + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any + uno::Reference< embed::XStorage > xResult; + try + { + if ( nStorageMode & embed::ElementModes::WRITE ) + { + if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists ) + { + ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); + bFolderExists = + MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :( + } + else if ( !bFolderExists ) + { + bFolderExists = + MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :( + } + } + else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) ) + throw io::IOException(); // TODO: access denied + + if ( !bFolderExists ) + throw io::IOException(); // there is no such folder + + ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + xResult = uno::Reference< embed::XStorage >( + static_cast< OWeakObject* >( new FSStorage( aResultContent, + nStorageMode, + uno::Sequence< beans::PropertyValue >(), + m_pImpl->m_xFactory ) ), + uno::UNO_QUERY ); + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } + + return xResult; +} + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const ::rtl::OUString& aStreamName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked + INetURLObject aFileURL( m_pImpl->m_aURL ); + aFileURL.Append( aStreamName ); + + uno::Reference < io::XStream > xTempResult; + try + { + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); + + xTempResult = uno::Reference < io::XStream >( + m_pImpl->m_xFactory->createInstance ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile")) ), + uno::UNO_QUERY_THROW ); + uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream(); + uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream(); + + if ( !xTempOut.is() || !xTempIn.is() ) + throw io::IOException(); + + ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut ); + xTempOut->closeOutput(); + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( packages::WrongPasswordException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } + + return xTempResult; +} + +//----------------------------------------------- +uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement( + const ::rtl::OUString&, + const ::rtl::OUString& ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + throw packages::NoEncryptionException(); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::copyLastCommitTo( + const uno::Reference< embed::XStorage >& xTargetStorage ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + copyToStorage( xTargetStorage ); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::copyStorageElementLastCommitTo( + const ::rtl::OUString& aStorName, + const uno::Reference< embed::XStorage >& xTargetStorage ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ), + uno::UNO_QUERY_THROW ); + xSourceStor->copyToStorage( xTargetStorage ); +} + +//----------------------------------------------- +sal_Bool SAL_CALL FSStorage::isStreamElement( const ::rtl::OUString& aElementName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw embed::InvalidStorageException(); // TODO: error handling + + INetURLObject aURL( m_pImpl->m_aURL ); + aURL.Append( aElementName ); + + return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); +} + +//----------------------------------------------- +sal_Bool SAL_CALL FSStorage::isStorageElement( const ::rtl::OUString& aElementName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw embed::InvalidStorageException(); // TODO: error handling + + INetURLObject aURL( m_pImpl->m_aURL ); + aURL.Append( aElementName ); + + return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::removeElement( const ::rtl::OUString& aElementName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + INetURLObject aURL( m_pImpl->m_aURL ); + aURL.Append( aElementName ); + + if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) + && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw container::NoSuchElementException(); // TODO: + + ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + container::ElementExistException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + INetURLObject aOldURL( m_pImpl->m_aURL ); + aOldURL.Append( aElementName ); + + INetURLObject aNewURL( m_pImpl->m_aURL ); + aNewURL.Append( aNewName ); + + if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) + && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw container::NoSuchElementException(); // TODO: + + if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) + || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw container::ElementExistException(); // TODO: + + try + { + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + + if ( !GetContent()->transferContent( aSourceContent, + ::ucbhelper::InsertOperation_MOVE, + aNewName, + ucb::NameClash::ERROR ) ) + throw io::IOException(); // TODO: error handling + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( container::NoSuchElementException& ) + { + throw; + } + catch( container::ElementExistException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } +} + +//----------------------------------------------- +void SAL_CALL FSStorage::copyElementTo( const ::rtl::OUString& aElementName, + const uno::Reference< embed::XStorage >& xDest, + const ::rtl::OUString& aNewName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + container::ElementExistException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !xDest.is() ) + throw uno::RuntimeException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + INetURLObject aOwnURL( m_pImpl->m_aURL ); + aOwnURL.Append( aElementName ); + + if ( xDest->hasByName( aNewName ) ) + throw container::ElementExistException(); // TODO: + + try + { + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; + if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + uno::Reference< embed::XStorage > xDestSubStor( + xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ), + uno::UNO_QUERY_THROW ); + + CopyContentToStorage_Impl( &aSourceContent, xDestSubStor ); + } + else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName ); + } + else + throw container::NoSuchElementException(); // TODO: + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( container::NoSuchElementException& ) + { + throw; + } + catch( container::ElementExistException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } +} + +//----------------------------------------------- +void SAL_CALL FSStorage::moveElementTo( const ::rtl::OUString& aElementName, + const uno::Reference< embed::XStorage >& xDest, + const ::rtl::OUString& aNewName ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + container::ElementExistException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + copyElementTo( aElementName, xDest, aNewName ); + + INetURLObject aOwnURL( m_pImpl->m_aURL ); + aOwnURL.Append( aElementName ); + if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: error handling +} + +//____________________________________________________________________________________________________ +// XNameAccess +//____________________________________________________________________________________________________ + +//----------------------------------------------- +uno::Any SAL_CALL FSStorage::getByName( const ::rtl::OUString& aName ) + throw ( container::NoSuchElementException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + if ( !aName.getLength() ) + throw lang::IllegalArgumentException(); + + INetURLObject aURL( m_pImpl->m_aURL ); + aURL.Append( aName ); + + uno::Any aResult; + try + { + if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + aResult <<= openStorageElement( aName, embed::ElementModes::READ ); + } + else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + aResult <<= openStreamElement( aName, embed::ElementModes::READ ); + } + else + throw container::NoSuchElementException(); // TODO: + } + catch( container::NoSuchElementException& ) + { + throw; + } + catch( lang::WrappedTargetException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch ( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open element!\n")), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + + return aResult; +} + + +//----------------------------------------------- +uno::Sequence< ::rtl::OUString > SAL_CALL FSStorage::getElementNames() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + uno::Sequence< ::rtl::OUString > aProps( 1 ); + ::rtl::OUString* pProps = aProps.getArray(); + pProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")); + ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; + + uno::Sequence< ::rtl::OUString > aResult; + sal_Int32 nSize = 0; + + try + { + uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude ); + uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); + uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); + if ( xResultSet.is() ) + { + // go through the list + while ( xResultSet->next() ) + { + ::rtl::OUString aName( xRow->getString( 1 ) ); + aResult.realloc( ++nSize ); + aResult[nSize-1] = aName; + } + } + } + catch( ucb::InteractiveIOException& r ) + { + if ( r.Code == ucb::IOErrorCode_NOT_EXISTING ) + OSL_FAIL( "The folder does not exist!\n" ); + else + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + } + catch( uno::RuntimeException& ) + { + throw; + } + catch ( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + + return aResult; +} + + +//----------------------------------------------- +sal_Bool SAL_CALL FSStorage::hasByName( const ::rtl::OUString& aName ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + try + { + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + if ( !aName.getLength() ) + throw lang::IllegalArgumentException(); + } + catch( uno::RuntimeException& ) + { + throw; + } + catch ( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + + INetURLObject aURL( m_pImpl->m_aURL ); + aURL.Append( aName ); + + return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) + || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ); +} + +//----------------------------------------------- +uno::Type SAL_CALL FSStorage::getElementType() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + // it is a multitype container + return uno::Type(); +} + +//----------------------------------------------- +sal_Bool SAL_CALL FSStorage::hasElements() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + uno::Sequence< ::rtl::OUString > aProps( 1 ); + aProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); + ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; + + try + { + uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude ); + return ( xResultSet.is() && xResultSet->next() ); + } + catch( uno::Exception& ) + { + throw uno::RuntimeException(); + } +} + + +//____________________________________________________________________________________________________ +// XDisposable +//____________________________________________________________________________________________________ + +//----------------------------------------------- +void SAL_CALL FSStorage::dispose() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( m_pImpl->m_pListenersContainer ) + { + lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); + m_pImpl->m_pListenersContainer->disposeAndClear( aSource ); + } + + delete m_pImpl; + m_pImpl = NULL; +} + +//----------------------------------------------- +void SAL_CALL FSStorage::addEventListener( + const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !m_pImpl->m_pListenersContainer ) + m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pImpl->m_pListenersContainer->addInterface( xListener ); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::removeEventListener( + const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( m_pImpl->m_pListenersContainer ) + m_pImpl->m_pListenersContainer->removeInterface( xListener ); +} + +//____________________________________________________________________________________________________ +// XPropertySet +//____________________________________________________________________________________________________ + +//----------------------------------------------- +uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + //TODO: + return uno::Reference< beans::XPropertySetInfo >(); +} + + +//----------------------------------------------- +void SAL_CALL FSStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& ) + throw ( beans::UnknownPropertyException, + beans::PropertyVetoException, + lang::IllegalArgumentException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("URL")) || aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OpenMode")) ) + throw beans::PropertyVetoException(); // TODO + else + throw beans::UnknownPropertyException(); // TODO +} + + +//----------------------------------------------- +uno::Any SAL_CALL FSStorage::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("URL")) ) + return uno::makeAny( m_pImpl->m_aURL ); + else if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OpenMode")) ) + return uno::makeAny( m_pImpl->m_nMode ); + + throw beans::UnknownPropertyException(); // TODO +} + + +//----------------------------------------------- +void SAL_CALL FSStorage::addPropertyChangeListener( + const ::rtl::OUString& /*aPropertyName*/, + const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + //TODO: +} + + +//----------------------------------------------- +void SAL_CALL FSStorage::removePropertyChangeListener( + const ::rtl::OUString& /*aPropertyName*/, + const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + //TODO: +} + + +//----------------------------------------------- +void SAL_CALL FSStorage::addVetoableChangeListener( + const ::rtl::OUString& /*PropertyName*/, + const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + //TODO: +} + + +//----------------------------------------------- +void SAL_CALL FSStorage::removeVetoableChangeListener( + const ::rtl::OUString& /*PropertyName*/, + const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + //TODO: +} + +//____________________________________________________________________________________________________ +// XHierarchicalStorageAccess +//____________________________________________________________________________________________________ +//----------------------------------------------- +uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( sStreamPath.toChar() == '/' ) + throw lang::IllegalArgumentException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + INetURLObject aBaseURL( m_pImpl->m_aURL ); + if ( !aBaseURL.setFinalSlash() ) + throw uno::RuntimeException(); + + INetURLObject aFileURL = INetURLObject::GetAbsURL( + aBaseURL.GetMainURL( INetURLObject::NO_DECODE ), + sStreamPath ); + + if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); + + if ( ( nOpenMode & embed::ElementModes::NOCREATE ) + && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: + + uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any + uno::Reference< io::XStream > xResult; + try + { + if ( nOpenMode & embed::ElementModes::WRITE ) + { + if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( + m_pImpl->m_xFactory->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), + uno::UNO_QUERY_THROW ); + uno::Reference< io::XStream > xStream = + xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ); + + xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) ); + } + else + { + // TODO: test whether it really works for http and fwp + SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), + STREAM_STD_WRITE ); + if ( pStream ) + { + if ( !pStream->GetError() ) + { + uno::Reference< io::XStream > xStream = + uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) ); + xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) ); + } + else + delete pStream; + } + } + + if ( !xResult.is() ) + throw io::IOException(); + + if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) ) + { + uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW ); + xTrunc->truncate(); + } + } + else + { + if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) + || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: access denied + + ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); + xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); + } + } + catch( embed::InvalidStorageException& ) + { + throw; + } + catch( lang::IllegalArgumentException& ) + { + throw; + } + catch( packages::WrongPasswordException& ) + { + throw; + } + catch( embed::StorageWrappedTargetException& ) + { + throw; + } + catch( io::IOException& ) + { + throw; + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), + uno::Reference< io::XInputStream >(), + aCaught ); + } + + return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW ); +} + +//----------------------------------------------- +uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const ::rtl::OUString& /*sPassword*/ ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + packages::NoEncryptionException, + packages::WrongPasswordException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + throw packages::NoEncryptionException(); +} + +//----------------------------------------------- +void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath ) + throw ( embed::InvalidStorageException, + lang::IllegalArgumentException, + container::NoSuchElementException, + io::IOException, + embed::StorageWrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_pImpl ) + throw lang::DisposedException(); + + if ( !GetContent() ) + throw io::IOException(); // TODO: error handling + + // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked + INetURLObject aBaseURL( m_pImpl->m_aURL ); + if ( !aBaseURL.setFinalSlash() ) + throw uno::RuntimeException(); + + INetURLObject aFileURL = INetURLObject::GetAbsURL( + aBaseURL.GetMainURL( INetURLObject::NO_DECODE ), + sStreamPath ); + + if ( !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + { + if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw lang::IllegalArgumentException(); + else + throw container::NoSuchElementException(); // TODO: + } + + if ( !::utl::UCBContentHelper::Kill( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) + throw io::IOException(); // TODO: error handling +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/fsstorage.hxx b/svl/source/fsstor/fsstorage.hxx new file mode 100644 index 000000000000..7d8a14489453 --- /dev/null +++ b/svl/source/fsstor/fsstorage.hxx @@ -0,0 +1,339 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __XSTORAGE_HXX_ +#define __XSTORAGE_HXX_ + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/packages/NoEncryptionException.hpp> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/interfacecontainer.h> + +#include <ucbhelper/content.hxx> + +struct FSStorage_Impl; +class FSStorage : public ::com::sun::star::lang::XTypeProvider + , public ::com::sun::star::embed::XStorage + , public ::com::sun::star::embed::XHierarchicalStorageAccess + , public ::com::sun::star::beans::XPropertySet + , public ::cppu::OWeakObject +{ + ::osl::Mutex m_aMutex; + FSStorage_Impl* m_pImpl; + +protected: + +public: + + FSStorage( const ::ucbhelper::Content& aContent, + sal_Int32 nMode, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ); + + virtual ~FSStorage(); + + ::ucbhelper::Content* GetContent(); + + void CopyStreamToSubStream( const ::rtl::OUString& aSourceURL, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, + const ::rtl::OUString& aNewEntryName ); + + void CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ); + + static sal_Bool MakeFolderNoUI( const String& rFolder, sal_Bool bNewOnly ); + + //____________________________________________________________________________________________________ + // XInterface + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL acquire() throw(); + + virtual void SAL_CALL release() throw(); + + //____________________________________________________________________________________________________ + // XTypeProvider + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() + throw( ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XStorage + //____________________________________________________________________________________________________ + + virtual void SAL_CALL copyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openStreamElement( + const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStreamElement( + const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL openStorageElement( + const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneStreamElement( + const ::rtl::OUString& aStreamName ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStreamElement( + const ::rtl::OUString& aStreamName, const ::rtl::OUString& aPass ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL copyLastCommitTo( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL copyStorageElementLastCommitTo( + const ::rtl::OUString& aStorName, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isStreamElement( const ::rtl::OUString& aElementName ) + throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isStorageElement( const ::rtl::OUString& aElementName ) + throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeElement( const ::rtl::OUString& aElementName ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL renameElement( const ::rtl::OUString& rEleName, const ::rtl::OUString& rNewName ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::container::ElementExistException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL copyElementTo( const ::rtl::OUString& aElementName, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, + const ::rtl::OUString& aNewName ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::container::ElementExistException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL moveElementTo( const ::rtl::OUString& aElementName, + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, + const ::rtl::OUString& rNewName ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::container::ElementExistException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XNameAccess + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) + throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Type SAL_CALL getElementType() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL hasElements() + throw ( ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XComponent + //____________________________________________________________________________________________________ + + virtual void SAL_CALL dispose() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw ( ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XPropertySet + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() + throw ( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + //____________________________________________________________________________________________________ + // XHierarchicalStorageAccess + //____________________________________________________________________________________________________ + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::packages::NoEncryptionException, + ::com::sun::star::packages::WrongPasswordException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeStreamElementByHierarchicalName( const ::rtl::OUString& sElementPath ) + throw ( ::com::sun::star::embed::InvalidStorageException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::io::IOException, + ::com::sun::star::embed::StorageWrappedTargetException, + ::com::sun::star::uno::RuntimeException ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/oinputstreamcontainer.cxx b/svl/source/fsstor/oinputstreamcontainer.cxx new file mode 100644 index 000000000000..dfa81504ba61 --- /dev/null +++ b/svl/source/fsstor/oinputstreamcontainer.cxx @@ -0,0 +1,349 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include "oinputstreamcontainer.hxx" +#include <cppuhelper/typeprovider.hxx> + +using namespace ::com::sun::star; + +//----------------------------------------------- +OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream ) +: m_xInputStream( xStream ) +, m_xSeekable( xStream, uno::UNO_QUERY ) +, m_bSeekable( sal_False ) +, m_bDisposed( sal_False ) +, m_pListenersContainer( NULL ) +{ + m_bSeekable = m_xSeekable.is(); +} + +//----------------------------------------------- +OFSInputStreamContainer::~OFSInputStreamContainer() +{ + if ( m_pListenersContainer ) + { + delete m_pListenersContainer; + m_pListenersContainer = NULL; + } +} + +//----------------------------------------------- +uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes() + throw ( uno::RuntimeException ) +{ + static ::cppu::OTypeCollection* pTypeCollection = NULL ; + + if ( pTypeCollection == NULL ) + { + ::osl::MutexGuard aGuard( m_aMutex ) ; + + if ( pTypeCollection == NULL ) + { + if ( m_bSeekable ) + { + static ::cppu::OTypeCollection aTypeCollection( + ::getCppuType(( const uno::Reference< io::XStream >* )NULL ), + ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ), + ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) ); + + pTypeCollection = &aTypeCollection ; + } + else + { + static ::cppu::OTypeCollection aTypeCollection( + ::getCppuType(( const uno::Reference< io::XStream >* )NULL ), + ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) ); + + pTypeCollection = &aTypeCollection ; + } + } + } + + return pTypeCollection->getTypes() ; + +} + +//----------------------------------------------- +uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + uno::Any aReturn; + if ( m_bSeekable ) + aReturn = uno::Any( ::cppu::queryInterface( rType, + static_cast< io::XStream* >( this ), + static_cast< io::XInputStream* >( this ), + static_cast< io::XSeekable* >( this ) ) ); + else + aReturn = uno::Any( ::cppu::queryInterface( rType, + static_cast< io::XStream* >( this ), + static_cast< io::XInputStream* >( this ) ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + + return ::cppu::OWeakObject::queryInterface( rType ) ; +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::acquire() + throw() +{ + ::cppu::OWeakObject::acquire(); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::release() + throw() +{ + ::cppu::OWeakObject::release(); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->readBytes( aData, nBytesToRead ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + m_xInputStream->skipBytes( nBytesToSkip ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OFSInputStreamContainer::available( ) + throw ( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->available(); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::closeInput( ) + throw ( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + dispose(); +} + +//----------------------------------------------- +uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + return uno::Reference< io::XInputStream >(); + + return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); +} + +//----------------------------------------------- +uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + return uno::Reference< io::XOutputStream >(); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location ) + throw ( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xSeekable.is() ) + throw uno::RuntimeException(); + + m_xSeekable->seek( location ); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition() + throw ( io::IOException, + uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xSeekable.is() ) + throw uno::RuntimeException(); + + return m_xSeekable->getPosition(); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OFSInputStreamContainer::getLength() + throw ( io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xSeekable.is() ) + throw uno::RuntimeException(); + + return m_xSeekable->getLength(); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::dispose( ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xInputStream.is() ) + throw uno::RuntimeException(); + + m_xInputStream->closeInput(); + + if ( m_pListenersContainer ) + { + lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); + m_pListenersContainer->disposeAndClear( aSource ); + } + + m_bDisposed = sal_True; +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_pListenersContainer ) + m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pListenersContainer->addInterface( xListener ); +} + +//----------------------------------------------- +void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( m_pListenersContainer ) + m_pListenersContainer->removeInterface( xListener ); +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/oinputstreamcontainer.hxx b/svl/source/fsstor/oinputstreamcontainer.hxx new file mode 100644 index 000000000000..e417b8e874c2 --- /dev/null +++ b/svl/source/fsstor/oinputstreamcontainer.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _OINPUTSTREAMCONTAINER_HXX_ +#define _OINPUTSTREAMCONTAINER_HXX_ + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/embed/XExtendedStorageStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> + + +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/interfacecontainer.h> + +#include <osl/mutex.hxx> + +class OFSInputStreamContainer : public cppu::WeakImplHelper2 < ::com::sun::star::io::XInputStream + ,::com::sun::star::embed::XExtendedStorageStream > + , public ::com::sun::star::io::XSeekable +{ +protected: + ::osl::Mutex m_aMutex; + + ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInputStream; + ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; + + sal_Bool m_bSeekable; + + sal_Bool m_bDisposed; + + ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners + +public: + OFSInputStreamContainer( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream ); + + virtual ~OFSInputStreamContainer(); + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL available( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeInput( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + //XStream + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); + + //XSeekable + virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + //XComponent + virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/ostreamcontainer.cxx b/svl/source/fsstor/ostreamcontainer.cxx new file mode 100644 index 000000000000..99c00d83b908 --- /dev/null +++ b/svl/source/fsstor/ostreamcontainer.cxx @@ -0,0 +1,569 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include "ostreamcontainer.hxx" + + +using namespace ::com::sun::star; + +//----------------------------------------------- +OFSStreamContainer::OFSStreamContainer( const uno::Reference < io::XStream >& xStream ) +: m_bDisposed( sal_False ) +, m_bInputClosed( sal_False ) +, m_bOutputClosed( sal_False ) +, m_pListenersContainer( NULL ) +, m_pTypeCollection( NULL ) +{ + try + { + m_xStream = xStream; + if ( !m_xStream.is() ) + throw uno::RuntimeException(); + + m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY ); + m_xInputStream = xStream->getInputStream(); + m_xOutputStream = xStream->getOutputStream(); + m_xTruncate = uno::Reference< io::XTruncate >( m_xOutputStream, uno::UNO_QUERY ); + m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >( m_xOutputStream, uno::UNO_QUERY ); + } + catch( uno::Exception& ) + { + m_xStream = uno::Reference< io::XStream >(); + m_xSeekable = uno::Reference< io::XSeekable >(); + m_xInputStream = uno::Reference< io::XInputStream >(); + m_xOutputStream = uno::Reference< io::XOutputStream >(); + m_xTruncate = uno::Reference< io::XTruncate >(); + m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >(); + } +} + +//----------------------------------------------- +OFSStreamContainer::~OFSStreamContainer() +{ + if ( m_pListenersContainer ) + { + delete m_pListenersContainer; + m_pListenersContainer = NULL; + } +} + +// XInterface +//----------------------------------------------- +uno::Any SAL_CALL OFSStreamContainer::queryInterface( const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aReturn; + + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<lang::XTypeProvider*> ( this ) + , static_cast<io::XStream*> ( this ) + , static_cast<embed::XExtendedStorageStream*> ( this ) + , static_cast<lang::XComponent*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + + if ( m_xSeekable.is() ) + { + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<io::XSeekable*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + } + + if ( m_xInputStream.is() ) + { + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<io::XInputStream*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + } + if ( m_xOutputStream.is() ) + { + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<io::XOutputStream*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + } + if ( m_xTruncate.is() ) + { + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<io::XTruncate*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + } + if ( m_xAsyncOutputMonitor.is() ) + { + aReturn <<= ::cppu::queryInterface + ( rType + , static_cast<io::XAsyncOutputMonitor*> ( this ) ); + + if ( aReturn.hasValue() == sal_True ) + return aReturn ; + } + + return OWeakObject::queryInterface( rType ); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::acquire() + throw() +{ + OWeakObject::acquire(); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::release() + throw() +{ + OWeakObject::release(); +} + +// XTypeProvider +//----------------------------------------------- +uno::Sequence< uno::Type > SAL_CALL OFSStreamContainer::getTypes() + throw( uno::RuntimeException ) +{ + if ( m_pTypeCollection == NULL ) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pTypeCollection == NULL ) + { + ::cppu::OTypeCollection aTypeCollection + ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) ); + + if ( m_xSeekable.is() ) + aTypeCollection = ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ), + aTypeCollection.getTypes() ); + if ( m_xInputStream.is() ) + aTypeCollection = ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ), + aTypeCollection.getTypes() ); + + if ( m_xOutputStream.is() ) + aTypeCollection = ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ), + aTypeCollection.getTypes() ); + if ( m_xTruncate.is() ) + aTypeCollection = ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ), + aTypeCollection.getTypes() ); + if ( m_xAsyncOutputMonitor.is() ) + aTypeCollection = ::cppu::OTypeCollection + ( ::getCppuType( ( const uno::Reference< io::XAsyncOutputMonitor >* )NULL ), + aTypeCollection.getTypes() ); + + m_pTypeCollection = new ::cppu::OTypeCollection( aTypeCollection ); + } + } + return m_pTypeCollection->getTypes() ; +} + +//----------------------------------------------- +uno::Sequence< sal_Int8 > SAL_CALL OFSStreamContainer::getImplementationId() + throw( uno::RuntimeException ) +{ + static ::cppu::OImplementationId* pID = NULL ; + + if ( pID == NULL ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; + + if ( pID == NULL ) + { + static ::cppu::OImplementationId aID( sal_False ) ; + pID = &aID ; + } + } + + return pID->getImplementationId() ; +} + +// XStream +//----------------------------------------------- +uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() ) + throw uno::RuntimeException(); + + if ( m_xInputStream.is() ) + return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ) ); + + return uno::Reference< io::XInputStream >(); +} + +//----------------------------------------------- +uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() ) + throw uno::RuntimeException(); + + if ( m_xOutputStream.is() ) + return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ) ); + + return uno::Reference< io::XOutputStream >(); +} + +// XComponent +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::dispose() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() ) + throw uno::RuntimeException(); + + if ( m_xInputStream.is() && !m_bInputClosed ) + { + m_xInputStream->closeInput(); + m_bInputClosed = sal_True; + } + + if ( m_xOutputStream.is() && !m_bOutputClosed ) + { + m_xOutputStream->closeOutput(); + m_bOutputClosed = sal_True; + } + + if ( m_pListenersContainer ) + { + lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); + m_pListenersContainer->disposeAndClear( aSource ); + } + + m_bDisposed = sal_True; +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_pListenersContainer ) + m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pListenersContainer->addInterface( xListener ); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( m_pListenersContainer ) + m_pListenersContainer->removeInterface( xListener ); +} + + +// XSeekable +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::seek( sal_Int64 location ) + throw ( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xSeekable.is() ) + throw uno::RuntimeException(); + + m_xSeekable->seek( location ); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OFSStreamContainer::getPosition() + throw ( io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xSeekable.is() ) + throw uno::RuntimeException(); + + return m_xSeekable->getPosition(); +} + +//----------------------------------------------- +sal_Int64 SAL_CALL OFSStreamContainer::getLength() + throw ( io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xSeekable.is() ) + throw uno::RuntimeException(); + + return m_xSeekable->getLength(); +} + + +// XInputStream +//----------------------------------------------- +sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->readBytes( aData, nBytesToRead ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xInputStream.is() ) + throw uno::RuntimeException(); + + m_xInputStream->skipBytes( nBytesToSkip ); +} + +//----------------------------------------------- +sal_Int32 SAL_CALL OFSStreamContainer::available() + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xInputStream.is() ) + throw uno::RuntimeException(); + + return m_xInputStream->available(); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::closeInput() + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xInputStream.is() ) + throw uno::RuntimeException(); + + if ( m_xInputStream.is() ) + { + m_xInputStream->closeInput(); + m_bInputClosed = sal_True; + } + + if ( m_bOutputClosed ) + dispose(); +} + +// XOutputStream +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& aData ) + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xOutputStream.is() ) + throw uno::RuntimeException(); + + return m_xOutputStream->writeBytes( aData ); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::flush() + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xOutputStream.is() ) + throw uno::RuntimeException(); + + return m_xOutputStream->flush(); +} + +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::closeOutput() + throw ( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xOutputStream.is() ) + throw uno::RuntimeException(); + + if ( m_xOutputStream.is() ) + { + m_xOutputStream->closeOutput(); + m_bOutputClosed = sal_True; + } + + if ( m_bInputClosed ) + dispose(); +} + + +// XTruncate +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::truncate() + throw ( io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xTruncate.is() ) + throw uno::RuntimeException(); + + m_xTruncate->truncate(); +} + + +// XAsyncOutputMonitor +//----------------------------------------------- +void SAL_CALL OFSStreamContainer::waitForCompletion() + throw ( io::IOException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if ( m_bDisposed ) + throw lang::DisposedException(); + + if ( !m_xStream.is() || !m_xAsyncOutputMonitor.is() ) + throw uno::RuntimeException(); + + m_xAsyncOutputMonitor->waitForCompletion(); +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/ostreamcontainer.hxx b/svl/source/fsstor/ostreamcontainer.hxx new file mode 100644 index 000000000000..42c2045a11d2 --- /dev/null +++ b/svl/source/fsstor/ostreamcontainer.hxx @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _OSTREAMCONTAINER_HXX_ +#define _OSTREAMCONTAINER_HXX_ + +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/embed/XExtendedStorageStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XStream.hpp> +#include "com/sun/star/io/XAsyncOutputMonitor.hpp" +#include <cppuhelper/weak.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <osl/mutex.hxx> + +class OFSStreamContainer : public cppu::OWeakObject, + public ::com::sun::star::lang::XTypeProvider, + public ::com::sun::star::embed::XExtendedStorageStream, + public ::com::sun::star::io::XSeekable, + public ::com::sun::star::io::XInputStream, + public ::com::sun::star::io::XOutputStream, + public ::com::sun::star::io::XTruncate, + public ::com::sun::star::io::XAsyncOutputMonitor +{ + ::osl::Mutex m_aMutex; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > m_xOutputStream; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate > m_xTruncate; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XAsyncOutputMonitor > m_xAsyncOutputMonitor; + + sal_Bool m_bDisposed; + sal_Bool m_bInputClosed; + sal_Bool m_bOutputClosed; + + ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners + ::cppu::OTypeCollection* m_pTypeCollection; + +public: + OFSStreamContainer( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream ); + virtual ~OFSStreamContainer(); + + // XInterface + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + + // XTypeProvider + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() + throw( ::com::sun::star::uno::RuntimeException ); + + // XStream + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + + // XSeekable + virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL available( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeInput( ) + throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + // XOutputStream + virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + // XTruncate + virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + + // XAsyncOutputMonitor + virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |