Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1374 | jmachado | 1 | package pt.estgp.estgweb.web.tags; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import org.apache.struts.util.RequestUtils; |
||
5 | |||
6 | import javax.servlet.jsp.JspException; |
||
7 | import javax.servlet.jsp.JspWriter; |
||
8 | import javax.servlet.jsp.tagext.BodyTagSupport; |
||
9 | |||
10 | public class InstanceOfTag extends BodyTagSupport |
||
11 | { |
||
12 | |||
13 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(InstanceOfTag.class); |
||
14 | |||
15 | private 1.5.0/docs/api/java/lang/String.html">String name; |
||
16 | |||
17 | private 1.5.0/docs/api/java/lang/String.html">String property; |
||
18 | |||
19 | private 1.5.0/docs/api/java/lang/String.html">String value; |
||
20 | |||
21 | public 1.5.0/docs/api/java/lang/String.html">String getName() |
||
22 | { |
||
23 | return name; |
||
24 | } |
||
25 | |||
26 | public void setName(1.5.0/docs/api/java/lang/String.html">String name) |
||
27 | { |
||
28 | this.name = name; |
||
29 | } |
||
30 | |||
31 | public 1.5.0/docs/api/java/lang/String.html">String getProperty() |
||
32 | { |
||
33 | return property; |
||
34 | } |
||
35 | |||
36 | public void setProperty(1.5.0/docs/api/java/lang/String.html">String property) |
||
37 | { |
||
38 | this.property = property; |
||
39 | } |
||
40 | |||
41 | public 1.5.0/docs/api/java/lang/String.html">String getValue() { |
||
42 | return value; |
||
43 | } |
||
44 | |||
45 | public void setValue(1.5.0/docs/api/java/lang/String.html">String value) { |
||
46 | this.value = value; |
||
47 | } |
||
48 | |||
49 | public int doStartTag() throws JspException |
||
50 | { |
||
51 | if (go()) |
||
52 | { |
||
53 | return EVAL_BODY_TAG; |
||
54 | } |
||
55 | else |
||
56 | return SKIP_BODY; |
||
57 | } |
||
58 | |||
59 | public boolean go() throws JspException |
||
60 | { |
||
61 | |||
62 | 5+0%2Fdocs%2Fapi+Object">Object obj = RequestUtils.lookup(pageContext, name, property, null); |
||
63 | try |
||
64 | { |
||
65 | return 1.5.0/docs/api/java/lang/Class.html">Class.forName(value).isInstance(obj); |
||
66 | } |
||
67 | catch (1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException e) |
||
68 | { |
||
69 | return false; |
||
70 | } |
||
71 | |||
72 | } |
||
73 | |||
74 | public int doEndTag() throws JspException |
||
75 | { |
||
76 | if (go()) |
||
77 | { |
||
78 | 1.5.0/docs/api/java/lang/String.html">String toPage = bodyContent.getString().trim(); |
||
79 | JspWriter writer = pageContext.getOut(); |
||
80 | try |
||
81 | { |
||
82 | writer.write(toPage); |
||
83 | } |
||
84 | catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
85 | { |
||
86 | logger.error(e, e); |
||
87 | throw new JspException(e); |
||
88 | } |
||
89 | } |
||
90 | // Continue processing this page |
||
91 | return EVAL_PAGE; |
||
92 | } |
||
93 | |||
94 | |||
95 | |||
96 | } |