Changeset 16926 for greenstone3/trunk
- Timestamp:
- 2008-08-21T09:48:20+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java
r16688 r16926 88 88 String sess_expire = config.getInitParameter(GSXML.SESSION_EXPIRATION); 89 89 if (sess_expire != null && !sess_expire.equals("")) { 90 90 this.session_expiration = Integer.parseInt(sess_expire); 91 91 } 92 92 … … 250 250 protected void cleanupCache(String coll_name) { 251 251 if (coll_name_params_table.containsKey(coll_name)) { 252 252 coll_name_params_table.remove(coll_name); 253 253 } 254 254 } 255 255 protected Hashtable getParamsTable() { 256 256 return coll_name_params_table; 257 257 } 258 258 public void valueBound(HttpSessionBindingEvent event) { 259 // Do nothing259 // Do nothing 260 260 } 261 261 … … 266 266 } 267 267 public int tableSize() { 268 268 return (coll_name_params_table == null)? 0 : coll_name_params_table.size(); 269 269 } 270 270 } 271 271 272 272 public void doGet (HttpServletRequest request, 273 HttpServletResponse response)273 HttpServletResponse response) 274 274 throws ServletException, IOException { 275 275 logUsageInfo (request); … … 277 277 String query_string = request.getQueryString(); 278 278 if (query_string!=null){ 279 String[] query_arr = query_string.split("&"); 280 boolean redirect = false; 281 String href = null; 282 String rl = null; 283 for (int i=0;i<query_arr.length;i++){ 284 if (query_arr[i].startsWith("el")){ 285 if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){ 286 redirect = true; 287 } 288 }else if(query_arr[i].startsWith("href")){ 289 href = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 290 href = href.replaceAll("%2f", "/"); 291 href = href.replaceAll("%7e", "~"); 292 href = href.replaceAll("%3f", "?"); 293 href = href.replaceAll("%3A", "\\:"); 294 }else if(query_arr[i].startsWith("rl")){ 295 rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 296 } 279 String[] query_arr = query_string.split("&"); 280 boolean redirect = false; 281 String href = null; 282 String rl = null; 283 for (int i=0;i<query_arr.length;i++){ 284 if (query_arr[i].startsWith("el")){ 285 if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){ 286 redirect = true; 287 } 288 }else if(query_arr[i].startsWith("href")){ 289 href = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 290 href = href.replaceAll("%2f", "/"); 291 href = href.replaceAll("%7e", "~"); 292 href = href.replaceAll("%3f", "?"); 293 href = href.replaceAll("%3A", "\\:"); 294 }else if(query_arr[i].startsWith("rl")){ 295 rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 297 296 } 298 //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 299 //"rl=0" this is an external link 300 //"rl=1" this is an internal link 301 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://...") 302 response.setContentType("text/xml"); 303 response.sendRedirect(href); 304 } 297 } 298 //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 299 //"rl=0" this is an external link 300 //"rl=1" this is an internal link 301 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://...") 302 response.setContentType("text/xml"); 303 response.sendRedirect(href); 304 } 305 305 } 306 306 // Nested Diagnostic Configurator to identify the client for … … 345 345 String collection = request.getParameter(GSParams.COLLECTION); 346 346 347 348 347 //specifically we clean up the cache session_ids_table if the two reconfigure command 348 //are issued: a=s&sa=c and a=s&sa=c&c=coll_name, in which case there is no caching action to be taken 349 349 boolean should_cache = true; 350 if(action != null && action.equals(GSParams.SYSTEM) 351 && subaction != null && subaction.equals(GSParams.CONFIGURE)) { 352 if (collection == null || collection.equals("")) { 353 //user reconfiugred the whole site, clean up all cached info 354 //logger.info("clear cache for the whole site."); 355 session_ids_table = new Hashtable(); 356 session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 357 } else { 358 //clean up all cache info related to the collection 359 //logger.info("clear cache for collection: " + collection); 360 ArrayList cache_list = new ArrayList(session_ids_table.values()); 361 for (int i=0; i<cache_list.size(); i++) { 362 UserSessionCache cache = (UserSessionCache)cache_list.get(i); 363 cache.cleanupCache(collection); 364 } 365 } 366 should_cache = false; 350 if(action != null && action.equals(GSParams.SYSTEM) 351 && subaction != null && subaction.equals(GSParams.CONFIGURE)) { 352 if (collection == null || collection.equals("")) { 353 //user reconfiugred the whole site, clean up all cached info 354 //logger.info("clear cache for the whole site."); 355 session_ids_table = new Hashtable(); 356 session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 357 } else { 358 //clean up all cache info related to the collection 359 //logger.info("clear cache for collection: " + collection); 360 ArrayList cache_list = new ArrayList(session_ids_table.values()); 361 for (int i=0; i<cache_list.size(); i++) { 362 UserSessionCache cache = (UserSessionCache)cache_list.get(i); 363 cache.cleanupCache(collection); 367 364 } 368 365 } 366 should_cache = false; 367 } 368 369 369 // logger.info("should_cache= " + should_cache); 370 370 //clear the collection-specific cache in the session, since we have no way to know whether this session is … … 372 372 Enumeration attributeNames = session.getAttributeNames(); 373 373 while(attributeNames.hasMoreElements()) { 374 375 376 377 378 379 380 } 381 374 String name = (String)attributeNames.nextElement(); 375 if (!name.equals (GSXML.USER_SESSION_CACHE_ATT) 376 && !name.equals (GSParams.LANGUAGE) 377 && !name.equals (GSXML.USER_ID_ATT)) { 378 session.removeAttribute(name); 379 } 380 } 381 382 382 // create a dumy collection name for Authentication 383 383 if (subaction != null && subaction.equals("authen")){ 384 384 collection = "0000000000"; 385 385 } 386 386 … … 390 390 String sid = session.getId(); 391 391 if (should_cache == true && collection != null && !collection.equals("")) { 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 392 String key_str = valid_site_name + collection; 393 if (session_ids_table.containsKey(sid)) { 394 session_cache = (UserSessionCache)session_ids_table.get(sid); 395 param_table = session_cache.getParamsTable(); 396 logger.info("collections in table: " + tableToString(param_table)); 397 if (param_table.containsKey(key_str)) { 398 //logger.info("existing table: " + collection); 399 table = (Hashtable)param_table.get(key_str); 400 } else { 401 table = new Hashtable(); 402 param_table.put(key_str, table); 403 //logger.info("new table: " + collection); 404 } 405 } else { 406 param_table = new Hashtable(); 407 table = new Hashtable(); 408 param_table.put(key_str, table); 409 session_cache = new UserSessionCache(sid, param_table); 410 session_ids_table.put(sid, session_cache); 411 session.setAttribute(GSXML.USER_SESSION_CACHE_ATT, session_cache); 412 //logger.info("new session id"); 413 } 414 414 } 415 415 … … 439 439 String name = (String)params.nextElement (); 440 440 if (!name.equals (GSParams.ACTION) 441 442 443 441 && !name.equals (GSParams.SUBACTION) 442 && !name.equals (GSParams.LANGUAGE) 443 && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 444 444 String value=""; 445 445 String [] values = request.getParameterValues (name); … … 452 452 // either add it to the param list straight away, or save it to the session and add it later 453 453 if (this.params.shouldSave (name)) { 454 455 456 454 if (table != null) { 455 table.put(name, value); 456 } 457 457 } else { 458 458 Element param = this.doc.createElement (GSXML.PARAM_ELEM); … … 465 465 //put everything in the table into the session 466 466 if (table != null) { 467 468 469 470 471 467 Enumeration keys = table.keys (); 468 while(keys.hasMoreElements ()) { 469 String name = (String)keys.nextElement(); 470 session.setAttribute(name, (String)table.get(name)); 471 } 472 472 } 473 473 … … 478 478 479 479 if ( !name.equals (GSXML.USER_SESSION_CACHE_ATT) 480 481 482 480 && !name.equals (GSParams.LANGUAGE) 481 && !name.equals (GSXML.USER_ID_ATT)) { 482 // lang and uid are stored but we dont want it in the param list cos its already in the request 483 483 Element param = this.doc.createElement (GSXML.PARAM_ELEM); 484 484 param.setAttribute (GSXML.NAME_ATT, name); … … 506 506 //a debugging method 507 507 private void displaySize(Hashtable table) { 508 509 510 511 512 513 514 515 516 517 518 519 520 521 508 if(table == null) { 509 logger.info("cached table is null"); 510 return; 511 } 512 if (table.size() == 0) { 513 logger.info("cached table size is zero"); 514 return; 515 } 516 int num_cached_coll = 0; 517 ArrayList cache_list = new ArrayList(table.values()); 518 for (int i=0; i<cache_list.size(); i++) { 519 num_cached_coll += ((UserSessionCache)cache_list.get(i)).tableSize(); 520 } 521 logger.info("Number of sessions : total number of cached collection info = " + table.size() + " : " + num_cached_coll); 522 522 } 523 523 /** merely a debugging method! */ 524 524 private String tableToString(Hashtable table) { 525 526 527 528 529 530 531 525 String str = ""; 526 Enumeration keys = table.keys (); 527 while(keys.hasMoreElements ()) { 528 String name = (String)keys.nextElement(); 529 str += name + ", "; 530 } 531 return str; 532 532 } 533 533 … … 546 546 short nodeType = dataNode.getNodeType(); 547 547 if (nodeType == Node.DOCUMENT_NODE) { 548 549 548 Document docNode = (Document)dataNode; 549 data = docNode.getDocumentElement() ; 550 550 } 551 551 else { 552 552 data = (Element)dataNode; 553 553 } 554 554 … … 586 586 587 587 public void doPost(HttpServletRequest request, 588 HttpServletResponse response)588 HttpServletResponse response) 589 589 throws ServletException, IOException { 590 590 doGet(request,response);
Note:
See TracChangeset
for help on using the changeset viewer.