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 
27 #include "elementmark.hxx"
28 #include "elementcollector.hxx"
29 #include "buffernode.hxx"
30 #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
31 
32 namespace cssu = com::sun::star::uno;
33 namespace cssxc = com::sun::star::xml::crypto;
34 
ElementCollector(sal_Int32 nSecurityId,sal_Int32 nBufferId,cssxc::sax::ElementMarkPriority nPriority,bool bToModify,const com::sun::star::uno::Reference<com::sun::star::xml::crypto::sax::XReferenceResolvedListener> & xReferenceResolvedListener)35 ElementCollector::ElementCollector(
36 	sal_Int32 nSecurityId,
37 	sal_Int32 nBufferId,
38 	cssxc::sax::ElementMarkPriority nPriority,
39 	bool bToModify,
40 	const com::sun::star::uno::Reference<
41 		com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
42 		xReferenceResolvedListener)
43 	:ElementMark(nSecurityId, nBufferId),
44 	 m_nPriority(nPriority),
45 	 m_bToModify(bToModify),
46  	 m_bAbleToNotify(false),
47  	 m_bNotified(false),
48 	 m_xReferenceResolvedListener(xReferenceResolvedListener)
49 /****** ElementCollector/ElementCollector *************************************
50  *
51  *   NAME
52  *	ElementCollector -- constructor method
53  *
54  *   SYNOPSIS
55  *	ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
56  *	                 xReferenceResolvedListener);
57  *
58  *   FUNCTION
59  *	construct an ElementCollector object.
60  *
61  *   INPUTS
62  *	nSecurityId - 	represents which security entity the buffer node is
63  *			related with. Either a signature or an encryption is
64  *			a security entity.
65  *	nBufferId -	the id of the element bufferred in the document
66  *			wrapper component. The document wrapper component
67  *			uses this id to search the particular bufferred
68  *			element.
69  *	nPriority -	the priority value. ElementCollector with lower
70  *			priority value can't notify until all ElementCollectors
71  *			with higher priority value have notified.
72  *	bToModify -	A flag representing whether this ElementCollector
73  *			notification will cause the modification of its working
74  *	                element.
75  *	xReferenceResolvedListener
76  *	          -	the listener that this ElementCollector notifies to.
77  *
78  *   RESULT
79  *	empty
80  *
81  *   HISTORY
82  *	05.01.2004 -	implemented
83  *
84  *   AUTHOR
85  *	Michael Mi
86  *	Email: michael.mi@sun.com
87  ******************************************************************************/
88 {
89 	m_type = cssxc::sax::ElementMarkType_ELEMENTCOLLECTOR;
90 }
91 
92 /*
93 bool ElementCollector::isInternalNotificationSuppressed() const
94 {
95 	return m_bInternalNotificationSuppressed;
96 }
97 */
98 
getPriority() const99 cssxc::sax::ElementMarkPriority ElementCollector::getPriority() const
100 {
101 	return m_nPriority;
102 }
103 
getModify() const104 bool ElementCollector::getModify() const
105 {
106 	return m_bToModify;
107 }
108 
notifyListener()109 void ElementCollector::notifyListener()
110 /****** ElementCollector/notifyListener ***************************************
111  *
112  *   NAME
113  *	notifyListener -- enable the ability to notify the listener
114  *
115  *   SYNOPSIS
116  *	notifyListener();
117  *
118  *   FUNCTION
119  *	enable the ability to notify the listener and try to notify then.
120  *
121  *   INPUTS
122  *	empty
123  *
124  *   RESULT
125  *	empty
126  *
127  *   HISTORY
128  *	05.01.2004 -	implemented
129  *
130  *   AUTHOR
131  *	Michael Mi
132  *	Email: michael.mi@sun.com
133  ******************************************************************************/
134 {
135 	m_bAbleToNotify = true;
136 	doNotify();
137 }
138 
isAbleToNotify() const139 bool ElementCollector::isAbleToNotify() const
140 {
141 	return m_bAbleToNotify;
142 }
143 
setReferenceResolvedListener(const cssu::Reference<cssxc::sax::XReferenceResolvedListener> & xReferenceResolvedListener)144 void ElementCollector::setReferenceResolvedListener(
145 	const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
146 /****** ElementCollector/setReferenceResolvedListener *************************
147  *
148  *   NAME
149  *	setReferenceResolvedListener -- configures a listener for the buffer
150  *	node in this object
151  *
152  *   SYNOPSIS
153  *	setReferenceResolvedListener(xReferenceResolvedListener);
154  *
155  *   FUNCTION
156  *	configures a new listener and try to notify then.
157  *
158  *   INPUTS
159  *	xReferenceResolvedListener - the new listener
160  *
161  *   RESULT
162  *	empty
163  *
164  *   HISTORY
165  *	05.01.2004 -	implemented
166  *
167  *   AUTHOR
168  *	Michael Mi
169  *	Email: michael.mi@sun.com
170  ******************************************************************************/
171 {
172 	m_xReferenceResolvedListener = xReferenceResolvedListener;
173 	doNotify();
174 }
175 
setSecurityId(sal_Int32 nSecurityId)176 void ElementCollector::setSecurityId(sal_Int32 nSecurityId)
177 /****** ElementCollector/setSecurityId ****************************************
178  *
179  *   NAME
180  *	setSecurityId -- configures the security Id of the buffer node
181  *
182  *   SYNOPSIS
183  *	setSecurityId(nSecurityId);
184  *
185  *   FUNCTION
186  *	configures the security Id and try to notify then
187  *
188  *   INPUTS
189  *	nSecurityId - the security Id
190  *
191  *   RESULT
192  *	empty
193  *
194  *   HISTORY
195  *	05.01.2004 -	implemented
196  *
197  *   AUTHOR
198  *	Michael Mi
199  *	Email: michael.mi@sun.com
200  ******************************************************************************/
201 {
202 	m_nSecurityId = nSecurityId;
203 	doNotify();
204 }
205 
doNotify()206 void ElementCollector::doNotify()
207 /****** ElementCollector/doNotify *********************************************
208  *
209  *   NAME
210  *	doNotify -- tries to notify the listener
211  *
212  *   SYNOPSIS
213  *	doNotify();
214  *
215  *   FUNCTION
216  *	notifies the listener when all below conditions are satisfied:
217  *	the listener has not been notified;
218  *	the notify right is granted;
219  *	the listener has already been configured;
220  *	the security id has already been configure
221  *
222  *   INPUTS
223  *	empty
224  *
225  *   RESULT
226  *	empty
227  *
228  *   HISTORY
229  *	05.01.2004 -	implemented
230  *
231  *   AUTHOR
232  *	Michael Mi
233  *	Email: michael.mi@sun.com
234  ******************************************************************************/
235 {
236 	if (!m_bNotified &&
237 	    m_bAbleToNotify &&
238 	    m_xReferenceResolvedListener.is() &&
239 	    m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
240 	{
241 		m_bNotified = true;
242 		m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
243 	}
244 }
245 
clone(sal_Int32 nBufferId,cssxc::sax::ElementMarkPriority nPriority) const246 ElementCollector* ElementCollector::clone(
247 	sal_Int32 nBufferId,
248 	cssxc::sax::ElementMarkPriority nPriority ) const
249 /****** ElementCollector/clone ************************************************
250  *
251  *   NAME
252  *	clone -- duplicates this ElementCollector object
253  *
254  *   SYNOPSIS
255  *	cloned = clone(nBufferId, nPriority);
256  *
257  *   FUNCTION
258  *	duplicates this ElementCollector object with new buffer Id, priority.
259  *
260  *   INPUTS
261  *	nBufferId -	the buffer node's Id
262  *	nPriority -	the priority
263  *
264  *   RESULT
265  *	clone - 	a new ElementCollector
266  *
267  *   HISTORY
268  *	05.01.2004 -	implemented
269  *
270  *   AUTHOR
271  *	Michael Mi
272  *	Email: michael.mi@sun.com
273  ******************************************************************************/
274 {
275 	ElementCollector* pClonedOne
276 		= new ElementCollector(m_nSecurityId,
277 				       nBufferId, nPriority, m_bToModify,
278 				       m_xReferenceResolvedListener);
279 
280 	if (m_bAbleToNotify)
281 	{
282 		pClonedOne->notifyListener();
283 	}
284 
285 	if (m_pBufferNode != NULL)
286 	{
287 		m_pBufferNode->addElementCollector(pClonedOne);
288 	}
289 
290 	return pClonedOne;
291 }
292 
293