Update ooo320-m1
[ooovba.git] / uui / source / services.cxx
bloba72f4145914ee880ec2ceef3d91c315964aabab5
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: services.cxx,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 #include <com/sun/star/registry/XRegistryKey.hpp>
32 #include <cppu/macros.hxx>
33 #include <cppuhelper/factory.hxx>
34 #include <rtl/ustring.hxx>
35 #include <sal/types.h>
36 #include <uno/environment.h>
38 #include "interactionhandler.hxx"
39 #include "requeststringresolver.hxx"
41 using namespace rtl;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::registry;
46 namespace {
48 sal_Bool writeInfo( void * pRegistryKey,
49 const char * pImplementationName,
50 Sequence< OUString > const & rServiceNames )
52 OUString aKeyName( OUString::createFromAscii( "/" ) );
53 aKeyName += OUString::createFromAscii( pImplementationName );
54 aKeyName += OUString::createFromAscii( "/UNO/SERVICES" );
56 Reference< XRegistryKey > xKey;
57 try
59 xKey = static_cast< XRegistryKey * >(
60 pRegistryKey )->createKey( aKeyName );
62 catch ( InvalidRegistryException const & )
66 if ( !xKey.is() )
68 return sal_False;
70 sal_Bool bSuccess = sal_True;
72 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
74 try
76 xKey->createKey( rServiceNames[ n ] );
78 catch ( InvalidRegistryException const & )
80 bSuccess = sal_False;
81 break;
84 return bSuccess;
87 } // namespace
89 //============================================================================
91 // component_getImplementationEnvironment
93 //============================================================================
95 extern "C" void SAL_CALL
96 component_getImplementationEnvironment(sal_Char const ** pEnvTypeName,
97 uno_Environment **)
99 *pEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
102 //============================================================================
104 // component_writeInfo
106 //============================================================================
108 extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * pRegistryKey)
110 return pRegistryKey &&
112 //////////////////////////////////////////////////////////////////////
113 // UUI Interaction Handler.
114 //////////////////////////////////////////////////////////////////////
116 writeInfo( pRegistryKey,
117 UUIInteractionHandler::m_aImplementationName,
118 UUIInteractionHandler::getSupportedServiceNames_static() ) &&
120 //////////////////////////////////////////////////////////////////////
121 // UUI Interaction Request String Resolver.
122 //////////////////////////////////////////////////////////////////////
124 writeInfo( pRegistryKey,
125 UUIInteractionRequestStringResolver::m_aImplementationName,
126 UUIInteractionRequestStringResolver::getSupportedServiceNames_static() );
129 //============================================================================
131 // component_getFactory
133 //============================================================================
135 extern "C" void * SAL_CALL component_getFactory(sal_Char const * pImplName,
136 void * pServiceManager,
137 void *)
139 if (!pImplName)
140 return 0;
142 void * pRet = 0;
144 Reference< XMultiServiceFactory > xSMgr(
145 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
146 Reference< XSingleServiceFactory > xFactory;
148 //////////////////////////////////////////////////////////////////////
149 // UUI Interaction Handler.
150 //////////////////////////////////////////////////////////////////////
152 if ( rtl_str_compare(pImplName,
153 UUIInteractionHandler::m_aImplementationName)
154 == 0)
156 xFactory =
157 cppu::createSingleFactory(
158 static_cast< XMultiServiceFactory * >(
159 pServiceManager),
160 OUString::createFromAscii(
161 UUIInteractionHandler::m_aImplementationName),
162 &UUIInteractionHandler::createInstance,
163 UUIInteractionHandler::getSupportedServiceNames_static());
166 //////////////////////////////////////////////////////////////////////
167 // UUI Interaction Request String Resolver.
168 //////////////////////////////////////////////////////////////////////
170 else if ( rtl_str_compare(pImplName,
171 UUIInteractionRequestStringResolver::m_aImplementationName)
172 == 0)
174 xFactory =
175 cppu::createSingleFactory(
176 static_cast< XMultiServiceFactory * >(
177 pServiceManager),
178 OUString::createFromAscii(
179 UUIInteractionRequestStringResolver::m_aImplementationName),
180 &UUIInteractionRequestStringResolver::createInstance,
181 UUIInteractionRequestStringResolver::getSupportedServiceNames_static());
184 //////////////////////////////////////////////////////////////////////
186 if ( xFactory.is() )
188 xFactory->acquire();
189 pRet = xFactory.get();
192 return pRet;