merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / source / framework / elementcollector.cxx
blob7f720bb86250a1d1876807fb10569735831f6d61
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include "elementmark.hxx"
32 #include "elementcollector.hxx"
33 #include "buffernode.hxx"
34 #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
36 namespace cssu = com::sun::star::uno;
37 namespace cssxc = com::sun::star::xml::crypto;
39 ElementCollector::ElementCollector(
40 sal_Int32 nSecurityId,
41 sal_Int32 nBufferId,
42 cssxc::sax::ElementMarkPriority nPriority,
43 bool bToModify,
44 const com::sun::star::uno::Reference<
45 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
46 xReferenceResolvedListener)
47 :ElementMark(nSecurityId, nBufferId),
48 m_nPriority(nPriority),
49 m_bToModify(bToModify),
50 m_bAbleToNotify(false),
51 m_bNotified(false),
52 m_xReferenceResolvedListener(xReferenceResolvedListener)
53 /****** ElementCollector/ElementCollector *************************************
55 * NAME
56 * ElementCollector -- constructor method
58 * SYNOPSIS
59 * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
60 * xReferenceResolvedListener);
62 * FUNCTION
63 * construct an ElementCollector object.
65 * INPUTS
66 * nSecurityId - represents which security entity the buffer node is
67 * related with. Either a signature or an encryption is
68 * a security entity.
69 * nBufferId - the id of the element bufferred in the document
70 * wrapper component. The document wrapper component
71 * uses this id to search the particular bufferred
72 * element.
73 * nPriority - the priority value. ElementCollector with lower
74 * priority value can't notify until all ElementCollectors
75 * with higher priority value have notified.
76 * bToModify - A flag representing whether this ElementCollector
77 * notification will cause the modification of its working
78 * element.
79 * xReferenceResolvedListener
80 * - the listener that this ElementCollector notifies to.
82 * RESULT
83 * empty
85 * HISTORY
86 * 05.01.2004 - implemented
88 * AUTHOR
89 * Michael Mi
90 * Email: michael.mi@sun.com
91 ******************************************************************************/
93 m_type = cssxc::sax::ElementMarkType_ELEMENTCOLLECTOR;
97 bool ElementCollector::isInternalNotificationSuppressed() const
99 return m_bInternalNotificationSuppressed;
103 cssxc::sax::ElementMarkPriority ElementCollector::getPriority() const
105 return m_nPriority;
108 bool ElementCollector::getModify() const
110 return m_bToModify;
113 void ElementCollector::notifyListener()
114 /****** ElementCollector/notifyListener ***************************************
116 * NAME
117 * notifyListener -- enable the ability to notify the listener
119 * SYNOPSIS
120 * notifyListener();
122 * FUNCTION
123 * enable the ability to notify the listener and try to notify then.
125 * INPUTS
126 * empty
128 * RESULT
129 * empty
131 * HISTORY
132 * 05.01.2004 - implemented
134 * AUTHOR
135 * Michael Mi
136 * Email: michael.mi@sun.com
137 ******************************************************************************/
139 m_bAbleToNotify = true;
140 doNotify();
143 bool ElementCollector::isAbleToNotify() const
145 return m_bAbleToNotify;
148 void ElementCollector::setReferenceResolvedListener(
149 const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
150 /****** ElementCollector/setReferenceResolvedListener *************************
152 * NAME
153 * setReferenceResolvedListener -- configures a listener for the buffer
154 * node in this object
156 * SYNOPSIS
157 * setReferenceResolvedListener(xReferenceResolvedListener);
159 * FUNCTION
160 * configures a new listener and try to notify then.
162 * INPUTS
163 * xReferenceResolvedListener - the new listener
165 * RESULT
166 * empty
168 * HISTORY
169 * 05.01.2004 - implemented
171 * AUTHOR
172 * Michael Mi
173 * Email: michael.mi@sun.com
174 ******************************************************************************/
176 m_xReferenceResolvedListener = xReferenceResolvedListener;
177 doNotify();
180 void ElementCollector::setSecurityId(sal_Int32 nSecurityId)
181 /****** ElementCollector/setSecurityId ****************************************
183 * NAME
184 * setSecurityId -- configures the security Id of the buffer node
186 * SYNOPSIS
187 * setSecurityId(nSecurityId);
189 * FUNCTION
190 * configures the security Id and try to notify then
192 * INPUTS
193 * nSecurityId - the security Id
195 * RESULT
196 * empty
198 * HISTORY
199 * 05.01.2004 - implemented
201 * AUTHOR
202 * Michael Mi
203 * Email: michael.mi@sun.com
204 ******************************************************************************/
206 m_nSecurityId = nSecurityId;
207 doNotify();
210 void ElementCollector::doNotify()
211 /****** ElementCollector/doNotify *********************************************
213 * NAME
214 * doNotify -- tries to notify the listener
216 * SYNOPSIS
217 * doNotify();
219 * FUNCTION
220 * notifies the listener when all below conditions are satisfied:
221 * the listener has not been notified;
222 * the notify right is granted;
223 * the listener has already been configured;
224 * the security id has already been configure
226 * INPUTS
227 * empty
229 * RESULT
230 * empty
232 * HISTORY
233 * 05.01.2004 - implemented
235 * AUTHOR
236 * Michael Mi
237 * Email: michael.mi@sun.com
238 ******************************************************************************/
240 if (!m_bNotified &&
241 m_bAbleToNotify &&
242 m_xReferenceResolvedListener.is() &&
243 m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
245 m_bNotified = true;
246 m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
250 ElementCollector* ElementCollector::clone(
251 sal_Int32 nBufferId,
252 cssxc::sax::ElementMarkPriority nPriority ) const
253 /****** ElementCollector/clone ************************************************
255 * NAME
256 * clone -- duplicates this ElementCollector object
258 * SYNOPSIS
259 * cloned = clone(nBufferId, nPriority);
261 * FUNCTION
262 * duplicates this ElementCollector object with new buffer Id, priority.
264 * INPUTS
265 * nBufferId - the buffer node's Id
266 * nPriority - the priority
268 * RESULT
269 * clone - a new ElementCollector
271 * HISTORY
272 * 05.01.2004 - implemented
274 * AUTHOR
275 * Michael Mi
276 * Email: michael.mi@sun.com
277 ******************************************************************************/
279 ElementCollector* pClonedOne
280 = new ElementCollector(m_nSecurityId,
281 nBufferId, nPriority, m_bToModify,
282 m_xReferenceResolvedListener);
284 if (m_bAbleToNotify)
286 pClonedOne->notifyListener();
289 if (m_pBufferNode != NULL)
291 m_pBufferNode->addElementCollector(pClonedOne);
294 return pClonedOne;