KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > MenuItemTag2


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.menu.MenuComponent;
6 import fr.improve.struts.taglib.layout.util.LayoutUtils;
7 import fr.improve.struts.taglib.layout.util.MenuInterface;
8
9 /**
10  * Menu tag used to specify the menu to display.
11  * The menu can be defined in the jsp page by nesting menuItem tag
12  * or taken from the repository by giving the menu name.
13  * Compatible with Scott Sayles menu framework.
14  *
15  * @author: Jean-Noël Ribette
16  */

17 public class MenuItemTag2 extends javax.servlet.jsp.tagext.TagSupport JavaDoc implements MenuInterface {
18     protected String JavaDoc key = null;
19     protected String JavaDoc link = null;
20     protected String JavaDoc page = null;
21     protected String JavaDoc action = null;
22     protected String JavaDoc forward = null;
23     protected String JavaDoc style = null;
24     
25     protected String JavaDoc name = null;
26     protected String JavaDoc image = null;
27     protected String JavaDoc target = null;
28     protected MenuComponent menu = null;
29 public void addItem(MenuComponent item) {
30     if (menu==null) menu = new MenuComponent();
31     menu.addMenuComponent(item);
32 }
33 public int doEndTag() throws JspException JavaDoc {
34     if (name==null) {
35         if (menu==null) menu = new MenuComponent();
36         menu.setTitle(key);
37         menu.setLocation(link);
38         menu.setForward(forward);
39         menu.setPage(page);
40         menu.setAction(action);
41         menu.setImage(image);
42         menu.setStyle(style);
43         menu.setTarget(target);
44     } else
45         menu = LayoutUtils.getMenu(pageContext, name);
46         if (menu==null) throw new JspException JavaDoc("Menu " + name + " not found in repository");
47     try {
48         MenuInterface menuTag = (MenuInterface) findAncestorWithClass(this, MenuInterface.class);
49         menuTag.addItem(menu);
50     } catch (ClassCastException JavaDoc e) {
51         throw new JspException JavaDoc("menuItem tag not in a menu or a menuItem tag");
52     } catch (NullPointerException JavaDoc e) {
53         throw new JspException JavaDoc("menuItem tag not in a menu or a menuItem tag");
54     }
55     menu = null;
56     return EVAL_PAGE;
57 }
58     public int doStartTag() throws JspException JavaDoc {
59         return EVAL_BODY_INCLUDE;
60     }
61 public void release() {
62     super.release();
63     key = null;
64     link = null;
65     forward = null;
66     action = null;
67     page = null;
68     menu = null;
69     name = null;
70     image = null;
71     style = null;
72     target = null;
73 }
74     public void setImage(String JavaDoc image) {
75         this.image = image;
76     }
77 public void setKey(String JavaDoc key) {
78     this.key = key;
79 }
80 public void setLink(String JavaDoc link) {
81     this.link = link;
82 }
83 public void setName(String JavaDoc name) {
84     this.name = name;
85 }
86     /**
87      * Gets the target.
88      * @return Returns a String
89      */

90     public String JavaDoc getTarget() {
91         return target;
92     }
93
94     /**
95      * Sets the target.
96      * @param target The target to set
97      */

98     public void setTarget(String JavaDoc target) {
99         this.target = target;
100     }
101
102     /**
103      * Sets the forward.
104      * @param forward The forward to set
105      */

106     public void setForward(String JavaDoc forward) {
107         this.forward = forward;
108     }
109
110     /**
111      * Sets the page.
112      * @param page The page to set
113      */

114     public void setPage(String JavaDoc page) {
115         this.page = page;
116     }
117
118     public void setStyle(String JavaDoc in_string) {
119         style = in_string;
120     }
121     
122     public void setAction(String JavaDoc in_action) {
123         action = in_action;
124     }
125
126 }
127
Popular Tags