diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2016-01-05 18:04:14 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2016-01-05 20:41:12 +0100 |
commit | 7f36d2e25572978ee6ee79a4089db81c191df260 (patch) | |
tree | 01782a45a9619ef80eec216d3d9a8f4de9f303e5 /sot | |
parent | 3b7150c0ab5ca40f88ab8c3b914d601501cbf4e7 (diff) |
tdf#74608: Ctor function for css.embed.OLESimpleStorage
Change-Id: I20b91ad65514e27094ff702d1d94a48ef9a82fe6
Diffstat (limited to 'sot')
-rw-r--r-- | sot/Library_sot.mk | 1 | ||||
-rw-r--r-- | sot/source/unoolestorage/register.cxx | 59 | ||||
-rw-r--r-- | sot/source/unoolestorage/xolesimplestorage.cxx | 253 | ||||
-rw-r--r-- | sot/source/unoolestorage/xolesimplestorage.hxx | 45 | ||||
-rw-r--r-- | sot/util/sot.component | 5 |
5 files changed, 114 insertions, 249 deletions
diff --git a/sot/Library_sot.mk b/sot/Library_sot.mk index 3c443e50a598..6c7655561b06 100644 --- a/sot/Library_sot.mk +++ b/sot/Library_sot.mk @@ -51,7 +51,6 @@ $(eval $(call gb_Library_use_libraries,sot,\ $(eval $(call gb_Library_add_exception_objects,sot,\ sot/source/unoolestorage/xolesimplestorage \ - sot/source/unoolestorage/register \ sot/source/base/formats \ sot/source/base/object \ sot/source/base/exchange \ diff --git a/sot/source/unoolestorage/register.cxx b/sot/source/unoolestorage/register.cxx deleted file mode 100644 index 1c6531105f27..000000000000 --- a/sot/source/unoolestorage/register.cxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <com/sun/star/registry/InvalidRegistryException.hpp> -#include <cppuhelper/factory.hxx> - -#include "xolesimplestorage.hxx" - -using namespace ::com::sun::star; - - -extern "C" { - -SAL_DLLPUBLIC_EXPORT void * SAL_CALL sot_component_getFactory( - const sal_Char * pImplName, void * pServiceManager, - SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ ) -{ - void * pRet = nullptr; - - OUString aImplName( OUString::createFromAscii( pImplName ) ); - uno::Reference< lang::XSingleServiceFactory > xFactory; - - if ( pServiceManager && aImplName.equals( OLESimpleStorage::impl_staticGetImplementationName() ) ) - { - xFactory= ::cppu::createSingleFactory( static_cast< lang::XMultiServiceFactory*>( pServiceManager ), - OLESimpleStorage::impl_staticGetImplementationName(), - OLESimpleStorage::impl_staticCreateSelfInstance, - OLESimpleStorage::impl_staticGetSupportedServiceNames() ); - } - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - - return pRet; -} - -} // extern "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index 9bd8411ef850..599e0f95e513 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -17,8 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "xolesimplestorage.hxx" + +#include <com/sun/star/embed/OLESimpleStorage.hpp> #include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XSeekable.hpp> @@ -27,36 +29,113 @@ #include <comphelper/processfactory.hxx> #include <comphelper/storagehelper.hxx> - #include <unotools/ucbstreamhelper.hxx> - #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/supportsservice.hxx> - #include <sot/storinfo.hxx> -#include "xolesimplestorage.hxx" - - using namespace ::com::sun::star; const sal_Int32 nBytesCount = 32000; - -OLESimpleStorage::OLESimpleStorage( uno::Reference< lang::XMultiServiceFactory > xFactory ) +OLESimpleStorage::OLESimpleStorage( + css::uno::Reference<css::uno::XComponentContext> xContext, + css::uno::Sequence<css::uno::Any> const &aArguments) : m_bDisposed( false ) , m_pStream( nullptr ) , m_pStorage( nullptr ) , m_pListenersContainer( nullptr ) -, m_xFactory( xFactory ) +, m_xContext( xContext ) , m_bNoTemporaryCopy( false ) { - OSL_ENSURE( m_xFactory.is(), "No factory is provided on creation!\n" ); - if ( !m_xFactory.is() ) - throw uno::RuntimeException(); -} + sal_Int32 nArgNum = aArguments.getLength(); + if ( nArgNum < 1 || nArgNum > 2 ) + throw lang::IllegalArgumentException(); // TODO: + uno::Reference< io::XStream > xStream; + uno::Reference< io::XInputStream > xInputStream; + if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) ) + throw lang::IllegalArgumentException(); // TODO: + + if ( nArgNum == 2 ) + { + if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) ) + throw lang::IllegalArgumentException(); // TODO: + } + + if ( m_bNoTemporaryCopy ) + { + // TODO: ??? + // If the temporary stream is not created, the original stream must be wrapped + // since SvStream wrapper closes the stream is owns + if ( xInputStream.is() ) + { + // the stream must be seekable for direct access + uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); + m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, false ); + } + else if ( xStream.is() ) + { + // the stream must be seekable for direct access + uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW ); + m_pStream = ::utl::UcbStreamHelper::CreateStream( xStream, false ); + } + else + throw lang::IllegalArgumentException(); // TODO: + } + else + { + uno::Reference < io::XStream > xTempFile( io::TempFile::create(m_xContext), + uno::UNO_QUERY_THROW ); + uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW ); + uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream(); + if ( !xTempOut.is() ) + throw uno::RuntimeException(); + + if ( xInputStream.is() ) + { + try + { + uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); + xSeek->seek( 0 ); + } + catch( uno::Exception& ) + {} + + ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut ); + xTempOut->closeOutput(); + xTempSeek->seek( 0 ); + uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream(); + m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempInput, false ); + } + else if ( xStream.is() ) + { + // not sure that the storage flashes the stream on commit + m_xStream = xStream; + m_xTempStream = xTempFile; + + uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW ); + xSeek->seek( 0 ); + uno::Reference< io::XInputStream > xInpStream = xStream->getInputStream(); + if ( !xInpStream.is() || !xStream->getOutputStream().is() ) + throw uno::RuntimeException(); + + ::comphelper::OStorageHelper::CopyInputToOutput( xInpStream, xTempOut ); + xTempOut->flush(); + xTempSeek->seek( 0 ); + + m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, false ); + } + else + throw lang::IllegalArgumentException(); // TODO: + } + + if ( !m_pStream || m_pStream->GetError() ) + throw io::IOException(); // TODO + + m_pStorage = new Storage( *m_pStream, false ); +} OLESimpleStorage::~OLESimpleStorage() { @@ -73,27 +152,6 @@ OLESimpleStorage::~OLESimpleStorage() } } - -uno::Sequence< OUString > SAL_CALL OLESimpleStorage::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< OUString > aRet { "com.sun.star.embed.OLESimpleStorage" }; - return aRet; -} - - -OUString SAL_CALL OLESimpleStorage::impl_staticGetImplementationName() -{ - return OUString("com.sun.star.comp.embed.OLESimpleStorage"); -} - - -uno::Reference< uno::XInterface > SAL_CALL OLESimpleStorage::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) -{ - return uno::Reference< uno::XInterface >( *new OLESimpleStorage( xServiceManager ) ); -} - - void OLESimpleStorage::UpdateOriginal_Impl() { if ( !m_bNoTemporaryCopy ) @@ -209,109 +267,6 @@ void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, co } -// XInitialization - - -void SAL_CALL OLESimpleStorage::initialize( const uno::Sequence< uno::Any >& aArguments ) - throw ( uno::Exception, - uno::RuntimeException, std::exception) -{ - if ( m_pStream || m_pStorage ) - throw io::IOException(); // TODO: already initilized - - sal_Int32 nArgNum = aArguments.getLength(); - OSL_ENSURE( nArgNum >= 1 && nArgNum <= 2, "Wrong parameter number" ); - - if ( nArgNum < 1 || nArgNum > 2 ) - throw lang::IllegalArgumentException(); // TODO: - - uno::Reference< io::XStream > xStream; - uno::Reference< io::XInputStream > xInputStream; - if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) ) - throw lang::IllegalArgumentException(); // TODO: - - if ( nArgNum == 2 ) - { - if ( !( aArguments[1] >>= m_bNoTemporaryCopy ) ) - throw lang::IllegalArgumentException(); // TODO: - } - - if ( m_bNoTemporaryCopy ) - { - // TODO: ??? - // If the temporary stream is not created, the original stream must be wrapped - // since SvStream wrapper closes the stream is owns - if ( xInputStream.is() ) - { - // the stream must be seekable for direct access - uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); - m_pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream, false ); - } - else if ( xStream.is() ) - { - // the stream must be seekable for direct access - uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW ); - m_pStream = ::utl::UcbStreamHelper::CreateStream( xStream, false ); - } - else - throw lang::IllegalArgumentException(); // TODO: - } - else - { - uno::Reference < io::XStream > xTempFile( - io::TempFile::create(comphelper::getComponentContext(m_xFactory)), - uno::UNO_QUERY_THROW ); - uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW ); - uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream(); - if ( !xTempOut.is() ) - throw uno::RuntimeException(); - - if ( xInputStream.is() ) - { - try - { - uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - } - catch( uno::Exception& ) - {} - - ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut ); - xTempOut->closeOutput(); - xTempSeek->seek( 0 ); - uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream(); - m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempInput, false ); - } - else if ( xStream.is() ) - { - // not sure that the storage flashes the stream on commit - m_xStream = xStream; - m_xTempStream = xTempFile; - - uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - uno::Reference< io::XInputStream > xInpStream = xStream->getInputStream(); - if ( !xInpStream.is() || !xStream->getOutputStream().is() ) - throw uno::RuntimeException(); - - ::comphelper::OStorageHelper::CopyInputToOutput( xInpStream, xTempOut ); - xTempOut->flush(); - xTempSeek->seek( 0 ); - - m_pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, false ); - } - else - throw lang::IllegalArgumentException(); // TODO: - } - - if ( !m_pStream || m_pStream->GetError() ) - throw io::IOException(); // TODO - - m_pStorage = new Storage( *m_pStream, false ); -} - - - // XNameContainer @@ -444,8 +399,7 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName ) uno::Any aResult; uno::Reference< io::XStream > xTempFile( - io::TempFile::create(comphelper::getComponentContext(m_xFactory)), - uno::UNO_QUERY ); + io::TempFile::create(m_xContext), uno::UNO_QUERY ); uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW ); uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream(); uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream(); @@ -474,14 +428,8 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName ) if ( !bSuccess ) throw uno::RuntimeException(); - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[0] <<= xInputStream; // allow readonly access only - aArgs[1] <<= true; // do not create copy - uno::Reference< container::XNameContainer > xResultNameContainer( - m_xFactory->createInstanceWithArguments( - "com.sun.star.embed.OLESimpleStorage", - aArgs ), + css::embed::OLESimpleStorage::createFromInputStream(m_xContext, xInputStream, true), uno::UNO_QUERY_THROW ); aResult <<= xResultNameContainer; @@ -774,7 +722,7 @@ void SAL_CALL OLESimpleStorage::setClassInfo( const uno::Sequence< sal_Int8 >& / OUString SAL_CALL OLESimpleStorage::getImplementationName() throw ( uno::RuntimeException, std::exception ) { - return impl_staticGetImplementationName(); + return OUString("com.sun.star.comp.embed.OLESimpleStorage"); } sal_Bool SAL_CALL OLESimpleStorage::supportsService( const OUString& ServiceName ) @@ -786,8 +734,15 @@ sal_Bool SAL_CALL OLESimpleStorage::supportsService( const OUString& ServiceName uno::Sequence< OUString > SAL_CALL OLESimpleStorage::getSupportedServiceNames() throw ( uno::RuntimeException, std::exception ) { - return impl_staticGetSupportedServiceNames(); + return { "com.sun.star.embed.OLESimpleStorage" }; } +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_embed_OLESimpleStorage( + css::uno::XComponentContext *context, + css::uno::Sequence<css::uno::Any> const &arguments) +{ + return cppu::acquire(new OLESimpleStorage(context, arguments)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sot/source/unoolestorage/xolesimplestorage.hxx b/sot/source/unoolestorage/xolesimplestorage.hxx index 7c58c1977f87..bac3a4bce248 100644 --- a/sot/source/unoolestorage/xolesimplestorage.hxx +++ b/sot/source/unoolestorage/xolesimplestorage.hxx @@ -20,6 +20,8 @@ #ifndef INCLUDED_SOT_SOURCE_UNOOLESTORAGE_XOLESIMPLESTORAGE_HXX #define INCLUDED_SOT_SOURCE_UNOOLESTORAGE_XOLESIMPLESTORAGE_HXX +#include <sal/config.h> + #include <com/sun/star/embed/XOLESimpleStorage.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/lang/XComponent.hpp> @@ -27,21 +29,13 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/embed/XClassifiedObject.hpp> - - -#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/implbase.hxx> #include <cppuhelper/interfacecontainer.h> - #include <osl/mutex.hxx> - #include <sot/stg.hxx> - -class OLESimpleStorage : public ::cppu::WeakImplHelper - < css::embed::XOLESimpleStorage - , css::lang::XInitialization - , css::lang::XServiceInfo > +class OLESimpleStorage : public cppu::WeakImplHelper<css::embed::XOLESimpleStorage, css::lang::XServiceInfo> { ::osl::Mutex m_aMutex; @@ -53,7 +47,7 @@ class OLESimpleStorage : public ::cppu::WeakImplHelper BaseStorage* m_pStorage; ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners - css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory; + css::uno::Reference<css::uno::XComponentContext> m_xContext; bool m_bNoTemporaryCopy; @@ -67,29 +61,13 @@ class OLESimpleStorage : public ::cppu::WeakImplHelper public: - explicit OLESimpleStorage( css::uno::Reference< css::lang::XMultiServiceFactory > xFactory ); + OLESimpleStorage(css::uno::Reference<css::uno::XComponentContext> xContext, + css::uno::Sequence<css::uno::Any> const &arguments); virtual ~OLESimpleStorage(); - static css::uno::Sequence< OUString > SAL_CALL impl_staticGetSupportedServiceNames(); - static OUString SAL_CALL impl_staticGetImplementationName(); - static css::uno::Reference< css::uno::XInterface > SAL_CALL - impl_staticCreateSelfInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); - - - - // XInitialization - - - virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) - throw ( css::uno::Exception, - css::uno::RuntimeException, std::exception) override; - - // XNameContainer - virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) throw ( css::lang::IllegalArgumentException, css::container::ElementExistException, @@ -124,10 +102,8 @@ public: virtual sal_Bool SAL_CALL hasElements() throw ( css::uno::RuntimeException, std::exception ) override; - // XComponent - virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException, std::exception ) override; @@ -139,10 +115,8 @@ public: const css::uno::Reference< css::lang::XEventListener >& xListener ) throw ( css::uno::RuntimeException, std::exception ) override; - // XTransactedObject - virtual void SAL_CALL commit() throw ( css::io::IOException, css::lang::WrappedTargetException, @@ -153,10 +127,8 @@ public: css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception ) override; - // XClassifiedObject - virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getClassID() throw ( css::uno::RuntimeException, std::exception ) override; @@ -168,10 +140,8 @@ public: throw ( css::lang::NoSupportException, css::uno::RuntimeException, std::exception ) override; - // XServiceInfo - virtual OUString SAL_CALL getImplementationName() throw ( css::uno::RuntimeException, std::exception ) override; @@ -180,7 +150,6 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( css::uno::RuntimeException, std::exception ) override; - }; #endif diff --git a/sot/util/sot.component b/sot/util/sot.component index 7fc9cc3b6e20..84b98871e359 100644 --- a/sot/util/sot.component +++ b/sot/util/sot.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="sot" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.embed.OLESimpleStorage"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.embed.OLESimpleStorage" + constructor="com_sun_star_comp_embed_OLESimpleStorage"> <service name="com.sun.star.embed.OLESimpleStorage"/> </implementation> </component> |