Debian Codegraph @

net/sf/saxon/functions/Sort_2.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.functions;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.lib.StringCollator;
12 import net.sf.saxon.om.Sequence;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.value.StringValue;
15
16 import java.util.List;
17
18 /**
19 * This class implements the function fn:sort#2, according to the new XPath 3.1 spec in bug 29792
20 */
21
22 public class Sort_2 extends Sort_1 {
23
24 /**
25 * Evaluate the expression
26 *
27 * @param context the dynamic evaluation context
28 * @param arguments the values of the arguments, supplied as SequenceIterators
29 * @return the result of the evaluation, in the form of a SequenceIterator
30 * @throws net.sf.saxon.trans.XPathException if a dynamic error occurs during the evaluation of the expression
31 */
32 public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {
33 final List<ItemToBeSorted> inputList = getItemsToBeSorted(arguments[0]);
34 return doSort(inputList, getCollation(context, arguments[1]), context);
35 }
36
37 protected StringCollator getCollation(XPathContext context, Sequence<?> collationArg) throws XPathException {
38 StringValue secondArg = (StringValue)collationArg.head();
39 if (secondArg == null) {
40 return context.getConfiguration().getCollation(getRetainedStaticContext().getDefaultCollationName());
41 } else {
42 return context.getConfiguration().getCollation(secondArg.getStringValue(), getStaticBaseUriString());
43 }
44 }
45
46
47 }