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