/*
* 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.NavigationContext;
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 declare a page as an entry for a named webflow.
*
* @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
* @version 1.0.6
*/
public class WebflowTag extends TagSupport {
/**
* The previous webflow to force
*/
private String forcePrevious;
/**
* Sets the webflow name.
*/
private String name;
/**
* The object set owner expression for this weflow.
*/
private String owner;
/**
* Set the previous webflo to force
*
* @param forcePrevious the previou webflow to force
*/
public void setForcePrevious(String forcePrevious) {
this.forcePrevious = forcePrevious;
}
/**
* Sets the webflow name.
*
* @param name the webflow name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the object set owner expression.
*
* @param owner Dthe object set owner expression
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* Implements the start of the page 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()) {
NavigationContext navigationContext = NavigationContextFactory.getInstance();
navigationContext.setWebflowName(name);
if ((forcePrevious != null) && (forcePrevious.trim().length() > 0)) {
navigationContext.setPreviousWebflowToForce(forcePrevious);
}
int ownership = 0;
if ((owner != null) && (owner.length() > 0)) {
ownership = StringUtils.findIgnoreCase(owner, NavigationManager.OWNERSHIP_DESC);
if (ownership < 0) {
throw new JspException("The ownership must be included in " +
Arrays.asList(NavigationManager.OWNERSHIP_DESC).toString());
}
} else {
ownership = Config.getInstance().getDefaultOwnership();
}
navigationContext.setDefaultOwnership(ownership);
}
return SKIP_BODY;
}
}