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