KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > utils > EvalHelper


1 /*
2  * $Id: EvalHelper.java 54933 2004-10-16 17:04:52Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.strutsel.taglib.utils;
20
21 import javax.servlet.jsp.PageContext JavaDoc;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.Tag JavaDoc;
24 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
25
26 /**
27  * This class is used in the <code>evaluateExpressions</code> method of each
28  * Tag class. It is used to process the original attribute value through the
29  * JSTL EL engine to produce an evaluated value. It provides functions to
30  * evaluate the expression assuming it is an Object, String, Integer, or
31  * Boolean result.
32  */

33 public final class EvalHelper
34 {
35     private EvalHelper() {}
36
37     /**
38      * Evaluates the attribute value in the JSTL EL engine, returning the raw
39      * Object value of the evaluated expression. If the original expression is
40      * null, or the resulting value is null, it will return null.
41      */

42     public static Object JavaDoc eval(String JavaDoc attrName,
43                               String JavaDoc attrValue,
44                               Tag JavaDoc tagObject,
45                               PageContext JavaDoc pageContext)
46         throws JspException JavaDoc
47     {
48         Object JavaDoc result = null;
49         if (attrValue != null) {
50             result =
51                 ExpressionEvaluatorManager.
52                 evaluate(attrName, attrValue, Object JavaDoc.class, tagObject,
53                          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 null,
62      * or the resulting value is null, it will return null.
63      */

64     public static String JavaDoc evalString(String JavaDoc attrName,
65                                     String JavaDoc attrValue,
66                                     Tag JavaDoc tagObject,
67                                     PageContext JavaDoc pageContext)
68         throws JspException JavaDoc
69     {
70         Object JavaDoc result = null;
71         if (attrValue != null) {
72             result =
73                 ExpressionEvaluatorManager.
74                 evaluate(attrName, attrValue, String JavaDoc.class, tagObject,
75                          pageContext);
76         }
77
78         return ((String JavaDoc) result);
79     }
80
81     /**
82      * Evaluates the attribute value in the JSTL EL engine, assuming the
83      * resulting value is an Integer object. If the original expression is
84      * null, or the resulting value is null, it will return null.
85      */

86     public static Integer JavaDoc evalInteger(String JavaDoc attrName,
87                                       String JavaDoc attrValue,
88                                       Tag JavaDoc tagObject,
89                                       PageContext JavaDoc pageContext)
90         throws JspException JavaDoc
91     {
92         Object JavaDoc result = null;
93         if (attrValue != null) {
94             result = ExpressionEvaluatorManager.
95                 evaluate(attrName, attrValue, Integer JavaDoc.class, tagObject,
96                          pageContext);
97         }
98
99         return ((Integer JavaDoc) result);
100     }
101
102     /**
103      * Evaluates the attribute value in the JSTL EL engine, assuming the
104      * resulting value is an Boolean object. If the original expression is
105      * null, or the resulting value is null, it will return null.
106      */

107     public static Boolean JavaDoc evalBoolean(String JavaDoc attrName,
108                                       String JavaDoc attrValue,
109                                       Tag JavaDoc tagObject,
110                                       PageContext JavaDoc pageContext)
111         throws JspException JavaDoc
112     {
113         Object JavaDoc result = null;
114         if (attrValue != null) {
115             result = ExpressionEvaluatorManager.
116                 evaluate(attrName, attrValue, Boolean JavaDoc.class, tagObject,
117                          pageContext);
118         }
119
120         return ((Boolean JavaDoc) result);
121     }
122 }
123
Popular Tags