1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
package net.sf.infrared.web.customtags; |
24 |
|
|
25 |
|
import java.lang.reflect.InvocationTargetException; |
26 |
|
|
27 |
|
import javax.servlet.jsp.JspException; |
28 |
|
import javax.servlet.jsp.tagext.TagSupport; |
29 |
|
|
30 |
|
import net.sf.infrared.web.util.WebConfig; |
31 |
|
|
32 |
|
import org.apache.commons.beanutils.PropertyUtils; |
33 |
|
import org.apache.struts.util.RequestUtils; |
34 |
|
|
35 |
0 |
public class ColorThresholdTag extends TagSupport { |
36 |
0 |
private static final int COLOR_THRESHOLD = WebConfig.getColorThreshold(); |
37 |
|
protected String name; |
38 |
|
|
39 |
|
protected String property; |
40 |
|
|
41 |
|
protected String scope; |
42 |
|
|
43 |
|
public String getScope() { |
44 |
0 |
return scope; |
45 |
|
} |
46 |
|
|
47 |
|
public void setScope(String scope) { |
48 |
0 |
this.scope = scope; |
49 |
0 |
} |
50 |
|
|
51 |
|
public String getName() { |
52 |
0 |
return name; |
53 |
|
} |
54 |
|
|
55 |
|
public void setName(String name) { |
56 |
0 |
this.name = name; |
57 |
0 |
} |
58 |
|
|
59 |
|
public String getProperty() { |
60 |
0 |
return property; |
61 |
|
} |
62 |
|
|
63 |
|
public void setProperty(String property) { |
64 |
0 |
this.property = property; |
65 |
0 |
} |
66 |
|
|
67 |
|
public int doStartTag() throws JspException { |
68 |
0 |
Object formBean = RequestUtils.lookup(pageContext, name, scope); |
69 |
|
|
70 |
0 |
String beanProperty = null; |
71 |
|
try { |
72 |
0 |
beanProperty = (String) PropertyUtils.getProperty(formBean, property); |
73 |
|
} |
74 |
0 |
catch (IllegalAccessException e) { |
75 |
0 |
throw new JspException("Unable to find the property " + property + " in the bean", e); |
76 |
|
} |
77 |
0 |
catch (InvocationTargetException e) { |
78 |
0 |
throw new JspException("Unable to find the property " + property + " in the bean", e); |
79 |
|
} |
80 |
0 |
catch (NoSuchMethodException e) { |
81 |
0 |
throw new JspException("Unable to find the property " + property + " in the bean", e); |
82 |
0 |
} |
83 |
0 |
double value = Double.parseDouble(beanProperty); |
84 |
|
|
85 |
0 |
if (value > COLOR_THRESHOLD) |
86 |
0 |
return (EVAL_BODY_INCLUDE); |
87 |
|
else |
88 |
0 |
return (SKIP_BODY); |
89 |
|
} |
90 |
|
|
91 |
|
public int doEndTag() throws JspException { |
92 |
0 |
release(); |
93 |
0 |
return super.doEndTag(); |
94 |
|
} |
95 |
|
|
96 |
|
public void release() { |
97 |
0 |
super.release(); |
98 |
0 |
name = null; |
99 |
0 |
property = null; |
100 |
0 |
scope = null; |
101 |
0 |
} |
102 |
|
|
103 |
|
} |