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 import org.apache.taglibs.standard.lang.jpath.adapter.JSPList; 25 26 33 public class FilterOperator extends SimpleNode implements Introspectable { 34 35 42 public FilterOperator(int id) { 43 super(id); 44 } 45 46 54 public FilterOperator(Parser p, int id) { 55 super(p, id); 56 } 57 58 68 public String toNormalizedString() { 69 70 String normalized = ""; 71 72 normalized = jjtGetChild(0).toNormalizedString() 73 + jjtGetChild(1).toNormalizedString(); 74 75 return normalized; 76 } 77 78 95 public Object evaluate(PageContext pageContext, IterationContext icontext) 96 throws EvaluationException { 97 98 Object result; 99 100 try { 101 JSPList leftSide = 102 Convert.toJSPList(jjtGetChild(0).evaluate(pageContext, 103 icontext)); 104 Predicate predicate = (Predicate) jjtGetChild(1); 105 boolean oneItem = leftSide.applyPredicate(pageContext, predicate); 106 107 if (oneItem) { 108 if (leftSide.getLast() == 1) { 109 result = leftSide.next(); 110 } else { 111 result = null; 112 } 113 } else { 114 result = leftSide; 115 } 116 } catch (ConversionException ce) { 117 throw new EvaluationException(this, ce.getMessage()); 118 } 119 120 return result; 121 } 122 123 136 public Object evaluate( 137 PageContext pageContext, IterationContext icontext, int scope) 138 throws EvaluationException { 139 140 Object result; 141 142 try { 143 JSPList leftSide = 144 Convert.toJSPList(((Introspectable) jjtGetChild(0)) 145 .evaluate(pageContext, icontext, scope)); 146 Predicate predicate = (Predicate) jjtGetChild(1); 147 boolean oneItem = leftSide.applyPredicate(pageContext, predicate); 148 149 if (oneItem) { 150 if (leftSide.getLast() == 1) { 151 result = leftSide.next(); 152 } else { 153 result = null; 154 } 155 } else { 156 result = leftSide; 157 } 158 } catch (ConversionException ce) { 159 throw new EvaluationException(this, ce.getMessage()); 160 } 161 162 return result; 163 } 164 165 178 public Object evaluate( 179 PageContext pageContext, IterationContext icontext, Object parent) 180 throws EvaluationException { 181 182 Object result; 183 184 try { 185 JSPList leftSide = 186 Convert.toJSPList(((Introspectable) jjtGetChild(0)) 187 .evaluate(pageContext, icontext, parent)); 188 Predicate predicate = (Predicate) jjtGetChild(1); 189 boolean oneItem = leftSide.applyPredicate(pageContext, predicate); 190 191 if (oneItem) { 192 if (leftSide.getLast() == 1) { 193 result = leftSide.next(); 194 } else { 195 result = null; 196 } 197 } else { 198 result = leftSide; 199 } 200 } catch (ConversionException ce) { 201 throw new EvaluationException(this, ce.getMessage()); 202 } 203 204 return result; 205 } 206 } 207 | Popular Tags |