1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "txNodeSetAdaptor.h"
#include "txXPathTreeWalker.h"
txNodeSetAdaptor::txNodeSetAdaptor()
: txXPathObjectAdaptor(),
mWritable(true)
{
}
txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
: txXPathObjectAdaptor(aNodeSet),
mWritable(false)
{
}
NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
nsresult
txNodeSetAdaptor::Init()
{
if (!mValue) {
mValue = new txNodeSet(nullptr);
}
return NS_OK;
}
NS_IMETHODIMP
txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
{
*aResult = nullptr;
if (aIndex > (uint32_t)NodeSet()->size()) {
return NS_ERROR_ILLEGAL_VALUE;
}
return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
}
NS_IMETHODIMP
txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
{
if (aIndex > (uint32_t)NodeSet()->size()) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsAutoString result;
txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
*aResult = txDouble::toDouble(result);
return NS_OK;
}
NS_IMETHODIMP
txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
{
if (aIndex > (uint32_t)NodeSet()->size()) {
return NS_ERROR_ILLEGAL_VALUE;
}
txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
return NS_OK;
}
NS_IMETHODIMP
txNodeSetAdaptor::GetLength(uint32_t *aLength)
{
*aLength = (uint32_t)NodeSet()->size();
return NS_OK;
}
NS_IMETHODIMP
txNodeSetAdaptor::Add(nsIDOMNode *aNode)
{
NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
true));
return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
}
|