Debian Codegraph @

net/sf/saxon/functions/CurrentOutputUri.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.Callable;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.StaticProperty;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.om.ZeroOrOne;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.value.AnyURIValue;
18
19 /**
20 * This class implements the XSLT 3.0 function current-output-uri()
21 */
22
23
24 public class CurrentOutputUri extends SystemFunction implements Callable {
25
26 /**
27 * Determine the special properties of this function. The general rule
28 * is that a system function call is non-creative if its return type is
29 * atomic, or if all its arguments are non-creative. This is overridden
30 * for the generate-id() function, which is considered creative if
31 * its operand is creative (because the result depends on the
32 * identity of the operand)
33 * @param arguments the actual arguments to the function call
34 */
35 @Override
36 public int getSpecialProperties(Expression[] arguments) {
37 // Prevent inlining of stylesheet functions calling current-output-uri()
38 return super.getSpecialProperties(arguments) | StaticProperty.HAS_SIDE_EFFECTS;
39 }
40
41 /**
42 * Evaluate in a general context
43 */
44
45 public AnyURIValue evaluateItem(XPathContext context) throws XPathException {
46 String uri = context.getCurrentOutputUri();
47 return uri == null ? null : new AnyURIValue(uri);
48 }
49
50 /**
51 * Call the Callable.
52 *
53 * @param context the dynamic evaluation context
54 * @param arguments the values of the arguments, supplied as Sequences.
55 * <p>Generally it is advisable, if calling iterate() to process a supplied sequence, to
56 * call it only once; if the value is required more than once, it should first be converted
57 * to a {@link net.sf.saxon.om.GroundedValue} by calling the utility methd
58 * SequenceTool.toGroundedValue().</p>
59 * <p>If the expected value is a single item, the item should be obtained by calling
60 * Sequence.head(): it cannot be assumed that the item will be passed as an instance of
61 * {@link net.sf.saxon.om.Item} or {@link net.sf.saxon.value.AtomicValue}.</p>
62 * <p>It is the caller's responsibility to perform any type conversions required
63 * to convert arguments to the type expected by the callee. An exception is where
64 * this Callable is explicitly an argument-converting wrapper around the original
65 * Callable.</p>
66 * @return the result of the evaluation, in the form of a Sequence. It is the responsibility
67 * of the callee to ensure that the type of result conforms to the expected result type.
68 * @throws net.sf.saxon.trans.XPathException
69 * if a dynamic error occurs during the evaluation of the expression
70 */
71 public ZeroOrOne<AnyURIValue> call(XPathContext context, Sequence[] arguments) throws XPathException {
72 return new ZeroOrOne<>(evaluateItem(context));
73 }
74
75 }
76
77