1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xsec_framework.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
36 #include <osl/mutex.hxx>
37 #include <osl/thread.h>
38 #include <cppuhelper/factory.hxx>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <decryptorimpl.hxx>
42 #include <encryptorimpl.hxx>
43 #include <signaturecreatorimpl.hxx>
44 #include <signatureverifierimpl.hxx>
45 #include <saxeventkeeperimpl.hxx>
46 #include <xmlencryptiontemplateimpl.hxx>
47 #include <xmlsignaturetemplateimpl.hxx>
49 using namespace ::rtl
;
50 using namespace ::cppu
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::registry
;
57 //==================================================================================================
58 void SAL_CALL
component_getImplementationEnvironment(
59 const sal_Char
** ppEnvTypeName
, uno_Environment
**)
61 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
64 //==================================================================================================
65 sal_Bool SAL_CALL
component_writeInfo(
66 void * /*pServiceManager*/, void * pRegistryKey
)
74 Reference
< XRegistryKey
> xNewKey(
75 reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( DecryptorImpl_getImplementationName() ) );
76 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
78 const Sequence
< OUString
> & rSNL
= DecryptorImpl_getSupportedServiceNames();
79 const OUString
* pArray
= rSNL
.getConstArray();
80 for ( nPos
= rSNL
.getLength(); nPos
--; )
81 xNewKey
->createKey( pArray
[nPos
] );
84 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( EncryptorImpl_getImplementationName() );
85 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
86 const Sequence
< OUString
> & rSNL2
= EncryptorImpl_getSupportedServiceNames();
87 pArray
= rSNL2
.getConstArray();
88 for ( nPos
= rSNL2
.getLength(); nPos
--; )
89 xNewKey
->createKey( pArray
[nPos
] );
92 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( SignatureCreatorImpl_getImplementationName() );
93 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
94 const Sequence
< OUString
> & rSNL3
= SignatureCreatorImpl_getSupportedServiceNames();
95 pArray
= rSNL3
.getConstArray();
96 for ( nPos
= rSNL3
.getLength(); nPos
--; )
97 xNewKey
->createKey( pArray
[nPos
] );
100 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( SignatureVerifierImpl_getImplementationName() );
101 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
102 const Sequence
< OUString
> & rSNL4
= SignatureVerifierImpl_getSupportedServiceNames();
103 pArray
= rSNL4
.getConstArray();
104 for ( nPos
= rSNL4
.getLength(); nPos
--; )
105 xNewKey
->createKey( pArray
[nPos
] );
108 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( SAXEventKeeperImpl_getImplementationName() );
109 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
110 const Sequence
< OUString
> & rSNL5
= SAXEventKeeperImpl_getSupportedServiceNames();
111 pArray
= rSNL5
.getConstArray();
112 for ( nPos
= rSNL5
.getLength(); nPos
--; )
113 xNewKey
->createKey( pArray
[nPos
] );
115 //XMLSignatureTemplateImpl
116 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( XMLSignatureTemplateImpl::impl_getImplementationName() );
117 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
118 const Sequence
< OUString
> & rSNL6
= XMLSignatureTemplateImpl::impl_getSupportedServiceNames();
119 pArray
= rSNL6
.getConstArray();
120 for ( nPos
= rSNL6
.getLength(); nPos
--; )
121 xNewKey
->createKey( pArray
[nPos
] );
123 // XMLEncryptionTemplateImpl
124 xNewKey
= reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( XMLEncryptionTemplateImpl::impl_getImplementationName() );
125 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
126 const Sequence
< OUString
> & rSNL7
= XMLEncryptionTemplateImpl::impl_getSupportedServiceNames();
127 pArray
= rSNL7
.getConstArray();
128 for ( nPos
= rSNL7
.getLength(); nPos
--; )
129 xNewKey
->createKey( pArray
[nPos
] );
133 catch (InvalidRegistryException
&)
135 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
141 //==================================================================================================
142 void * SAL_CALL
component_getFactory(
143 const sal_Char
* pImplName
, void * pServiceManager
, void * /*pRegistryKey*/ )
148 OUString implName
= OUString::createFromAscii( pImplName
);
149 if ( pServiceManager
&& implName
.equals(DecryptorImpl_getImplementationName()) )
151 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
152 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
153 OUString::createFromAscii( pImplName
),
154 DecryptorImpl_createInstance
, DecryptorImpl_getSupportedServiceNames() ) );
159 pRet
= xFactory
.get();
164 if ( pServiceManager
&& implName
.equals(EncryptorImpl_getImplementationName()) )
166 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
167 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
168 OUString::createFromAscii( pImplName
),
169 EncryptorImpl_createInstance
, EncryptorImpl_getSupportedServiceNames() ) );
174 pRet
= xFactory
.get();
179 if ( pServiceManager
&& implName
.equals(SignatureCreatorImpl_getImplementationName()) )
181 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
182 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
183 OUString::createFromAscii( pImplName
),
184 SignatureCreatorImpl_createInstance
, SignatureCreatorImpl_getSupportedServiceNames() ) );
189 pRet
= xFactory
.get();
194 if ( pServiceManager
&& implName
.equals(SignatureVerifierImpl_getImplementationName()) )
196 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
197 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
198 OUString::createFromAscii( pImplName
),
199 SignatureVerifierImpl_createInstance
, SignatureVerifierImpl_getSupportedServiceNames() ) );
204 pRet
= xFactory
.get();
209 if ( pServiceManager
&& implName
.equals(SAXEventKeeperImpl_getImplementationName()) )
211 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
212 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
213 OUString::createFromAscii( pImplName
),
214 SAXEventKeeperImpl_createInstance
, SAXEventKeeperImpl_getSupportedServiceNames() ) );
219 pRet
= xFactory
.get();
223 //XMLSignatureTemplate
224 if ( pServiceManager
&& implName
.equals( XMLSignatureTemplateImpl::impl_getImplementationName()) )
226 Reference
< XSingleServiceFactory
> xFactory
= XMLSignatureTemplateImpl::impl_createFactory(
227 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
) ) ;
232 pRet
= xFactory
.get();
236 //XMLEncryptionTemplate
237 if ( pServiceManager
&& implName
.equals( XMLEncryptionTemplateImpl::impl_getImplementationName()) )
239 Reference
< XSingleServiceFactory
> xFactory
= XMLEncryptionTemplateImpl::impl_createFactory(
240 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
) ) ;
245 pRet
= xFactory
.get();