sfx: Use constructor feature for OwnSubFilterService.

Change-Id: I5bc7844c74043640494330fefc87914d4c02b768
This commit is contained in:
Matúš Kukan
2014-01-15 14:59:38 +01:00
parent 0791e661ae
commit dbd640e501
4 changed files with 65 additions and 159 deletions

View File

@@ -59,7 +59,6 @@
#include <comphelper/sequence.hxx>
#include <framework/documentundoguard.hxx>
#include <osl/mutex.hxx>
#include <ownsubfilterservice.hxx>
#include <rtl/ustrbuf.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
@@ -1799,7 +1798,6 @@ SFX2_DLLPUBLIC void* SAL_CALL sfx_component_getFactory(
IF_NAME_CREATECOMPONENTFACTORY( TestKeyHandler )
IF_NAME_CREATECOMPONENTFACTORY( TestMouseClickHandler )
#endif
IF_NAME_CREATECOMPONENTFACTORY( ::sfx2::OwnSubFilterService )
if ( ::comp_SfxDocumentMetaData::_getImplementationName().equals(
OUString::createFromAscii( pImplementationName ) ) )
{

View File

@@ -19,89 +19,46 @@
#include <com/sun/star/frame/DoubleInitializationException.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <ownsubfilterservice.hxx>
#include <cppuhelper/implbase2.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ref.hxx>
#include <sfx2/objsh.hxx>
using namespace ::com::sun::star;
using namespace css;
namespace sfx2 {
namespace {
//-------------------------------------------------------------------------
OwnSubFilterService::OwnSubFilterService( const uno::Reference < lang::XMultiServiceFactory >& xFactory )
: m_xFactory( xFactory )
, m_pObjectShell( NULL )
class OwnSubFilterService : public cppu::WeakImplHelper2 < document::XFilter
,lang::XServiceInfo >
{
}
uno::Reference< frame::XModel > m_xModel;
uno::Reference< io::XStream > m_xStream;
SfxObjectShell* m_pObjectShell;
//-------------------------------------------------------------------------
OwnSubFilterService::~OwnSubFilterService()
{
}
public:
OwnSubFilterService( const uno::Sequence< uno::Any >& aArguments )
throw (uno::Exception, uno::RuntimeException);
virtual ~OwnSubFilterService();
//-------------------------------------------------------------------------
uno::Sequence< OUString > SAL_CALL OwnSubFilterService::impl_getStaticSupportedServiceNames()
{
uno::Sequence< OUString > aRet(2);
aRet[0] = "com.sun.star.document.OwnSubFilter";
aRet[1] = "com.sun.star.comp.document.OwnSubFilter";
return aRet;
}
// XFilter
virtual ::sal_Bool SAL_CALL filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw (uno::RuntimeException);
virtual void SAL_CALL cancel() throw (uno::RuntimeException);
//-------------------------------------------------------------------------
OUString SAL_CALL OwnSubFilterService::impl_getStaticImplementationName()
{
return OUString("com.sun.star.comp.document.OwnSubFilter");
}
// XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) throw (uno::RuntimeException);
virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (uno::RuntimeException);
virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (uno::RuntimeException);
};
//-------------------------------------------------------------------------
uno::Reference< uno::XInterface > SAL_CALL OwnSubFilterService::impl_staticCreateSelfInstance(
const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
{
return uno::Reference< uno::XInterface >( *new OwnSubFilterService( xServiceManager ) );
}
//-------------------------------------------------------------------------
uno::Reference< lang::XSingleServiceFactory > SAL_CALL OwnSubFilterService::impl_createFactory(
const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
{
return ::cppu::createSingleFactory( xServiceManager,
OwnSubFilterService::impl_getStaticImplementationName(),
OwnSubFilterService::impl_staticCreateSelfInstance,
OwnSubFilterService::impl_getStaticSupportedServiceNames() );
}
// XFilter
//-------------------------------------------------------------------------
sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
throw (uno::RuntimeException)
{
if ( !m_pObjectShell )
throw uno::RuntimeException();
return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
}
//-------------------------------------------------------------------------
void SAL_CALL OwnSubFilterService::cancel()
throw (uno::RuntimeException)
{
// not implemented
}
// XInitialization
//-------------------------------------------------------------------------
void SAL_CALL OwnSubFilterService::initialize( const uno::Sequence< uno::Any >& aArguments )
OwnSubFilterService::OwnSubFilterService( const uno::Sequence< uno::Any >& aArguments )
throw (uno::Exception, uno::RuntimeException)
: m_pObjectShell( NULL )
{
if ( !m_xFactory.is() )
throw uno::RuntimeException();
if ( aArguments.getLength() != 2 )
throw lang::IllegalArgumentException();
@@ -122,11 +79,29 @@ void SAL_CALL OwnSubFilterService::initialize( const uno::Sequence< uno::Any >&
throw lang::IllegalArgumentException();
}
// XServiceInfo
OwnSubFilterService::~OwnSubFilterService()
{
}
sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
throw (uno::RuntimeException)
{
if ( !m_pObjectShell )
throw uno::RuntimeException();
return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
}
void SAL_CALL OwnSubFilterService::cancel()
throw (uno::RuntimeException)
{
// not implemented
}
OUString SAL_CALL OwnSubFilterService::getImplementationName()
throw ( uno::RuntimeException )
{
return impl_getStaticImplementationName();
return OUString("com.sun.star.comp.document.OwnSubFilter");
}
sal_Bool SAL_CALL OwnSubFilterService::supportsService( const OUString& ServiceName )
@@ -138,9 +113,22 @@ sal_Bool SAL_CALL OwnSubFilterService::supportsService( const OUString& ServiceN
uno::Sequence< OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
throw ( uno::RuntimeException )
{
return impl_getStaticSupportedServiceNames();
uno::Sequence< OUString > aRet(2);
aRet[0] = "com.sun.star.document.OwnSubFilter";
aRet[1] = "com.sun.star.comp.document.OwnSubFilter";
return aRet;
}
} // namespace sfx2
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
com_sun_star_comp_document_OwnSubFilter_get_implementation(
css::uno::XComponentContext *,
css::uno::Sequence<css::uno::Any> const &arguments)
{
rtl::Reference<OwnSubFilterService> x(new OwnSubFilterService(arguments));
x->acquire();
return static_cast<cppu::OWeakObject *>(x.get());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -1,81 +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 .
*/
#ifndef INCLUDED_SFX2_SOURCE_INC_OWNSUBFILTERSERVICE_HXX
#define INCLUDED_SFX2_SOURCE_INC_OWNSUBFILTERSERVICE_HXX
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <cppuhelper/implbase3.hxx>
class SfxObjectShell;
namespace sfx2 {
class OwnSubFilterService : public cppu::WeakImplHelper3 < ::com::sun::star::document::XFilter
,::com::sun::star::lang::XInitialization
,::com::sun::star::lang::XServiceInfo >
{
::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream;
SfxObjectShell* m_pObjectShell;
public:
OwnSubFilterService(const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory);
virtual ~OwnSubFilterService();
static ::com::sun::star::uno::Sequence< OUString > SAL_CALL
impl_getStaticSupportedServiceNames();
static OUString SAL_CALL impl_getStaticImplementationName();
static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
impl_staticCreateSelfInstance(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
impl_createFactory(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
// XFilter
virtual ::sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL cancel() throw (::com::sun::star::uno::RuntimeException);
// XInitialization
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
};
} // namespace sfx2
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -32,7 +32,8 @@
<implementation name="com.sun.star.comp.desktop.QuickstartWrapper">
<service name="com.sun.star.office.Quickstart"/>
</implementation>
<implementation name="com.sun.star.comp.document.OwnSubFilter">
<implementation name="com.sun.star.comp.document.OwnSubFilter"
constructor="com_sun_star_comp_document_OwnSubFilter_get_implementation">
<service name="com.sun.star.comp.document.OwnSubFilter"/>
<service name="com.sun.star.document.OwnSubFilter"/>
</implementation>