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.NavigationContextFactory;
9   import net.sf.wfnm.NavigationManager;
10  import net.sf.wfnm.StringUtils;
11  
12  import java.util.Arrays;
13  
14  import javax.servlet.jsp.JspException;
15  import javax.servlet.jsp.tagext.TagSupport;
16  
17  
18  /***
19   * This tag allows to define the ownership of an object that will be placed into the http session.
20   *
21   * @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
22   * @version 1.0.6
23   */
24  public class OwnerTag extends TagSupport {
25      /*** 
26       * The key of the object.
27       */
28      private String key;
29  
30      /*** 
31       * The ownership.
32       */
33      private String owner;
34  
35      /***
36       * Sets the key of the object.
37       *
38       * @param key the key of the object
39       */
40      public void setKey(String key) {
41          this.key = key;
42      }
43  
44      /***
45       * Gets the key of the object.
46       *
47       * @return the key of the object
48       */
49      public String getKey() {
50          return key;
51      }
52  
53      /***
54       * Sets the ownership.
55       *
56       * @param owner the ownership
57       */
58      public void setOwner(String owner) {
59          this.owner = owner;
60      }
61  
62      /***
63       * Gets the ownership.
64       *
65       * @return the ownership
66       */
67      public String getOwner() {
68          return owner;
69      }
70  
71      /***
72       * Implements the start of the owner tag.
73       *
74       * @return always SKIP_BODY in order to skip the body
75       *
76       * @throws JspException if the parameters of this tags are wrong
77       */
78      public int doStartTag() throws JspException {
79          if (Config.getInstance().isEnabled()) {
80              int ownership = StringUtils.findIgnoreCase(owner, NavigationManager.OWNERSHIP_DESC);
81  
82              if (ownership < 0) {
83                  throw new JspException("The ownership must be included in " +
84                      Arrays.asList(NavigationManager.OWNERSHIP_DESC));
85              }
86  
87              NavigationContextFactory.getInstance().addOwnership(key, ownership);
88          }
89  
90          return SKIP_BODY;
91      }
92  }