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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/* -*- 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 "txIXPathContext.h"
#include "nsGkAtoms.h"
#include "nsError.h"
#include "txXMLUtils.h"
#include "txXSLTFunctions.h"
#include "txExpandedName.h"
#include "txNamespaceMap.h"
nsresult
txXSLTEnvironmentFunctionCall::evaluate(txIEvalContext* aContext,
txAExprResult** aResult)
{
*aResult = nullptr;
if (!requireParams(1, 1, aContext)) {
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
}
nsAutoString property;
nsresult rv = mParams[0]->evaluateToString(aContext, property);
NS_ENSURE_SUCCESS(rv, rv);
txExpandedName qname;
rv = qname.init(property, mMappings, mType != FUNCTION_AVAILABLE);
NS_ENSURE_SUCCESS(rv, rv);
switch (mType) {
case SYSTEM_PROPERTY:
{
if (qname.mNamespaceID == kNameSpaceID_XSLT) {
if (qname.mLocalName == nsGkAtoms::version) {
return aContext->recycler()->getNumberResult(1.0, aResult);
}
if (qname.mLocalName == nsGkAtoms::vendor) {
return aContext->recycler()->getStringResult(
NS_LITERAL_STRING("Transformiix"), aResult);
}
if (qname.mLocalName == nsGkAtoms::vendorUrl) {
return aContext->recycler()->getStringResult(
NS_LITERAL_STRING("http://www.mozilla.org/projects/xslt/"),
aResult);
}
}
aContext->recycler()->getEmptyStringResult(aResult);
break;
}
case ELEMENT_AVAILABLE:
{
bool val = qname.mNamespaceID == kNameSpaceID_XSLT &&
(qname.mLocalName == nsGkAtoms::applyImports ||
qname.mLocalName == nsGkAtoms::applyTemplates ||
qname.mLocalName == nsGkAtoms::attribute ||
qname.mLocalName == nsGkAtoms::attributeSet ||
qname.mLocalName == nsGkAtoms::callTemplate ||
qname.mLocalName == nsGkAtoms::choose ||
qname.mLocalName == nsGkAtoms::comment ||
qname.mLocalName == nsGkAtoms::copy ||
qname.mLocalName == nsGkAtoms::copyOf ||
qname.mLocalName == nsGkAtoms::decimalFormat ||
qname.mLocalName == nsGkAtoms::element ||
qname.mLocalName == nsGkAtoms::fallback ||
qname.mLocalName == nsGkAtoms::forEach ||
qname.mLocalName == nsGkAtoms::_if ||
qname.mLocalName == nsGkAtoms::import ||
qname.mLocalName == nsGkAtoms::include ||
qname.mLocalName == nsGkAtoms::key ||
qname.mLocalName == nsGkAtoms::message ||
//qname.mLocalName == nsGkAtoms::namespaceAlias ||
qname.mLocalName == nsGkAtoms::number ||
qname.mLocalName == nsGkAtoms::otherwise ||
qname.mLocalName == nsGkAtoms::output ||
qname.mLocalName == nsGkAtoms::param ||
qname.mLocalName == nsGkAtoms::preserveSpace ||
qname.mLocalName == nsGkAtoms::processingInstruction ||
qname.mLocalName == nsGkAtoms::sort ||
qname.mLocalName == nsGkAtoms::stripSpace ||
qname.mLocalName == nsGkAtoms::stylesheet ||
qname.mLocalName == nsGkAtoms::_template ||
qname.mLocalName == nsGkAtoms::text ||
qname.mLocalName == nsGkAtoms::transform ||
qname.mLocalName == nsGkAtoms::valueOf ||
qname.mLocalName == nsGkAtoms::variable ||
qname.mLocalName == nsGkAtoms::when ||
qname.mLocalName == nsGkAtoms::withParam);
aContext->recycler()->getBoolResult(val, aResult);
break;
}
case FUNCTION_AVAILABLE:
{
extern bool TX_XSLTFunctionAvailable(nsIAtom* aName,
int32_t aNameSpaceID);
txCoreFunctionCall::eType type;
bool val = (qname.mNamespaceID == kNameSpaceID_None &&
txCoreFunctionCall::getTypeFromAtom(qname.mLocalName,
type)) ||
TX_XSLTFunctionAvailable(qname.mLocalName,
qname.mNamespaceID);
aContext->recycler()->getBoolResult(val, aResult);
break;
}
}
return NS_OK;
}
Expr::ResultType
txXSLTEnvironmentFunctionCall::getReturnType()
{
return mType == SYSTEM_PROPERTY ? (STRING_RESULT | NUMBER_RESULT) :
BOOLEAN_RESULT;
}
bool
txXSLTEnvironmentFunctionCall::isSensitiveTo(ContextSensitivity aContext)
{
return argsSensitiveTo(aContext);
}
#ifdef TX_TO_STRING
nsresult
txXSLTEnvironmentFunctionCall::getNameAtom(nsIAtom** aAtom)
{
*aAtom = mType == SYSTEM_PROPERTY ? nsGkAtoms::systemProperty :
mType == ELEMENT_AVAILABLE ? nsGkAtoms::elementAvailable :
nsGkAtoms::functionAvailable;
NS_ADDREF(*aAtom);
return NS_OK;
}
#endif
|