xref: /aoo4110/main/unoxml/source/dom/elementlist.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef DOM_ELEMENTLIST_HXX
25 #define DOM_ELEMENTLIST_HXX
26 
27 #include <vector>
28 
29 #include <boost/scoped_array.hpp>
30 
31 #include <libxml/tree.h>
32 
33 #include <sal/types.h>
34 #include <rtl/ref.hxx>
35 
36 #include <com/sun/star/uno/Reference.h>
37 #include <com/sun/star/uno/Exception.hpp>
38 #include <com/sun/star/xml/dom/XNode.hpp>
39 #include <com/sun/star/xml/dom/XNodeList.hpp>
40 #include <com/sun/star/xml/dom/events/XEvent.hpp>
41 #include <com/sun/star/xml/dom/events/XEventListener.hpp>
42 
43 #include <cppuhelper/implbase2.hxx>
44 
45 
46 using ::rtl::OUString;
47 using namespace com::sun::star::uno;
48 using namespace com::sun::star::xml::dom;
49 using namespace com::sun::star::xml::dom::events;
50 
51 namespace DOM
52 {
53     class CElement;
54 
55     typedef std::vector< xmlNodePtr > nodevector_t;
56 
57     class CElementList
58         : public cppu::WeakImplHelper2< XNodeList,
59                 com::sun::star::xml::dom::events::XEventListener >
60     {
61     private:
62         ::rtl::Reference<CElement> const m_pElement;
63         ::osl::Mutex & m_rMutex;
64         ::boost::scoped_array<xmlChar> const m_pName;
65         ::boost::scoped_array<xmlChar> const m_pURI;
66         bool m_bRebuild;
67         nodevector_t m_nodevector;
68 
69         void buildlist(xmlNodePtr pNode, sal_Bool start=sal_True);
70         void registerListener(CElement & rElement);
71 
72     public:
73         CElementList(::rtl::Reference<CElement> const& pElement,
74                 ::osl::Mutex & rMutex,
75                 OUString const& rName, OUString const*const pURI = 0);
76 
77         /**
78         The number of nodes in the list.
79         */
80         virtual sal_Int32 SAL_CALL getLength() throw (RuntimeException);
81         /**
82         Returns the indexth item in the collection.
83         */
84         virtual Reference< XNode > SAL_CALL item(sal_Int32 index)
85             throw (RuntimeException);
86 
87         // XEventListener
88         virtual void SAL_CALL handleEvent(const Reference< XEvent >& evt)
89             throw (RuntimeException);
90     };
91 }
92 
93 #endif
94