Subversion Repositories bacoAlunos

Rev

Rev 152 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.web.tags;

import org.apache.log4j.Logger;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import pt.estgp.estgweb.domain.UserSessionImpl;
import pt.estgp.estgweb.domain.UserImpl;
import pt.estgp.estgweb.Globals;

public class IsAdminTag extends BodyTagSupport
{

    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(IsAdminTag.class);


    /**
     *
     * @return
     * @throws JspException
     */

    public int doStartTag() throws JspException
    {
        if (go())
        {
            return EVAL_BODY_BUFFERED;
        }
        else
            return SKIP_BODY;

    }

    public boolean go()
    {
        UserSessionImpl userSession = (UserSessionImpl) pageContext.getRequest().getAttribute(Globals.USER_SESSION_KEY);
        return userSession != null && userSession.getUser() != null && ((userSession.getUser()).isSuperuserOrAdmin());
    }

    public int doEndTag() throws JspException
    {

        if (go())
        {
            1.5.0/docs/api/java/lang/String.html">String toPage = bodyContent.getString().trim();
            JspWriter writer = pageContext.getOut();
            try
            {
                writer.write(toPage);
            }
            catch (1.5.0/docs/api/java/lang/Exception.html">Exception e)
            {
                logger.error(e, e);
                throw new JspException(e);
            }
        }

        // Continue processing this page
        return EVAL_PAGE;
    }


}