| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 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 |
|