Version 24.8.3.2, tag libreoffice-24.8.3.2
[LibreOffice.git] / unoxml / source / xpath / nodelist.cxx
blobb9e4e70c443a1eac32bde026a9c5dc7b0e943fd4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <utility>
22 #include "nodelist.hxx"
24 #include "../dom/document.hxx"
26 using namespace css::uno;
27 using namespace css::xml::dom;
29 namespace XPath
31 CNodeList::CNodeList(
32 ::rtl::Reference<DOM::CDocument> pDocument,
33 ::osl::Mutex & rMutex,
34 std::shared_ptr<xmlXPathObject> const& rxpathObj)
35 : m_pDocument(std::move(pDocument))
36 , m_rMutex(rMutex)
37 , m_pNodeSet(nullptr)
39 if (rxpathObj != nullptr && rxpathObj->type == XPATH_NODESET)
41 m_pNodeSet = rxpathObj->nodesetval;
42 m_pXPathObj = rxpathObj;
46 /**
47 The number of nodes in the list.
49 sal_Int32 SAL_CALL CNodeList::getLength()
51 ::osl::MutexGuard const g(m_rMutex);
53 sal_Int32 value = 0;
54 if (m_pNodeSet != nullptr)
55 value = xmlXPathNodeSetGetLength(m_pNodeSet);
56 return value;
59 /**
60 Returns the indexth item in the collection.
62 Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index)
64 ::osl::MutexGuard const g(m_rMutex);
66 if (nullptr == m_pNodeSet) {
67 return nullptr;
69 xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index);
70 return m_pDocument->GetCNode(pNode);
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */