update credits
[LibreOffice.git] / xmlsecurity / source / framework / saxeventkeeperimpl.hxx
blobdeb5e062dc14d411baac79f79ee8bec202e199ad
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 .
20 #ifndef _SAXEVENTKEEPERIMPL_HXX
21 #define _SAXEVENTKEEPERIMPL_HXX
23 #include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
24 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
25 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
26 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp>
27 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
28 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
29 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <cppuhelper/implbase6.hxx>
34 #include "buffernode.hxx"
35 #include "elementmark.hxx"
36 #include "elementcollector.hxx"
38 #include <vector>
40 class SAXEventKeeperImpl : public cppu::WeakImplHelper6
42 com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper,
43 com::sun::star::xml::crypto::sax::XReferenceResolvedBroadcaster,
44 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster,
45 com::sun::star::xml::sax::XDocumentHandler,
46 com::sun::star::lang::XInitialization,
47 com::sun::star::lang::XServiceInfo
49 /****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
51 * NAME
52 * SAXEventKeeperImpl -- SAX events buffer controller
54 * FUNCTION
55 * Controls SAX events to be bufferred, and controls bufferred SAX events
56 * to be released.
58 * AUTHOR
59 * Michael Mi
60 * Email: michael.mi@sun.com
61 ******************************************************************************/
63 private:
65 * the XMLDocumentWrapper component which maintains all bufferred SAX
66 * in DOM format.
68 com::sun::star::uno::Reference<
69 com::sun::star::xml::wrapper::XXMLDocumentWrapper >
70 m_xXMLDocument;
73 * the document handler provided by the XMLDocumentWrapper component.
75 com::sun::star::uno::Reference<
76 com::sun::star::xml::sax::XDocumentHandler > m_xDocumentHandler;
79 * the compressed document handler provided by the XMLDocumentWrapper
80 * component, the handler has more effient method definition that the
81 * normal document handler.
83 com::sun::star::uno::Reference<
84 com::sun::star::xml::csax::XCompressedDocumentHandler >
85 m_xCompressedDocumentHandler;
88 * a listener which receives this SAXEventKeeper's status change
89 * notification.
90 * Based on the status changes, the listener can decide whether the
91 * SAXEventKeeper should chain on/chain off the SAX chain, or whether
92 * the SAXEventKeeper is useless any long.
94 com::sun::star::uno::Reference<
95 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >
96 m_xSAXEventKeeperStatusChangeListener;
99 * the root node of the BufferNode tree.
100 * the BufferNode tree is used to keep track of all bufferred elements,
101 * it has the same structure with the document which maintains those
102 * elements physically.
104 BufferNode* m_pRootBufferNode;
107 * the current active BufferNode.
108 * this is used to keep track the current location in the BufferNode tree,
109 * the next generated BufferNode will become a child BufferNode of it.
111 BufferNode* m_pCurrentBufferNode;
114 * the next Id for a coming ElementMark.
115 * the variable is increased by 1 when an new ElementMark is generated,
116 * in this way, we can promise the Id of any ElementMark is unique.
118 sal_Int32 m_nNextElementMarkId;
121 * maintains a collection of all ElementMarks.
123 std::vector< const ElementMark* > m_vElementMarkBuffers;
126 * maintains a list of new ElementCollectors that will be created
127 * on the element represented by the next incoming startElement SAX
128 * event.
129 * The reason that such the m_vNewElementCollectors is necessary
130 * is: when an ElementCollector is asked to create, it can't be
131 * created completely at once, because the BufferNode it will be
132 * working on has not been created until the next startElement
133 * SAX event comes.
135 std::vector< const ElementCollector* > m_vNewElementCollectors;
138 * maintains the new Blocker that will be created
139 * on the element represented by the next incoming startElement SAX
140 * event.
142 ElementMark* m_pNewBlocker;
145 * the document handler to which all received SAX events will be
146 * forwarded.
148 com::sun::star::uno::Reference<
149 com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
152 * the current BufferNode which prevents the SAX events to be
153 * forwarded to the m_xNextHandler.
155 BufferNode* m_pCurrentBlockingBufferNode;
158 * maintains a list of ElementMark that has been asked to release.
159 * Because during processing a request of releasing an ElementMark,
160 * another releasing ElementMark request can be invoked. To avoid
161 * reentering the same method, a such request only add that ElementMark
162 * into this ElementMark list, then all ElementMarks will be processed in
163 * order.
165 std::vector< sal_Int32 > m_vReleasedElementMarkBuffers;
168 * a flag to indicate whether the ElementMark releasing process is runing.
169 * When a releasing request comes, the assigned ElementMark is added to
170 * the m_vReleasedElementMarkBuffers first, then this flag is checked.
171 * If the ElementMark releasing process is not running, then call that
172 * method.
174 bool m_bIsReleasing;
177 * a flag to indicate whether it is the "Forwarding" mode now.
178 * A "Forwarding" mode means that all received SAX events are from the
179 * XMLDocumentWrapper component, instead of up-stream component in the
180 * SAX chain.
181 * The difference between "Forwarding" mode and normal mode is that:
182 * no SAX events need to be transferred to the XMLDocumentWrapper component
183 * again even if a buffer request happens.
185 bool m_bIsForwarding;
187 void setCurrentBufferNode(BufferNode* pBufferNode);
189 BufferNode* addNewElementMarkBuffers();
191 ElementMark* findElementMarkBuffer(sal_Int32 nId) const;
193 void removeElementMarkBuffer(sal_Int32 nId);
195 OUString printBufferNode(
196 BufferNode* pBufferNode, sal_Int32 nIndent) const;
198 com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
199 com::sun::star::xml::wrapper::XXMLElementWrapper > >
200 collectChildWorkingElement(BufferNode* pBufferNode) const;
202 void smashBufferNode(
203 BufferNode* pBufferNode, bool bClearRoot) const;
205 BufferNode* findNextBlockingBufferNode(
206 BufferNode* pStartBufferNode) const;
208 void diffuse(BufferNode* pBufferNode) const;
210 void releaseElementMarkBuffer();
212 void markElementMarkBuffer(sal_Int32 nId);
214 sal_Int32 createElementCollector(
215 sal_Int32 nSecurityId,
216 com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority,
217 bool bModifyElement,
218 const com::sun::star::uno::Reference<
219 com::sun::star::xml::crypto::sax::XReferenceResolvedListener>&
220 xReferenceResolvedListener);
222 sal_Int32 createBlocker(sal_Int32 nSecurityId);
224 public:
225 SAXEventKeeperImpl();
226 virtual ~SAXEventKeeperImpl();
228 /* XSAXEventKeeper */
229 virtual sal_Int32 SAL_CALL addElementCollector( )
230 throw (com::sun::star::uno::RuntimeException);
231 virtual void SAL_CALL removeElementCollector( sal_Int32 id )
232 throw (com::sun::star::uno::RuntimeException);
233 virtual sal_Int32 SAL_CALL addBlocker( )
234 throw (com::sun::star::uno::RuntimeException);
235 virtual void SAL_CALL removeBlocker( sal_Int32 id )
236 throw (com::sun::star::uno::RuntimeException);
237 virtual sal_Bool SAL_CALL isBlocking( )
238 throw (com::sun::star::uno::RuntimeException);
239 virtual com::sun::star::uno::Reference<
240 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
241 getElement( sal_Int32 id )
242 throw (com::sun::star::uno::RuntimeException);
243 virtual void SAL_CALL setElement(
244 sal_Int32 id,
245 const com::sun::star::uno::Reference<
246 com::sun::star::xml::wrapper::XXMLElementWrapper >&
247 aElement )
248 throw (com::sun::star::uno::RuntimeException);
249 virtual com::sun::star::uno::Reference<
250 com::sun::star::xml::sax::XDocumentHandler > SAL_CALL
251 setNextHandler( const com::sun::star::uno::Reference<
252 com::sun::star::xml::sax::XDocumentHandler >& xNewHandler )
253 throw (com::sun::star::uno::RuntimeException);
254 virtual OUString SAL_CALL printBufferNodeTree()
255 throw (com::sun::star::uno::RuntimeException);
256 virtual com::sun::star::uno::Reference<
257 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
258 getCurrentBlockingNode()
259 throw (com::sun::star::uno::RuntimeException);
261 /* XSecuritySAXEventKeeper */
262 virtual sal_Int32 SAL_CALL addSecurityElementCollector(
263 com::sun::star::xml::crypto::sax::ElementMarkPriority priority,
264 sal_Bool modifyElement )
265 throw (com::sun::star::uno::RuntimeException);
266 virtual sal_Int32 SAL_CALL cloneElementCollector(
267 sal_Int32 referenceId,
268 com::sun::star::xml::crypto::sax::ElementMarkPriority priority )
269 throw (com::sun::star::uno::RuntimeException);
270 virtual void SAL_CALL setSecurityId( sal_Int32 id, sal_Int32 securityId )
271 throw (com::sun::star::uno::RuntimeException);
273 /* XReferenceResolvedBroadcaster */
274 virtual void SAL_CALL addReferenceResolvedListener(
275 sal_Int32 referenceId,
276 const com::sun::star::uno::Reference<
277 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
278 listener )
279 throw (com::sun::star::uno::RuntimeException);
280 virtual void SAL_CALL removeReferenceResolvedListener(
281 sal_Int32 referenceId,
282 const com::sun::star::uno::Reference<
283 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
284 listener )
285 throw (com::sun::star::uno::RuntimeException);
287 /* XSAXEventKeeperStatusChangeBroadcaster */
288 virtual void SAL_CALL addSAXEventKeeperStatusChangeListener(
289 const com::sun::star::uno::Reference<
290 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
291 listener )
292 throw (com::sun::star::uno::RuntimeException);
293 virtual void SAL_CALL removeSAXEventKeeperStatusChangeListener(
294 const com::sun::star::uno::Reference<
295 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
296 listener )
297 throw (com::sun::star::uno::RuntimeException);
299 /* XDocumentHandler */
300 virtual void SAL_CALL startDocument( )
301 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
302 virtual void SAL_CALL endDocument( )
303 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
304 virtual void SAL_CALL startElement(
305 const OUString& aName,
306 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >&
307 xAttribs )
308 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
309 virtual void SAL_CALL endElement( const OUString& aName )
310 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
311 virtual void SAL_CALL characters( const OUString& aChars )
312 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
313 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces )
314 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
315 virtual void SAL_CALL processingInstruction(
316 const OUString& aTarget, const OUString& aData )
317 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
318 virtual void SAL_CALL setDocumentLocator(
319 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator )
320 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
322 /* XInitialization */
323 virtual void SAL_CALL initialize(
324 const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
325 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
327 /* XServiceInfo */
328 virtual OUString SAL_CALL getImplementationName( )
329 throw (com::sun::star::uno::RuntimeException);
330 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
331 throw (com::sun::star::uno::RuntimeException);
332 virtual com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
333 throw (com::sun::star::uno::RuntimeException);
336 OUString SAXEventKeeperImpl_getImplementationName()
337 throw ( com::sun::star::uno::RuntimeException );
339 sal_Bool SAL_CALL SAXEventKeeperImpl_supportsService( const OUString& ServiceName )
340 throw ( com::sun::star::uno::RuntimeException );
342 com::sun::star::uno::Sequence< OUString > SAL_CALL SAXEventKeeperImpl_getSupportedServiceNames( )
343 throw ( com::sun::star::uno::RuntimeException );
345 com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
346 SAL_CALL SAXEventKeeperImpl_createInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr)
347 throw ( com::sun::star::uno::Exception );
349 #endif
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */