1 18 package net.sf.uitags.tagutil; 19 20 import java.util.Collection ; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.Tag ; 25 26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 27 28 35 public final class ElEvaluator { 36 39 private Tag tag; 40 43 private PageContext pageContext; 44 45 52 public ElEvaluator(Tag tag, PageContext pageContext) { 53 this.tag = tag; 54 this.pageContext = pageContext; 55 } 56 57 68 public Object toObject(String attrName, String expr, Class expected) { 69 try { 70 return (expr == null) ? null : 71 ExpressionEvaluatorManager.evaluate( 72 attrName, expr, expected, this.tag, this.pageContext); 73 } 74 catch (JspException e) { 75 throw new RuntimeException (e); 76 } 77 } 78 79 89 public String toString(String attrName, String expr) { 90 try { 91 return (expr == null) ? null : 92 (String ) ExpressionEvaluatorManager.evaluate( 93 attrName, expr, String .class, this.tag, this.pageContext); 94 } 95 catch (JspException e) { 96 throw new RuntimeException (e); 97 } 98 } 99 100 110 public Integer toIntegerObject(String attrName, String expr) { 111 try { 112 return (expr == null) ? null : 113 (Integer ) ExpressionEvaluatorManager.evaluate( 114 attrName, expr, Integer .class, this.tag, this.pageContext); 115 } 116 catch (JspException e) { 117 throw new RuntimeException (e); 118 } 119 } 120 121 129 public int toIntegerValue(String attrName, String expr) { 130 return toIntegerObject(attrName, expr).intValue(); 131 } 132 133 143 public Boolean toBooleanObject(String attrName, String expr) { 144 try { 145 return (expr == null) ? null : 146 (Boolean ) ExpressionEvaluatorManager.evaluate( 147 attrName, expr, Boolean .class, this.tag, this.pageContext); 148 } 149 catch (JspException e) { 150 throw new RuntimeException (e); 151 } 152 } 153 154 162 public boolean toBooleanValue(String attrName, String expr) { 163 return toBooleanObject(attrName, expr).booleanValue(); 164 } 165 166 176 public Collection toCollection(String attrName, String expr) { 177 try { 178 return (expr == null) ? null : 179 (Collection ) ExpressionEvaluatorManager.evaluate( 180 attrName, expr, Collection .class, this.tag, this.pageContext); 181 } 182 catch (JspException e) { 183 throw new RuntimeException (e); 184 } 185 } 186 } | Popular Tags |