1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 import javax.servlet.jsp.PageContext ; 20 21 import org.apache.taglibs.standard.lang.jpath.adapter.ConversionException; 22 import org.apache.taglibs.standard.lang.jpath.adapter.Convert; 23 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext; 24 25 32 public class StartsWithFunction extends SimpleNode { 33 34 41 public StartsWithFunction(int id) { 42 super(id); 43 } 44 45 53 public StartsWithFunction(Parser p, int id) { 54 super(p, id); 55 } 56 57 67 public String toNormalizedString() { 68 69 boolean first = true; 70 String normalized; 71 72 normalized = "substring("; 73 74 if (children != null) { 75 for (int i = 0; i < children.length; ++i) { 76 if (!first) { 77 normalized = normalized + ","; 78 } 79 80 first = false; 81 82 SimpleNode n = (SimpleNode) children[i]; 83 84 if (n != null) { 85 normalized = normalized + n.toNormalizedString(); 86 } 87 } 88 } 89 90 normalized = normalized + ")"; 91 92 return normalized; 93 } 94 95 112 public Object evaluate(PageContext pageContext, IterationContext icontext) 113 throws EvaluationException { 114 115 Boolean result; 116 117 try { 118 String arg1 = 119 Convert.toString(jjtGetChild(0).evaluate(pageContext, 120 icontext)); 121 String arg2 = 122 Convert.toString(jjtGetChild(1).evaluate(pageContext, 123 icontext)); 124 125 result = new Boolean (arg1.startsWith(arg2)); 126 } catch (ConversionException ce) { 127 throw new EvaluationException(this, ce.getMessage()); 128 } 129 130 return result; 131 } 132 } 133 | Popular Tags |