View Javadoc
1   package org.andromda.taglibs.breadcrumbs;
2   
3   import javax.servlet.jsp.JspException;
4   import javax.servlet.jsp.PageContext;
5   import javax.servlet.jsp.tagext.Tag;
6   import javax.servlet.jsp.tagext.TagSupport;
7   
8   /**
9    *
10   */
11  public class DefineTag extends TagSupport
12  {
13      private static final long serialVersionUID = 34L;
14      private String id = null;
15      private String toScope = null;
16  
17      /**
18       * @see javax.servlet.jsp.tagext.TagSupport#getId()
19       */
20      public String getId()
21      {
22          return id;
23      }
24  
25      /**
26       * @see javax.servlet.jsp.tagext.TagSupport#setId(String)
27       */
28      public void setId(String id)
29      {
30          this.id = id;
31      }
32  
33      /**
34       * @return toScope
35       */
36      public String getToScope()
37      {
38          return toScope;
39      }
40  
41      /**
42       * @param toScope
43       */
44      public void setToScope(String toScope)
45      {
46          this.toScope = toScope;
47      }
48  
49      /**
50       * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
51       */
52      public int doStartTag() throws JspException
53      {
54          Object breadCrumbsObject = this.pageContext.getAttribute(BreadCrumbs.SESSION_KEY, PageContext.SESSION_SCOPE);
55  
56          if (breadCrumbsObject == null)
57          {
58              BreadCrumbs breadCrumbs = new BreadCrumbs();
59              this.pageContext.setAttribute(BreadCrumbs.SESSION_KEY, breadCrumbs, PageContext.SESSION_SCOPE);
60          }
61          else if (breadCrumbsObject instanceof BreadCrumbs)
62          {
63              int scope = PageContext.PAGE_SCOPE;
64  
65              if (toScope != null)
66              {
67                  if ("page".equals(toScope))
68                      scope = PageContext.PAGE_SCOPE;
69                  if ("session".equals(toScope))
70                      scope = PageContext.SESSION_SCOPE;
71                  if ("application".equals(toScope))
72                      scope = PageContext.APPLICATION_SCOPE;
73                  if ("request".equals(toScope))
74                      scope = PageContext.REQUEST_SCOPE;
75              }
76  
77              this.pageContext.setAttribute(id, breadCrumbsObject, scope);
78          }
79  
80          return Tag.SKIP_BODY;
81      }
82  }