Subversion Repositories bacoAlunos

Rev

Rev 1312 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1312 jmachado 1
package pt.estgp.estgweb.web.tags;
2
 
3
import org.apache.log4j.Logger;
1814 jmachado 4
import pt.estgp.estgweb.utils.Globals;
1312 jmachado 5
import pt.estgp.estgweb.domain.UserSessionImpl;
6
 
7
import javax.servlet.jsp.JspException;
8
import javax.servlet.jsp.JspWriter;
9
import javax.servlet.jsp.tagext.BodyTagSupport;
10
 
11
public class IsNotSuperUserTag extends BodyTagSupport
12
{
13
 
14
    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(IsNotSuperUserTag.class);
15
 
16
    boolean go = false;
17
    public int doStartTag() throws JspException
18
    {
19
        go = go();
20
        if (!go)
21
            return EVAL_BODY_TAG;
22
        else
23
            return SKIP_BODY;
24
    }
25
 
26
    public boolean go()
27
    {
28
        UserSessionImpl userSession = (UserSessionImpl) pageContext.getRequest().getAttribute(Globals.USER_SESSION_KEY);
29
        return userSession != null && userSession.getUser() != null && (userSession.getUser()).hasRole(Globals.SUPER_USER_ROLE);
30
    }
31
 
32
    public int doEndTag() throws JspException
33
    {
34
        if (!go)
35
        {
36
            1.5.0/docs/api/java/lang/String.html">String toPage = bodyContent.getString().trim();
37
            JspWriter writer = pageContext.getOut();
38
            try
39
            {
40
                writer.write(toPage);
41
            }
42
            catch (1.5.0/docs/api/java/lang/Exception.html">Exception e)
43
            {
44
                logger.error(e, e);
45
                throw new JspException(e);
46
            }
47
        }
48
        // Continue processing this page
49
        return EVAL_PAGE;
50
    }
51
 
52
 
53
}