Skip to content

Commit 55308a3

Browse files
authored
Merge branch 'eXist-db:develop' into rest-client-encoding
2 parents b4cbad3 + 5086400 commit 55308a3

File tree

22 files changed

+316
-36
lines changed

22 files changed

+316
-36
lines changed

exist-core/src/main/java/org/exist/dom/memtree/NodeImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.xml.sax.SAXException;
4343
import org.xml.sax.ext.LexicalHandler;
4444

45+
import javax.annotation.Nullable;
4546
import javax.xml.XMLConstants;
4647
import java.util.Iterator;
4748
import java.util.Properties;
@@ -762,7 +763,7 @@ public boolean contains(final Item item) {
762763
}
763764

764765
@Override
765-
public void destroy(final XQueryContext context, final Sequence contextSequence) {
766+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
766767
}
767768

768769

exist-core/src/main/java/org/exist/dom/persistent/NodeProxy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.xml.sax.SAXException;
4646
import org.xml.sax.ext.LexicalHandler;
4747

48+
import javax.annotation.Nullable;
4849
import javax.xml.stream.XMLStreamException;
4950
import javax.xml.stream.XMLStreamReader;
5051
import java.io.IOException;
@@ -987,7 +988,7 @@ public boolean contains(final Item item) {
987988
}
988989

989990
@Override
990-
public void destroy(final XQueryContext context, final Sequence contextSequence) {
991+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
991992
// Nothing to do
992993
}
993994

exist-core/src/main/java/org/exist/xquery/DeferredFunctionCall.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.exist.xquery.value.SequenceIterator;
3636
import org.exist.xquery.value.Type;
3737

38+
import javax.annotation.Nullable;
3839
import java.util.Iterator;
3940

4041
public abstract class DeferredFunctionCall implements Sequence {
@@ -309,7 +310,7 @@ public boolean isCacheable() {
309310
}
310311

311312
@Override
312-
public void destroy(XQueryContext context, Sequence contextSequence) {
313+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
313314
// nothing to do
314315
}
315316
}

exist-core/src/main/java/org/exist/xquery/ModuleContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public void popLocalVariables(final LocalVariable var) {
311311
}
312312

