use insert function instead of for loop
[LibreOffice.git] / xmlsecurity / source / framework / elementcollector.cxx
blobd8f7fb04e77675b98fa55317ac496167dc55df8c
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 <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
24 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
25 #include <utility>
27 ElementCollector::ElementCollector(
28 sal_Int32 nBufferId,
29 css::xml::crypto::sax::ElementMarkPriority nPriority,
30 bool bToModify,
31 css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener > xReferenceResolvedListener)
32 :ElementMark(css::xml::crypto::sax::ConstOfSecurityId::UNDEFINEDSECURITYID, nBufferId),
33 m_nPriority(nPriority),
34 m_bToModify(bToModify),
35 m_bAbleToNotify(false),
36 m_bNotified(false),
37 m_xReferenceResolvedListener(std::move(xReferenceResolvedListener))
38 /****** ElementCollector/ElementCollector *************************************
40 * NAME
41 * ElementCollector -- constructor method
43 * SYNOPSIS
44 * ElementCollector(nSecurityId, nBufferId, nPriority, bToModify
45 * xReferenceResolvedListener);
47 * FUNCTION
48 * construct an ElementCollector object.
50 * INPUTS
51 * nSecurityId - represents which security entity the buffer node is
52 * related with. Either a signature or an encryption is
53 * a security entity.
54 * nBufferId - the id of the element buffered in the document
55 * wrapper component. The document wrapper component
56 * uses this id to search the particular buffered
57 * element.
58 * nPriority - the priority value. ElementCollector with lower
59 * priority value can't notify until all ElementCollectors
60 * with higher priority value have notified.
61 * bToModify - A flag representing whether this ElementCollector
62 * notification will cause the modification of its working
63 * element.
64 * xReferenceResolvedListener
65 * - the listener that this ElementCollector notifies to.
66 ******************************************************************************/
68 m_type = css::xml::crypto::sax::ElementMarkType_ELEMENTCOLLECTOR;
72 void ElementCollector::notifyListener()
73 /****** ElementCollector/notifyListener ***************************************
75 * NAME
76 * notifyListener -- enable the ability to notify the listener
78 * SYNOPSIS
79 * notifyListener();
81 * FUNCTION
82 * enable the ability to notify the listener and try to notify then.
83 ******************************************************************************/
85 m_bAbleToNotify = true;
86 doNotify();
89 void ElementCollector::setReferenceResolvedListener(
90 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener >& xReferenceResolvedListener)
91 /****** ElementCollector/setReferenceResolvedListener *************************
93 * NAME
94 * setReferenceResolvedListener -- configures a listener for the buffer
95 * node in this object
97 * SYNOPSIS
98 * setReferenceResolvedListener(xReferenceResolvedListener);
100 * FUNCTION
101 * configures a new listener and try to notify then.
103 * INPUTS
104 * xReferenceResolvedListener - the new listener
105 ******************************************************************************/
107 m_xReferenceResolvedListener = xReferenceResolvedListener;
108 doNotify();
111 void ElementCollector::doNotify()
112 /****** ElementCollector/doNotify *********************************************
114 * NAME
115 * doNotify -- tries to notify the listener
117 * SYNOPSIS
118 * doNotify();
120 * FUNCTION
121 * notifies the listener when all below conditions are satisfied:
122 * the listener has not been notified;
123 * the notify right is granted;
124 * the listener has already been configured;
125 * the security id has already been configure
126 ******************************************************************************/
128 if (!m_bNotified &&
129 m_bAbleToNotify &&
130 m_xReferenceResolvedListener.is() &&
131 m_nSecurityId != css::xml::crypto::sax::ConstOfSecurityId::UNDEFINEDSECURITYID)
133 m_bNotified = true;
134 m_xReferenceResolvedListener->referenceResolved(m_nBufferId);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */