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