|
22 | 22 | package org.exist.xquery.functions.util;
|
23 | 23 |
|
24 | 24 | import org.exist.SystemProperties;
|
25 |
| -import org.exist.dom.QName; |
26 | 25 | import org.exist.xquery.BasicFunction;
|
27 |
| -import org.exist.xquery.Cardinality; |
28 | 26 | import org.exist.xquery.FunctionSignature;
|
29 | 27 | import org.exist.xquery.XPathException;
|
30 | 28 | import org.exist.xquery.XQueryContext;
|
31 |
| -import org.exist.xquery.value.FunctionParameterSequenceType; |
32 |
| -import org.exist.xquery.value.FunctionReturnSequenceType; |
33 | 29 | import org.exist.xquery.value.Sequence;
|
34 |
| -import org.exist.xquery.value.SequenceType; |
35 | 30 | import org.exist.xquery.value.StringValue;
|
36 | 31 | import org.exist.xquery.value.Type;
|
37 | 32 |
|
| 33 | +import static org.exist.xquery.FunctionDSL.param; |
| 34 | +import static org.exist.xquery.FunctionDSL.returnsOpt; |
| 35 | +import static org.exist.xquery.functions.util.UtilModule.functionSignature; |
| 36 | + |
38 | 37 | /**
|
39 |
| - * Libary function to retrieve the value of a system property. |
| 38 | + * Library function to retrieve the value of a system property. |
| 39 | + * |
40 | 40 | * @author Wolfgang Meier
|
41 | 41 | * @author Loren Cahlander
|
42 | 42 | */
|
43 | 43 | public class SystemProperty extends BasicFunction {
|
44 | 44 |
|
45 |
| - public final static FunctionSignature signature = new FunctionSignature( |
46 |
| - new QName("system-property", UtilModule.NAMESPACE_URI, UtilModule.PREFIX), |
47 |
| - "Returns the value of a system property. Similar to the corresponding XSLT function. " + |
48 |
| - "Predefined properties are: vendor, vendor-url, product-name, product-version, product-build, and all Java " + |
49 |
| - "system properties.", |
50 |
| - new SequenceType[] { |
51 |
| - new FunctionParameterSequenceType("property-name", Type.STRING, Cardinality.EXACTLY_ONE, "The name of the system property to retrieve the value of.") |
52 |
| - }, |
53 |
| - new FunctionReturnSequenceType(Type.STRING, Cardinality.ZERO_OR_ONE, "the value of the named system property") |
| 45 | + public final static FunctionSignature signature = functionSignature( |
| 46 | + "system-property", |
| 47 | + "Returns the value of a system property. Similar to the corresponding XSLT function. " + |
| 48 | + "Predefined properties are: vendor, vendor-url, product-name, product-version, product-build, and all Java " + |
| 49 | + "System Properties.", |
| 50 | + returnsOpt(Type.STRING, "the value of the named system property"), |
| 51 | + param("property-name", Type.STRING, "The name of the system property to retrieve the value of.") |
54 | 52 | );
|
55 | 53 |
|
56 |
| - public SystemProperty(XQueryContext context, FunctionSignature signature) { |
| 54 | + public SystemProperty(final XQueryContext context, final FunctionSignature signature) { |
57 | 55 | super(context, signature);
|
58 | 56 | }
|
59 | 57 |
|
60 |
| - /* (non-Javadoc) |
61 |
| - * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence) |
62 |
| - */ |
63 | 58 | @Override
|
64 |
| - public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { |
65 |
| - |
| 59 | + public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException { |
66 | 60 | final String key = args[0].getStringValue();
|
67 | 61 | String value = SystemProperties.getInstance().getSystemProperty(key, null);
|
68 |
| - if(value == null) { |
69 |
| - value = System.getProperty(key); |
| 62 | + if (value == null) { |
| 63 | + value = System.getProperty(key); |
70 | 64 | }
|
71 | 65 | return value == null ? Sequence.EMPTY_SEQUENCE : new StringValue(this, value);
|
72 | 66 | }
|
|
0 commit comments