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.trans.XPathException;
08: import net.sf.saxon.value.StringValue;
09:
10: /**
11: * Implement XPath function string()
12: */
13:
14: public class StringFn 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
28: */
29:
30: public Item evaluateItem(XPathContext c) throws XPathException {
31: Item arg = argument[0].evaluateItem(c);
32: if (arg == null) {
33: return StringValue.EMPTY_STRING;
34: } else {
35: return StringValue.makeStringValue(arg.getStringValueCS());
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: //
|