update dev300-m58
[ooovba.git] / xmlhelp / source / treeview / tvfactory.cxx
blobb8fa21c7c1ae6618029b72048a9d0adf632c5707
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tvfactory.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_xmlhelp.hxx"
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include "tvfactory.hxx"
38 #include "tvread.hxx"
41 using namespace treeview;
42 using namespace com::sun::star;
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::lang;
45 using namespace com::sun::star::beans;
46 using namespace com::sun::star::container;
50 TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
51 : m_xMSF( xMSF )
56 TVFactory::~TVFactory()
61 //////////////////////////////////////////////////////////////////////////
62 // XInterface
63 //////////////////////////////////////////////////////////////////////////
65 void SAL_CALL
66 TVFactory::acquire(
67 void )
68 throw()
70 OWeakObject::acquire();
74 void SAL_CALL
75 TVFactory::release(
76 void )
77 throw()
79 OWeakObject::release();
83 Any SAL_CALL
84 TVFactory::queryInterface(
85 const Type& rType )
86 throw( RuntimeException )
88 Any aRet = cppu::queryInterface( rType,
89 SAL_STATIC_CAST( XServiceInfo*, this ),
90 SAL_STATIC_CAST( XTypeProvider*, this ),
91 SAL_STATIC_CAST( XMultiServiceFactory*, this ) );
93 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
97 ////////////////////////////////////////////////////////////////////////////////
99 // XTypeProvider methods.
101 XTYPEPROVIDER_IMPL_3( TVFactory,
102 XServiceInfo,
103 XTypeProvider,
104 XMultiServiceFactory );
108 ////////////////////////////////////////////////////////////////////////////////
110 // XServiceInfo methods.
112 rtl::OUString SAL_CALL
113 TVFactory::getImplementationName()
114 throw( RuntimeException )
116 return TVFactory::getImplementationName_static();
120 sal_Bool SAL_CALL
121 TVFactory::supportsService(
122 const rtl::OUString& ServiceName )
123 throw( RuntimeException )
125 return
126 ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
127 ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
131 Sequence< rtl::OUString > SAL_CALL
132 TVFactory::getSupportedServiceNames( void )
133 throw( RuntimeException )
135 return TVFactory::getSupportedServiceNames_static();
140 // XMultiServiceFactory
142 Reference< XInterface > SAL_CALL
143 TVFactory::createInstance(
144 const rtl::OUString& aServiceSpecifier )
145 throw( Exception,
146 RuntimeException )
148 Any aAny;
149 aAny <<= rtl::OUString();
150 Sequence< Any > seq( 1 );
151 seq[0] <<= PropertyValue(
152 rtl::OUString::createFromAscii( "nodepath" ),
154 aAny,
155 PropertyState_DIRECT_VALUE );
157 return createInstanceWithArguments( aServiceSpecifier,
158 seq );
162 Reference< XInterface > SAL_CALL
163 TVFactory::createInstanceWithArguments(
164 const rtl::OUString& ServiceSpecifier,
165 const Sequence< Any >& Arguments )
166 throw( Exception,
167 RuntimeException )
169 (void)ServiceSpecifier;
171 if( ! m_xHDS.is() )
173 cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
174 m_xHDS = Reference< XInterface >( p );
177 Reference< XInterface > ret = m_xHDS;
179 rtl::OUString hierview;
180 for( int i = 0; i < Arguments.getLength(); ++i )
182 PropertyValue pV;
183 if( ! ( Arguments[i] >>= pV ) )
184 continue;
186 if( pV.Name.compareToAscii( "nodepath" ) )
187 continue;
189 if( ! ( pV.Value >>= hierview ) )
190 continue;
192 break;
195 if( hierview.getLength() )
197 Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
198 Any aAny = xhieraccess->getByHierarchicalName( hierview );
199 Reference< XInterface > xInterface;
200 aAny >>= xInterface;
201 return xInterface;
203 else
204 return m_xHDS;
208 Sequence< rtl::OUString > SAL_CALL
209 TVFactory::getAvailableServiceNames( )
210 throw( RuntimeException )
212 Sequence< rtl::OUString > seq( 1 );
213 seq[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" );
214 return seq;
219 // static
222 rtl::OUString SAL_CALL
223 TVFactory::getImplementationName_static()
225 return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" );
229 Sequence< rtl::OUString > SAL_CALL
230 TVFactory::getSupportedServiceNames_static()
232 Sequence< rtl::OUString > seq( 2 );
233 seq[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" );
234 seq[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" );
235 return seq;
239 Reference< XSingleServiceFactory > SAL_CALL
240 TVFactory::createServiceFactory(
241 const Reference< XMultiServiceFactory >& rxServiceMgr )
243 return Reference< XSingleServiceFactory > (
244 cppu::createSingleFactory(
245 rxServiceMgr,
246 TVFactory::getImplementationName_static(),
247 TVFactory::CreateInstance,
248 TVFactory::getSupportedServiceNames_static() ) );
253 Reference< XInterface > SAL_CALL
254 TVFactory::CreateInstance(
255 const Reference< XMultiServiceFactory >& xMultiServiceFactory )
257 XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
258 return Reference< XInterface >::query( xP );
263 //=========================================================================
264 static sal_Bool writeInfo( void * pRegistryKey,
265 const rtl::OUString & rImplementationName,
266 Sequence< rtl::OUString > const & rServiceNames )
268 rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) );
269 aKeyName += rImplementationName;
270 aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" );
272 Reference< registry::XRegistryKey > xKey;
275 xKey = static_cast< registry::XRegistryKey * >(
276 pRegistryKey )->createKey( aKeyName );
278 catch ( registry::InvalidRegistryException const & )
282 if ( !xKey.is() )
283 return sal_False;
285 sal_Bool bSuccess = sal_True;
287 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
291 xKey->createKey( rServiceNames[ n ] );
293 catch ( registry::InvalidRegistryException const & )
295 bSuccess = sal_False;
296 break;
299 return bSuccess;
304 //=========================================================================
305 extern "C" void SAL_CALL component_getImplementationEnvironment(
306 const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
308 (void)ppEnv;
310 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
315 //=========================================================================
316 extern "C" sal_Bool SAL_CALL component_writeInfo(
317 void * pServiceManager, void * pRegistryKey )
319 (void)pServiceManager;
321 return pRegistryKey && writeInfo( pRegistryKey,
322 TVFactory::getImplementationName_static(),
323 TVFactory::getSupportedServiceNames_static() );
327 //=========================================================================
328 extern "C" void * SAL_CALL component_getFactory(
329 const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
331 (void)pRegistryKey;
333 void * pRet = 0;
335 Reference< XMultiServiceFactory > xSMgr(
336 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
338 Reference< XSingleServiceFactory > xFactory;
340 //////////////////////////////////////////////////////////////////////
341 // File Content Provider.
342 //////////////////////////////////////////////////////////////////////
344 if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
346 xFactory = TVFactory::createServiceFactory( xSMgr );
349 //////////////////////////////////////////////////////////////////////
351 if ( xFactory.is() )
353 xFactory->acquire();
354 pRet = xFactory.get();
357 return pRet;