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