1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 29 #include <stdio.h> 30 31 #include <osl/mutex.hxx> 32 #include <osl/thread.h> 33 #include <cppuhelper/factory.hxx> 34 #include <rtl/ustring.hxx> 35 #include <rtl/ustrbuf.hxx> 36 #include <sal/types.h> 37 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 38 39 #include "MyProtocolHandler.h" 40 #include "MyListener.h" 41 42 namespace css = ::com::sun::star; 43 44 // static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey , 45 // const char* pImplementationName, 46 // const char* pServiceName ) 47 // { 48 // ::rtl::OUStringBuffer sKey(256); 49 // sKey.append (::rtl::OUString::createFromAscii(pImplementationName)); 50 // sKey.appendAscii("/UNO/SERVICES/"); 51 // sKey.append (::rtl::OUString::createFromAscii(pServiceName)); 52 53 // xRegistryKey->createKey(sKey.makeStringAndClear()); 54 // } 55 56 extern "C" 57 { 58 //================================================================================================== 59 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** ppEnvTypeName, 60 uno_Environment** ppEnv ) 61 { 62 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 63 } 64 65 // This method not longer necessary since OOo 3.4 where the component registration was 66 // was changed to passive component registration. For more details see 67 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 68 //================================================================================================== 69 // SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager, 70 // void* pRegistryKey ) 71 // { 72 // if (!pRegistryKey) 73 // return sal_False; 74 75 // try 76 // { 77 // css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY); 78 79 // writeInfo( xKey, MYLISTENER_IMPLEMENTATIONNAME , MYLISTENER_SERVICENAME ); 80 // writeInfo( xKey, MYPROTOCOLHANDLER_IMPLEMENTATIONNAME, MYPROTOCOLHANDLER_SERVICENAME ); 81 82 // return sal_True; 83 // } 84 // catch(const css::registry::InvalidRegistryException&) 85 // { OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); } 86 87 // return sal_False; 88 // } 89 90 //================================================================================================== 91 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName , 92 void* pServiceManager, 93 void* pRegistryKey ) 94 { 95 if ( !pServiceManager || !pImplName ) 96 return 0; 97 98 css::uno::Reference< css::lang::XSingleServiceFactory > xFactory ; 99 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY); 100 ::rtl::OUString sImplName = ::rtl::OUString::createFromAscii(pImplName); 101 102 if (sImplName.equalsAscii(MYLISTENER_IMPLEMENTATIONNAME)) 103 { 104 css::uno::Sequence< ::rtl::OUString > lNames(1); 105 lNames[0] = ::rtl::OUString::createFromAscii(MYLISTENER_IMPLEMENTATIONNAME); 106 xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames); 107 } 108 else 109 if (sImplName.equalsAscii(MYPROTOCOLHANDLER_IMPLEMENTATIONNAME)) 110 { 111 css::uno::Sequence< ::rtl::OUString > lNames(1); 112 lNames[0] = ::rtl::OUString::createFromAscii(MYPROTOCOLHANDLER_SERVICENAME); 113 xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyProtocolHandler_createInstance, lNames); 114 } 115 116 if (!xFactory.is()) 117 return 0; 118 119 xFactory->acquire(); 120 return xFactory.get(); 121 } 122 123 } // extern C 124