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