LibreOffice Module sfx2 (master) 1
ownsubfilterservice.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <com/sun/star/frame/DoubleInitializationException.hpp>
21#include <com/sun/star/document/XFilter.hpp>
22#include <com/sun/star/lang/XServiceInfo.hpp>
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/io/XStream.hpp>
27
30#include <sfx2/objsh.hxx>
31
32using namespace css;
33
34namespace {
35
36class OwnSubFilterService : public cppu::WeakImplHelper < document::XFilter
37 ,lang::XServiceInfo >
38{
39 uno::Reference< frame::XModel > m_xModel;
40 uno::Reference< io::XStream > m_xStream;
41 SfxObjectShell* m_pObjectShell;
42
43public:
46 explicit OwnSubFilterService(const css::uno::Sequence< css::uno::Any >& aArguments);
47
48 // XFilter
49 virtual sal_Bool SAL_CALL filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) override;
50 virtual void SAL_CALL cancel() override;
51
52 // XServiceInfo
53 virtual OUString SAL_CALL getImplementationName( ) override;
54 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
55 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
56};
57
58OwnSubFilterService::OwnSubFilterService(const css::uno::Sequence< css::uno::Any >& aArguments)
59 : m_pObjectShell( nullptr )
60{
61 if ( aArguments.getLength() != 2 )
62 throw lang::IllegalArgumentException();
63
64 if ( m_pObjectShell )
65 throw frame::DoubleInitializationException();
66
67 if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
68 && ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
69 {
70 m_pObjectShell = SfxObjectShell::GetShellFromComponent(m_xModel);
71 }
72
73 if ( !m_pObjectShell )
74 throw lang::IllegalArgumentException();
75}
76
77sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
78{
79 if ( !m_pObjectShell )
80 throw uno::RuntimeException();
81
82 return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
83}
84
85void SAL_CALL OwnSubFilterService::cancel()
86{
87 // not implemented
88}
89
90OUString SAL_CALL OwnSubFilterService::getImplementationName()
91{
92 return "com.sun.star.comp.document.OwnSubFilter";
93}
94
95sal_Bool SAL_CALL OwnSubFilterService::supportsService( const OUString& ServiceName )
96{
97 return cppu::supportsService(this, ServiceName);
98}
99
100uno::Sequence< OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
101{
102 return { "com.sun.star.document.OwnSubFilter", "com.sun.star.comp.document.OwnSubFilter" };
103}
104
105}
106
107extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
109 css::uno::XComponentContext *,
110 css::uno::Sequence<css::uno::Any> const &arguments)
111{
112 return cppu::acquire(new OwnSubFilterService(arguments));
113}
114
115/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SfxObjectShell * GetShellFromComponent(const css::uno::Reference< css::uno::XInterface > &xComp)
Definition: objxtor.cxx:1039
Reference< frame::XModel > m_xModel
Sequence< PropertyValue > aArguments
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_document_OwnSubFilter_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &arguments)
unsigned char sal_Bool
Reference< XStream > m_xStream