Bump version to 5.0-14
[LibreOffice.git] / xmlsecurity / source / framework / elementcollector.cxx
blob96c242020e58c0510227232e73c6a9d14e8888a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "elementmark.hxx"
22 #include "elementcollector.hxx"
23 #include "buffernode.hxx"
24 #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
26 namespace cssu = com::sun::star::uno;
27 namespace cssxc = com::sun::star::xml::crypto;
29 ElementCollector::ElementCollector(
30 sal_Int32 nSecurityId,
31 sal_Int32 nBufferId,
32 cssxc::sax::ElementMarkPriority nPriority,
33 bool bToModify,
34 const com::sun::star::uno::Reference<
35 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
36 xReferenceResolvedListener)
37 :ElementMark(nSecurityId, nBufferId),
38 m_nPriority(nPriority),
39 m_bToModify(bToModify),
40 m_bAbleToNotify(false),
41 m_bNotified(false),
42 m_xReferenceResolvedListener(xReferenceResolvedListener)
43 /****** ElementCollector/ElementCollector *************************************
45 * NAME
46 * ElementCollector -- constructor method
48 * SYNOPSIS
49 * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
50 * xReferenceResolvedListener);
52 * FUNCTION
53 * construct an ElementCollector object.
55 * INPUTS
56 * nSecurityId - represents which security entity the buffer node is
57 * related with. Either a signature or an encryption is
58 * a security entity.
59 * nBufferId - the id of the element bufferred in the document
60 * wrapper component. The document wrapper component
61 * uses this id to search the particular bufferred
62 * element.
63 * nPriority - the priority value. ElementCollector with lower
64 * priority value can't notify until all ElementCollectors
65 * with higher priority value have notified.
66 * bToModify - A flag representing whether this ElementCollector
67 * notification will cause the modification of its working
68 * element.
69 * xReferenceResolvedListener
70 * - the listener that this ElementCollector notifies to.
72 * RESULT
73 * empty
75 * AUTHOR
76 * Michael Mi
77 * Email: michael.mi@sun.com
78 ******************************************************************************/
80 m_type = cssxc::sax::ElementMarkType_ELEMENTCOLLECTOR;
85 void ElementCollector::notifyListener()
86 /****** ElementCollector/notifyListener ***************************************
88 * NAME
89 * notifyListener -- enable the ability to notify the listener
91 * SYNOPSIS
92 * notifyListener();
94 * FUNCTION
95 * enable the ability to notify the listener and try to notify then.
97 * INPUTS
98 * empty
100 * RESULT
101 * empty
103 * AUTHOR
104 * Michael Mi
105 * Email: michael.mi@sun.com
106 ******************************************************************************/
108 m_bAbleToNotify = true;
109 doNotify();
112 void ElementCollector::setReferenceResolvedListener(
113 const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
114 /****** ElementCollector/setReferenceResolvedListener *************************
116 * NAME
117 * setReferenceResolvedListener -- configures a listener for the buffer
118 * node in this object
120 * SYNOPSIS
121 * setReferenceResolvedListener(xReferenceResolvedListener);
123 * FUNCTION
124 * configures a new listener and try to notify then.
126 * INPUTS
127 * xReferenceResolvedListener - the new listener
129 * RESULT
130 * empty
132 * AUTHOR
133 * Michael Mi
134 * Email: michael.mi@sun.com
135 ******************************************************************************/
137 m_xReferenceResolvedListener = xReferenceResolvedListener;
138 doNotify();
141 void ElementCollector::doNotify()
142 /****** ElementCollector/doNotify *********************************************
144 * NAME
145 * doNotify -- tries to notify the listener
147 * SYNOPSIS
148 * doNotify();
150 * FUNCTION
151 * notifies the listener when all below conditions are satisfied:
152 * the listener has not been notified;
153 * the notify right is granted;
154 * the listener has already been configured;
155 * the security id has already been configure
157 * INPUTS
158 * empty
160 * RESULT
161 * empty
163 * AUTHOR
164 * Michael Mi
165 * Email: michael.mi@sun.com
166 ******************************************************************************/
168 if (!m_bNotified &&
169 m_bAbleToNotify &&
170 m_xReferenceResolvedListener.is() &&
171 m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
173 m_bNotified = true;
174 m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
178 ElementCollector* ElementCollector::clone(
179 sal_Int32 nBufferId,
180 cssxc::sax::ElementMarkPriority nPriority ) const
181 /****** ElementCollector/clone ************************************************
183 * NAME
184 * clone -- duplicates this ElementCollector object
186 * SYNOPSIS
187 * cloned = clone(nBufferId, nPriority);
189 * FUNCTION
190 * duplicates this ElementCollector object with new buffer Id, priority.
192 * INPUTS
193 * nBufferId - the buffer node's Id
194 * nPriority - the priority
196 * RESULT
197 * clone - a new ElementCollector
199 * AUTHOR
200 * Michael Mi
201 * Email: michael.mi@sun.com
202 ******************************************************************************/
204 ElementCollector* pClonedOne
205 = new ElementCollector(m_nSecurityId,
206 nBufferId, nPriority, m_bToModify,
207 m_xReferenceResolvedListener);
209 if (m_bAbleToNotify)
211 pClonedOne->notifyListener();
214 if (m_pBufferNode != NULL)
216 m_pBufferNode->addElementCollector(pClonedOne);
219 return pClonedOne;
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */