Skip to content

Commit 4e4d25b

Browse files
authored
Merge pull request #58 from evolvedbinary/7.x.x/hotfix/compression-extract-compat-exist6
[7.x.x] Make compression extract filter functions compatible with eXist-db 6.3.0
2 parents 043b339 + 43e28e0 commit 4e4d25b

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/AbstractExtractFunction.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
104104
final FunctionSignature entryFilterFunctionSignature = entryFilterFunction.getSignature();
105105

106106
if (args.length < 5) {
107-
if (!validateFunctionSignature(entryFilterFunctionSignature, new SequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE))) {
107+
if (!validateFunctionSignature(entryFilterFunctionSignature, new SequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) })) {
108108
throw new XPathException(this, "entry-filter function must have a signature that matches: entry-filter($path as xs:string, $data-type as xs:string) as xs:boolean");
109109
}
110110

@@ -116,12 +116,12 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
116116
entryDataFunction = (FunctionReference) args[2].itemAt(0);
117117
final FunctionSignature entryDataFunctionSignature = entryDataFunction.getSignature();
118118
if (entryDataFunctionSignature.getArgumentCount() == 2) {
119-
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE))) {
119+
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) })) {
120120
throw new XPathException(this, "entry-path function must have a signature that matches: entry-path($path as xs:string, $data-type as xs:string) as xs:anyURI");
121121
}
122122
dataParams = new Sequence[2];
123123
} else if (entryDataFunctionSignature.getArgumentCount() == 3) {
124-
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.ITEM, Cardinality.ZERO_OR_ONE))) {
124+
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.ITEM, Cardinality.ZERO_OR_ONE) })) {
125125
throw new XPathException(this, "entry-data function must have a signature that matches: entry-data($path as xs:string, $data-type as xs:string, $data as item()?) as item()*");
126126
}
127127
dataParams = new Sequence[3];
@@ -136,7 +136,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
136136
}
137137

138138
} else {
139-
if (!validateFunctionSignature(entryFilterFunctionSignature, new SequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE))) {
139+
if (!validateFunctionSignature(entryFilterFunctionSignature, new SequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE) })) {
140140
throw new XPathException(this, "entry-filter function must have a signature that matches: entry-filter($path as xs:string, $data-type as xs:string, $param as item()*) as xs:boolean");
141141
}
142142

@@ -149,13 +149,13 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
149149
entryDataFunction = (FunctionReference) args[3].itemAt(0);
150150
final FunctionSignature entryDataFunctionSignature = entryDataFunction.getSignature();
151151
if (entryDataFunctionSignature.getArgumentCount() == 3) {
152-
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE))) {
152+
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE) })) {
153153
throw new XPathException(this, "entry-path function must have a signature that matches: entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI");
154154
}
155155
dataParams = new Sequence[3];
156156
dataParams[2] = args[4];
157157
} else if (entryDataFunctionSignature.getArgumentCount() == 4) {
158-
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE), new SequenceType(Type.ITEM, Cardinality.ZERO_OR_ONE), new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE))) {
158+
if (!validateFunctionSignature(entryDataFunctionSignature, new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE), new SequenceType[]{ new SequenceType(Type.ANY_URI, Cardinality.EXACTLY_ONE), new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.STRING, Cardinality.EXACTLY_ONE) }, new SequenceType[]{ new SequenceType(Type.ITEM, Cardinality.ZERO_OR_ONE) }, new SequenceType[]{ new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE) })) {
159159
throw new XPathException(this, "entry-data function must have a signature that matches: entry-data($path as xs:string, $data-type as xs:string, $data as item()?, $param as item()*) as item()*");
160160
}
161161
dataParams = new Sequence[4];
@@ -187,19 +187,37 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
187187
}
188188
}
189189

190-
private boolean validateFunctionSignature(final FunctionSignature functionSignature, final SequenceType expectedReturnType, final SequenceType... expectedArgumentTypes) {
190+
private boolean validateFunctionSignature(final FunctionSignature functionSignature, final SequenceType expectedReturnType, final SequenceType[]...expectedArgumentTypePossibilities) {
191191
final SequenceType actualReturnType = functionSignature.getReturnType();
192192

193193
if (!areSequenceTypesCompatible(expectedReturnType, actualReturnType)) {
194194
return false;
195195
}
196196

197197
final SequenceType[] actualArgumentTypes = functionSignature.getArgumentTypes();
198-
for (int i = 0; i < expectedArgumentTypes.length; i++) {
199-
final SequenceType expectedArgumentType = expectedArgumentTypes[i];
198+
if (actualArgumentTypes.length != expectedArgumentTypePossibilities.length) {
199+
return false;
200+
}
201+
202+
// iterate through the actual argument types
203+
for (int i = 0; i < actualArgumentTypes.length; i++) {
200204
final SequenceType actualArgumentType = actualArgumentTypes[i];
201205

202-
if (!areSequenceTypesCompatible(expectedArgumentType, actualArgumentType)) {
206+
// the actualArgumentType must match any one of the possibleExpectedArgumentTypes
207+
final SequenceType[] possibleExpectedArgumentTypes = expectedArgumentTypePossibilities[i];
208+
209+
boolean actualArgumentTypeMatchedPossibleExpectedArgumentType = false;
210+
for (int j = 0; j < possibleExpectedArgumentTypes.length; j++) {
211+
final SequenceType possibleExpectedArgumentType = possibleExpectedArgumentTypes[j];
212+
213+
if (areSequenceTypesCompatible(possibleExpectedArgumentType, actualArgumentType)) {
214+
actualArgumentTypeMatchedPossibleExpectedArgumentType = true;
215+
break;
216+
}
217+
}
218+
219+
if (!actualArgumentTypeMatchedPossibleExpectedArgumentType) {
220+
// actual argument type did NOT match any of the possibleExpectedArgumentTypes
203221
return false;
204222
}
205223
}

0 commit comments

Comments
 (0)