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