1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir #include <com/sun/star/frame/DoubleInitializationException.hpp>
27cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <ownsubfilterservice.hxx>
30cdf0e10cSrcweir #include <sfx2/objsh.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace sfx2 {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //-------------------------------------------------------------------------
OwnSubFilterService(const uno::Reference<lang::XMultiServiceFactory> & xFactory)37cdf0e10cSrcweir OwnSubFilterService::OwnSubFilterService( const uno::Reference < lang::XMultiServiceFactory >& xFactory )
38cdf0e10cSrcweir : m_xFactory( xFactory )
39cdf0e10cSrcweir , m_pObjectShell( NULL )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //-------------------------------------------------------------------------
~OwnSubFilterService()44cdf0e10cSrcweir OwnSubFilterService::~OwnSubFilterService()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_getStaticSupportedServiceNames()49cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OwnSubFilterService::impl_getStaticSupportedServiceNames()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(2);
52cdf0e10cSrcweir     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.document.OwnSubFilter");
53cdf0e10cSrcweir     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
54cdf0e10cSrcweir     return aRet;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_getStaticImplementationName()58cdf0e10cSrcweir ::rtl::OUString SAL_CALL OwnSubFilterService::impl_getStaticImplementationName()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)64cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OwnSubFilterService::impl_staticCreateSelfInstance(
65cdf0e10cSrcweir 			const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	return uno::Reference< uno::XInterface >( *new OwnSubFilterService( xServiceManager ) );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_createFactory(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)71cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > SAL_CALL OwnSubFilterService::impl_createFactory(
72cdf0e10cSrcweir 			const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	return ::cppu::createSingleFactory( xServiceManager,
75cdf0e10cSrcweir 								OwnSubFilterService::impl_getStaticImplementationName(),
76cdf0e10cSrcweir 								OwnSubFilterService::impl_staticCreateSelfInstance,
77cdf0e10cSrcweir 								OwnSubFilterService::impl_getStaticSupportedServiceNames() );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // XFilter
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //-------------------------------------------------------------------------
filter(const uno::Sequence<beans::PropertyValue> & aDescriptor)84cdf0e10cSrcweir sal_Bool SAL_CALL OwnSubFilterService::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
85cdf0e10cSrcweir 	throw (uno::RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	if ( !m_pObjectShell )
88cdf0e10cSrcweir 		throw uno::RuntimeException();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	return m_pObjectShell->ImportFromGeneratedStream_Impl( m_xStream, aDescriptor );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //-------------------------------------------------------------------------
cancel()94cdf0e10cSrcweir void SAL_CALL OwnSubFilterService::cancel()
95cdf0e10cSrcweir 	throw (uno::RuntimeException)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	// not implemented
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // XInitialization
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //-------------------------------------------------------------------------
initialize(const uno::Sequence<uno::Any> & aArguments)104cdf0e10cSrcweir void SAL_CALL OwnSubFilterService::initialize( const uno::Sequence< uno::Any >& aArguments )
105cdf0e10cSrcweir 	throw (uno::Exception, uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	if ( !m_xFactory.is() )
108cdf0e10cSrcweir 		throw uno::RuntimeException();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	if ( aArguments.getLength() != 2 )
111cdf0e10cSrcweir 		throw lang::IllegalArgumentException();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	if ( m_pObjectShell )
114cdf0e10cSrcweir 		throw frame::DoubleInitializationException();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
117cdf0e10cSrcweir 	  && ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( m_xModel, uno::UNO_QUERY_THROW );
120cdf0e10cSrcweir 		::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
121cdf0e10cSrcweir 		sal_Int64 nHandle = xObj->getSomething( aSeq );
122cdf0e10cSrcweir 		if ( nHandle )
123cdf0e10cSrcweir 			m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	if ( !m_pObjectShell )
127cdf0e10cSrcweir 		throw lang::IllegalArgumentException();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // XServiceInfo
132cdf0e10cSrcweir 
133cdf0e10cSrcweir //-------------------------------------------------------------------------
getImplementationName()134cdf0e10cSrcweir ::rtl::OUString SAL_CALL OwnSubFilterService::getImplementationName()
135cdf0e10cSrcweir 	throw ( uno::RuntimeException )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	return impl_getStaticImplementationName();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)141cdf0e10cSrcweir sal_Bool SAL_CALL OwnSubFilterService::supportsService( const ::rtl::OUString& ServiceName )
142cdf0e10cSrcweir 	throw ( uno::RuntimeException )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq = impl_getStaticSupportedServiceNames();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
147cdf0e10cSrcweir     	if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
148cdf0e10cSrcweir         	return sal_True;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	return sal_False;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //-------------------------------------------------------------------------
getSupportedServiceNames()154cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OwnSubFilterService::getSupportedServiceNames()
155cdf0e10cSrcweir 	throw ( uno::RuntimeException )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir 	return impl_getStaticSupportedServiceNames();
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir } // namespace sfx2
161cdf0e10cSrcweir 
162