01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.StaticContext;
05: import net.sf.saxon.expr.XPathContext;
06: import net.sf.saxon.om.Item;
07: import net.sf.saxon.om.NodeInfo;
08: import net.sf.saxon.trans.XPathException;
09: import net.sf.saxon.value.AnyURIValue;
10:
11: /**
12: * This class supports the base-uri() functions in XPath 2.0
13: */
14:
15: public class BaseURI extends SystemFunction {
16:
17: /**
18: * Simplify and validate.
19: * This is a pure function so it can be simplified in advance if the arguments are known
20: */
21:
22: public Expression simplify(StaticContext env) throws XPathException {
23: useContextItemAsDefault();
24: return simplifyArguments(env);
25: }
26:
27: /**
28: * Evaluate the function at run-time
29: */
30:
31: public Item evaluateItem(XPathContext c) throws XPathException {
32: NodeInfo node = (NodeInfo) argument[0].evaluateItem(c);
33: if (node == null) {
34: return null;
35: }
36: String s = node.getBaseURI();
37: if (s == null) {
38: return null;
39: }
40: return new AnyURIValue(s);
41: }
42:
43: }
44:
45: //
46: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
47: // you may not use this file except in compliance with the License. You may obtain a copy of the
48: // License at http://www.mozilla.org/MPL/
49: //
50: // Software distributed under the License is distributed on an "AS IS" basis,
51: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
52: // See the License for the specific language governing rights and limitations under the License.
53: //
54: // The Original Code is: all this file.
55: //
56: // The Initial Developer of the Original Code is Michael H. Kay.
57: //
58: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
59: //
60: // Contributor(s): none.
61: //
|