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