1 6 package org.contineo.admin; 7 8 import java.util.ArrayList ; 9 import java.util.Collection ; 10 import org.contineo.admin.dao.MenuDAO; 11 12 17 public class Menu { 18 19 public static final int MENUTYPE_DIRECTORY = 3; 20 21 22 public static final int MENUTYPE_FILE = 5; 23 24 27 protected int menuId; 28 31 protected String menuText; 32 35 protected int menuParent; 36 39 protected int menuSort; 40 43 protected String menuIcon; 44 47 protected String menuPath; 48 51 protected int menuType; 52 55 protected int menuHier; 56 59 protected String menuRef; 60 61 65 protected Collection <MenuGroup> menuGroup; 66 67 68 69 public Menu() { 70 menuId = 0; 71 menuText = ""; 72 menuParent = 0; 73 menuSort = 0; 74 menuIcon = ""; 75 menuPath = ""; 76 menuType = 2; 77 menuHier = 0; 78 menuRef = ""; 79 menuGroup = new ArrayList <MenuGroup>(); 80 } 81 82 86 public int getMenuId() { 87 return menuId; 88 } 89 90 94 public String getMenuText() { 95 return menuText; 96 } 97 98 102 public int getMenuParent() { 103 return menuParent; 104 } 105 106 110 public int getMenuSort() { 111 return menuSort; 112 } 113 114 118 public String getMenuIcon() { 119 return menuIcon; 120 } 121 122 126 public String getMenuPath() { 127 return menuPath; 128 } 129 130 134 public int getMenuType() { 135 return menuType; 136 } 137 138 142 public int getMenuHier() { 143 return menuHier; 144 } 145 146 150 public String getMenuRef() { 151 return menuRef; 152 } 153 154 158 public Collection <MenuGroup> getMenuGroup() { 159 return menuGroup; 160 } 161 162 166 protected void setMenuId(int id) { 167 menuId = id; 168 } 169 170 174 public void setMenuText(String text) { 175 menuText = text; 176 } 177 178 182 public void setMenuParent(int parent) { 183 menuParent = parent; 184 } 185 186 190 public void setMenuSort(int sort) { 191 menuSort = sort; 192 } 193 194 198 public void setMenuIcon(String icon) { 199 menuIcon = icon; 200 } 201 202 206 public void setMenuPath(String path) { 207 menuPath = path; 208 } 209 210 214 public void setMenuType(int type) { 215 menuType = type; 216 } 217 218 222 public void setMenuHier(int hier) { 223 menuHier = hier; 224 } 225 226 230 public void setMenuRef(String ref) { 231 menuRef = ref; 232 } 233 234 238 public void setMenuGroup(Collection <MenuGroup> mgroup) { 239 menuGroup = mgroup; 240 } 241 242 246 public void setMenuGroup(String [] groups) { 247 for (int i=0; i<groups.length; i++) { 248 MenuGroup mg = new MenuGroup(); 249 mg.setMenuId(menuId); 250 mg.setGroupName(groups[i]); 251 mg.setWriteEnable(1); 252 menuGroup.add(mg); 253 } 254 } 255 256 260 public Menu copy() { 261 Menu menu = new Menu(); 262 menu.setMenuId(this.getMenuId()); 263 menu.setMenuText(this.getMenuText()); 264 menu.setMenuParent(this.getMenuParent()); 265 menu.setMenuSort(this.getMenuSort()); 266 menu.setMenuIcon(this.getMenuIcon()); 267 menu.setMenuPath(this.getMenuPath()); 268 menu.setMenuType(this.getMenuType()); 269 menu.setMenuHier(this.getMenuHier()); 270 menu.setMenuRef(this.getMenuRef()); 271 menu.setMenuGroup(this.getMenuGroup()); 272 return menu; 273 } 274 275 280 public Collection getParents() { 281 Collection <Menu> coll = new ArrayList <Menu>(); 282 try { 283 String menus[] = menuPath.split("/"); 284 if (menus.length > 0) { 285 if (menus[0].length() > 0) { 286 MenuDAO menuDao = new MenuDAO(); 287 Menu home = menuDao.findByPrimaryKey(1); 288 coll.add(home); 289 for (int i=1; i<menus.length; i++) { 290 try { 291 Menu menu = menuDao.findByPrimaryKey(Integer.parseInt(menus[i])); 292 coll.add(menu); 293 } catch (NumberFormatException nfe) { 294 295 } 296 } 297 } 298 } 299 } catch (Exception e) { 300 301 } 302 return coll; 303 } 304 } 305 | Popular Tags |