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