313313
@Override
314-
public void popLocalVariables(final LocalVariable var, final Sequence resultSequence) {
314+
public void popLocalVariables(final LocalVariable var, @Nullable final Sequence resultSequence) {
315315
parentContext.popLocalVariables(var, resultSequence);
316316
}
317317

exist-core/src/main/java/org/exist/xquery/VariableImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.w3c.dom.Document;
3131
import org.w3c.dom.Element;
3232

33+
import javax.annotation.Nullable;
34+
3335
/**
3436
* An XQuery/XPath variable, consisting of a QName and a value.
3537
*
@@ -164,9 +166,10 @@ public void setIsInitialized(boolean initialized) {
164166
this.initialized = initialized;
165167
}
166168

167-
public void destroy(XQueryContext context, Sequence contextSequence) {
168-
if (value != null)
169-
{value.destroy(context, contextSequence);}
169+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
170+
if (value != null) {
171+
value.destroy(context, contextSequence);
172+
}
170173
}
171174

172175
@Override

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ public void popLocalVariables(@Nullable final LocalVariable var) {
23542354
* @param var only clear variables after this variable, or null
23552355
* @param resultSeq the result sequence
23562356
*/
2357-
public void popLocalVariables(@Nullable final LocalVariable var, final Sequence resultSeq) {
2357+
public void popLocalVariables(@Nullable final LocalVariable var, @Nullable final Sequence resultSeq) {
23582358
if (var != null) {
23592359
// clear all variables registered after var. they should be out of scope.
23602360
LocalVariable outOfScope = var.after;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class FnModule extends AbstractInternalModule {
5252
new FunctionDef(FunCeiling.signature, FunCeiling.class),
5353
new FunctionDef(FunCodepointEqual.signature, FunCodepointEqual.class),
5454
new FunctionDef(FunCodepointsToString.signature, FunCodepointsToString.class),
55+
new FunctionDef(FunCollationKey.FS_COLLATION_KEY_SIGNATURES[0], FunCollationKey.class),
56+
new FunctionDef(FunCollationKey.FS_COLLATION_KEY_SIGNATURES[1], FunCollationKey.class),
5557
new FunctionDef(FunCompare.signatures[0], FunCompare.class),
5658
new FunctionDef(FunCompare.signatures[1], FunCompare.class),
5759
new FunctionDef(FunConcat.signature, FunConcat.class),
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
23+
package org.exist.xquery.functions.fn;
24+
25+
import org.apache.commons.codec.binary.Base64;
26+
import org.exist.util.Collations;
27+
import org.exist.xquery.*;
28+
import org.exist.xquery.value.*;
29+
30+
import com.ibm.icu.text.Collator;
31+
32+
import java.io.IOException;
33+
import java.nio.charset.StandardCharsets;
34+
35+
import static org.exist.xquery.FunctionDSL.*;
36+
import static org.exist.xquery.functions.fn.FnModule.functionSignatures;
37+
38+
public class FunCollationKey extends BasicFunction {
39+
40+
private static final String FN_NAME = "collation-key";
41+
private static final String FN_DESCRIPTION =
42+
"Given a $value-string value and a $collation-string " +
43+
"collation, generates an internal value called a collation key, with the " +
44+
"property that the matching and ordering of collation " +
45+
"keys reflects the matching and ordering of strings " +
46+
"under the specified collation.";
47+
private static final FunctionReturnSequenceType FN_RETURN = returnsOpt(Type.BASE64_BINARY, "the collation key");
48+
private static final FunctionParameterSequenceType PARAM_VALUE_STRING = param("value-string", Type.STRING, "The value string");
49+
private static final FunctionParameterSequenceType PARAM_COLLATION_STRING = param("collation-string", Type.STRING, "The collation string");
50+
public static final FunctionSignature[] FS_COLLATION_KEY_SIGNATURES = functionSignatures(
51+
FN_NAME,
52+
FN_DESCRIPTION,
53+
FN_RETURN,
54+
arities(
55+
arity(PARAM_VALUE_STRING),
56+
arity(PARAM_VALUE_STRING, PARAM_COLLATION_STRING)
57+
)
58+
);
59+
60+
public FunCollationKey(final XQueryContext context, final FunctionSignature signature) {
61+
super(context, signature);
62+
}
63+
64+
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
65+
final String source = (args.length >= 1) ? args[0].itemAt(0).toString() : "";
66+
final Collator collator = (args.length >= 2) ? Collations.getCollationFromURI(args[1].itemAt(0).toString()) : null;
67+
final Sequence sequence;
68+
try (BinaryValueFromBinaryString binaryValue = new BinaryValueFromBinaryString(
69+
new Base64BinaryValueType(),
70+
Base64.encodeBase64String(
71+
(collator == null) ?
72+
source.getBytes(StandardCharsets.UTF_8) :
73+
new String(collator.getCollationKey(source).toByteArray()).getBytes(StandardCharsets.UTF_8)))) {
74+
sequence = binaryValue.convertTo(new Base64BinaryValueType());
75+
} catch (IOException e) {
76+
return null;
77+
}
78+
return sequence;
79+
}
80+
}

exist-core/src/main/java/org/exist/xquery/value/AbstractSequence.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.exist.xquery.XPathException;
3333
import org.exist.xquery.XQueryContext;
3434

35+
import javax.annotation.Nullable;
3536
import java.lang.reflect.Array;
3637
import java.util.ArrayList;
3738
import java.util.Iterator;
@@ -287,7 +288,7 @@ public boolean hasChanged(final int previousState) {
287288
}
288289

289290
@Override
290-
public void destroy(final XQueryContext context, final Sequence contextSequence) {
291+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
291292
// do nothing by default
292293
}
293294
}

exist-core/src/main/java/org/exist/xquery/value/ArrayListValueSequence.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public boolean contains(final Item item) {
255255
}
256256

257257
@Override
258-
public void destroy(final XQueryContext context, final Sequence contextSequence) {
258+
public void destroy(final XQueryContext context, @Nullable final Sequence contextSequence) {
259259
for (final Item value : values) {
260260
value.destroy(context, contextSequence);
261261
}

0 commit comments

Comments
 (0)