/*
 * $Id: IsLdapUserTag.java,v 1.1 2004/10/18 13:05:14 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: IsLdapUserTag.java,v $
 * Revision 1.1  2004/10/18 13:05:14  jonyp
 * first strike
 *
 * 
 */
package vkc.view.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import vkc.db.entities.VKCUser;
import vkc.ldap.VKCLdapUser;
import vkc.util.ServletUtils;
import vkc.view.WebShare;

/**
 * Tag zur Überprüfung, ob LDAP der aktuelle User ein LdapUser ist
 *
 * @author jonyP
 */
public class IsLdapUserTag extends TagSupport{

    public IsLdapUserTag() {
    }
    
    private boolean isLdapUser() throws JspTagException {
        VKCUser user = ServletUtils.getUser((HttpServletRequest)pageContext.getRequest());

        if (user == null) {
           throw new JspTagException(
               "A User object in session scope not found! (KEY=" + WebShare.USER_KEY + ")");
        }
       
        if (user instanceof VKCLdapUser) {
            return true;
        }
           
        return false;     
    }

    /**
     * Aufruf der Methode am Anfang des Tags
     */
    public int doStartTag() throws JspException {
        if (isLdapUser()){   
		    return EVAL_BODY_INCLUDE;
		} 
        
        return SKIP_BODY;
    }

    /**
     * Aufruf der Methode am Ende des Tags
     */
    public int doEndTag() throws JspException {
	
		return EVAL_PAGE;
    }
}