Skip to content

Commit 6bb96d3

Browse files
authored
Merge pull request #4470 from evolvedbinary/bugfix/cardinality-enforcement
Bugfix/cardinality enforcement
2 parents 96230d1 + 0aabb4b commit 6bb96d3

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/ExtCollection.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public class ExtCollection extends Function {
6060
" Documents contained in sub-collections are also included. If no value is supplied, the statically know documents are used, for the REST Server this could be the addressed collection.",
6161
new SequenceType[]{
6262
//Different from the official specs
63-
new FunctionParameterSequenceType("collection-uris", Type.STRING,
64-
Cardinality.ZERO_OR_MORE, "The collection-URIs for which to include the documents")},
63+
new FunctionParameterSequenceType("collection-uri", Type.STRING,
64+
Cardinality.ZERO_OR_ONE, "The collection URI for which to include the documents")},
6565
new FunctionReturnSequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE,
6666
"The document nodes contained in or under the given collections"),
6767
true);
@@ -109,20 +109,18 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
109109
result = dynamicCollection;
110110
} else {
111111
final MutableDocumentSet ndocs = new DefaultDocumentSet();
112-
for (final String next : args) {
113-
final XmldbURI uri = new AnyURIValue(this, next).toXmldbURI();
114-
try (final Collection coll = context.getBroker().openCollection(uri, Lock.LockMode.READ_LOCK)) {
115-
if (coll == null) {
116-
if (context.isRaiseErrorOnFailedRetrieval()) {
117-
throw new XPathException(this, ErrorCodes.FODC0002, "Can not access collection '" + uri + "'");
118-
}
112+
final XmldbURI uri = new AnyURIValue(this, args.get(0)).toXmldbURI();
113+
try (final Collection coll = context.getBroker().openCollection(uri, Lock.LockMode.READ_LOCK)) {
114+
if (coll == null) {
115+
if (context.isRaiseErrorOnFailedRetrieval()) {
116+
throw new XPathException(this, ErrorCodes.FODC0002, "Can not access collection '" + uri + "'");
117+
}
118+
} else {
119+
if (context.inProtectedMode()) {
120+
context.getProtectedDocs().getDocsByCollection(coll, ndocs);
119121
} else {
120-
if (context.inProtectedMode()) {
121-
context.getProtectedDocs().getDocsByCollection(coll, ndocs);
122-
} else {
123-
coll.allDocs(context.getBroker(), ndocs,
124-
includeSubCollections, context.getProtectedDocs());
125-
}
122+
coll.allDocs(context.getBroker(), ndocs,
123+
includeSubCollections, context.getProtectedDocs());
126124
}
127125
}
128126
}

exist-core/src/main/java/org/exist/xquery/functions/fn/FnFormatIntegers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747
public class FnFormatIntegers extends BasicFunction {
4848

49-
private static final FunctionParameterSequenceType FS_PARAM_VALUE = optParam("value", Type.NUMBER, "The number to format");
49+
private static final FunctionParameterSequenceType FS_PARAM_VALUE = optParam("value", Type.INTEGER, "The number to format");
5050
private static final FunctionParameterSequenceType FS_PARAM_PICTURE = param("picture", Type.STRING, "The picture string to use for formatting. To understand the picture string syntax, see: https://www.w3.org/TR/xpath-functions-31/#func-format-number");
5151

5252
private static final String FS_FORMAT_INTEGER_NAME = "format-integer";

exist-core/src/main/java/org/exist/xquery/functions/fn/FunDocumentURI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.exist.xquery.*;
2828
import org.exist.xquery.value.*;
2929

30-
import static org.exist.xquery.FunctionDSL.optManyParam;
30+
import static org.exist.xquery.FunctionDSL.optParam;
3131
import static org.exist.xquery.FunctionDSL.returnsOpt;
3232
import static org.exist.xquery.functions.fn.FnModule.functionSignature;
3333

@@ -37,7 +37,7 @@
3737
*/
3838
public class FunDocumentURI extends Function {
3939

40-
private static final FunctionParameterSequenceType FS_PARAM_NODE = optManyParam("value", Type.NODE, "The document node.");
40+
private static final FunctionParameterSequenceType FS_PARAM_NODE = optParam("value", Type.NODE, "The document node.");
4141

4242
private static final String FS_DOCUMENT_URI = "document-uri";
4343
private static final String FS_DESCRIPTION = "Returns the URI of a resource where a document can be found, if available.";

exist-core/src/main/java/org/exist/xquery/functions/fn/FunXmlToJson.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class FunXmlToJson extends BasicFunction {
4848

4949
private static final String FS_XML_TO_JSON_NAME = "xml-to-json";
5050
private static final FunctionParameterSequenceType FS_XML_TO_JSON_OPT_PARAM_NODE = optParam("node", Type.NODE, "The input node");
51-
private static final FunctionParameterSequenceType FS_XML_TO_JSON_OPT_PARAM_OPTIONS = optParam("options", Type.MAP, "The options map");
51+
private static final FunctionParameterSequenceType FS_XML_TO_JSON_OPT_PARAM_OPTIONS = param("options", Type.MAP, "The options map");
5252
static final FunctionSignature[] FS_XML_TO_JSON = functionSignatures(
5353
new QName(FS_XML_TO_JSON_NAME, Function.BUILTIN_FUNCTION_NS),
5454
"Converts an XML tree (in w3c 'XML Representation of JSON' format) into a string conforming to the JSON grammar. Basic string (un)escaping.",
@@ -67,7 +67,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
6767
final Sequence result;
6868
final Sequence seq = (getArgumentCount() > 0) ? args[0] : Sequence.EMPTY_SEQUENCE;
6969
//TODO: implement handling of options
70-
final MapType options = (getArgumentCount() > 1) ? (MapType) args[1].itemAt(0) : new MapType(this, context);
70+
final MapType options = (getArgumentCount() == 2) ? (MapType) args[1].itemAt(0) : new MapType(this, context);
7171

7272
if (seq.isEmpty()) {
7373
result = Sequence.EMPTY_SEQUENCE;

exist-core/src/main/java/org/exist/xquery/functions/fn/JSON.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class JSON extends BasicFunction {
9090
static final FunctionSignature[] FS_JSON_TO_XML = functionSignatures(
9191
FS_JSON_TO_XML_NAME,
9292
"Parses a string supplied in the form of a JSON text, returning the results in the form of an XML document node.",
93-
returnsOpt(Type.ITEM, "The parsed data as XML"),
93+
returnsOpt(Type.DOCUMENT, "The parsed data as XML"),
9494
arities(
9595
arity(
9696
FS_PARAM_JSON_TEXT

0 commit comments

Comments
 (0)