|
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 "nsIAtom.h" |
|
7 #include "txIXPathContext.h" |
|
8 #include "txNodeSet.h" |
|
9 #include "txExpr.h" |
|
10 #include "txXPathTreeWalker.h" |
|
11 |
|
12 txNamedAttributeStep::txNamedAttributeStep(int32_t aNsID, |
|
13 nsIAtom* aPrefix, |
|
14 nsIAtom* aLocalName) |
|
15 : mNamespace(aNsID), |
|
16 mPrefix(aPrefix), |
|
17 mLocalName(aLocalName) |
|
18 { |
|
19 } |
|
20 |
|
21 nsresult |
|
22 txNamedAttributeStep::evaluate(txIEvalContext* aContext, |
|
23 txAExprResult** aResult) |
|
24 { |
|
25 *aResult = nullptr; |
|
26 |
|
27 nsRefPtr<txNodeSet> nodes; |
|
28 nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); |
|
29 NS_ENSURE_SUCCESS(rv, rv); |
|
30 |
|
31 txXPathTreeWalker walker(aContext->getContextNode()); |
|
32 if (walker.moveToNamedAttribute(mLocalName, mNamespace)) { |
|
33 rv = nodes->append(walker.getCurrentPosition()); |
|
34 NS_ENSURE_SUCCESS(rv, rv); |
|
35 } |
|
36 NS_ADDREF(*aResult = nodes); |
|
37 |
|
38 return NS_OK; |
|
39 } |
|
40 |
|
41 TX_IMPL_EXPR_STUBS_0(txNamedAttributeStep, NODESET_RESULT) |
|
42 |
|
43 bool |
|
44 txNamedAttributeStep::isSensitiveTo(ContextSensitivity aContext) |
|
45 { |
|
46 return !!(aContext & NODE_CONTEXT); |
|
47 } |
|
48 |
|
49 #ifdef TX_TO_STRING |
|
50 void |
|
51 txNamedAttributeStep::toString(nsAString& aDest) |
|
52 { |
|
53 aDest.Append(char16_t('@')); |
|
54 if (mPrefix) { |
|
55 nsAutoString prefix; |
|
56 mPrefix->ToString(prefix); |
|
57 aDest.Append(prefix); |
|
58 aDest.Append(char16_t(':')); |
|
59 } |
|
60 nsAutoString localName; |
|
61 mLocalName->ToString(localName); |
|
62 aDest.Append(localName); |
|
63 } |
|
64 #endif |