Update ooo320-m1
[ooovba.git] / xmlsecurity / source / framework / saxeventkeeperimpl.hxx
blob1dddc821fc1431d2b4d0c145294d99c1dc732531
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: saxeventkeeperimpl.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SAXEVENTKEEPERIMPL_HXX
32 #define _SAXEVENTKEEPERIMPL_HXX
34 #include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
35 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
36 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
37 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp>
38 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
39 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
40 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
41 #include <com/sun/star/lang/XInitialization.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <cppuhelper/implbase6.hxx>
45 #include "buffernode.hxx"
46 #include "elementmark.hxx"
47 #include "elementcollector.hxx"
49 #ifndef INCLUDED_VECTOR
50 #include <vector>
51 #define INCLUDED_VECTOR
52 #endif
54 class SAXEventKeeperImpl : public cppu::WeakImplHelper6
56 com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper,
57 com::sun::star::xml::crypto::sax::XReferenceResolvedBroadcaster,
58 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster,
59 com::sun::star::xml::sax::XDocumentHandler,
60 com::sun::star::lang::XInitialization,
61 com::sun::star::lang::XServiceInfo
63 /****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
65 * NAME
66 * SAXEventKeeperImpl -- SAX events buffer controller
68 * FUNCTION
69 * Controls SAX events to be bufferred, and controls bufferred SAX events
70 * to be released.
72 * HISTORY
73 * 05.01.2004 - Interface supported: XSecuritySAXEventKeeper,
74 * XReferenceResolvedBroadcaster,
75 * XSAXEventKeeperStatusChangeBroadcaster,
76 * XDocumentHandler, XInitialization, XServiceInfo
78 * AUTHOR
79 * Michael Mi
80 * Email: michael.mi@sun.com
81 ******************************************************************************/
83 private:
85 * the XMLDocumentWrapper component which maintains all bufferred SAX
86 * in DOM format.
88 com::sun::star::uno::Reference<
89 com::sun::star::xml::wrapper::XXMLDocumentWrapper >
90 m_xXMLDocument;
93 * the document handler provided by the XMLDocumentWrapper component.
95 com::sun::star::uno::Reference<
96 com::sun::star::xml::sax::XDocumentHandler > m_xDocumentHandler;
99 * the compressed document handler provided by the XMLDocumentWrapper
100 * component, the handler has more effient method definition that the
101 * normal document handler.
103 com::sun::star::uno::Reference<
104 com::sun::star::xml::csax::XCompressedDocumentHandler >
105 m_xCompressedDocumentHandler;
108 * a listener which receives this SAXEventKeeper's status change
109 * notification.
110 * Based on the status changes, the listener can decide whether the
111 * SAXEventKeeper should chain on/chain off the SAX chain, or whether
112 * the SAXEventKeeper is useless any long.
114 com::sun::star::uno::Reference<
115 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >
116 m_xSAXEventKeeperStatusChangeListener;
119 * the root node of the BufferNode tree.
120 * the BufferNode tree is used to keep track of all bufferred elements,
121 * it has the same structure with the document which maintains those
122 * elements physically.
124 BufferNode* m_pRootBufferNode;
127 * the current active BufferNode.
128 * this is used to keep track the current location in the BufferNode tree,
129 * the next generated BufferNode will become a child BufferNode of it.
131 BufferNode* m_pCurrentBufferNode;
134 * the next Id for a coming ElementMark.
135 * the variable is increased by 1 when an new ElementMark is generated,
136 * in this way, we can promise the Id of any ElementMark is unique.
138 sal_Int32 m_nNextElementMarkId;
141 * maintains a collection of all ElementMarks.
143 std::vector< const ElementMark* > m_vElementMarkBuffers;
146 * maintains a list of new ElementCollectors that will be created
147 * on the element represented by the next incoming startElement SAX
148 * event.
149 * The reason that such the m_vNewElementCollectors is necessary
150 * is: when an ElementCollector is asked to create, it can't be
151 * created completely at once, because the BufferNode it will be
152 * working on has not been created until the next startElement
153 * SAX event comes.
155 std::vector< const ElementCollector* > m_vNewElementCollectors;
158 * maintains the new Blocker that will be created
159 * on the element represented by the next incoming startElement SAX
160 * event.
162 ElementMark* m_pNewBlocker;
165 * the document handler to which all received SAX events will be
166 * forwarded.
168 com::sun::star::uno::Reference<
169 com::sun::star::xml::sax::XDocumentHandler > m_xNextHandler;
172 * the current BufferNode which prevents the SAX events to be
173 * forwarded to the m_xNextHandler.
175 BufferNode* m_pCurrentBlockingBufferNode;
178 * maintains a list of ElementMark that has been asked to release.
179 * Because during processing a request of releasing an ElementMark,
180 * another releasing ElementMark request can be invoked. To avoid
181 * reentering the same method, a such request only add that ElementMark
182 * into this ElementMark list, then all ElementMarks will be processed in
183 * order.
185 std::vector< sal_Int32 > m_vReleasedElementMarkBuffers;
188 * a flag to indicate whether the ElementMark releasing process is runing.
189 * When a releasing request comes, the assigned ElementMark is added to
190 * the m_vReleasedElementMarkBuffers first, then this flag is checked.
191 * If the ElementMark releasing process is not running, then call that
192 * method.
194 bool m_bIsReleasing;
197 * a flag to indicate whether it is the "Forwarding" mode now.
198 * A "Forwarding" mode means that all received SAX events are from the
199 * XMLDocumentWrapper component, instead of up-stream component in the
200 * SAX chain.
201 * The difference between "Forwarding" mode and normal mode is that:
202 * no SAX events need to be transferred to the XMLDocumentWrapper component
203 * again even if a buffer request happens.
205 bool m_bIsForwarding;
207 void setCurrentBufferNode(BufferNode* pBufferNode);
209 BufferNode* addNewElementMarkBuffers();
211 ElementMark* findElementMarkBuffer(sal_Int32 nId) const;
213 void removeElementMarkBuffer(sal_Int32 nId);
215 rtl::OUString printBufferNode(
216 BufferNode* pBufferNode, sal_Int32 nIndent) const;
218 com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
219 com::sun::star::xml::wrapper::XXMLElementWrapper > >
220 collectChildWorkingElement(BufferNode* pBufferNode) const;
222 void smashBufferNode(
223 BufferNode* pBufferNode, bool bClearRoot) const;
225 BufferNode* findNextBlockingBufferNode(
226 BufferNode* pStartBufferNode) const;
228 void diffuse(BufferNode* pBufferNode) const;
230 void releaseElementMarkBuffer();
232 void markElementMarkBuffer(sal_Int32 nId);
234 sal_Int32 createElementCollector(
235 sal_Int32 nSecurityId,
236 com::sun::star::xml::crypto::sax::ElementMarkPriority nPriority,
237 bool bModifyElement,
238 const com::sun::star::uno::Reference<
239 com::sun::star::xml::crypto::sax::XReferenceResolvedListener>&
240 xReferenceResolvedListener);
242 sal_Int32 createBlocker(sal_Int32 nSecurityId);
244 public:
245 SAXEventKeeperImpl();
246 virtual ~SAXEventKeeperImpl();
248 /* XSAXEventKeeper */
249 virtual sal_Int32 SAL_CALL addElementCollector( )
250 throw (com::sun::star::uno::RuntimeException);
251 virtual void SAL_CALL removeElementCollector( sal_Int32 id )
252 throw (com::sun::star::uno::RuntimeException);
253 virtual sal_Int32 SAL_CALL addBlocker( )
254 throw (com::sun::star::uno::RuntimeException);
255 virtual void SAL_CALL removeBlocker( sal_Int32 id )
256 throw (com::sun::star::uno::RuntimeException);
257 virtual sal_Bool SAL_CALL isBlocking( )
258 throw (com::sun::star::uno::RuntimeException);
259 virtual com::sun::star::uno::Reference<
260 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
261 getElement( sal_Int32 id )
262 throw (com::sun::star::uno::RuntimeException);
263 virtual void SAL_CALL setElement(
264 sal_Int32 id,
265 const com::sun::star::uno::Reference<
266 com::sun::star::xml::wrapper::XXMLElementWrapper >&
267 aElement )
268 throw (com::sun::star::uno::RuntimeException);
269 virtual com::sun::star::uno::Reference<
270 com::sun::star::xml::sax::XDocumentHandler > SAL_CALL
271 setNextHandler( const com::sun::star::uno::Reference<
272 com::sun::star::xml::sax::XDocumentHandler >& xNewHandler )
273 throw (com::sun::star::uno::RuntimeException);
274 virtual rtl::OUString SAL_CALL printBufferNodeTree()
275 throw (com::sun::star::uno::RuntimeException);
276 virtual com::sun::star::uno::Reference<
277 com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL
278 getCurrentBlockingNode()
279 throw (com::sun::star::uno::RuntimeException);
281 /* XSecuritySAXEventKeeper */
282 virtual sal_Int32 SAL_CALL addSecurityElementCollector(
283 com::sun::star::xml::crypto::sax::ElementMarkPriority priority,
284 sal_Bool modifyElement )
285 throw (com::sun::star::uno::RuntimeException);
286 virtual sal_Int32 SAL_CALL cloneElementCollector(
287 sal_Int32 referenceId,
288 com::sun::star::xml::crypto::sax::ElementMarkPriority priority )
289 throw (com::sun::star::uno::RuntimeException);
290 virtual void SAL_CALL setSecurityId( sal_Int32 id, sal_Int32 securityId )
291 throw (com::sun::star::uno::RuntimeException);
293 /* XReferenceResolvedBroadcaster */
294 virtual void SAL_CALL addReferenceResolvedListener(
295 sal_Int32 referenceId,
296 const com::sun::star::uno::Reference<
297 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
298 listener )
299 throw (com::sun::star::uno::RuntimeException);
300 virtual void SAL_CALL removeReferenceResolvedListener(
301 sal_Int32 referenceId,
302 const com::sun::star::uno::Reference<
303 com::sun::star::xml::crypto::sax::XReferenceResolvedListener >&
304 listener )
305 throw (com::sun::star::uno::RuntimeException);
307 /* XSAXEventKeeperStatusChangeBroadcaster */
308 virtual void SAL_CALL addSAXEventKeeperStatusChangeListener(
309 const com::sun::star::uno::Reference<
310 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
311 listener )
312 throw (com::sun::star::uno::RuntimeException);
313 virtual void SAL_CALL removeSAXEventKeeperStatusChangeListener(
314 const com::sun::star::uno::Reference<
315 com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >&
316 listener )
317 throw (com::sun::star::uno::RuntimeException);
319 /* XDocumentHandler */
320 virtual void SAL_CALL startDocument( )
321 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
322 virtual void SAL_CALL endDocument( )
323 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
324 virtual void SAL_CALL startElement(
325 const rtl::OUString& aName,
326 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >&
327 xAttribs )
328 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
329 virtual void SAL_CALL endElement( const rtl::OUString& aName )
330 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
331 virtual void SAL_CALL characters( const rtl::OUString& aChars )
332 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
333 virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces )
334 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
335 virtual void SAL_CALL processingInstruction(
336 const rtl::OUString& aTarget, const rtl::OUString& aData )
337 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
338 virtual void SAL_CALL setDocumentLocator(
339 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator )
340 throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
342 /* XInitialization */
343 virtual void SAL_CALL initialize(
344 const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments )
345 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
347 /* XServiceInfo */
348 virtual rtl::OUString SAL_CALL getImplementationName( )
349 throw (com::sun::star::uno::RuntimeException);
350 virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName )
351 throw (com::sun::star::uno::RuntimeException);
352 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( )
353 throw (com::sun::star::uno::RuntimeException);
356 rtl::OUString SAXEventKeeperImpl_getImplementationName()
357 throw ( com::sun::star::uno::RuntimeException );
359 sal_Bool SAL_CALL SAXEventKeeperImpl_supportsService( const rtl::OUString& ServiceName )
360 throw ( com::sun::star::uno::RuntimeException );
362 com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SAXEventKeeperImpl_getSupportedServiceNames( )
363 throw ( com::sun::star::uno::RuntimeException );
365 com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
366 SAL_CALL SAXEventKeeperImpl_createInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr)
367 throw ( com::sun::star::uno::Exception );
369 #endif