1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.expr.*; 4 5 import java.util.*; 6 import java.text.*; 7 8 9 10 public class StartsWith extends Function { 11 12 15 16 public String getName() { 17 return "starts-with"; 18 }; 19 20 24 25 public int getDataType() { 26 return Value.BOOLEAN; 27 } 28 29 33 34 public Expression simplify() throws XPathException { 35 checkArgumentCount(2, 2); 36 argument[0] = argument[0].simplify(); 37 argument[1] = argument[1].simplify(); 38 39 if (argument[0] instanceof Value && argument[1] instanceof Value) { 40 return evaluate(null); 41 } 42 43 if (argument[1] instanceof Value && 44 ((Value)argument[1]).asString().equals("")) { 45 return new BooleanValue(true); 46 } 47 48 return this; 49 } 50 51 54 55 public boolean evaluateAsBoolean(Context c) throws XPathException { 56 String arg0 = argument[0].evaluateAsString(c); 57 String arg1 = argument[1].evaluateAsString(c); 58 return arg0.startsWith(arg1); 59 } 60 61 64 65 public Value evaluate(Context c) throws XPathException { 66 return new BooleanValue(evaluateAsBoolean(c)); 67 } 68 69 72 73 public int getDependencies() { 74 return argument[0].getDependencies() | argument[1].getDependencies(); 75 } 76 77 80 81 public Expression reduce(int dep, Context c) throws XPathException { 82 StartsWith f = new StartsWith(); 83 f.addArgument(argument[0].reduce(dep, c)); 84 f.addArgument(argument[1].reduce(dep, c)); 85 f.setStaticContext(getStaticContext()); 86 return f.simplify(); 87 } 88 89 } 90 91 92 93 | Popular Tags |