Changeset 8724 for trunk/greenstone3-extensions/gsdl-as/src
- Timestamp:
- 2004-12-02T16:20:11+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8717 r8724 14 14 import java.util.*; 15 15 16 import javax.mail.Session; 16 17 import javax.servlet.http.*; 17 18 … … 38 39 actions.add("login"); 39 40 actions.add("register"); 41 actions.add("logout"); 40 42 } 41 43 … … 99 101 return "login.vm"; 100 102 } 101 // TODO handle wizard-style stuff 102 // if "finish" 103 ProfileStore.getInstance().createSubscription(arguments); 104 return listSubscriptions(arguments, context); 105 // else show next page 103 if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) { 104 ProfileStore.getInstance().createSubscription(arguments); 105 return listSubscriptions(arguments, context); 106 } else { 107 return showSubscriptionWizardPage(arguments, context, true); 108 } 106 109 } 107 110 … … 117 120 } 118 121 119 public String editSubscription(Map arguments, Context context) {122 public String editSubscription(Map arguments, Context context) throws Exception { 120 123 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 121 124 if (!UserManager.getInstance().isLoggedIn(session)) { … … 123 126 return "login.vm"; 124 127 } 125 // TODO handle wizard-style stuff 126 // if "finish" 127 ProfileStore.getInstance().changeSubscription(arguments, session); 128 return listSubscriptions(arguments, context); 129 // else show next page 128 if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) { 129 ProfileStore.getInstance().changeSubscription(arguments, session); 130 return listSubscriptions(arguments, context); 131 } else { 132 return showSubscriptionWizardPage(arguments, context, false); 133 } 130 134 } 131 135 … … 156 160 UserManager.getInstance().createUser(arguments, session); 157 161 return login(arguments, context); 162 } 163 164 public String logout(Map arguments, Context context) { 165 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 166 Enumeration atts = session.getAttributeNames(); 167 while (atts.hasMoreElements()) { 168 session.removeAttribute((String) atts.nextElement()); 169 } 170 session.invalidate(); 171 return "general.vm"; 158 172 } 159 173 … … 211 225 return null; 212 226 } 227 228 /** 229 * @param arguments 230 * @param context 231 * @param create 232 * @return 233 * @throws Exception 234 */ 235 private String showSubscriptionWizardPage(Map arguments, Context context, boolean create) throws Exception { 236 if (create) { 237 context.put("action", "createSubscription"); 238 } else { 239 context.put("action", "editSubscription"); 240 } 241 if (!arguments.containsKey("current_page")) { 242 return "sub_type-details.vm"; 243 } 244 245 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 246 String currentPage = (String) arguments.get("current_page"); 247 String direction = (String) arguments.get("next_page"); 248 249 // save page arguments 250 savePageArgsToSession(currentPage, arguments, session); 251 252 String nextPage = getNextPage(currentPage, direction); 253 254 // fill prefill 255 context.put("prefill", getPageArgsFromSession(nextPage, session)); 256 257 // fill preview 258 context.put("preview", getPagePreview(nextPage, session)); 259 260 // get page-specific stuff 261 if (nextPage.equals("host")) { 262 263 } else if (nextPage.equals("collection")) { 264 265 } 266 267 return "sub_" + nextPage + ".vm"; 268 } 269 270 /** 271 * @param nextPage 272 * @param session 273 * @return 274 */ 275 private Map getPagePreview(String nextPage, HttpSession session) { 276 Map preview = new TreeMap(); 277 if (nextPage.equals("type-details")) { 278 return preview; 279 } 280 preview.putAll(getPageArgsFromSession("type-details", session)); 281 if (nextPage.equals("host")) { 282 return preview; 283 } 284 preview.putAll(getPageArgsFromSession("host", session)); 285 if (nextPage.equals("collection")) { 286 return preview; 287 } 288 preview.putAll(getPageArgsFromSession("collection", session)); 289 return preview; 290 } 291 292 /** 293 * @param currentPage 294 * @param direction 295 * @return 296 * @throws Exception 297 */ 298 private String getNextPage(String currentPage, String direction) throws Exception { 299 String nextPage; 300 if (currentPage.equals("host") && direction.equals("back")) { 301 nextPage = "type-details"; 302 } else if (currentPage.equals("type-details") || (currentPage.equals("collection") && direction.equals("back"))) { 303 nextPage = "host"; 304 } else if (currentPage.equals("host") || (currentPage.equals("notification") && direction.equals("back"))) { 305 nextPage = "collection"; 306 } else if (currentPage.equals("collection")) { 307 nextPage = "notification"; 308 } else { 309 throw new Exception("unknown combination of currentPage=" + currentPage + " and nextPage=" + direction); 310 } 311 return nextPage; 312 } 313 314 /** 315 * @param page 316 * @param session 317 * @return TODO 318 */ 319 private Map getPageArgsFromSession(String page, HttpSession session) { 320 Map pageArgs = (Map) session.getAttribute("page_args"); 321 if (pageArgs == null || !pageArgs.containsKey(page)) 322 return new TreeMap(); 323 return (Map) pageArgs.get(page); 324 } 325 326 /** 327 * @param page 328 * @param arguments 329 * @param session 330 */ 331 private void savePageArgsToSession(String page, Map arguments, HttpSession session) { 332 Map pageArgs = (Map) session.getAttribute("page_args"); 333 if (pageArgs == null) { 334 pageArgs = new TreeMap(); 335 } 336 pageArgs.put(page, arguments); 337 session.setAttribute("page_args", pageArgs); 338 } 213 339 }
Note:
See TracChangeset
for help on using the changeset viewer.