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_ucbhelper.hxx" 26 27 #include "com/sun/star/lang/XMultiServiceFactory.hpp" 28 #include "com/sun/star/lang/XSingleServiceFactory.hpp" 29 #include "com/sun/star/registry/XRegistryKey.hpp" 30 31 #include "myucp_provider.hxx" 32 33 using namespace com::sun::star; 34 35 namespace { 36 37 //========================================================================= 38 sal_Bool writeInfo( void * pRegistryKey, 39 const rtl::OUString & rImplementationName, 40 uno::Sequence< rtl::OUString > const & rServiceNames ) 41 { 42 rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) ); 43 aKeyName += rImplementationName; 44 aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" ); 45 46 uno::Reference< registry::XRegistryKey > xKey; 47 try 48 { 49 xKey = static_cast< registry::XRegistryKey * >( 50 pRegistryKey )->createKey( aKeyName ); 51 } 52 catch ( registry::InvalidRegistryException const & ) 53 { 54 } 55 56 if ( !xKey.is() ) 57 return sal_False; 58 59 sal_Bool bSuccess = sal_True; 60 61 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) 62 { 63 try 64 { 65 xKey->createKey( rServiceNames[ n ] ); 66 } 67 catch ( registry::InvalidRegistryException const & ) 68 { 69 bSuccess = sal_False; 70 break; 71 } 72 } 73 return bSuccess; 74 } 75 76 } 77 78 //========================================================================= 79 extern "C" void SAL_CALL component_getImplementationEnvironment( 80 const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 81 { 82 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 83 } 84 85 //========================================================================= 86 extern "C" sal_Bool SAL_CALL component_writeInfo( 87 void * /*pServiceManager*/, void * pRegistryKey ) 88 { 89 return pRegistryKey && 90 91 ////////////////////////////////////////////////////////////////////// 92 // Write info into registry. 93 ////////////////////////////////////////////////////////////////////// 94 95 // @@@ Adjust namespace names. 96 writeInfo( pRegistryKey, 97 ::myucp::ContentProvider::getImplementationName_Static(), 98 ::myucp::ContentProvider::getSupportedServiceNames_Static() ); 99 } 100 101 //========================================================================= 102 extern "C" void * SAL_CALL component_getFactory( 103 const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) 104 { 105 void * pRet = 0; 106 107 uno::Reference< lang::XMultiServiceFactory > xSMgr( 108 reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) ); 109 uno::Reference< lang::XSingleServiceFactory > xFactory; 110 111 ////////////////////////////////////////////////////////////////////// 112 // Create factory, if implementation name matches. 113 ////////////////////////////////////////////////////////////////////// 114 115 // @@@ Adjust namespace names. 116 if ( ::myucp::ContentProvider::getImplementationName_Static(). 117 compareToAscii( pImplName ) == 0 ) 118 { 119 xFactory = ::myucp::ContentProvider::createServiceFactory( xSMgr ); 120 } 121 122 ////////////////////////////////////////////////////////////////////// 123 124 if ( xFactory.is() ) 125 { 126 xFactory->acquire(); 127 pRet = xFactory.get(); 128 } 129 130 return pRet; 131 } 132 133