package it.mice.voila.runtime.springmvc.taglibs;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;


public class SecurityAllowFieldTag extends TagSupport {
	/**
	 * serial
	 */
	private static final long serialVersionUID = 3407922243756477174L;

	/**
	 * The parameter name to allow for posting
	 */
	private String name = null;

	/**
	 * Specific value to allow for parameter post value
	 */
	private String value = null;

	/**
	 * The parameter type (i.e. text for allow any value)
	 */
	private String type = "text";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	/**
     * Includes its body if condition() evaluates to true.
     */
    public int doStartTag() throws JspException {
        TagUtils.getSecuritySessionBean().addFormField(getName(), getValue(), getType());
        TagUtils.getSecuritySessionBean().setReadOnly(getName(), false, getValue());
   		return SKIP_BODY;
    }
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
	 */
	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}

	/**
     * Releases any resources this ConditionalTagSupport may have (or inherit).
     */
    public void release() {
        super.release();
        name = null;
        value = null;
        type = "text";
    }
}
