1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/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>
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <sfx2/objsh.hxx>
36 class OwnSubFilterService
: public cppu::WeakImplHelper
< document::XFilter
39 uno::Reference
< frame::XModel
> m_xModel
;
40 uno::Reference
< io::XStream
> m_xStream
;
41 SfxObjectShell
* m_pObjectShell
;
44 /// @throws css::uno::Exception
45 /// @throws css::uno::RuntimeException
46 explicit OwnSubFilterService(const css::uno::Sequence
< css::uno::Any
>& aArguments
);
49 virtual sal_Bool SAL_CALL
filter( const uno::Sequence
< beans::PropertyValue
>& aDescriptor
) override
;
50 virtual void SAL_CALL
cancel() override
;
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
;
58 OwnSubFilterService::OwnSubFilterService(const css::uno::Sequence
< css::uno::Any
>& aArguments
)
59 : m_pObjectShell( nullptr )
61 if ( aArguments
.getLength() != 2 )
62 throw lang::IllegalArgumentException();
65 throw frame::DoubleInitializationException();
67 if ( ( aArguments
[1] >>= m_xStream
) && m_xStream
.is()
68 && ( aArguments
[0] >>= m_xModel
) && m_xModel
.is() )
70 m_pObjectShell
= SfxObjectShell::GetShellFromComponent(m_xModel
);
73 if ( !m_pObjectShell
)
74 throw lang::IllegalArgumentException();
77 sal_Bool SAL_CALL
OwnSubFilterService::filter( const uno::Sequence
< beans::PropertyValue
>& aDescriptor
)
79 if ( !m_pObjectShell
)
80 throw uno::RuntimeException();
82 return m_pObjectShell
->ImportFromGeneratedStream_Impl( m_xStream
, aDescriptor
);
85 void SAL_CALL
OwnSubFilterService::cancel()
90 OUString SAL_CALL
OwnSubFilterService::getImplementationName()
92 return "com.sun.star.comp.document.OwnSubFilter";
95 sal_Bool SAL_CALL
OwnSubFilterService::supportsService( const OUString
& ServiceName
)
97 return cppu::supportsService(this, ServiceName
);
100 uno::Sequence
< OUString
> SAL_CALL
OwnSubFilterService::getSupportedServiceNames()
102 return { "com.sun.star.document.OwnSubFilter", "com.sun.star.comp.document.OwnSubFilter" };
107 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
108 com_sun_star_comp_document_OwnSubFilter_get_implementation(
109 css::uno::XComponentContext
*,
110 css::uno::Sequence
<css::uno::Any
> const &arguments
)
112 return cppu::acquire(new OwnSubFilterService(arguments
));
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */