1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_XMLSECURITY_SOURCE_FRAMEWORK_SAXEVENTKEEPERIMPL_HXX
21 #define INCLUDED_XMLSECURITY_SOURCE_FRAMEWORK_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 <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <cppuhelper/implbase6.hxx>
35 #include "buffernode.hxx"
36 #include "elementmark.hxx"
37 #include "elementcollector.hxx"
41 class SAXEventKeeperImpl
: public cppu::WeakImplHelper6
43 com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper
,
44 com::sun::star::xml::crypto::sax::XReferenceResolvedBroadcaster
,
45 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster
,
46 com::sun::star::xml::sax::XDocumentHandler
,
47 com::sun::star::lang::XInitialization
,
48 com::sun::star::lang::XServiceInfo
50 /****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
53 * SAXEventKeeperImpl -- SAX events buffer controller
56 * Controls SAX events to be bufferred, and controls bufferred SAX events
61 * Email: michael.mi@sun.com
62 ******************************************************************************/
66 * the XMLDocumentWrapper component which maintains all bufferred SAX
69 com::sun::star::uno::Reference
<
70 com::sun::star::xml::wrapper::XXMLDocumentWrapper
>
74 * the document handler provided by the XMLDocumentWrapper component.
76 com::sun::star::uno::Reference
<
77 com::sun::star::xml::sax::XDocumentHandler
> m_xDocumentHandler
;
80 * the compressed document handler provided by the XMLDocumentWrapper
81 * component, the handler has more effient method definition that the
82 * normal document handler.
84 com::sun::star::uno::Reference
<
85 com::sun::star::xml::csax::XCompressedDocumentHandler
>
86 m_xCompressedDocumentHandler
;
89 * a listener which receives this SAXEventKeeper's status change
91 * Based on the status changes, the listener can decide whether the
92 * SAXEventKeeper should chain on/chain off the SAX chain, or whether
93 * the SAXEventKeeper is useless any long.
95 com::sun::star::uno::Reference
<
96 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener
>
97 m_xSAXEventKeeperStatusChangeListener
;
100 * the root node of the BufferNode tree.
101 * the BufferNode tree is used to keep track of all bufferred elements,
102 * it has the same structure with the document which maintains those
103 * elements physically.
105 BufferNode
* m_pRootBufferNode
;
108 * the current active BufferNode.
109 * this is used to keep track the current location in the BufferNode tree,
110 * the next generated BufferNode will become a child BufferNode of it.
112 BufferNode
* m_pCurrentBufferNode
;
115 * the next Id for a coming ElementMark.
116 * the variable is increased by 1 when an new ElementMark is generated,
117 * in this way, we can promise the Id of any ElementMark is unique.
119 sal_Int32 m_nNextElementMarkId
;
122 * maintains a collection of all ElementMarks.
124 std::vector
< const ElementMark
* > m_vElementMarkBuffers
;
127 * maintains a list of new ElementCollectors that will be created
128 * on the element represented by the next incoming startElement SAX
130 * The reason that such the m_vNewElementCollectors is necessary
131 * is: when an ElementCollector is asked to create, it can't be
132 * created completely at once, because the BufferNode it will be
133 * working on has not been created until the next startElement
136 std::vector
< const ElementCollector
* > m_vNewElementCollectors
;
139 * maintains the new Blocker that will be created
140 * on the element represented by the next incoming startElement SAX
143 ElementMark
* m_pNewBlocker
;
146 * the document handler to which all received SAX events will be
149 com::sun::star::uno::Reference
<
150 com::sun::star::xml::sax::XDocumentHandler
> m_xNextHandler
;
153 * the current BufferNode which prevents the SAX events to be
154 * forwarded to the m_xNextHandler.
156 BufferNode
* m_pCurrentBlockingBufferNode
;
159 * maintains a list of ElementMark that has been asked to release.
160 * Because during processing a request of releasing an ElementMark,
161 * another releasing ElementMark request can be invoked. To avoid
162 * reentering the same method, a such request only add that ElementMark
163 * into this ElementMark list, then all ElementMarks will be processed in
166 std::vector
< sal_Int32
> m_vReleasedElementMarkBuffers
;
169 * a flag to indicate whether the ElementMark releasing process is running.
170 * When a releasing request comes, the assigned ElementMark is added to
171 * the m_vReleasedElementMarkBuffers first, then this flag is checked.
172 * If the ElementMark releasing process is not running, then call that
178 * a flag to indicate whether it is the "Forwarding" mode now.
179 * A "Forwarding" mode means that all received SAX events are from the
180 * XMLDocumentWrapper component, instead of up-stream component in the
182 * The difference between "Forwarding" mode and normal mode is that:
183 * no SAX events need to be transferred to the XMLDocumentWrapper component
184 * again even if a buffer request happens.
186 bool m_bIsForwarding
;
188 void setCurrentBufferNode(BufferNode
* pBufferNode
);
190 BufferNode
* addNewElementMarkBuffers();
192 ElementMark
* findElementMarkBuffer(sal_Int32 nId
) const;
194 void removeElementMarkBuffer(sal_Int32 nId
);
196 OUString
printBufferNode(
197 BufferNode
* pBufferNode
, sal_Int32 nIndent
) const;
199 static com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
200 com::sun::star::xml::wrapper::XXMLElementWrapper
> >
201 collectChildWorkingElement(BufferNode
* pBufferNode
);
203 void smashBufferNode(
204 BufferNode
* pBufferNode
, bool bClearRoot
) const;
206 static BufferNode
* findNextBlockingBufferNode(
207 BufferNode
* pStartBufferNode
);
209 static void diffuse(BufferNode
* pBufferNode
);
211 void releaseElementMarkBuffer();
213 void markElementMarkBuffer(sal_Int32 nId
);
215 sal_Int32
createElementCollector(
216 sal_Int32 nSecurityId
,
217 com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority
,
219 const com::sun::star::uno::Reference
<
220 com::sun::star::xml::crypto::sax::XReferenceResolvedListener
>&
221 xReferenceResolvedListener
);
223 sal_Int32
createBlocker(sal_Int32 nSecurityId
);
226 SAXEventKeeperImpl();
227 virtual ~SAXEventKeeperImpl();
229 /* XSAXEventKeeper */
230 virtual sal_Int32 SAL_CALL
addElementCollector( )
231 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
232 virtual void SAL_CALL
removeElementCollector( sal_Int32 id
)
233 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
234 virtual sal_Int32 SAL_CALL
addBlocker( )
235 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
236 virtual void SAL_CALL
removeBlocker( sal_Int32 id
)
237 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
238 virtual sal_Bool SAL_CALL
isBlocking( )
239 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
240 virtual com::sun::star::uno::Reference
<
241 com::sun::star::xml::wrapper::XXMLElementWrapper
> SAL_CALL
242 getElement( sal_Int32 id
)
243 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
244 virtual void SAL_CALL
setElement(
246 const com::sun::star::uno::Reference
<
247 com::sun::star::xml::wrapper::XXMLElementWrapper
>&
249 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
250 virtual com::sun::star::uno::Reference
<
251 com::sun::star::xml::sax::XDocumentHandler
> SAL_CALL
252 setNextHandler( const com::sun::star::uno::Reference
<
253 com::sun::star::xml::sax::XDocumentHandler
>& xNewHandler
)
254 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
255 virtual OUString SAL_CALL
printBufferNodeTree()
256 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 virtual com::sun::star::uno::Reference
<
258 com::sun::star::xml::wrapper::XXMLElementWrapper
> SAL_CALL
259 getCurrentBlockingNode()
260 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
262 /* XSecuritySAXEventKeeper */
263 virtual sal_Int32 SAL_CALL
addSecurityElementCollector(
264 com::sun::star::xml::crypto::sax::ElementMarkPriority priority
,
265 sal_Bool modifyElement
)
266 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
267 virtual sal_Int32 SAL_CALL
cloneElementCollector(
268 sal_Int32 referenceId
,
269 com::sun::star::xml::crypto::sax::ElementMarkPriority priority
)
270 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
271 virtual void SAL_CALL
setSecurityId( sal_Int32 id
, sal_Int32 securityId
)
272 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
274 /* XReferenceResolvedBroadcaster */
275 virtual void SAL_CALL
addReferenceResolvedListener(
276 sal_Int32 referenceId
,
277 const com::sun::star::uno::Reference
<
278 com::sun::star::xml::crypto::sax::XReferenceResolvedListener
>&
280 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
281 virtual void SAL_CALL
removeReferenceResolvedListener(
282 sal_Int32 referenceId
,
283 const com::sun::star::uno::Reference
<
284 com::sun::star::xml::crypto::sax::XReferenceResolvedListener
>&
286 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
288 /* XSAXEventKeeperStatusChangeBroadcaster */
289 virtual void SAL_CALL
addSAXEventKeeperStatusChangeListener(
290 const com::sun::star::uno::Reference
<
291 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener
>&
293 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
294 virtual void SAL_CALL
removeSAXEventKeeperStatusChangeListener(
295 const com::sun::star::uno::Reference
<
296 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener
>&
298 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
300 /* XDocumentHandler */
301 virtual void SAL_CALL
startDocument( )
302 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
303 virtual void SAL_CALL
endDocument( )
304 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
305 virtual void SAL_CALL
startElement(
306 const OUString
& aName
,
307 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>&
309 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
310 virtual void SAL_CALL
endElement( const OUString
& aName
)
311 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
312 virtual void SAL_CALL
characters( const OUString
& aChars
)
313 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
314 virtual void SAL_CALL
ignorableWhitespace( const OUString
& aWhitespaces
)
315 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
316 virtual void SAL_CALL
processingInstruction(
317 const OUString
& aTarget
, const OUString
& aData
)
318 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
319 virtual void SAL_CALL
setDocumentLocator(
320 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XLocator
>& xLocator
)
321 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
323 /* XInitialization */
324 virtual void SAL_CALL
initialize(
325 const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
>& aArguments
)
326 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
329 virtual OUString SAL_CALL
getImplementationName( )
330 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
331 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
332 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
333 virtual com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( )
334 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
337 OUString
SAXEventKeeperImpl_getImplementationName()
338 throw ( com::sun::star::uno::RuntimeException
);
340 com::sun::star::uno::Sequence
< OUString
> SAL_CALL
SAXEventKeeperImpl_getSupportedServiceNames( )
341 throw ( com::sun::star::uno::RuntimeException
);
343 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
344 SAL_CALL
SAXEventKeeperImpl_createInstance( const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> & rSMgr
)
345 throw ( com::sun::star::uno::Exception
);
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */