1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.strutsel.taglib.utils;
22
23 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
24
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.PageContext;
27 import javax.servlet.jsp.tagext.Tag;
28
29 /**
30 * This class is used in the <code>evaluateExpressions</code> method of each
31 * Tag class. It is used to process the original attribute value through the
32 * JSTL EL engine to produce an evaluated value. It provides functions to
33 * evaluate the expression assuming it is an Object, String, Integer, or
34 * Boolean result.
35 */
36 public final class EvalHelper {
37 private EvalHelper() {
38 }
39
40 /**
41 * Evaluates the attribute value in the JSTL EL engine, returning the raw
42 * Object value of the evaluated expression. If the original expression
43 * is null, or the resulting value is null, it will return null.
44 */
45 public static Object eval(String attrName, String attrValue, Tag tagObject,
46 PageContext pageContext)
47 throws JspException {
48 Object result = null;
49
50 if (attrValue != null) {
51 result =
52 ExpressionEvaluatorManager.evaluate(attrName, attrValue,
53 Object.class, tagObject, pageContext);
54 }
55
56 return (result);
57 }
58
59 /**
60 * Evaluates the attribute value in the JSTL EL engine, assuming the
61 * resulting value is a String object. If the original expression is
62 * null, or the resulting value is null, it will return null.
63 */
64 public static String evalString(String attrName, String attrValue,
65 Tag tagObject, PageContext pageContext)
66 throws JspException {
67 Object result = null;
68
69 if (attrValue != null) {
70 result =
71 ExpressionEvaluatorManager.evaluate(attrName, attrValue,
72 String.class, tagObject, pageContext);
73 }
74
75 return ((String) result);
76 }
77
78 /**
79 * Evaluates the attribute value in the JSTL EL engine, assuming the
80 * resulting value is an Integer object. If the original expression is
81 * null, or the resulting value is null, it will return null.
82 */
83 public static Integer evalInteger(String attrName, String attrValue,
84 Tag tagObject, PageContext pageContext)
85 throws JspException {
86 Object result = null;
87
88 if (attrValue != null) {
89 result =
90 ExpressionEvaluatorManager.evaluate(attrName, attrValue,
91 Integer.class, tagObject, pageContext);
92 }
93
94 return ((Integer) result);
95 }
96
97 /**
98 * Evaluates the attribute value in the JSTL EL engine, assuming the
99 * resulting value is an Boolean object. If the original expression is
100 * null, or the resulting value is null, it will return null.
101 */
102 public static Boolean evalBoolean(String attrName, String attrValue,
103 Tag tagObject, PageContext pageContext)
104 throws JspException {
105 Object result = null;
106
107 if (attrValue != null) {
108 result =
109 ExpressionEvaluatorManager.evaluate(attrName, attrValue,
110 Boolean.class, tagObject, pageContext);
111 }
112
113 return ((Boolean) result);
114 }
115 }