Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
146 | 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.tagext.BodyTagSupport; |
||
7 | import javax.servlet.jsp.JspException; |
||
8 | import javax.servlet.jsp.JspWriter; |
||
9 | |||
10 | import pt.estgp.estgweb.domain.*; |
||
1814 | jmachado | 11 | import pt.estgp.estgweb.utils.Globals; |
146 | jmachado | 12 | |
13 | public class CanAddContentTag extends BodyTagSupport |
||
14 | { |
||
15 | |||
16 | 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(CanAddContentTag.class); |
||
17 | |||
18 | private 1.5.0/docs/api/java/lang/String.html">String name; |
||
19 | |||
20 | private 1.5.0/docs/api/java/lang/String.html">String property; |
||
21 | |||
22 | public 1.5.0/docs/api/java/lang/String.html">String getName() |
||
23 | { |
||
24 | return name; |
||
25 | } |
||
26 | |||
27 | public void setName(1.5.0/docs/api/java/lang/String.html">String name) |
||
28 | { |
||
29 | this.name = name; |
||
30 | } |
||
31 | |||
32 | public 1.5.0/docs/api/java/lang/String.html">String getProperty() |
||
33 | { |
||
34 | return property; |
||
35 | } |
||
36 | |||
37 | public void setProperty(1.5.0/docs/api/java/lang/String.html">String property) |
||
38 | { |
||
39 | this.property = property; |
||
40 | } |
||
41 | |||
42 | public int doStartTag() throws JspException |
||
43 | { |
||
152 | jmachado | 44 | if (go()) |
45 | { |
||
46 | return EVAL_BODY_TAG; |
||
47 | } |
||
48 | else |
||
49 | return SKIP_BODY; |
||
146 | jmachado | 50 | } |
152 | jmachado | 51 | |
52 | public boolean go() throws JspException |
||
146 | jmachado | 53 | { |
1814 | jmachado | 54 | UserSessionImpl userSession = (UserSessionImpl) pageContext.getRequest().getAttribute(Globals.USER_SESSION_KEY); |
152 | jmachado | 55 | IAddContents iAddContents = (IAddContents) RequestUtils.lookup(pageContext, name, property, null); |
56 | return iAddContents != null && userSession.getUser() != null && (iAddContents.canAddContent(userSession.getUser())); |
||
57 | } |
||
146 | jmachado | 58 | |
152 | jmachado | 59 | public int doEndTag() throws JspException |
60 | { |
||
61 | if (go()) |
||
146 | jmachado | 62 | { |
63 | 1.5.0/docs/api/java/lang/String.html">String toPage = bodyContent.getString().trim(); |
||
64 | JspWriter writer = pageContext.getOut(); |
||
65 | try |
||
66 | { |
||
67 | writer.write(toPage); |
||
68 | } |
||
152 | jmachado | 69 | catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) |
146 | jmachado | 70 | { |
152 | jmachado | 71 | logger.error(e, e); |
146 | jmachado | 72 | throw new JspException(e); |
73 | } |
||
74 | } |
||
75 | // Continue processing this page |
||
76 | return EVAL_PAGE; |
||
77 | } |
||
78 | |||
79 | |||
80 | } |