View Javadoc

1   /*
2    * WebFlow Navigation Manager: webflow definiton, server side navigation history and automatic session cleaning.
3    * Distributed under LGPL license at web site http://wfnm.sourceforge.net .
4    */
5   package net.sf.wfnm.web.taglib;
6   
7   import net.sf.wfnm.Config;
8   import net.sf.wfnm.NavigationContext;
9   import net.sf.wfnm.NavigationContextFactory;
10  import net.sf.wfnm.NavigationManager;
11  import net.sf.wfnm.StringUtils;
12  
13  import java.util.Arrays;
14  
15  import javax.servlet.jsp.JspException;
16  import javax.servlet.jsp.tagext.TagSupport;
17  
18  
19  /***
20   * This tag allows to declare a page as an entry for a named webflow.
21   *
22   * @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
23   * @version 1.0.6
24   */
25  public class WebflowTag extends TagSupport {
26      /*** 
27       * The previous webflow to force
28       */
29      private String forcePrevious;
30  
31      /*** 
32       * Sets the webflow name.
33       */
34      private String name;
35  
36      /*** 
37       * The object set owner expression for this weflow.
38       */
39      private String owner;
40  
41      /***
42       * Set the previous webflo to force
43       *
44       * @param forcePrevious the previou webflow to force
45       */
46      public void setForcePrevious(String forcePrevious) {
47          this.forcePrevious = forcePrevious;
48      }
49  
50      /***
51       * Sets the webflow name.
52       *
53       * @param name the webflow name
54       */
55      public void setName(String name) {
56          this.name = name;
57      }
58  
59      /***
60       * Sets the object set owner expression.
61       *
62       * @param owner Dthe object set owner expression
63       */
64      public void setOwner(String owner) {
65          this.owner = owner;
66      }
67  
68      /***
69       * Implements the start of the page tag.
70       *
71       * @return always SKIP_BODY in order to skip the body
72       *
73       * @throws JspException if the parameters of this tags are wrong
74       */
75      public int doStartTag() throws JspException {
76          if (Config.getInstance().isEnabled()) {
77              NavigationContext navigationContext = NavigationContextFactory.getInstance();
78              navigationContext.setWebflowName(name);
79  
80              if ((forcePrevious != null) && (forcePrevious.trim().length() > 0)) {
81                  navigationContext.setPreviousWebflowToForce(forcePrevious);
82              }
83  
84              int ownership = 0;
85  
86              if ((owner != null) && (owner.length() > 0)) {
87                  ownership = StringUtils.findIgnoreCase(owner, NavigationManager.OWNERSHIP_DESC);
88  
89                  if (ownership < 0) {
90                      throw new JspException("The ownership must be included in " +
91                          Arrays.asList(NavigationManager.OWNERSHIP_DESC).toString());
92                  }
93              } else {
94                  ownership = Config.getInstance().getDefaultOwnership();
95              }
96  
97              navigationContext.setDefaultOwnership(ownership);
98          }
99  
100         return SKIP_BODY;
101     }
102 }