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 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_xmlhelp.hxx"
27 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include "tvfactory.hxx"
31 #include "tvread.hxx"
32 
33 
34 using namespace treeview;
35 using namespace com::sun::star;
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::beans;
39 using namespace com::sun::star::container;
40 
41 
42 
TVFactory(const uno::Reference<XMultiServiceFactory> & xMSF)43 TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
44 	: m_xMSF( xMSF )
45 {
46 }
47 
48 
~TVFactory()49 TVFactory::~TVFactory()
50 {
51 }
52 
53 
54 //////////////////////////////////////////////////////////////////////////
55 // XInterface
56 //////////////////////////////////////////////////////////////////////////
57 
58 void SAL_CALL
acquire(void)59 TVFactory::acquire(
60 	void )
61 	throw()
62 {
63   OWeakObject::acquire();
64 }
65 
66 
67 void SAL_CALL
release(void)68 TVFactory::release(
69 		      void )
70   throw()
71 {
72   OWeakObject::release();
73 }
74 
75 
76 Any SAL_CALL
queryInterface(const Type & rType)77 TVFactory::queryInterface(
78 	const Type& rType )
79 	throw( RuntimeException )
80 {
81 	Any aRet = cppu::queryInterface( rType,
82 									 SAL_STATIC_CAST( XServiceInfo*,  this ),
83 									 SAL_STATIC_CAST( XTypeProvider*, this ),
84 									 SAL_STATIC_CAST( XMultiServiceFactory*, this ) );
85 
86 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
87 }
88 
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 //
92 // XTypeProvider methods.
93 
94 XTYPEPROVIDER_IMPL_3( TVFactory,
95 				   	  XServiceInfo,
96 				   	  XTypeProvider,
97 				   	  XMultiServiceFactory );
98 
99 
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 
103 // XServiceInfo methods.
104 
105 rtl::OUString SAL_CALL
getImplementationName()106 TVFactory::getImplementationName()
107 	throw( RuntimeException )
108 {
109 	return TVFactory::getImplementationName_static();
110 }
111 
112 
113 sal_Bool SAL_CALL
supportsService(const rtl::OUString & ServiceName)114 TVFactory::supportsService(
115 	const rtl::OUString& ServiceName )
116 	throw( RuntimeException )
117 {
118 	return
119 		ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
120 		ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
121 }
122 
123 
124 Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames(void)125 TVFactory::getSupportedServiceNames( void )
126 	throw( RuntimeException )
127 {
128 	return TVFactory::getSupportedServiceNames_static();
129 }
130 
131 
132 
133 // XMultiServiceFactory
134 
135 Reference< XInterface > SAL_CALL
createInstance(const rtl::OUString & aServiceSpecifier)136 TVFactory::createInstance(
137 	const rtl::OUString& aServiceSpecifier )
138 	throw( Exception,
139 		   RuntimeException )
140 {
141 	Any aAny;
142 	aAny <<= rtl::OUString();
143 	Sequence< Any > seq( 1 );
144 	seq[0] <<= PropertyValue(
145 		rtl::OUString::createFromAscii( "nodepath" ),
146 		-1,
147 		aAny,
148 		PropertyState_DIRECT_VALUE );
149 
150 	return createInstanceWithArguments( aServiceSpecifier,
151 										seq );
152 }
153 
154 
155 Reference< XInterface > SAL_CALL
createInstanceWithArguments(const rtl::OUString & ServiceSpecifier,const Sequence<Any> & Arguments)156 TVFactory::createInstanceWithArguments(
157 	const rtl::OUString& ServiceSpecifier,
158 	const Sequence< Any >& Arguments )
159 	throw( Exception,
160 		   RuntimeException )
161 {
162 	(void)ServiceSpecifier;
163 
164 	if( ! m_xHDS.is() )
165 	{
166 		cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
167 		m_xHDS = Reference< XInterface >( p );
168 	}
169 
170 	Reference< XInterface > ret = m_xHDS;
171 
172 	rtl::OUString hierview;
173 	for( int i = 0; i < Arguments.getLength(); ++i )
174 	{
175 		PropertyValue pV;
176 		if( ! ( Arguments[i] >>= pV ) )
177 			continue;
178 
179 		if( pV.Name.compareToAscii( "nodepath" ) )
180 			continue;
181 
182 		if( ! ( pV.Value >>= hierview ) )
183 			continue;
184 
185 		break;
186 	}
187 
188 	if( hierview.getLength() )
189 	{
190 		Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
191 		Any aAny = xhieraccess->getByHierarchicalName( hierview );
192 		Reference< XInterface > xInterface;
193 		aAny >>= xInterface;
194 		return xInterface;
195 	}
196 	else
197 		return m_xHDS;
198 }
199 
200 
201 Sequence< rtl::OUString > SAL_CALL
getAvailableServiceNames()202 TVFactory::getAvailableServiceNames( )
203 	throw( RuntimeException )
204 {
205 	Sequence< rtl::OUString > seq( 1 );
206 	seq[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" );
207 	return seq;
208 }
209 
210 
211 
212 // static
213 
214 
215 rtl::OUString SAL_CALL
getImplementationName_static()216 TVFactory::getImplementationName_static()
217 {
218 	return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" );
219 }
220 
221 
222 Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames_static()223 TVFactory::getSupportedServiceNames_static()
224 {
225 	Sequence< rtl::OUString > seq( 2 );
226 	seq[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" );
227 	seq[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" );
228 	return seq;
229 }
230 
231 
232 Reference< XSingleServiceFactory > SAL_CALL
createServiceFactory(const Reference<XMultiServiceFactory> & rxServiceMgr)233 TVFactory::createServiceFactory(
234 	const Reference< XMultiServiceFactory >& rxServiceMgr )
235 {
236 	return Reference< XSingleServiceFactory > (
237 		cppu::createSingleFactory(
238 			rxServiceMgr,
239 			TVFactory::getImplementationName_static(),
240 			TVFactory::CreateInstance,
241 			TVFactory::getSupportedServiceNames_static() ) );
242 }
243 
244 
245 
246 Reference< XInterface > SAL_CALL
CreateInstance(const Reference<XMultiServiceFactory> & xMultiServiceFactory)247 TVFactory::CreateInstance(
248 	const Reference< XMultiServiceFactory >& xMultiServiceFactory )
249 {
250 	XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
251 	return Reference< XInterface >::query( xP );
252 }
253 
254 //=========================================================================
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)255 extern "C" void SAL_CALL component_getImplementationEnvironment(
256 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
257 {
258 	(void)ppEnv;
259 
260 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
261 }
262 
263 //=========================================================================
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)264 extern "C" void * SAL_CALL component_getFactory(
265 	const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
266 {
267 	(void)pRegistryKey;
268 
269 	void * pRet = 0;
270 
271 	Reference< XMultiServiceFactory > xSMgr(
272 		reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
273 
274 	Reference< XSingleServiceFactory > xFactory;
275 
276 	//////////////////////////////////////////////////////////////////////
277 	// File Content Provider.
278 	//////////////////////////////////////////////////////////////////////
279 
280 	if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
281 	{
282 		xFactory = TVFactory::createServiceFactory( xSMgr );
283 	}
284 
285 	//////////////////////////////////////////////////////////////////////
286 
287 	if ( xFactory.is() )
288 	{
289 		xFactory->acquire();
290 		pRet = xFactory.get();
291 	}
292 
293 	return pRet;
294 }
295