/*
* WebFlow Navigation Manager: webflow definiton, server side navigation history and automatic session cleaning.
* Distributed under LGPL license at web site http://wfnm.sourceforge.net .
*/
package net.sf.wfnm.web.taglib;
import net.sf.wfnm.Config;
import net.sf.wfnm.NavigationContextFactory;
import net.sf.wfnm.NavigationManager;
import net.sf.wfnm.StringUtils;
import java.util.Arrays;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
/**
* This tag allows to define the ownership of an object that will be placed into the http session.
*
* @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
* @version 1.0.6
*/
public class OwnerTag extends TagSupport {
/**
* The key of the object.
*/
private String key;
/**
* The ownership.
*/
private String owner;
/**
* Sets the key of the object.
*
* @param key the key of the object
*/
public void setKey(String key) {
this.key = key;
}
/**
* Gets the key of the object.
*
* @return the key of the object
*/
public String getKey() {
return key;
}
/**
* Sets the ownership.
*
* @param owner the ownership
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* Gets the ownership.
*
* @return the ownership
*/
public String getOwner() {
return owner;
}
/**
* Implements the start of the owner tag.
*
* @return always SKIP_BODY in order to skip the body
*
* @throws JspException if the parameters of this tags are wrong
*/
public int doStartTag() throws JspException {
if (Config.getInstance().isEnabled()) {
int ownership = StringUtils.findIgnoreCase(owner, NavigationManager.OWNERSHIP_DESC);
if (ownership < 0) {
throw new JspException("The ownership must be included in " +
Arrays.asList(NavigationManager.OWNERSHIP_DESC));
}
NavigationContextFactory.getInstance().addOwnership(key, ownership);
}
return SKIP_BODY;
}
}