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_xmlsecurity.hxx"
26 #include <sal/config.h>
27 #include <rtl/uuid.h>
28 #include "xmlencryptiontemplateimpl.hxx"
29 
30 using namespace ::com::sun::star::uno ;
31 using ::com::sun::star::lang::XMultiServiceFactory ;
32 using ::com::sun::star::lang::XSingleServiceFactory ;
33 using ::rtl::OUString ;
34 
35 using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
36 using ::com::sun::star::xml::crypto::XXMLEncryptionTemplate ;
37 
XMLEncryptionTemplateImpl(const Reference<XMultiServiceFactory> & aFactory)38 XMLEncryptionTemplateImpl :: XMLEncryptionTemplateImpl( const Reference< XMultiServiceFactory >& aFactory )
39 	: m_xTemplate( NULL ),
40       m_xTarget( NULL ),
41       m_xServiceManager( aFactory ),
42 	  m_nStatus ( ::com::sun::star::xml::crypto::SecurityOperationStatus_UNKNOWN ) {
43 }
44 
~XMLEncryptionTemplateImpl()45 XMLEncryptionTemplateImpl :: ~XMLEncryptionTemplateImpl() {
46 }
47 
48 /* XXMLEncryptionTemplate */
setTemplate(const Reference<XXMLElementWrapper> & aTemplate)49 void SAL_CALL XMLEncryptionTemplateImpl :: setTemplate( const Reference< XXMLElementWrapper >& aTemplate )
50 	throw (com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
51 {
52 	m_xTemplate = aTemplate ;
53 }
54 
55 /* XXMLEncryptionTemplate */
getTemplate()56 Reference< XXMLElementWrapper > SAL_CALL XMLEncryptionTemplateImpl :: getTemplate()
57 throw (com::sun::star::uno::RuntimeException)
58 {
59 	return m_xTemplate ;
60 }
61 
62 /* XXMLEncryptionTemplate */
setTarget(const Reference<XXMLElementWrapper> & aTarget)63 void SAL_CALL XMLEncryptionTemplateImpl :: setTarget( const Reference< XXMLElementWrapper >& aTarget )
64 	throw( com::sun::star::lang::IllegalArgumentException ) {
65 	m_xTarget = aTarget ;
66 }
67 
68 /* XXMLEncryptionTemplate */
getTarget()69 Reference< XXMLElementWrapper > SAL_CALL XMLEncryptionTemplateImpl :: getTarget()
70 throw (com::sun::star::uno::RuntimeException)
71 {
72 	return m_xTarget ;
73 }
74 
setStatus(::com::sun::star::xml::crypto::SecurityOperationStatus status)75 void SAL_CALL XMLEncryptionTemplateImpl::setStatus(
76 	::com::sun::star::xml::crypto::SecurityOperationStatus status )
77 	throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
78 {
79 	m_nStatus = status;
80 }
81 
getStatus()82 ::com::sun::star::xml::crypto::SecurityOperationStatus SAL_CALL XMLEncryptionTemplateImpl::getStatus(  )
83 	throw (::com::sun::star::uno::RuntimeException)
84 {
85 	return m_nStatus;
86 }
87 
88 /* XInitialization */
initialize(const Sequence<Any> &)89 void SAL_CALL XMLEncryptionTemplateImpl :: initialize( const Sequence< Any >& /*aArguments*/ )
90     throw( Exception, RuntimeException ) {
91 	// TBD
92 } ;
93 
94 /* XServiceInfo */
getImplementationName()95 OUString SAL_CALL XMLEncryptionTemplateImpl :: getImplementationName() throw( RuntimeException ) {
96 	return impl_getImplementationName() ;
97 }
98 
99 /* XServiceInfo */
supportsService(const OUString & serviceName)100 sal_Bool SAL_CALL XMLEncryptionTemplateImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
101 	Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
102 	const OUString* pArray = seqServiceNames.getConstArray() ;
103 	for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
104 		if( *( pArray + i ) == serviceName )
105 			return sal_True ;
106 	}
107 	return sal_False ;
108 }
109 
110 /* XServiceInfo */
getSupportedServiceNames()111 Sequence< OUString > SAL_CALL XMLEncryptionTemplateImpl :: getSupportedServiceNames() throw( RuntimeException ) {
112 	return impl_getSupportedServiceNames() ;
113 }
114 
115 //Helper for XServiceInfo
impl_getSupportedServiceNames()116 Sequence< OUString > XMLEncryptionTemplateImpl :: impl_getSupportedServiceNames() {
117 	::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
118 	Sequence< OUString > seqServiceNames( 1 ) ;
119 	seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLEncryptionTemplate" ) ;
120 	return seqServiceNames ;
121 }
122 
impl_getImplementationName()123 OUString XMLEncryptionTemplateImpl :: impl_getImplementationName() throw( RuntimeException ) {
124 	return OUString::createFromAscii( "com.sun.star.xml.security.framework.XMLEncryptionTemplateImpl" ) ;
125 }
126 
127 //Helper for registry
impl_createInstance(const Reference<XMultiServiceFactory> & aServiceManager)128 Reference< XInterface > SAL_CALL XMLEncryptionTemplateImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
129 	return Reference< XInterface >( *new XMLEncryptionTemplateImpl( aServiceManager ) ) ;
130 }
131 
impl_createFactory(const Reference<XMultiServiceFactory> & aServiceManager)132 Reference< XSingleServiceFactory > XMLEncryptionTemplateImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
133 	//Reference< XSingleServiceFactory > xFactory ;
134 	//xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
135 	//return xFactory ;
136 	return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
137 }
138 
139