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.util.Set; |
26 |
|
|
27 |
|
import javax.servlet.jsp.JspException; |
28 |
|
import javax.servlet.jsp.tagext.TagSupport; |
29 |
|
|
30 |
|
import org.apache.commons.beanutils.PropertyUtils; |
31 |
|
import org.apache.log4j.Logger; |
32 |
|
import org.apache.struts.util.RequestUtils; |
33 |
|
|
34 |
|
import net.sf.infrared.base.util.LoggingFactory; |
35 |
|
|
36 |
0 |
public class ContainsTag extends TagSupport { |
37 |
|
protected String name; |
38 |
|
|
39 |
|
protected String property; |
40 |
|
|
41 |
|
protected String scope; |
42 |
|
|
43 |
|
protected String selectedName; |
44 |
|
|
45 |
|
protected String notContains; |
46 |
|
|
47 |
0 |
protected boolean flag = false; |
48 |
|
|
49 |
0 |
private static final Logger logger = LoggingFactory.getLogger(ContainsTag.class); |
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 String getScope() { |
68 |
0 |
return scope; |
69 |
|
} |
70 |
|
|
71 |
|
public void setScope(String scope) { |
72 |
0 |
this.scope = scope; |
73 |
0 |
} |
74 |
|
|
75 |
|
public String getSelectedName() { |
76 |
0 |
return selectedName; |
77 |
|
} |
78 |
|
|
79 |
|
public void setSelectedName(String instanceName) { |
80 |
0 |
this.selectedName = instanceName; |
81 |
0 |
} |
82 |
|
|
83 |
|
public String isNotContains() { |
84 |
0 |
return notContains; |
85 |
|
} |
86 |
|
|
87 |
|
public void setNotContains(String notContains) { |
88 |
0 |
this.notContains = notContains; |
89 |
0 |
} |
90 |
|
|
91 |
|
public int doStartTag() throws JspException { |
92 |
0 |
Object formBean = RequestUtils.lookup(pageContext, name, scope); |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0 |
String instance = (String) RequestUtils.lookup(pageContext, selectedName, scope); |
99 |
0 |
flag = Boolean.valueOf(notContains).booleanValue(); |
100 |
|
|
101 |
0 |
Set currentInstance = null; |
102 |
|
try { |
103 |
0 |
currentInstance = (Set) PropertyUtils.getProperty(formBean, property); |
104 |
|
} |
105 |
0 |
catch (Exception e) { |
106 |
0 |
logger.error("Unable to find the property " + property + " in the bean", e); |
107 |
0 |
} |
108 |
|
|
109 |
0 |
if ((currentInstance.contains(instance) && !flag) |
110 |
|
|| (!currentInstance.contains(instance) && flag)) |
111 |
0 |
return (EVAL_BODY_INCLUDE); |
112 |
|
else |
113 |
0 |
return (SKIP_BODY); |
114 |
|
} |
115 |
|
|
116 |
|
public int doEndTag() throws JspException { |
117 |
0 |
release(); |
118 |
0 |
return super.doEndTag(); |
119 |
|
} |
120 |
|
|
121 |
|
public void release() { |
122 |
0 |
super.release(); |
123 |
0 |
name = null; |
124 |
0 |
property = null; |
125 |
0 |
scope = null; |
126 |
0 |
selectedName = null; |
127 |
0 |
notContains = null; |
128 |
0 |
} |
129 |
|
|
130 |
|
} |