1 19 20 package com.sslexplorer.core; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import com.sslexplorer.boot.Util; 29 import com.sslexplorer.security.SessionInfo; 30 31 32 44 public class AvailableMenuItem extends ArrayList implements Comparable { 45 46 private static final long serialVersionUID = -5447780375295861982L; 47 48 50 private MenuItem menuItem; 51 private AvailableMenuItem parent; 52 private String path; 53 private HttpServletRequest request; 54 private SessionInfo sessionInfo; 55 56 66 public AvailableMenuItem(MenuItem menuItem, AvailableMenuItem parent, HttpServletRequest request, String referer, int checkNavigationContext, SessionInfo sessionInfo) { 67 this.request = request; 68 this.sessionInfo = sessionInfo; 69 for(Iterator i = menuItem.availableChildren(checkNavigationContext, sessionInfo, request).iterator(); i.hasNext(); ) { 70 MenuItem it = (MenuItem)i.next(); 71 if(it.isLeaf() || ( !it.isLeaf() && !it.isEmpty())) { 72 add(new AvailableMenuItem(it, this, request, referer, checkNavigationContext, sessionInfo)); 73 } 74 } 75 Collections.sort(this); 76 this.menuItem = menuItem; 77 this.parent = parent; 78 79 path = menuItem.getPath(); 80 if(path != null) { 81 StringBuffer buf = new StringBuffer (); 82 buf.append(path); 83 if(referer != null && !path.startsWith("javascript:")) { 84 while(true) { 86 int idx = path.indexOf("referer="); 87 if(idx != -1) { 88 int end = path.indexOf('&', idx); 89 path = path.substring(0, idx) + ( end == -1 ? "" : path.substring(end) ); 90 } 91 else { 92 break; 93 } 94 } 95 if(path.indexOf("?") != -1) { 96 buf.append("&"); 97 } 98 else { 99 buf.append("?"); 100 } 101 buf.append("referer="); 102 buf.append(Util.urlEncode(referer)); 103 } 104 path = buf.toString(); 105 } 106 } 107 108 113 public boolean getEmpty() { 114 return size() == 0; 115 } 116 117 122 public AvailableMenuItem getParent() { 123 return parent; 124 } 125 126 131 public MenuItem getMenuItem() { 132 return menuItem; 133 } 134 135 141 public AvailableMenuItem getFirstAvailableChild() { 142 if(!menuItem.isLeaf() && !menuItem.isEmpty()) { 143 return null; 144 } 145 return (AvailableMenuItem)get(0); 146 } 147 148 153 public String getPath() { 154 return path; 155 } 156 157 160 public String toString() { 161 return menuItem == null ? "<no menu item>" : ( menuItem.getId() + " [" + menuItem.getPath() + "] empty = " + menuItem.isEmpty()); 162 } 163 164 167 public int compareTo(Object arg0) { 168 return getMenuItem().compareTo(((AvailableMenuItem)arg0).getMenuItem()); 169 } 170 171 176 public HttpServletRequest getRequest() { 177 return request; 178 } 179 180 185 public SessionInfo getSessionInfo() { 186 return sessionInfo; 187 } 188 } | Popular Tags |