Changeset 18223
- Timestamp:
- 2008-12-17T14:17:05+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java
r16938 r18223 39 39 /** the receptionist to send messages to */ 40 40 protected Receptionist recept=null; 41 41 42 /** the default language - is specified by setting a servlet param, 42 43 * otherwise DEFAULT_LANG is used*/ 43 44 protected String default_lang= null; 45 44 46 /** The default default - used if a default lang is not specified 45 47 * in the servlet params */ 46 48 protected final String DEFAULT_LANG = "en"; 49 47 50 /** container Document to create XML Nodes */ 48 51 protected Document doc=null; 52 49 53 /** a converter class to parse XML and create Docs */ 50 54 protected XMLConverter converter=null; 55 51 56 /** the cgi stuff - the Receptionist can add new args to this 52 57 * … … 78 83 // disable preferences - does this work anyway?? 79 84 //System.setProperty("java.util.prefs.PreferencesFactory", "org.greenstone.gsdl3.util.DisabledPreferencesFactory"); 80 81 85 82 86 String library_name = config.getInitParameter(GSConstants.LIBRARY_NAME); … … 247 251 protected void cleanupCache(String coll_name) { 248 252 if (coll_name_params_table.containsKey(coll_name)) { 249 coll_name_params_table.remove(coll_name); 250 } 251 } 253 coll_name_params_table.remove(coll_name); 254 } 255 } 256 252 257 protected Hashtable getParamsTable() { 253 258 return coll_name_params_table; 254 259 } 260 255 261 public void valueBound(HttpSessionBindingEvent event) { 256 262 // Do nothing … … 262 268 } 263 269 } 270 264 271 public int tableSize() { 265 272 return (coll_name_params_table == null)? 0 : coll_name_params_table.size(); 266 273 } 267 } 268 269 public void doGet (HttpServletRequest request,270 274 275 } 276 277 public void doGet (HttpServletRequest request, HttpServletResponse response) 271 278 throws ServletException, IOException { 272 279 logUsageInfo (request); … … 279 286 String rl = null; 280 287 for (int i=0;i<query_arr.length;i++){ 281 282 283 284 285 286 287 288 289 290 291 292 293 288 if (query_arr[i].startsWith("el")){ 289 if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){ 290 redirect = true; 291 } 292 }else if(query_arr[i].startsWith("href")){ 293 href = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 294 href = href.replaceAll("%2f", "/"); 295 href = href.replaceAll("%7e", "~"); 296 href = href.replaceAll("%3f", "?"); 297 href = href.replaceAll("%3A", "\\:"); 298 }else if(query_arr[i].startsWith("rl")){ 299 rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 300 } 294 301 } 295 302 //if query_string contains "el=", the web page will be redirected to the external URl, otherwise a greenstone page with an external URL will be displayed … … 297 304 //"rl=1" this is an internal link 298 305 if ((redirect) && (href != null) && (rl.equals("0"))){// This is an external link, the web page is re-directed to the external URL (&el=&rl=0&href="http://...") 299 300 306 response.setContentType("text/xml"); 307 response.sendRedirect(href); 301 308 } 302 309 } … … 357 364 String coll = request.getParameter(GSParams.SYSTEM_CLUSTER); 358 365 if (coll != null && !coll.equals("")) { 359 360 366 clean_all = false; 367 clean_collection = coll; 361 368 } else { 362 363 364 365 366 367 368 369 369 // check other system types 370 if (subaction.equals("a") || subaction.equals("d")) { 371 String module_name = request.getParameter("sn"); 372 if (module_name != null && !module_name.equals("")) { 373 clean_all = false; 374 clean_collection = module_name; 375 } 376 } 370 377 } 371 378 if (clean_all) { 372 373 379 session_ids_table = new Hashtable(); 380 session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 374 381 } else { 375 376 377 378 379 380 381 382 // just clean up info for clean_collection 383 ArrayList cache_list = new ArrayList(session_ids_table.values()); 384 for (int i=0; i<cache_list.size(); i++) { 385 UserSessionCache cache = (UserSessionCache)cache_list.get(i); 386 cache.cleanupCache(clean_collection); 387 } 388 382 389 } 383 390 … … 390 397 } 391 398 392 // 399 // logger.info("should_cache= " + should_cache); 393 400 394 401 //clear the collection-specific cache in the session, since we have no way to know whether this session is … … 398 405 String name = (String)attributeNames.nextElement(); 399 406 if (!name.equals (GSXML.USER_SESSION_CACHE_ATT) 400 && !name.equals (GSParams.LANGUAGE) 401 && !name.equals (GSXML.USER_ID_ATT)) { 402 session.removeAttribute(name); 407 && !name.equals (GSParams.LANGUAGE) 408 && !name.equals (GSXML.USER_ID_ATT)) { 409 410 session.removeAttribute(name); 403 411 } 404 412 } … … 408 416 cache_key = "0000000000"; 409 417 } 410 418 411 419 UserSessionCache session_cache = null; 412 420 Hashtable param_table = null; … … 415 423 if (should_cache == true && cache_key != null && !cache_key.equals("")) { 416 424 if (session_ids_table.containsKey(sid)) { 417 418 419 420 421 422 423 424 425 426 427 425 session_cache = (UserSessionCache)session_ids_table.get(sid); 426 param_table = session_cache.getParamsTable(); 427 logger.info("collections in table: " + tableToString(param_table)); 428 if (param_table.containsKey(cache_key)) { 429 //logger.info("existing table: " + collection); 430 table = (Hashtable)param_table.get(cache_key); 431 } else { 432 table = new Hashtable(); 433 param_table.put(cache_key, table); 434 //logger.info("new table: " + collection); 435 } 428 436 } else { 429 430 431 432 433 434 435 437 param_table = new Hashtable(); 438 table = new Hashtable(); 439 param_table.put(cache_key, table); 440 session_cache = new UserSessionCache(sid, param_table); 441 session_ids_table.put(sid, session_cache); 442 session.setAttribute(GSXML.USER_SESSION_CACHE_ATT, session_cache); 443 //logger.info("new session id"); 436 444 } 437 445 } … … 446 454 xml_request.setAttribute (GSXML.ACTION_ATT, action); 447 455 if (subaction != null) { 448 456 xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 449 457 } 450 458 … … 457 465 while(params.hasMoreElements ()) { 458 466 String name = (String)params.nextElement (); 459 if (!name.equals (GSParams.ACTION) 460 && !name.equals (GSParams.SUBACTION) 461 && !name.equals (GSParams.LANGUAGE) 462 && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 467 if (!name.equals (GSParams.ACTION) 468 && !name.equals (GSParams.SUBACTION) 469 && !name.equals (GSParams.LANGUAGE) 470 && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 471 463 472 String value=""; 464 473 String [] values = request.getParameterValues (name); … … 471 480 // either add it to the param list straight away, or save it to the session and add it later 472 481 if (this.params.shouldSave (name) && table != null) { 473 table.put(name, value); 482 table.put(name, value); 474 483 } else { 475 484 Element param = this.doc.createElement (GSXML.PARAM_ELEM); … … 483 492 // do we need to do this? why not just put from table into param list 484 493 if (table != null) { 485 486 487 488 489 494 Enumeration keys = table.keys (); 495 while(keys.hasMoreElements ()) { 496 String name = (String)keys.nextElement(); 497 session.setAttribute(name, (String)table.get(name)); 498 } 490 499 } 491 500 … … 496 505 497 506 if ( !name.equals (GSXML.USER_SESSION_CACHE_ATT) 498 && !name.equals (GSParams.LANGUAGE) 499 && !name.equals (GSXML.USER_ID_ATT)) { 500 // lang and uid are stored but we dont want it in the param list cos its already in the request 507 && !name.equals (GSParams.LANGUAGE) 508 && !name.equals (GSXML.USER_ID_ATT)) { 509 510 // lang and uid are stored but we dont want it in the param list cos its already in the request 501 511 Element param = this.doc.createElement (GSXML.PARAM_ELEM); 502 512 param.setAttribute (GSXML.NAME_ATT, name); 503 513 String value = GSXML.xmlSafe ((String)session.getAttribute (name)); 514 504 515 // ugly hack to undo : escaping 505 516 value = value.replaceAll ("%3A", "\\:"); … … 521 532 522 533 displaySize(session_ids_table); 523 } 534 535 } //end of doGet(HttpServletRequest, HttpServletResponse) 524 536 525 537 //a debugging method … … 536 548 ArrayList cache_list = new ArrayList(table.values()); 537 549 for (int i=0; i<cache_list.size(); i++) { 538 num_cached_coll += ((UserSessionCache)cache_list.get(i)).tableSize(); 550 num_cached_coll += ((UserSessionCache)cache_list.get(i)).tableSize(); 539 551 } 540 552 logger.info("Number of sessions : total number of cached collection info = " + table.size() + " : " + num_cached_coll); 541 } 553 } 554 542 555 /** merely a debugging method! */ 543 556 private String tableToString(Hashtable table) { … … 604 617 } 605 618 606 public void doPost(HttpServletRequest request, 607 HttpServletResponse response) 619 public void doPost(HttpServletRequest request, HttpServletResponse response) 608 620 throws ServletException, IOException { 621 609 622 doGet(request,response); 610 623 611 624 } 625 612 626 }
Note:
See TracChangeset
for help on using the changeset viewer.