1e9cbe144SAndrew Rist /************************************************************** 2e9cbe144SAndrew Rist * 3e9cbe144SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4e9cbe144SAndrew Rist * or more contributor license agreements. See the NOTICE file 5e9cbe144SAndrew Rist * distributed with this work for additional information 6e9cbe144SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7e9cbe144SAndrew Rist * to you under the Apache License, Version 2.0 (the 8e9cbe144SAndrew Rist * "License"); you may not use this file except in compliance 9e9cbe144SAndrew Rist * with the License. You may obtain a copy of the License at 10e9cbe144SAndrew Rist * 11e9cbe144SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12e9cbe144SAndrew Rist * 13e9cbe144SAndrew Rist * Unless required by applicable law or agreed to in writing, 14e9cbe144SAndrew Rist * software distributed under the License is distributed on an 15e9cbe144SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16e9cbe144SAndrew Rist * KIND, either express or implied. See the License for the 17e9cbe144SAndrew Rist * specific language governing permissions and limitations 18e9cbe144SAndrew Rist * under the License. 19e9cbe144SAndrew Rist * 20e9cbe144SAndrew Rist *************************************************************/ 21e9cbe144SAndrew Rist 22e9cbe144SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <nodelist.hxx> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "../dom/document.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir namespace XPath 29cdf0e10cSrcweir { CNodeList(::rtl::Reference<DOM::CDocument> const & pDocument,::osl::Mutex & rMutex,boost::shared_ptr<xmlXPathObject> const & rxpathObj)30cdf0e10cSrcweir CNodeList::CNodeList( 31cdf0e10cSrcweir ::rtl::Reference<DOM::CDocument> const& pDocument, 32cdf0e10cSrcweir ::osl::Mutex & rMutex, 33cdf0e10cSrcweir boost::shared_ptr<xmlXPathObject> const& rxpathObj) 34cdf0e10cSrcweir : m_pDocument(pDocument) 35cdf0e10cSrcweir , m_rMutex(rMutex) 36cdf0e10cSrcweir , m_pNodeSet(0) 37cdf0e10cSrcweir { 38*b862c97cSHerbert Dürr if( bool(rxpathObj) && rxpathObj->type == XPATH_NODESET) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir m_pNodeSet = rxpathObj->nodesetval; 41cdf0e10cSrcweir m_pXPathObj = rxpathObj; 42cdf0e10cSrcweir } 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** 46cdf0e10cSrcweir The number of nodes in the list. 47cdf0e10cSrcweir */ getLength()48cdf0e10cSrcweir sal_Int32 SAL_CALL CNodeList::getLength() throw (RuntimeException) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 51cdf0e10cSrcweir 52cdf0e10cSrcweir sal_Int32 value = 0; 53cdf0e10cSrcweir if (m_pNodeSet != NULL) 54cdf0e10cSrcweir value = xmlXPathNodeSetGetLength(m_pNodeSet); 55cdf0e10cSrcweir return value; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** 59cdf0e10cSrcweir Returns the indexth item in the collection. 60cdf0e10cSrcweir */ item(sal_Int32 index)61cdf0e10cSrcweir Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index) 62cdf0e10cSrcweir throw (RuntimeException) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 65cdf0e10cSrcweir 66cdf0e10cSrcweir if (0 == m_pNodeSet) { 67cdf0e10cSrcweir return 0; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index); 70cdf0e10cSrcweir Reference< XNode > const xNode(m_pDocument->GetCNode(pNode).get()); 71cdf0e10cSrcweir return xNode; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75