Debian Codegraph @

net/sf/saxon/functions/Put.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.Expression;
11 import net.sf.saxon.expr.PendingUpdateList;
12 import net.sf.saxon.expr.SystemFunctionCall;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.om.NodeInfo;
15 import net.sf.saxon.om.Sequence;
16 import net.sf.saxon.trans.Err;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.type.Type;
19
20 import java.net.URI;
21 import java.net.URISyntaxException;
22
23 /**
24 * Implements the fn:put() function in XQuery Update 1.0.
25 */
26 public class Put extends SystemFunction {
27
28 @Override
29 public Expression makeFunctionCall(Expression[] arguments) {
30 return new SystemFunctionCall(this, arguments) {
31
32 @Override
33 public boolean isUpdatingExpression() {
34 return true;
35 }
36
37 /**
38 * Evaluate an updating expression, adding the results to a Pending Update List.
39 * The default implementation of this method, which is used for non-updating expressions,
40 * throws an UnsupportedOperationException
41 *
42 * @param context the XPath dynamic evaluation context
43 * @param pul the pending update list to which the results should be written
44 */
45
46 public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException {
47 NodeInfo node = (NodeInfo) getArg(0).evaluateItem(context);
48 int kind = node.getNodeKind();
49 if (kind != Type.ELEMENT && kind != Type.DOCUMENT) {
50 throw new XPathException("Node in put() must be a document or element node",
51 "FOUP0001", context);
52 }
53 String relative = getArg(1).evaluateItem(context).getStringValue();
54 String abs;
55 try {
56 URI resolved = ResolveURI.makeAbsolute(relative, getStaticBaseUriString());
57 abs = resolved.toString();
58 } catch (URISyntaxException err) {
59 throw new XPathException("Base URI " + Err.wrap(getStaticBaseUriString()) + " is invalid: " + err.getMessage(),
60 "FOUP0002", context);
61 }
62 pul.addPutAction(node, abs, this);
63 }
64
65 };
66 }
67
68 /**
69 * Evaluate the expression
70 *
71 * @param context the dynamic evaluation context
72 * @param arguments the values of the arguments, supplied as Sequences
73 * @return the result of the evaluation, in the form of a Sequence
74 * @throws net.sf.saxon.trans.XPathException
75 * if a dynamic error occurs during the evaluation of the expression
76 */
77
78 public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException {
79 throw new XPathException("Dynamic evaluation of fn:put() is not supported");
80 }
81
82 }
83