29
29
import org .exist .xquery .value .Sequence ;
30
30
import org .exist .xquery .value .StringValue ;
31
31
import org .exist .xquery .value .Type ;
32
+ import org .exist .xquery .value .ValueSequence ;
32
33
33
- import static org .exist .xquery .FunctionDSL .param ;
34
- import static org .exist .xquery .FunctionDSL .returnsOpt ;
34
+ import java .util .HashSet ;
35
+ import java .util .Set ;
36
+
37
+ import static org .exist .xquery .FunctionDSL .*;
35
38
import static org .exist .xquery .functions .util .UtilModule .functionSignature ;
36
39
37
40
/**
42
45
*/
43
46
public class SystemProperty extends BasicFunction {
44
47
45
- public final static FunctionSignature signature = functionSignature (
46
- "system-property" ,
48
+ private final static String FS_AVAILABLE_SYSTEM_PROPERTIES_NAME = "available-system-properties" ;
49
+ public final static FunctionSignature FS_AVAILABLE_SYSTEM_PROPERTIES = functionSignature (
50
+ FS_AVAILABLE_SYSTEM_PROPERTIES_NAME ,
51
+ "Returns a list of available system properties. " +
52
+ "Predefined properties are: vendor, vendor-url, product-name, product-version, product-build, and all Java " +
53
+ "System Properties." ,
54
+ returnsOptMany (Type .STRING , "The names of the available system properties" )
55
+ );
56
+
57
+ private final static String FS_SYSTEM_PROPERTY_NAME = "system-property" ;
58
+ public final static FunctionSignature FS_SYSTEM_PROPERTY = functionSignature (
59
+ FS_SYSTEM_PROPERTY_NAME ,
47
60
"Returns the value of a system property. Similar to the corresponding XSLT function. " +
48
61
"Predefined properties are: vendor, vendor-url, product-name, product-version, product-build, and all Java " +
49
62
"System Properties." ,
@@ -57,11 +70,26 @@ public SystemProperty(final XQueryContext context, final FunctionSignature signa
57
70
58
71
@ Override
59
72
public Sequence eval (final Sequence [] args , final Sequence contextSequence ) throws XPathException {
60
- final String key = args [0 ].getStringValue ();
61
- String value = ExistSystemProperties .getInstance ().getExistSystemProperty (key , null );
62
- if (value == null ) {
63
- value = context .getJavaSystemProperties ().get (key , null );
73
+ if (isCalledAs (FS_AVAILABLE_SYSTEM_PROPERTIES_NAME )) {
74
+
75
+ final Set <String > availableProperties = new HashSet <>();
76
+ availableProperties .addAll (ExistSystemProperties .getInstance ().getAvailableExistSystemProperties ());
77
+ availableProperties .addAll (context .getJavaSystemProperties ().keys ().toSet ());
78
+
79
+ final ValueSequence result = new ValueSequence (availableProperties .size ());
80
+ for (final String availableProperty : availableProperties ) {
81
+ result .add (new StringValue (this , availableProperty ));
82
+ }
83
+
84
+ return result ;
85
+
86
+ } else {
87
+ final String key = args [0 ].getStringValue ();
88
+ String value = ExistSystemProperties .getInstance ().getExistSystemProperty (key , null );
89
+ if (value == null ) {
90
+ value = context .getJavaSystemProperties ().get (key , null );
91
+ }
92
+ return value == null ? Sequence .EMPTY_SEQUENCE : new StringValue (this , value );
64
93
}
65
- return value == null ? Sequence .EMPTY_SEQUENCE : new StringValue (this , value );
66
94
}
67
- }
95
+ }
0 commit comments