Line data Source code
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/lang/XUnoTunnel.hpp>
22 : #include <com/sun/star/document/XFilter.hpp>
23 : #include <com/sun/star/lang/XServiceInfo.hpp>
24 : #include <com/sun/star/frame/XModel.hpp>
25 : #include <com/sun/star/io/XStream.hpp>
26 :
27 : #include <cppuhelper/implbase2.hxx>
28 : #include <cppuhelper/supportsservice.hxx>
29 : #include <rtl/ref.hxx>
30 : #include <sfx2/objsh.hxx>
31 :
32 : using namespace css;
33 :
34 : namespace {
35 :
36 : class OwnSubFilterService : public cppu::WeakImplHelper2 < 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 :
43 : public:
44 : explicit OwnSubFilterService(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments)
45 : throw (uno::Exception, uno::RuntimeException);
46 :
47 : virtual ~OwnSubFilterService();
48 :
49 : // XFilter
50 : virtual sal_Bool SAL_CALL filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
51 : virtual void SAL_CALL cancel() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
52 :
53 : // XServiceInfo
54 : virtual OUString SAL_CALL getImplementationName( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
55 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
56 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
57 : };
58 :
59 0 : OwnSubFilterService::OwnSubFilterService(const css::uno::Sequence< css::uno::Any >& aArguments)
60 : throw (uno::Exception, uno::RuntimeException)
61 0 : : m_pObjectShell( NULL )
62 : {
63 0 : if ( aArguments.getLength() != 2 )
64 0 : throw lang::IllegalArgumentException();
65 :
66 0 : if ( m_pObjectShell )
67 0 : throw frame::DoubleInitializationException();
68 :
69 0 : if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
70 0 : && ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
71 : {
72 0 : ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( m_xModel, uno::UNO_QUERY_THROW );
73 0 : ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
74 0 : sal_Int64 nHandle = xObj->getSomething( aSeq );
75 0 : if ( nHandle )
76 0 : m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
77 : }
78 :
79 0 : if ( !m_pObjectShell )
80 0 : throw lang::IllegalArgumentException();
81 0 : }
82 :
83 0 : OwnSubFilterService::~OwnSubFilterService()
84 : {
85 0 : }
86 :
87 0 : sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
88 : throw (uno::RuntimeException, std::exception)
89 : {
90 0 : if ( !m_pObjectShell )
91 0 : throw uno::RuntimeException();
92 :
93 0 : return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
94 : }
95 :
96 0 : void SAL_CALL OwnSubFilterService::cancel()
97 : throw (uno::RuntimeException, std::exception)
98 : {
99 : // not implemented
100 0 : }
101 :
102 0 : OUString SAL_CALL OwnSubFilterService::getImplementationName()
103 : throw ( uno::RuntimeException, std::exception )
104 : {
105 0 : return OUString("com.sun.star.comp.document.OwnSubFilter");
106 : }
107 :
108 0 : sal_Bool SAL_CALL OwnSubFilterService::supportsService( const OUString& ServiceName )
109 : throw ( uno::RuntimeException, std::exception )
110 : {
111 0 : return cppu::supportsService(this, ServiceName);
112 : }
113 :
114 0 : uno::Sequence< OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
115 : throw ( uno::RuntimeException, std::exception )
116 : {
117 0 : uno::Sequence< OUString > aRet(2);
118 0 : aRet[0] = "com.sun.star.document.OwnSubFilter";
119 0 : aRet[1] = "com.sun.star.comp.document.OwnSubFilter";
120 0 : return aRet;
121 : }
122 :
123 : }
124 :
125 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
126 0 : com_sun_star_comp_document_OwnSubFilter_get_implementation(
127 : css::uno::XComponentContext *,
128 : css::uno::Sequence<css::uno::Any> const &arguments)
129 : {
130 0 : return cppu::acquire(new OwnSubFilterService(arguments));
131 : }
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|