1 package fr.improve.struts.taglib.layout; 2 3 import javax.servlet.jsp.JspException ; 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 17 public class MenuItemTag2 extends javax.servlet.jsp.tagext.TagSupport implements MenuInterface { 18 protected String key = null; 19 protected String link = null; 20 protected String page = null; 21 protected String action = null; 22 protected String forward = null; 23 protected String style = null; 24 25 protected String name = null; 26 protected String image = null; 27 protected String 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 { 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 ("Menu " + name + " not found in repository"); 47 try { 48 MenuInterface menuTag = (MenuInterface) findAncestorWithClass(this, MenuInterface.class); 49 menuTag.addItem(menu); 50 } catch (ClassCastException e) { 51 throw new JspException ("menuItem tag not in a menu or a menuItem tag"); 52 } catch (NullPointerException e) { 53 throw new JspException ("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 { 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 image) { 75 this.image = image; 76 } 77 public void setKey(String key) { 78 this.key = key; 79 } 80 public void setLink(String link) { 81 this.link = link; 82 } 83 public void setName(String name) { 84 this.name = name; 85 } 86 90 public String getTarget() { 91 return target; 92 } 93 94 98 public void setTarget(String target) { 99 this.target = target; 100 } 101 102 106 public void setForward(String forward) { 107 this.forward = forward; 108 } 109 110 114 public void setPage(String page) { 115 this.page = page; 116 } 117 118 public void setStyle(String in_string) { 119 style = in_string; 120 } 121 122 public void setAction(String in_action) { 123 action = in_action; 124 } 125 126 } 127 | Popular Tags |