Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "elementmark.hxx"
22 : #include "elementcollector.hxx"
23 : #include "buffernode.hxx"
24 : #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
25 :
26 : namespace cssu = com::sun::star::uno;
27 : namespace cssxc = com::sun::star::xml::crypto;
28 :
29 0 : 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 0 : m_xReferenceResolvedListener(xReferenceResolvedListener)
43 : /****** ElementCollector/ElementCollector *************************************
44 : *
45 : * NAME
46 : * ElementCollector -- constructor method
47 : *
48 : * SYNOPSIS
49 : * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
50 : * xReferenceResolvedListener);
51 : *
52 : * FUNCTION
53 : * construct an ElementCollector object.
54 : *
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.
71 : *
72 : * RESULT
73 : * empty
74 : *
75 : * AUTHOR
76 : * Michael Mi
77 : * Email: michael.mi@sun.com
78 : ******************************************************************************/
79 : {
80 0 : m_type = cssxc::sax::ElementMarkType_ELEMENTCOLLECTOR;
81 0 : }
82 :
83 0 : cssxc::sax::ElementMarkPriority ElementCollector::getPriority() const
84 : {
85 0 : return m_nPriority;
86 : }
87 :
88 0 : bool ElementCollector::getModify() const
89 : {
90 0 : return m_bToModify;
91 : }
92 :
93 0 : void ElementCollector::notifyListener()
94 : /****** ElementCollector/notifyListener ***************************************
95 : *
96 : * NAME
97 : * notifyListener -- enable the ability to notify the listener
98 : *
99 : * SYNOPSIS
100 : * notifyListener();
101 : *
102 : * FUNCTION
103 : * enable the ability to notify the listener and try to notify then.
104 : *
105 : * INPUTS
106 : * empty
107 : *
108 : * RESULT
109 : * empty
110 : *
111 : * AUTHOR
112 : * Michael Mi
113 : * Email: michael.mi@sun.com
114 : ******************************************************************************/
115 : {
116 0 : m_bAbleToNotify = true;
117 0 : doNotify();
118 0 : }
119 :
120 0 : void ElementCollector::setReferenceResolvedListener(
121 : const cssu::Reference< cssxc::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
122 : /****** ElementCollector/setReferenceResolvedListener *************************
123 : *
124 : * NAME
125 : * setReferenceResolvedListener -- configures a listener for the buffer
126 : * node in this object
127 : *
128 : * SYNOPSIS
129 : * setReferenceResolvedListener(xReferenceResolvedListener);
130 : *
131 : * FUNCTION
132 : * configures a new listener and try to notify then.
133 : *
134 : * INPUTS
135 : * xReferenceResolvedListener - the new listener
136 : *
137 : * RESULT
138 : * empty
139 : *
140 : * AUTHOR
141 : * Michael Mi
142 : * Email: michael.mi@sun.com
143 : ******************************************************************************/
144 : {
145 0 : m_xReferenceResolvedListener = xReferenceResolvedListener;
146 0 : doNotify();
147 0 : }
148 :
149 0 : void ElementCollector::doNotify()
150 : /****** ElementCollector/doNotify *********************************************
151 : *
152 : * NAME
153 : * doNotify -- tries to notify the listener
154 : *
155 : * SYNOPSIS
156 : * doNotify();
157 : *
158 : * FUNCTION
159 : * notifies the listener when all below conditions are satisfied:
160 : * the listener has not been notified;
161 : * the notify right is granted;
162 : * the listener has already been configured;
163 : * the security id has already been configure
164 : *
165 : * INPUTS
166 : * empty
167 : *
168 : * RESULT
169 : * empty
170 : *
171 : * AUTHOR
172 : * Michael Mi
173 : * Email: michael.mi@sun.com
174 : ******************************************************************************/
175 : {
176 0 : if (!m_bNotified &&
177 : m_bAbleToNotify &&
178 0 : m_xReferenceResolvedListener.is() &&
179 : m_nSecurityId != cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
180 : {
181 0 : m_bNotified = true;
182 0 : m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
183 : }
184 0 : }
185 :
186 0 : ElementCollector* ElementCollector::clone(
187 : sal_Int32 nBufferId,
188 : cssxc::sax::ElementMarkPriority nPriority ) const
189 : /****** ElementCollector/clone ************************************************
190 : *
191 : * NAME
192 : * clone -- duplicates this ElementCollector object
193 : *
194 : * SYNOPSIS
195 : * cloned = clone(nBufferId, nPriority);
196 : *
197 : * FUNCTION
198 : * duplicates this ElementCollector object with new buffer Id, priority.
199 : *
200 : * INPUTS
201 : * nBufferId - the buffer node's Id
202 : * nPriority - the priority
203 : *
204 : * RESULT
205 : * clone - a new ElementCollector
206 : *
207 : * AUTHOR
208 : * Michael Mi
209 : * Email: michael.mi@sun.com
210 : ******************************************************************************/
211 : {
212 : ElementCollector* pClonedOne
213 : = new ElementCollector(m_nSecurityId,
214 : nBufferId, nPriority, m_bToModify,
215 0 : m_xReferenceResolvedListener);
216 :
217 0 : if (m_bAbleToNotify)
218 : {
219 0 : pClonedOne->notifyListener();
220 : }
221 :
222 0 : if (m_pBufferNode != NULL)
223 : {
224 0 : m_pBufferNode->addElementCollector(pClonedOne);
225 : }
226 :
227 0 : return pClonedOne;
228 : }
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|