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