Debian Codegraph @

net/sf/saxon/functions/AvailableEnvironmentVariables.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.functions;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.SystemFunctionCall;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.expr.parser.ExpressionVisitor;
14 import net.sf.saxon.lib.EnvironmentVariableResolver;
15 import net.sf.saxon.lib.Feature;
16 import net.sf.saxon.om.Sequence;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.value.SequenceExtent;
19 import net.sf.saxon.value.StringValue;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 public class AvailableEnvironmentVariables extends SystemFunction {
25
26 /**
27 * Evaluate the expression (dynamic evaluation)
28 *
29 * @param context the dynamic evaluation context
30 * @param arguments the values of the arguments, supplied as SequenceIterators
31 * @return the result of the evaluation, in the form of a SequenceIterator
32 * @throws net.sf.saxon.trans.XPathException
33 * if a dynamic error occurs during the evaluation of the expression
34 */
35 public Sequence<StringValue> call(XPathContext context, Sequence[] arguments) throws XPathException {
36 EnvironmentVariableResolver resolver = context.getConfiguration().getConfigurationProperty(
37 Feature.ENVIRONMENT_VARIABLE_RESOLVER);
38 List<StringValue> myList = new ArrayList<>();
39 if (context.getConfiguration().getBooleanProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS)) {
40 for (java.lang.String s : resolver.getAvailableEnvironmentVariables()) {
41 myList.add(new StringValue(s));
42 }
43 }
44 return new SequenceExtent<>(myList);
45 }
46
47 @Override
48 public Expression makeFunctionCall(Expression[] arguments) {
49 return new SystemFunctionCall(this, arguments) {
50 // Suppress early evaluation
51 public Expression preEvaluate(ExpressionVisitor visitor) {
52 return this;
53 }
54 };
55 }
56 }
57
58 //Copyright (c) 2010-2012 Saxonica Limited.