Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / doc / ownsubfilterservice.cxx
blob7e1048da06b48e09a0524220cb397e6b7be87e2f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/frame/DoubleInitializationException.hpp>
21 #include <com/sun/star/lang/XUnoTunnel.hpp>
22 #include <com/sun/star/document/XFilter.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/io/XStream.hpp>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <sfx2/objsh.hxx>
33 using namespace css;
35 namespace {
37 class OwnSubFilterService : public cppu::WeakImplHelper < document::XFilter
38 ,lang::XServiceInfo >
40 uno::Reference< frame::XModel > m_xModel;
41 uno::Reference< io::XStream > m_xStream;
42 SfxObjectShell* m_pObjectShell;
44 public:
45 /// @throws css::uno::Exception
46 /// @throws css::uno::RuntimeException
47 explicit OwnSubFilterService(const css::uno::Sequence< css::uno::Any >& aArguments);
49 // XFilter
50 virtual sal_Bool SAL_CALL filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) override;
51 virtual void SAL_CALL cancel() override;
53 // XServiceInfo
54 virtual OUString SAL_CALL getImplementationName( ) override;
55 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
56 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
59 OwnSubFilterService::OwnSubFilterService(const css::uno::Sequence< css::uno::Any >& aArguments)
60 : m_pObjectShell( nullptr )
62 if ( aArguments.getLength() != 2 )
63 throw lang::IllegalArgumentException();
65 if ( m_pObjectShell )
66 throw frame::DoubleInitializationException();
68 if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
69 && ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
71 m_pObjectShell = SfxObjectShell::GetShellFromComponent(m_xModel);
74 if ( !m_pObjectShell )
75 throw lang::IllegalArgumentException();
78 sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
80 if ( !m_pObjectShell )
81 throw uno::RuntimeException();
83 return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
86 void SAL_CALL OwnSubFilterService::cancel()
88 // not implemented
91 OUString SAL_CALL OwnSubFilterService::getImplementationName()
93 return "com.sun.star.comp.document.OwnSubFilter";
96 sal_Bool SAL_CALL OwnSubFilterService::supportsService( const OUString& ServiceName )
98 return cppu::supportsService(this, ServiceName);
101 uno::Sequence< OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
103 return { "com.sun.star.document.OwnSubFilter", "com.sun.star.comp.document.OwnSubFilter" };
108 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
109 com_sun_star_comp_document_OwnSubFilter_get_implementation(
110 css::uno::XComponentContext *,
111 css::uno::Sequence<css::uno::Any> const &arguments)
113 return cppu::acquire(new OwnSubFilterService(arguments));
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */