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 #include <nodelist.hxx> 25 26 #include "../dom/document.hxx" 27 28 namespace XPath 29 { CNodeList(::rtl::Reference<DOM::CDocument> const & pDocument,::osl::Mutex & rMutex,boost::shared_ptr<xmlXPathObject> const & rxpathObj)30 CNodeList::CNodeList( 31 ::rtl::Reference<DOM::CDocument> const& pDocument, 32 ::osl::Mutex & rMutex, 33 boost::shared_ptr<xmlXPathObject> const& rxpathObj) 34 : m_pDocument(pDocument) 35 , m_rMutex(rMutex) 36 , m_pNodeSet(0) 37 { 38 if( bool(rxpathObj) && rxpathObj->type == XPATH_NODESET) 39 { 40 m_pNodeSet = rxpathObj->nodesetval; 41 m_pXPathObj = rxpathObj; 42 } 43 } 44 45 /** 46 The number of nodes in the list. 47 */ getLength()48 sal_Int32 SAL_CALL CNodeList::getLength() throw (RuntimeException) 49 { 50 ::osl::MutexGuard const g(m_rMutex); 51 52 sal_Int32 value = 0; 53 if (m_pNodeSet != NULL) 54 value = xmlXPathNodeSetGetLength(m_pNodeSet); 55 return value; 56 } 57 58 /** 59 Returns the indexth item in the collection. 60 */ item(sal_Int32 index)61 Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index) 62 throw (RuntimeException) 63 { 64 ::osl::MutexGuard const g(m_rMutex); 65 66 if (0 == m_pNodeSet) { 67 return 0; 68 } 69 xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index); 70 Reference< XNode > const xNode(m_pDocument->GetCNode(pNode).get()); 71 return xNode; 72 } 73 } 74 75