LibreOffice Module unoxml (master) 1
nodelist.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <utility>
21
22#include "nodelist.hxx"
23
24#include "../dom/document.hxx"
25
26using namespace css::uno;
27using namespace css::xml::dom;
28
29namespace XPath
30{
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)
38 {
39 if (rxpathObj != nullptr && rxpathObj->type == XPATH_NODESET)
40 {
41 m_pNodeSet = rxpathObj->nodesetval;
42 m_pXPathObj = rxpathObj;
43 }
44 }
45
49 sal_Int32 SAL_CALL CNodeList::getLength()
50 {
51 ::osl::MutexGuard const g(m_rMutex);
52
53 sal_Int32 value = 0;
54 if (m_pNodeSet != nullptr)
55 value = xmlXPathNodeSetGetLength(m_pNodeSet);
56 return value;
57 }
58
62 Reference< XNode > SAL_CALL CNodeList::item(sal_Int32 index)
63 {
64 ::osl::MutexGuard const g(m_rMutex);
65
66 if (nullptr == m_pNodeSet) {
67 return nullptr;
68 }
69 xmlNodePtr const pNode = xmlXPathNodeSetItem(m_pNodeSet, index);
70 return m_pDocument->GetCNode(pNode);
71 }
72}
73
74/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< xmlXPathObject > m_pXPathObj
retain the result set in case the CXPathObject is released
Definition: nodelist.hxx:51
::osl::Mutex & m_rMutex
Definition: nodelist.hxx:49
virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL item(sal_Int32 index) override
Returns the indexth item in the collection.
Definition: nodelist.cxx:62
virtual sal_Int32 SAL_CALL getLength() override
The number of nodes in the list.
Definition: nodelist.cxx:49
CNodeList(::rtl::Reference< DOM::CDocument > pDocument, ::osl::Mutex &rMutex, std::shared_ptr< xmlXPathObject > const &rxpathObj)
Definition: nodelist.cxx:31
::rtl::Reference< DOM::CDocument > const m_pDocument
#i115995# keep document alive
Definition: nodelist.hxx:48
xmlNodeSetPtr m_pNodeSet
Definition: nodelist.hxx:52
Any value
::osl::Mutex & m_rMutex
index