Skip to content

Commit 03e45ba

Browse files
add implementation of fn:system-properties (#2650)
1 parent 09609fd commit 03e45ba

4 files changed

Lines changed: 88 additions & 3 deletions

File tree

basex-core/src/main/java/org/basex/query/func/Function.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ public enum Function implements AFunction {
709709
SUM(FnSum::new, "sum(values[,zero])",
710710
params(ANY_ATOMIC_TYPE_ZM, ANY_ATOMIC_TYPE_ZO), ANY_ATOMIC_TYPE_ZO),
711711
/** XQuery function. */
712+
SYSTEM_PROPERTIES(FnSystemProperties::new, "system-properties()", params(),
713+
MapType.get(BasicType.QNAME, ANY_ATOMIC_TYPE_O).seqType()),
714+
/** XQuery function. */
712715
TAIL(FnTail::new, "tail(input)",
713716
params(ITEM_ZM), ITEM_ZM),
714717
/** XQuery function. */

basex-core/src/main/java/org/basex/query/func/fn/FnInvisibleXml.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.basex.query.QueryError.*;
44

55
import java.io.*;
6-
import java.util.*;
76

87
import org.basex.io.*;
98
import org.basex.query.*;
@@ -28,6 +27,9 @@
2827
* @author Gunther Rademacher
2928
*/
3029
public final class FnInvisibleXml extends StandardFunc {
30+
/** Required class names. */
31+
private static final String[] CLASSES = { "de.bottlecaps.markup.Blitz",
32+
"de.bottlecaps.markup.BlitzException", "de.bottlecaps.markup.BlitzParseException"};
3133
/** The function's argument type. */
3234
public static final SeqType ARG_TYPE = ChoiceItemType.get(BasicType.STRING,
3335
NodeType.get(NameTest.get(new QNm("ixml")))).seqType(Occ.ZERO_OR_ONE);
@@ -37,8 +39,7 @@ public final class FnInvisibleXml extends StandardFunc {
3739
@Override
3840
public FuncItem item(final QueryContext qc, final InputInfo ii) throws QueryException {
3941
if(generator == null) {
40-
for(final String className : Arrays.asList("de.bottlecaps.markup.Blitz",
41-
"de.bottlecaps.markup.BlitzException", "de.bottlecaps.markup.BlitzParseException")) {
42+
for(final String className : CLASSES) {
4243
if(!Reflect.available(className)) {
4344
throw BASEX_CLASSPATH_X_X.get(info, definition.name, className);
4445
}
@@ -48,6 +49,17 @@ public FuncItem item(final QueryContext qc, final InputInfo ii) throws QueryExce
4849
return generator.generate(qc);
4950
}
5051

52+
/**
53+
* Checks if Invisible XML support is available.
54+
* @return result of check
55+
*/
56+
public static boolean available() {
57+
for(final String className : CLASSES) {
58+
if(!Reflect.available(className)) return false;
59+
}
60+
return true;
61+
}
62+
5163
/**
5264
* Invisible XML parser generator.
5365
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.basex.query.func.fn;
2+
3+
import java.math.*;
4+
5+
import org.basex.query.*;
6+
import org.basex.query.func.*;
7+
import org.basex.query.value.item.*;
8+
import org.basex.query.value.map.*;
9+
import org.basex.util.*;
10+
11+
/**
12+
* Function implementation.
13+
*
14+
* @author BaseX Team, BSD License
15+
*/
16+
public final class FnSystemProperties extends StandardFunc {
17+
/** XPath version. */
18+
private static final Dec XPATH_VERSION = Dec.get(BigDecimal.valueOf(4));
19+
/** XSD version. */
20+
private static final Dec XSD_VERSION = Dec.get(BigDecimal.valueOf(11, 1));
21+
22+
@Override
23+
public XQMap item(final QueryContext qc, final InputInfo ii) throws QueryException {
24+
return new MapBuilder().
25+
put(property("xpath-version"), XPATH_VERSION).
26+
put(property("xsd-version"), XSD_VERSION).
27+
put(property("product-name"), Str.get(Prop.NAME)).
28+
put(property("product-version"), Str.get(Prop.VERSION)).
29+
put(property("schema-aware"), Bln.FALSE).
30+
put(property("accepts-typed-data"), Bln.FALSE).
31+
put(property("supports-xinclude"), Bln.TRUE).
32+
// supports-dtd: false, because id/idref is not fully supported
33+
put(property("supports-dtd"), Bln.FALSE).
34+
put(property("supports-invisible-xml"), Bln.get(FnInvisibleXml.available())).
35+
put(property("supports-dynamic-xquery"), Bln.TRUE).
36+
// supports-dynamic-xslt: false, because fn:transform is not available
37+
put(property("supports-dynamic-xslt"), Bln.FALSE).map();
38+
}
39+
40+
/**
41+
* Returns a no-namespace QName for a standardized property name.
42+
* @param local local name
43+
* @return QName
44+
*/
45+
private static QNm property(final String local) {
46+
return new QNm(local, "");
47+
}
48+
}

basex-core/src/test/java/org/basex/query/func/FnModuleTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.basex.query.expr.List;
1717
import org.basex.query.expr.constr.*;
1818
import org.basex.query.expr.gflwor.*;
19+
import org.basex.query.func.fn.*;
1920
import org.basex.query.func.prof.ProfType.*;
2021
import org.basex.query.value.item.*;
2122
import org.basex.query.value.seq.*;
@@ -3784,6 +3785,27 @@ public final class FnModuleTest extends SandboxTest {
37843785
1, type(SUM, "xs:anyAtomicType?"));
37853786
}
37863787

3788+
/** Test method. */
3789+
@Test public void systemProperties() {
3790+
final Function func = SYSTEM_PROPERTIES;
3791+
3792+
query("map:size(" + func.args() + ')', 11);
3793+
query(func.args() + "?#xpath-version", 4);
3794+
query(func.args() + "?#xsd-version", 1.1);
3795+
query(func.args() + "?#product-name", Prop.NAME);
3796+
query(func.args() + "?#product-version", Prop.VERSION);
3797+
query(func.args() + "?#schema-aware", false);
3798+
query(func.args() + "?#accepts-typed-data", false);
3799+
query(func.args() + "?#supports-xinclude", true);
3800+
query(func.args() + "?#supports-dtd", false);
3801+
query(func.args() + "?#supports-invisible-xml", FnInvisibleXml.available());
3802+
query(func.args() + "?#supports-dynamic-xquery", true);
3803+
query(func.args() + "?#supports-dynamic-xslt", false);
3804+
3805+
query("every $k in map:keys(" + func.args() + ") satisfies $k instance of xs:QName", true);
3806+
query("every $v in " + func.args() + "?* satisfies $v instance of xs:anyAtomicType", true);
3807+
}
3808+
37873809
/** Test method. */
37883810
@Test public void tail() {
37893811
final Function func = TAIL;

0 commit comments

Comments
 (0)