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 #include <cppuhelper/factory.hxx>
29 
30 #include "MyProtocolHandler.h"
31 #include "MyListener.h"
32 
33 namespace css = ::com::sun::star;
34 
35 #if 0
36 static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey       ,
37                       const char*                                               pImplementationName,
38                       const char*                                               pServiceName       )
39 {
40     ::rtl::OUStringBuffer sKey(256);
41 	sKey.append     (::rtl::OUString::createFromAscii(pImplementationName));
42     sKey.appendAscii("/UNO/SERVICES/");
43     sKey.append     (::rtl::OUString::createFromAscii(pServiceName));
44 
45     xRegistryKey->createKey(sKey.makeStringAndClear());
46 }
47 #endif
48 
49 extern "C"
50 {
51 //==================================================================================================
52 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char**        ppEnvTypeName,
53                                                                                  uno_Environment** ppEnv        )
54 {
55 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
56 }
57 
58 #if 0
59 /**
60  * This method not longer necessary since OOo 3.4 where the component registration was
61  * was changed to passive component registration. For more details see
62  * http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
63  */
64 //==================================================================================================
65 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
66                                                             void* pRegistryKey   )
67 {
68     if (!pRegistryKey)
69         return sal_False;
70 
71     try
72     {
73         css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY);
74 
75         writeInfo( xKey, MYLISTENER_IMPLEMENTATIONNAME       , MYLISTENER_SERVICENAME        );
76         writeInfo( xKey, MYPROTOCOLHANDLER_IMPLEMENTATIONNAME, MYPROTOCOLHANDLER_SERVICENAME );
77 
78         return sal_True;
79     }
80     catch(const css::registry::InvalidRegistryException&)
81         { OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); }
82 
83     return sal_False;
84 }
85 #endif
86 
87 //==================================================================================================
88 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName      ,
89                                                                 void*     pServiceManager,
90                                                                 void*     pRegistryKey   )
91 {
92     if ( !pServiceManager || !pImplName )
93         return 0;
94 
95     css::uno::Reference< css::lang::XSingleServiceFactory > xFactory  ;
96     css::uno::Reference< css::lang::XMultiServiceFactory >  xSMGR     (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY);
97     ::rtl::OUString                                         sImplName = ::rtl::OUString::createFromAscii(pImplName);
98 
99     if (sImplName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYLISTENER_IMPLEMENTATIONNAME ) ) )
100 	{
101         css::uno::Sequence< ::rtl::OUString > lNames(1);
102         lNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYLISTENER_IMPLEMENTATIONNAME ) );
103 		xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames);
104 	}
105     else
106     if (sImplName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYPROTOCOLHANDLER_IMPLEMENTATIONNAME ) ) )
107 	{
108         css::uno::Sequence< ::rtl::OUString > lNames(1);
109         lNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) );
110         xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyProtocolHandler_createInstance, lNames);
111 	}
112 
113     if (!xFactory.is())
114         return 0;
115 
116     xFactory->acquire();
117     return xFactory.get();
118 }
119 
120 } // extern C
121