Update ooo320-m1
[ooovba.git] / xmlsecurity / source / framework / buffernode.cxx
blob307d85e1337527555b2c99c26b4307565546193b
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: buffernode.cxx,v $
10 * $Revision: 1.6 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "elementmark.hxx"
35 #include "elementcollector.hxx"
36 #include "buffernode.hxx"
37 #include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
39 namespace cssu = com::sun::star::uno;
40 namespace cssxw = com::sun::star::xml::wrapper;
41 namespace cssxc = com::sun::star::xml::crypto;
43 BufferNode::BufferNode( const cssu::Reference< cssxw::XXMLElementWrapper >& xXMLElement )
44 :m_pParent(NULL),
45 m_pBlocker(NULL),
46 m_bAllReceived(false),
47 m_xXMLElement(xXMLElement)
51 bool BufferNode::isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const
52 /****** BufferNode/isECOfBeforeModifyIncluded ********************************
54 * NAME
55 * isECOfBeforeModifyIncluded -- checks whether there is some
56 * ElementCollector on this BufferNode, that has BEFORE-MODIFY priority.
58 * SYNOPSIS
59 * bExist = isECOfBeforeModifyIncluded(nIgnoredSecurityId);
61 * FUNCTION
62 * checks each ElementCollector on this BufferNode, if all following
63 * conditions are satisfied, then returns true:
64 * 1. the ElementCollector's priority is BEFOREMODIFY;
65 * 2. the ElementCollector's securityId can't be ignored.
66 * otherwise, returns false.
68 * INPUTS
69 * nIgnoredSecurityId - the security Id to be ignored. If it equals
70 * to UNDEFINEDSECURITYID, then no security Id
71 * will be ignored.
73 * RESULT
74 * bExist - true if a match found, false otherwise
76 * HISTORY
77 * 05.01.2004 - implemented
79 * AUTHOR
80 * Michael Mi
81 * Email: michael.mi@sun.com
82 ******************************************************************************/
84 bool rc = false;
85 std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
87 for( ; ii != m_vElementCollectors.end() ; ++ii )
89 ElementCollector* pElementCollector = (ElementCollector*)*ii;
91 if ((nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
92 pElementCollector->getSecurityId() != nIgnoredSecurityId) &&
93 (pElementCollector->getPriority() == cssxc::sax::ElementMarkPriority_BEFOREMODIFY))
95 rc = true;
96 break;
100 return rc;
103 void BufferNode::setReceivedAll()
104 /****** BufferNode/setReceiveAll *********************************************
106 * NAME
107 * setReceivedAll -- indicates that the element in this BufferNode has
108 * been compeletely bufferred.
110 * SYNOPSIS
111 * setReceivedAll();
113 * FUNCTION
114 * sets the all-received flag and launches ElementCollector's notify
115 * process.
117 * INPUTS
118 * empty
120 * RESULT
121 * empty
123 * HISTORY
124 * 05.01.2004 - implemented
126 * AUTHOR
127 * Michael Mi
128 * Email: michael.mi@sun.com
129 ******************************************************************************/
131 m_bAllReceived = true;
132 elementCollectorNotify();
135 bool BufferNode::isAllReceived() const
137 return m_bAllReceived;
140 void BufferNode::addElementCollector(const ElementCollector* pElementCollector)
141 /****** BufferNode/addElementCollector ***************************************
143 * NAME
144 * addElementCollector -- adds a new ElementCollector to this BufferNode.
146 * SYNOPSIS
147 * addElementCollector(pElementCollector);
149 * FUNCTION
150 * see NAME
152 * INPUTS
153 * pElementCollector - the ElementCollector to be added
155 * RESULT
156 * empty
158 * HISTORY
159 * 05.01.2004 - implemented
161 * AUTHOR
162 * Michael Mi
163 * Email: michael.mi@sun.com
164 ******************************************************************************/
166 m_vElementCollectors.push_back( pElementCollector );
167 ((ElementCollector*)pElementCollector)->setBufferNode(this);
170 void BufferNode::removeElementCollector(const ElementCollector* pElementCollector)
171 /****** BufferNode/removeElementCollector ************************************
173 * NAME
174 * removeElementCollector -- removes an ElementCollector from this
175 * BufferNode.
177 * SYNOPSIS
178 * removeElementCollector(pElementCollector);
180 * FUNCTION
181 * see NAME
183 * INPUTS
184 * pElementCollector - the ElementCollector to be removed
186 * RESULT
187 * empty
189 * HISTORY
190 * 05.01.2004 - implemented
192 * AUTHOR
193 * Michael Mi
194 * Email: michael.mi@sun.com
195 ******************************************************************************/
197 std::vector< const ElementCollector* >::iterator ii = m_vElementCollectors.begin();
199 for( ; ii != m_vElementCollectors.end() ; ++ii )
201 if( *ii == pElementCollector )
203 m_vElementCollectors.erase( ii );
204 ((ElementCollector*)pElementCollector)->setBufferNode(NULL);
205 break;
210 ElementMark* BufferNode::getBlocker() const
212 return m_pBlocker;
215 void BufferNode::setBlocker(const ElementMark* pBlocker)
216 /****** BufferNode/setBlocker ************************************************
218 * NAME
219 * setBlocker -- adds a blocker to this BufferNode.
221 * SYNOPSIS
222 * setBlocker(pBlocker);
224 * FUNCTION
225 * see NAME
227 * INPUTS
228 * pBlocker - the new blocker to be attached
230 * RESULT
231 * empty
233 * NOTES
234 * Because there is only one blocker permited for a BufferNode, so the
235 * old blocker on this BufferNode, if there is one, will be overcasted.
237 * HISTORY
238 * 05.01.2004 - implemented
240 * AUTHOR
241 * Michael Mi
242 * Email: michael.mi@sun.com
243 ******************************************************************************/
245 OSL_ASSERT(!(m_pBlocker != NULL && pBlocker != NULL));
247 m_pBlocker = (ElementMark*)pBlocker;
248 if (m_pBlocker != NULL)
250 m_pBlocker->setBufferNode(this);
254 rtl::OUString BufferNode::printChildren() const
255 /****** BufferNode/printChildren *********************************************
257 * NAME
258 * printChildren -- prints children information into a string.
260 * SYNOPSIS
261 * result = printChildren();
263 * FUNCTION
264 * see NAME
266 * INPUTS
267 * empty
269 * RESULT
270 * result - the information string
272 * HISTORY
273 * 05.01.2004 - implemented
275 * AUTHOR
276 * Michael Mi
277 * Email: michael.mi@sun.com
278 ******************************************************************************/
280 rtl::OUString rc;
281 std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
283 for( ; ii != m_vElementCollectors.end() ; ++ii )
285 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BufID=" ));
286 rc += rtl::OUString::valueOf((*ii)->getBufferId());
288 if (((ElementCollector*)(*ii))->getModify())
290 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[M]" ));
293 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ",Pri=" ));
295 switch (((ElementCollector*)(*ii))->getPriority())
297 case cssxc::sax::ElementMarkPriority_BEFOREMODIFY:
298 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BEFOREMODIFY" ));
299 break;
300 case cssxc::sax::ElementMarkPriority_AFTERMODIFY:
301 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AFTERMODIFY" ));
302 break;
303 default:
304 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UNKNOWN" ));
305 break;
308 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "(" ));
310 if (((ElementCollector*)(*ii))->isInternalNotificationSuppressed())
312 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*IN-Suppressed* " ));
315 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SecID=" ));
316 rc += rtl::OUString::valueOf(((ElementCollector*)(*ii))->getSecurityId());
317 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ));
318 rc += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
321 return rc;
324 bool BufferNode::hasAnything() const
325 /****** BufferNode/hasAnything ***********************************************
327 * NAME
328 * hasAnything -- checks whether there is any ElementCollector or blocker
329 * on this BufferNode.
331 * SYNOPSIS
332 * bExist = hasAnything();
334 * FUNCTION
335 * see NAME
337 * INPUTS
338 * empty
340 * RESULT
341 * bExist - true if there is, false otherwise.
343 * HISTORY
344 * 05.01.2004 - implemented
346 * AUTHOR
347 * Michael Mi
348 * Email: michael.mi@sun.com
349 ******************************************************************************/
351 return (m_pBlocker != NULL || m_vElementCollectors.size() > 0);
354 bool BufferNode::hasChildren() const
355 /****** BufferNode/hasChildren ***********************************************
357 * NAME
358 * hasChildren -- checks whether this BufferNode has any child
359 * BufferNode.
361 * SYNOPSIS
362 * bExist = hasChildren();
364 * FUNCTION
365 * see NAME
367 * INPUTS
368 * empty
370 * RESULT
371 * bExist - true if there is, false otherwise.
373 * HISTORY
374 * 05.01.2004 - implemented
376 * AUTHOR
377 * Michael Mi
378 * Email: michael.mi@sun.com
379 ******************************************************************************/
381 return (m_vChildren.size() > 0);
384 std::vector< const BufferNode* >* BufferNode::getChildren() const
386 return new std::vector< const BufferNode* >( m_vChildren );
389 const BufferNode* BufferNode::getFirstChild() const
390 /****** BufferNode/getFirstChild *********************************************
392 * NAME
393 * getFirstChild -- retrieves the first child BufferNode.
395 * SYNOPSIS
396 * child = getFirstChild();
398 * FUNCTION
399 * see NAME
401 * INPUTS
402 * empty
404 * RESULT
405 * child - the first child BufferNode, or NULL if there is no child
406 * BufferNode.
408 * HISTORY
409 * 05.01.2004 - implemented
411 * AUTHOR
412 * Michael Mi
413 * Email: michael.mi@sun.com
414 ******************************************************************************/
416 BufferNode* rc = NULL;
418 if (m_vChildren.size() > 0)
420 rc = (BufferNode*)m_vChildren.front();
423 return (const BufferNode*)rc;
426 void BufferNode::addChild(const BufferNode* pChild, sal_Int32 nPosition)
427 /****** BufferNode/addChild(pChild,nPosition) ********************************
429 * NAME
430 * addChild -- inserts a child BufferNode at specific position.
432 * SYNOPSIS
433 * addChild(pChild, nPosition);
435 * FUNCTION
436 * see NAME
438 * INPUTS
439 * pChild - the child BufferNode to be added.
440 * nPosition - the position where the new child locates.
442 * RESULT
443 * empty
445 * NOTES
446 * If the nPosition is -1, then the new child BufferNode is appended
447 * at the end.
449 * HISTORY
450 * 05.01.2004 - implemented
452 * AUTHOR
453 * Michael Mi
454 * Email: michael.mi@sun.com
455 ******************************************************************************/
457 if (nPosition == -1)
459 m_vChildren.push_back( pChild );
461 else
463 std::vector< const BufferNode* >::iterator ii = m_vChildren.begin();
464 ii += nPosition;
465 m_vChildren.insert(ii, pChild);
469 void BufferNode::addChild(const BufferNode* pChild)
470 /****** BufferNode/addChild() ************************************************
472 * NAME
473 * addChild -- add a new child BufferNode.
475 * SYNOPSIS
476 * addChild(pChild);
478 * FUNCTION
479 * see NAME
481 * INPUTS
482 * pChild - the child BufferNode to be added.
484 * RESULT
485 * empty
487 * NOTES
488 * The new child BufferNode is appended at the end.
490 * HISTORY
491 * 05.01.2004 - implemented
493 * AUTHOR
494 * Michael Mi
495 * Email: michael.mi@sun.com
496 ******************************************************************************/
498 addChild(pChild, -1);
501 void BufferNode::removeChild(const BufferNode* pChild)
502 /****** BufferNode/removeChild ***********************************************
504 * NAME
505 * removeChild -- removes a child BufferNode from the children list.
507 * SYNOPSIS
508 * removeChild(pChild);
510 * FUNCTION
511 * see NAME
513 * INPUTS
514 * pChild - the child BufferNode to be removed
516 * RESULT
517 * empty
519 * HISTORY
520 * 05.01.2004 - implemented
522 * AUTHOR
523 * Michael Mi
524 * Email: michael.mi@sun.com
525 ******************************************************************************/
527 std::vector< const BufferNode* >::iterator ii = m_vChildren.begin();
529 for( ; ii != m_vChildren.end() ; ++ii )
531 if( *ii == pChild )
533 m_vChildren.erase( ii );
534 break;
539 sal_Int32 BufferNode::indexOfChild(const BufferNode* pChild) const
540 /****** BufferNode/indexOfChild **********************************************
542 * NAME
543 * indexOfChild -- gets the index of a child BufferNode.
545 * SYNOPSIS
546 * index = indexOfChild(pChild);
548 * FUNCTION
549 * see NAME
551 * INPUTS
552 * pChild - the child BufferNode whose index to be gotten
554 * RESULT
555 * index - the index of that child BufferNode. If that child BufferNode
556 * is not found, -1 is returned.
558 * HISTORY
559 * 05.01.2004 - implemented
561 * AUTHOR
562 * Michael Mi
563 * Email: michael.mi@sun.com
564 ******************************************************************************/
566 sal_Int32 nIndex = 0;
567 bool bFound = false;
569 std::vector< const BufferNode * >::const_iterator ii = m_vChildren.begin();
571 for( ; ii != m_vChildren.end() ; ++ii )
573 if( *ii == pChild )
575 bFound = true;
576 break;
578 nIndex++;
581 if (!bFound )
583 nIndex = -1;
586 return nIndex;
589 const BufferNode* BufferNode::childAt(sal_Int32 nIndex) const
590 /****** BufferNode/childAt ***************************************************
592 * NAME
593 * childAt -- retrieves the child BufferNode at specific possition.
595 * SYNOPSIS
596 * child = childAt(nIndex);
598 * FUNCTION
599 * see NAME
601 * INPUTS
602 * nIndex - the index of the child BufferNode to be retrieved
604 * RESULT
605 * child - the child BufferNode at index position, or NULL if the index
606 * is out of the range of children.
608 * HISTORY
609 * 05.01.2004 - implemented
611 * AUTHOR
612 * Michael Mi
613 * Email: michael.mi@sun.com
614 ******************************************************************************/
616 BufferNode* rc = NULL;
618 if (nIndex < ((sal_Int32)m_vChildren.size()) && nIndex >= 0)
620 rc = (BufferNode*)m_vChildren[nIndex];
623 return (const BufferNode*)rc;
626 const BufferNode* BufferNode::getParent() const
628 return m_pParent;
631 void BufferNode::setParent(const BufferNode* pParent)
633 m_pParent = (BufferNode*)pParent;
636 const BufferNode* BufferNode::getNextSibling() const
637 /****** BufferNode/getNextSibling ********************************************
639 * NAME
640 * getNextSibling -- retrieves the next sibling BufferNode.
642 * SYNOPSIS
643 * sibling = getNextSibling();
645 * FUNCTION
646 * see NAME
648 * INPUTS
649 * empty
651 * RESULT
652 * sibling - the next sibling BufferNode, or NULL if there is none.
654 * HISTORY
655 * 05.01.2004 - implemented
657 * AUTHOR
658 * Michael Mi
659 * Email: michael.mi@sun.com
660 ******************************************************************************/
662 BufferNode* rc = NULL;
664 if (m_pParent != NULL)
666 rc = (BufferNode*)m_pParent->getNextChild(this);
669 return (const BufferNode*)rc;
672 const BufferNode* BufferNode::isAncestor(const BufferNode* pDescendant) const
673 /****** BufferNode/isAncestor ************************************************
675 * NAME
676 * isAncestor -- checks whether this BufferNode is an ancestor of another
677 * BufferNode.
679 * SYNOPSIS
680 * bIs = isAncestor(pDescendant);
682 * FUNCTION
683 * see NAME
685 * INPUTS
686 * pDescendant - the BufferNode to be checked as a descendant
688 * RESULT
689 * bIs - true if this BufferNode is an ancestor of the pDescendant,
690 * false otherwise.
692 * HISTORY
693 * 05.01.2004 - implemented
695 * AUTHOR
696 * Michael Mi
697 * Email: michael.mi@sun.com
698 ******************************************************************************/
700 BufferNode* rc = NULL;
702 if (pDescendant != NULL)
704 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
706 for( ; ii != m_vChildren.end() ; ++ii )
708 BufferNode* pChild = (BufferNode*)*ii;
710 if (pChild == pDescendant)
712 rc = pChild;
713 break;
716 if (pChild->isAncestor(pDescendant) != NULL)
718 rc = pChild;
719 break;
724 return (const BufferNode*)rc;
727 bool BufferNode::isPrevious(const BufferNode* pFollowing) const
728 /****** BufferNode/isPrevious ************************************************
730 * NAME
731 * isPrevious -- checks whether this BufferNode is ahead of another
732 * BufferNode in the tree order.
734 * SYNOPSIS
735 * bIs = isPrevious(pFollowing);
737 * FUNCTION
738 * see NAME
740 * INPUTS
741 * pFollowing - the BufferNode to be checked as a following
743 * RESULT
744 * bIs - true if this BufferNode is ahead in the tree order, false
745 * otherwise.
747 * HISTORY
748 * 05.01.2004 - implemented
750 * AUTHOR
751 * Michael Mi
752 * Email: michael.mi@sun.com
753 ******************************************************************************/
755 bool rc = false;
757 BufferNode* pNextBufferNode = (BufferNode*)getNextNodeByTreeOrder();
758 while (pNextBufferNode != NULL)
760 if (pNextBufferNode == pFollowing)
762 rc = true;
763 break;
766 pNextBufferNode = (BufferNode*)(pNextBufferNode->getNextNodeByTreeOrder());
769 return rc;
772 const BufferNode* BufferNode::getNextNodeByTreeOrder() const
773 /****** BufferNode/getNextNodeByTreeOrder ************************************
775 * NAME
776 * getNextNodeByTreeOrder -- retrieves the next BufferNode in the tree
777 * order.
779 * SYNOPSIS
780 * next = getNextNodeByTreeOrder();
782 * FUNCTION
783 * see NAME
785 * INPUTS
786 * empty
788 * RESULT
789 * next - the BufferNode following this BufferNode in the tree order,
790 * or NULL if there is none.
792 * NOTES
793 * The "next" node in tree order is defined as:
794 * 1. If a node has children, then the first child is;
795 * 2. otherwise, if it has a following sibling, then this sibling node is;
796 * 3. otherwise, if it has a parent node, the the parent's next sibling
797 * node is;
798 * 4. otherwise, no "next" node exists.
800 * HISTORY
801 * 05.01.2004 - implemented
803 * AUTHOR
804 * Michael Mi
805 * Email: michael.mi@sun.com
806 ******************************************************************************/
809 * If this buffer node has m_vChildren, then return the first
810 * child.
812 if (hasChildren())
814 return getFirstChild();
818 * Otherwise, it this buffer node has a following sibling,
819 * then return that sibling.
821 BufferNode* pNextSibling = (BufferNode*)getNextSibling();
822 if (pNextSibling != NULL)
824 return pNextSibling;
828 * Otherwise, it this buffer node has parent, then return
829 * its parent's following sibling.
831 BufferNode* pNode = (BufferNode*)this;
832 BufferNode* pParent;
833 BufferNode* pNextSiblingParent = NULL;
837 if (pNode == NULL)
839 break;
842 pParent = (BufferNode*)pNode->getParent();
843 if (pParent != NULL)
845 pNextSiblingParent = (BufferNode*)pParent->getNextSibling();
847 pNode = pParent;
849 }while (pNextSiblingParent == NULL);
851 return pNextSiblingParent;
854 cssu::Reference< cssxw::XXMLElementWrapper > BufferNode::getXMLElement() const
856 return m_xXMLElement;
859 void BufferNode::setXMLElement( const cssu::Reference< cssxw::XXMLElementWrapper >& xXMLElement )
861 m_xXMLElement = xXMLElement;
864 void BufferNode::notifyBranch()
865 /****** BufferNode/notifyBranch **********************************************
867 * NAME
868 * notifyBranch -- notifies each BufferNode in the branch of this
869 * BufferNode in the tree order.
871 * SYNOPSIS
872 * notifyBranch();
874 * FUNCTION
875 * see NAME
877 * INPUTS
878 * empty
880 * RESULT
881 * empty
883 * HISTORY
884 * 05.01.2004 - implemented
886 * AUTHOR
887 * Michael Mi
888 * Email: michael.mi@sun.com
889 ******************************************************************************/
891 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
893 for( ; ii != m_vChildren.end() ; ++ii )
895 BufferNode* pBufferNode = (BufferNode*)*ii;
896 pBufferNode->elementCollectorNotify();
897 pBufferNode->notifyBranch();
901 void BufferNode::notifyAncestor()
902 /****** BufferNode/notifyAncestor ********************************************
904 * NAME
905 * notifyAncestor -- notifies each ancestor BufferNode through the parent
906 * link.
908 * SYNOPSIS
909 * notifyAncestor();
911 * FUNCTION
912 * see NAME
914 * INPUTS
915 * empty
917 * RESULT
918 * empty
920 * HISTORY
921 * 05.01.2004 - implemented
923 * AUTHOR
924 * Michael Mi
925 * Email: michael.mi@sun.com
926 ******************************************************************************/
928 BufferNode* pParent = m_pParent;
929 while (pParent != NULL)
931 pParent->notifyAncestor();
932 pParent = (BufferNode*)pParent->getParent();
936 void BufferNode::elementCollectorNotify()
937 /****** BufferNode/elementCollectorNotify ************************************
939 * NAME
940 * elementCollectorNotify -- notifies this BufferNode.
942 * SYNOPSIS
943 * elementCollectorNotify();
945 * FUNCTION
946 * Notifies this BufferNode if the notification is not suppressed.
948 * INPUTS
949 * empty
951 * RESULT
952 * child - the first child BufferNode, or NULL if there is no child
953 * BufferNode.
955 * HISTORY
956 * 05.01.2004 - implemented
958 * AUTHOR
959 * Michael Mi
960 * Email: michael.mi@sun.com
961 ******************************************************************************/
963 if (m_vElementCollectors.size()>0)
965 cssxc::sax::ElementMarkPriority nMaxPriority = cssxc::sax::ElementMarkPriority_MINIMUM;
966 cssxc::sax::ElementMarkPriority nPriority;
969 * get the max priority among ElementCollectors on this BufferNode
971 std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
972 for( ; ii != m_vElementCollectors.end() ; ++ii )
974 ElementCollector* pElementCollector = (ElementCollector*)*ii;
975 nPriority = pElementCollector->getPriority();
976 if (nPriority > nMaxPriority)
978 nMaxPriority = nPriority;
982 std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors );
983 ii = vElementCollectors.begin();
985 for( ; ii != vElementCollectors.end() ; ++ii )
987 ElementCollector* pElementCollector = (ElementCollector*)*ii;
988 nPriority = pElementCollector->getPriority();
989 bool bToModify = pElementCollector->getModify();
992 * Only ElementCollector with the max priority can
993 * perform notify operation.
994 * Moreover, if any blocker exists in the subtree of
995 * this BufferNode, this ElementCollector can't do notify
996 * unless its priority is BEFOREMODIFY.
998 if (nPriority == nMaxPriority &&
999 (nPriority == cssxc::sax::ElementMarkPriority_BEFOREMODIFY ||
1000 !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId())))
1003 * If this ElementCollector will modify the bufferred element, then
1004 * special attention must be paid.
1006 * If there is any ElementCollector in the subtree or any ancestor
1007 * ElementCollector with PRI_BEFPREMODIFY priority, this
1008 * ElementCollector can't perform notify operation, otherwise, it
1009 * will destroy the bufferred element, in turn, ElementCollectors
1010 * mentioned above can't perform their mission.
1012 //if (!(nMaxPriority == cssxc::sax::ElementMarkPriority_PRI_MODIFY &&
1013 if (!(bToModify &&
1014 (isECInSubTreeIncluded(pElementCollector->getSecurityId()) ||
1015 isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId()))
1018 pElementCollector->notifyListener();
1025 bool BufferNode::isECInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
1026 /****** BufferNode/isECInSubTreeIncluded *************************************
1028 * NAME
1029 * isECInSubTreeIncluded -- checks whether there is any ElementCollector
1030 * in the branch of this BufferNode.
1032 * SYNOPSIS
1033 * bExist = isECInSubTreeIncluded(nIgnoredSecurityId);
1035 * FUNCTION
1036 * checks each BufferNode in the branch of this BufferNode, if there is
1037 * an ElementCollector whose signatureId is not ignored, then return
1038 * true, otherwise, false returned.
1040 * INPUTS
1041 * nIgnoredSecurityId - the security Id to be ignored. If it equals
1042 * to UNDEFINEDSECURITYID, then no security Id
1043 * will be ignored.
1045 * RESULT
1046 * bExist - true if a match found, false otherwise.
1048 * HISTORY
1049 * 05.01.2004 - implemented
1051 * AUTHOR
1052 * Michael Mi
1053 * Email: michael.mi@sun.com
1054 ******************************************************************************/
1056 bool rc = false;
1058 std::vector< const ElementCollector* >::const_iterator jj = m_vElementCollectors.begin();
1060 for( ; jj != m_vElementCollectors.end() ; ++jj )
1062 ElementCollector* pElementCollector = (ElementCollector*)*jj;
1063 if (nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
1064 pElementCollector->getSecurityId() != nIgnoredSecurityId)
1066 rc = true;
1067 break;
1071 if ( !rc )
1073 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
1075 for( ; ii != m_vChildren.end() ; ++ii )
1077 BufferNode* pBufferNode = (BufferNode*)*ii;
1079 if ( pBufferNode->isECInSubTreeIncluded(nIgnoredSecurityId))
1081 rc = true;
1082 break;
1087 return rc;
1090 bool BufferNode::isECOfBeforeModifyInAncestorIncluded(sal_Int32 nIgnoredSecurityId) const
1091 /****** BufferNode/isECOfBeforeModifyInAncestorIncluded **********************
1093 * NAME
1094 * isECOfBeforeModifyInAncestorIncluded -- checks whether there is some
1095 * ancestor BufferNode which has ElementCollector with PRI_BEFPREMODIFY
1096 * priority.
1098 * SYNOPSIS
1099 * bExist = isECOfBeforeModifyInAncestorIncluded(nIgnoredSecurityId);
1101 * FUNCTION
1102 * checks each ancestor BufferNode through the parent link, if there is
1103 * an ElementCollector with PRI_BEFPREMODIFY priority and its
1104 * signatureId is not ignored, then return true, otherwise, false
1105 * returned.
1107 * INPUTS
1108 * nIgnoredSecurityId - the security Id to be ignored. If it equals
1109 * to UNDEFINEDSECURITYID, then no security Id
1110 * will be ignored.
1112 * RESULT
1113 * bExist - true if a match found, false otherwise.
1115 * HISTORY
1116 * 05.01.2004 - implemented
1118 * AUTHOR
1119 * Michael Mi
1120 * Email: michael.mi@sun.com
1121 ******************************************************************************/
1123 bool rc = false;
1125 BufferNode* pParentNode = m_pParent;
1126 while (pParentNode != NULL)
1128 if (pParentNode->isECOfBeforeModifyIncluded(nIgnoredSecurityId))
1130 rc = true;
1131 break;
1134 pParentNode = (BufferNode*)pParentNode->getParent();
1137 return rc;
1140 bool BufferNode::isBlockerInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
1141 /****** BufferNode/isBlockerInSubTreeIncluded ********************************
1143 * NAME
1144 * isBlockerInSubTreeIncluded -- checks whether there is some BufferNode
1145 * which has blocker on it
1147 * SYNOPSIS
1148 * bExist = isBlockerInSubTreeIncluded(nIgnoredSecurityId);
1150 * FUNCTION
1151 * checks each BufferNode in the branch of this BufferNode, if one has
1152 * a blocker on it, and the blocker's securityId is not ignored, then
1153 * returns true; otherwise, false returns.
1155 * INPUTS
1156 * nIgnoredSecurityId - the security Id to be ignored. If it equals
1157 * to UNDEFINEDSECURITYID, then no security Id
1158 * will be ignored.
1160 * RESULT
1161 * bExist - true if a match found, false otherwise.
1163 * HISTORY
1164 * 05.01.2004 - implemented
1166 * AUTHOR
1167 * Michael Mi
1168 * Email: michael.mi@sun.com
1169 ******************************************************************************/
1171 bool rc = false;
1173 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
1175 for( ; ii != m_vChildren.end() ; ++ii )
1177 BufferNode* pBufferNode = (BufferNode*)*ii;
1178 ElementMark* pBlocker = pBufferNode->getBlocker();
1180 if (pBlocker != NULL &&
1181 (nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
1182 pBlocker->getSecurityId() != nIgnoredSecurityId ))
1184 rc = true;
1185 break;
1188 if (rc || pBufferNode->isBlockerInSubTreeIncluded(nIgnoredSecurityId))
1190 rc = true;
1191 break;
1195 return rc;
1198 const BufferNode* BufferNode::getNextChild(const BufferNode* pChild) const
1199 /****** BufferNode/getNextChild **********************************************
1201 * NAME
1202 * getNextChild -- get the next child BufferNode.
1204 * SYNOPSIS
1205 * nextChild = getNextChild();
1207 * FUNCTION
1208 * see NAME
1210 * INPUTS
1211 * pChild - the child BufferNode whose next node is retrieved.
1213 * RESULT
1214 * nextChild - the next child BufferNode after the pChild, or NULL if
1215 * there is none.
1217 * HISTORY
1218 * 05.01.2004 - implemented
1220 * AUTHOR
1221 * Michael Mi
1222 * Email: michael.mi@sun.com
1223 ******************************************************************************/
1225 BufferNode* rc = NULL;
1226 bool bChildFound = false;
1228 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
1229 for( ; ii != m_vChildren.end() ; ++ii )
1231 if (bChildFound)
1233 rc = (BufferNode*)*ii;
1234 break;
1237 if( *ii == pChild )
1239 bChildFound = true;
1243 return (const BufferNode*)rc;
1247 void BufferNode::freeAllChildren()
1248 /****** BufferNode/freeAllChildren *******************************************
1250 * NAME
1251 * freeAllChildren -- free all his child BufferNode.
1253 * SYNOPSIS
1254 * freeAllChildren();
1256 * FUNCTION
1257 * see NAME
1259 * INPUTS
1260 * empty
1262 * RESULT
1263 * empty
1265 * HISTORY
1266 * 30.03.2004 - the correct the memory leak bug
1268 * AUTHOR
1269 * Michael Mi
1270 * Email: michael.mi@sun.com
1271 ******************************************************************************/
1273 std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
1274 for( ; ii != m_vChildren.end() ; ++ii )
1276 BufferNode *pChild = (BufferNode *)(*ii);
1277 pChild->freeAllChildren();
1278 delete pChild;
1281 m_vChildren.clear();