1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 import java.util.ArrayList ; 20 import java.util.StringTokenizer ; 21 22 import javax.servlet.jsp.PageContext ; 23 24 import org.apache.taglibs.standard.lang.jpath.adapter.CollectionAdapter; 25 import org.apache.taglibs.standard.lang.jpath.adapter.ConversionException; 26 import org.apache.taglibs.standard.lang.jpath.adapter.Convert; 27 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext; 28 29 36 public class TokenizeFunction extends SimpleNode { 37 38 45 public TokenizeFunction(int id) { 46 super(id); 47 } 48 49 57 public TokenizeFunction(Parser p, int id) { 58 super(p, id); 59 } 60 61 71 public String toNormalizedString() { 72 73 boolean first = true; 74 String normalized; 75 76 normalized = "tokenize("; 77 78 if (children != null) { 79 for (int i = 0; i < children.length; ++i) { 80 if (!first) { 81 normalized = normalized + ","; 82 } 83 84 first = false; 85 86 SimpleNode n = (SimpleNode) children[i]; 87 88 if (n != null) { 89 normalized = normalized + n.toNormalizedString(); 90 } 91 } 92 } 93 94 normalized = normalized + ")"; 95 96 return normalized; 97 } 98 99 116 public Object evaluate(PageContext pageContext, IterationContext icontext) 117 throws EvaluationException { 118 119 Object result; 120 121 try { 122 String arg1 = 123 Convert.toString(jjtGetChild(0).evaluate(pageContext, 124 icontext)); 125 String arg2 = 126 Convert.toString(jjtGetChild(1).evaluate(pageContext, 127 icontext)); 128 StringTokenizer st = new StringTokenizer (arg1, arg2); 129 ArrayList a = new ArrayList (); 130 131 while (st.hasMoreTokens()) { 132 a.add(st.nextToken()); 133 } 134 135 result = CollectionAdapter.adapt(a); 136 } catch (ConversionException ce) { 137 throw new EvaluationException(this, ce.getMessage()); 138 } 139 140 return result; 141 } 142 } 143 | Popular Tags |