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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
30 #include <sal/config.h>
31 #include <rtl/ustring.hxx>
32 #include <rtl/uuid.h>
33 #include "xmlsignaturetemplateimpl.hxx"
34 
35 using namespace ::com::sun::star::uno ;
36 using ::com::sun::star::lang::XMultiServiceFactory ;
37 using ::com::sun::star::lang::XSingleServiceFactory ;
38 using ::rtl::OUString ;
39 
40 using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
41 using ::com::sun::star::xml::crypto::XXMLSignatureTemplate ;
42 
43 XMLSignatureTemplateImpl :: XMLSignatureTemplateImpl( const Reference< XMultiServiceFactory >& aFactory )
44 	:m_xTemplate( NULL ),
45      m_xServiceManager( aFactory ),
46 	 m_nStatus ( ::com::sun::star::xml::crypto::SecurityOperationStatus_UNKNOWN )
47 {
48 }
49 
50 XMLSignatureTemplateImpl :: ~XMLSignatureTemplateImpl() {
51 }
52 
53 /* XXMLSignatureTemplate */
54 void SAL_CALL XMLSignatureTemplateImpl :: setTemplate( const Reference< XXMLElementWrapper >& aTemplate )
55 	throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
56 {
57 	m_xTemplate = aTemplate ;
58 }
59 
60 /* XXMLSignatureTemplate */
61 Reference< XXMLElementWrapper > SAL_CALL XMLSignatureTemplateImpl :: getTemplate()
62 	throw (com::sun::star::uno::RuntimeException)
63 {
64 	return m_xTemplate ;
65 }
66 
67 void SAL_CALL XMLSignatureTemplateImpl :: setTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >& aXmlElement )
68 	throw( com::sun::star::uno::RuntimeException, com::sun::star::lang::IllegalArgumentException)
69 {
70 	targets.push_back( aXmlElement );
71 }
72 
73 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > > SAL_CALL XMLSignatureTemplateImpl :: getTargets()
74 	throw (com::sun::star::uno::RuntimeException)
75 {
76 	sal_Int32 length = targets.size();
77 	::com::sun::star::uno::Sequence<
78 		::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper >
79 		> aTargets (length);
80 
81 	sal_Int32 i;
82 
83 	for (i=0; i<length; i++)
84 	{
85 		aTargets[i] = targets[i];
86 	}
87 
88 	return aTargets;
89 }
90 
91 void SAL_CALL XMLSignatureTemplateImpl::setBinding(
92 	const ::com::sun::star::uno::Reference<
93 		::com::sun::star::xml::crypto::XUriBinding >& aUriBinding )
94 	throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
95 {
96 	m_xUriBinding = aUriBinding;
97 }
98 
99 ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding > SAL_CALL XMLSignatureTemplateImpl::getBinding()
100 	throw (::com::sun::star::uno::RuntimeException)
101 {
102 	return m_xUriBinding;
103 }
104 
105 void SAL_CALL XMLSignatureTemplateImpl::setStatus(
106 	::com::sun::star::xml::crypto::SecurityOperationStatus status )
107 	throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
108 {
109 	m_nStatus = status;
110 }
111 
112 ::com::sun::star::xml::crypto::SecurityOperationStatus SAL_CALL XMLSignatureTemplateImpl::getStatus(  )
113 	throw (::com::sun::star::uno::RuntimeException)
114 {
115 	return m_nStatus;
116 }
117 
118 /* XInitialization */
119 void SAL_CALL XMLSignatureTemplateImpl :: initialize( const Sequence< Any >& /*aArguments*/ ) throw( Exception, RuntimeException ) {
120 	// TBD
121 } ;
122 
123 /* XServiceInfo */
124 OUString SAL_CALL XMLSignatureTemplateImpl :: getImplementationName() throw( RuntimeException ) {
125 	return impl_getImplementationName() ;
126 }
127 
128 /* XServiceInfo */
129 sal_Bool SAL_CALL XMLSignatureTemplateImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
130 	Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
131 	const OUString* pArray = seqServiceNames.getConstArray() ;
132 	for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
133 		if( *( pArray + i ) == serviceName )
134 			return sal_True ;
135 	}
136 	return sal_False ;
137 }
138 
139 /* XServiceInfo */
140 Sequence< OUString > SAL_CALL XMLSignatureTemplateImpl :: getSupportedServiceNames() throw( RuntimeException ) {
141 	return impl_getSupportedServiceNames() ;
142 }
143 
144 //Helper for XServiceInfo
145 Sequence< OUString > XMLSignatureTemplateImpl :: impl_getSupportedServiceNames() {
146 	::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
147 	Sequence< OUString > seqServiceNames( 1 ) ;
148 	seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSignatureTemplate" ) ;
149 	return seqServiceNames ;
150 }
151 
152 OUString XMLSignatureTemplateImpl :: impl_getImplementationName() throw( RuntimeException ) {
153 	return OUString::createFromAscii( "com.sun.star.xml.security.framework.XMLSignatureTemplateImpl" ) ;
154 }
155 
156 //Helper for registry
157 Reference< XInterface > SAL_CALL XMLSignatureTemplateImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
158 	return Reference< XInterface >( *new XMLSignatureTemplateImpl( aServiceManager ) ) ;
159 }
160 
161 Reference< XSingleServiceFactory > XMLSignatureTemplateImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
162 	//Reference< XSingleServiceFactory > xFactory ;
163 	//xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
164 	//return xFactory ;
165 	return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
166 }
167 
168