1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.strutsel.taglib.logic;
19
20 import org.apache.struts.taglib.TagUtils;
21 import org.apache.struts.util.MessageResources;
22
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.PageContext;
25
26 /***
27 * This class is used as a helper class for both the <code>org.apache.strutsel.taglib.logic.ELMatchTag</code>
28 * and <code>org.apache.strutsel.taglib.logic.ELNotMatchTag</code> classes.
29 * It's <code>condition</code> method encapsulates the common logic needed to
30 * examine the <code>location</code> attribute to determine how to do the
31 * comparison.
32 */
33 class ELMatchSupport {
34 /***
35 * Performs a comparison of an expression and a value, with an optional
36 * location specifier in the expression (start or end).
37 *
38 * @param desired Indication of whether the "truth" value of the
39 * comparison is whether the expression and value are
40 * equal, or not equal.
41 * @param expr Expression to test against a value.
42 * @param value Value to test against an expression.
43 * @param location if set, is "start" or "end" to indicate to look at
44 * the start or end of the expression for the value.
45 * If null, look anywhere in the expression.
46 * @param messages <code>MessageResources</code> object to reference
47 * for error message text.
48 * @param pageContext used to save exception information, if needed.
49 * @return true if comparison result equals desired value, false
50 * otherwise.
51 */
52 public static boolean condition(boolean desired, String expr, String value,
53 String location, MessageResources messages, PageContext pageContext)
54 throws JspException {
55 boolean result = false;
56
57 if (expr != null) {
58
59 boolean matched = false;
60
61 if (location == null) {
62 matched = (expr.indexOf(value) >= 0);
63 } else if (location.equals("start")) {
64 matched = expr.startsWith(value);
65 } else if (location.equals("end")) {
66 matched = expr.endsWith(value);
67 } else {
68 JspException e =
69 new JspException(messages.getMessage("logic.location",
70 location));
71
72 TagUtils.getInstance().saveException(pageContext, e);
73 throw e;
74 }
75
76 result = (matched == desired);
77 }
78
79 return (result);
80 }
81 }