Update ooo320-m1
[ooovba.git] / xmlsecurity / source / framework / elementcollector.cxx
blobab0cdf6d2940d32a1a187fda7aac49f4b967c864
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: elementcollector.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "elementmark.hxx"
35 #include "elementcollector.hxx"
36 #include "buffernode.hxx"
37 #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
39 namespace cssu = com::sun::star::uno;
40 namespace cssxc = com::sun::star::xml::crypto;
42 ElementCollector::ElementCollector(
43 sal_Int32 nSecurityId,
44 sal_Int32 nBufferId,
45 cssxc::sax::ElementMarkPriority nPriority,
46 bool bToModify,
47 const com::sun::star::uno::Reference<
48 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
49 xReferenceResolvedListener)
50 :ElementMark(nSecurityId, nBufferId),
51 m_nPriority(nPriority),
52 m_bToModify(bToModify),
53 m_bAbleToNotify(false),
54 m_bNotified(false),
55 m_xReferenceResolvedListener(xReferenceResolvedListener)
56 /****** ElementCollector/ElementCollector *************************************
58 * NAME
59 * ElementCollector -- constructor method
61 * SYNOPSIS
62 * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
63 * xReferenceResolvedListener);
65 * FUNCTION
66 * construct an ElementCollector object.
68 * INPUTS
69 * nSecurityId - represents which security entity the buffer node is
70 * related with. Either a signature or an encryption is
71 * a security entity.
72 * nBufferId - the id of the element bufferred in the document
73 * wrapper component. The document wrapper component
74 * uses this id to search the particular bufferred
75 * element.
76 * nPriority - the priority value. ElementCollector with lower
77 * priority value can't notify until all ElementCollectors
78 * with higher priority value have notified.
79 * bToModify - A flag representing whether this ElementCollector
80 * notification will cause the modification of its working
81 * element.
82 * xReferenceResolvedListener
83 * - the listener that this ElementCollector notifies to.
85 * RESULT
86 * empty
88 * HISTORY
89 * 05.01.2004 - implemented
91 * AUTHOR
92 * Michael Mi
93 * Email: michael.mi@sun.com
94 ******************************************************************************/
96 m_type = cssxc::sax::ElementMarkType_ELEMENTCOLLECTOR;
100 bool ElementCollector::isInternalNotificationSuppressed() const
102 return m_bInternalNotificationSuppressed;
106 cssxc::sax::ElementMarkPriority ElementCollector::getPriority() const
108 return m_nPriority;
111 bool ElementCollector::getModify() const
113 return m_bToModify;
116 void ElementCollector::notifyListener()
117 /****** ElementCollector/notifyListener ***************************************
119 * NAME
120 * notifyListener -- enable the ability to notify the listener
122 * SYNOPSIS
123 * notifyListener();
125 * FUNCTION
126 * enable the ability to notify the listener and try to notify then.
128 * INPUTS
129 * empty
131 * RESULT
132 * empty
134 * HISTORY
135 * 05.01.2004 - implemented
137 * AUTHOR
138 * Michael Mi
139 * Email: michael.mi@sun.com
140 ******************************************************************************/
142 m_bAbleToNotify = true;
143 doNotify();
146 bool ElementCollector::isAbleToNotify() const
148 return m_bAbleToNotify;
151 void ElementCollector::setReferenceResolvedListener(
152 const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
153 /****** ElementCollector/setReferenceResolvedListener *************************
155 * NAME
156 * setReferenceResolvedListener -- configures a listener for the buffer
157 * node in this object
159 * SYNOPSIS
160 * setReferenceResolvedListener(xReferenceResolvedListener);
162 * FUNCTION
163 * configures a new listener and try to notify then.
165 * INPUTS
166 * xReferenceResolvedListener - the new listener
168 * RESULT
169 * empty
171 * HISTORY
172 * 05.01.2004 - implemented
174 * AUTHOR
175 * Michael Mi
176 * Email: michael.mi@sun.com
177 ******************************************************************************/
179 m_xReferenceResolvedListener = xReferenceResolvedListener;
180 doNotify();
183 void ElementCollector::setSecurityId(sal_Int32 nSecurityId)
184 /****** ElementCollector/setSecurityId ****************************************
186 * NAME
187 * setSecurityId -- configures the security Id of the buffer node
189 * SYNOPSIS
190 * setSecurityId(nSecurityId);
192 * FUNCTION
193 * configures the security Id and try to notify then
195 * INPUTS
196 * nSecurityId - the security Id
198 * RESULT
199 * empty
201 * HISTORY
202 * 05.01.2004 - implemented
204 * AUTHOR
205 * Michael Mi
206 * Email: michael.mi@sun.com
207 ******************************************************************************/
209 m_nSecurityId = nSecurityId;
210 doNotify();
213 void ElementCollector::doNotify()
214 /****** ElementCollector/doNotify *********************************************
216 * NAME
217 * doNotify -- tries to notify the listener
219 * SYNOPSIS
220 * doNotify();
222 * FUNCTION
223 * notifies the listener when all below conditions are satisfied:
224 * the listener has not been notified;
225 * the notify right is granted;
226 * the listener has already been configured;
227 * the security id has already been configure
229 * INPUTS
230 * empty
232 * RESULT
233 * empty
235 * HISTORY
236 * 05.01.2004 - implemented
238 * AUTHOR
239 * Michael Mi
240 * Email: michael.mi@sun.com
241 ******************************************************************************/
243 if (!m_bNotified &&
244 m_bAbleToNotify &&
245 m_xReferenceResolvedListener.is() &&
246 m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
248 m_bNotified = true;
249 m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
253 ElementCollector* ElementCollector::clone(
254 sal_Int32 nBufferId,
255 cssxc::sax::ElementMarkPriority nPriority ) const
256 /****** ElementCollector/clone ************************************************
258 * NAME
259 * clone -- duplicates this ElementCollector object
261 * SYNOPSIS
262 * cloned = clone(nBufferId, nPriority);
264 * FUNCTION
265 * duplicates this ElementCollector object with new buffer Id, priority.
267 * INPUTS
268 * nBufferId - the buffer node's Id
269 * nPriority - the priority
271 * RESULT
272 * clone - a new ElementCollector
274 * HISTORY
275 * 05.01.2004 - implemented
277 * AUTHOR
278 * Michael Mi
279 * Email: michael.mi@sun.com
280 ******************************************************************************/
282 ElementCollector* pClonedOne
283 = new ElementCollector(m_nSecurityId,
284 nBufferId, nPriority, m_bToModify,
285 m_xReferenceResolvedListener);
287 if (m_bAbleToNotify)
289 pClonedOne->notifyListener();
292 if (m_pBufferNode != NULL)
294 m_pBufferNode->addElementCollector(pClonedOne);
297 return pClonedOne;