Changeset 16926

Show
Ignore:
Timestamp:
21.08.2008 09:48:20 (11 years ago)
Author:
kjdon
Message:

indented the file consistently

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r16688 r16926  
    8888    String sess_expire = config.getInitParameter(GSXML.SESSION_EXPIRATION); 
    8989    if (sess_expire != null && !sess_expire.equals("")) { 
    90         this.session_expiration = Integer.parseInt(sess_expire); 
     90      this.session_expiration = Integer.parseInt(sess_expire); 
    9191    } 
    9292     
     
    250250    protected void cleanupCache(String coll_name) { 
    251251      if (coll_name_params_table.containsKey(coll_name)) { 
    252           coll_name_params_table.remove(coll_name); 
     252    coll_name_params_table.remove(coll_name); 
    253253      } 
    254254    } 
    255255    protected Hashtable getParamsTable() { 
    256         return coll_name_params_table; 
     256      return coll_name_params_table; 
    257257    } 
    258258    public void valueBound(HttpSessionBindingEvent event) { 
    259     // Do nothing 
     259      // Do nothing 
    260260    } 
    261261 
     
    266266    } 
    267267    public int tableSize() { 
    268         return (coll_name_params_table == null)? 0 : coll_name_params_table.size(); 
     268      return (coll_name_params_table == null)? 0 : coll_name_params_table.size(); 
    269269    } 
    270270  } 
    271271   
    272272  public void doGet (HttpServletRequest request, 
    273     HttpServletResponse response) 
     273             HttpServletResponse response) 
    274274    throws ServletException, IOException { 
    275275    logUsageInfo (request); 
     
    277277    String query_string = request.getQueryString(); 
    278278    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()); 
    297296    } 
    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      } 
    305305    } 
    306306    // Nested Diagnostic Configurator to identify the client for 
     
    345345    String collection = request.getParameter(GSParams.COLLECTION); 
    346346 
    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 
     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 
    349349    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); 
    367364    } 
    368  
     365      } 
     366      should_cache = false; 
     367    } 
     368     
    369369    //  logger.info("should_cache= " + should_cache); 
    370370    //clear the collection-specific cache in the session, since we have no way to know whether this session is  
     
    372372    Enumeration attributeNames = session.getAttributeNames(); 
    373373    while(attributeNames.hasMoreElements()) { 
    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  
     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     
    382382    // create a dumy collection name for Authentication  
    383383    if (subaction != null && subaction.equals("authen")){ 
    384     collection = "0000000000"; 
     384      collection = "0000000000"; 
    385385    } 
    386386     
     
    390390    String sid = session.getId(); 
    391391    if (should_cache == true && collection != null && !collection.equals("")) { 
    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         } 
     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      } 
    414414    } 
    415415 
     
    439439        String name = (String)params.nextElement (); 
    440440        if (!name.equals (GSParams.ACTION)  
    441                 && !name.equals (GSParams.SUBACTION)  
    442                 && !name.equals (GSParams.LANGUAGE)  
    443                 && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 
     441        && !name.equals (GSParams.SUBACTION)  
     442        && !name.equals (GSParams.LANGUAGE)  
     443        && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 
    444444          String value=""; 
    445445          String [] values = request.getParameterValues (name); 
     
    452452          // either add it to the param list straight away, or save it to the session and add it later 
    453453          if (this.params.shouldSave (name)) { 
    454               if (table != null) {               
    455                   table.put(name, value);                     
    456               } 
     454        if (table != null) {                 
     455          table.put(name, value);                     
     456        } 
    457457          } else { 
    458458            Element param = this.doc.createElement (GSXML.PARAM_ELEM); 
     
    465465      //put everything in the table into the session 
    466466      if (table != null) { 
    467           Enumeration keys = table.keys (); 
    468           while(keys.hasMoreElements ()) { 
    469               String name = (String)keys.nextElement(); 
    470               session.setAttribute(name, (String)table.get(name)); 
    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    } 
    472472      } 
    473473       
     
    478478         
    479479        if ( !name.equals (GSXML.USER_SESSION_CACHE_ATT)  
    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 
     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 
    483483          Element param = this.doc.createElement (GSXML.PARAM_ELEM); 
    484484          param.setAttribute (GSXML.NAME_ATT, name); 
     
    506506  //a debugging method 
    507507  private void displaySize(Hashtable table) { 
    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); 
     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); 
    522522  }   
    523523  /** merely a debugging method! */ 
    524524  private String tableToString(Hashtable table) { 
    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; 
     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; 
    532532  } 
    533533 
     
    546546    short nodeType = dataNode.getNodeType(); 
    547547    if (nodeType == Node.DOCUMENT_NODE) { 
    548     Document docNode = (Document)dataNode; 
    549     data = docNode.getDocumentElement() ; 
     548      Document docNode = (Document)dataNode; 
     549      data = docNode.getDocumentElement() ; 
    550550    } 
    551551    else { 
    552     data = (Element)dataNode; 
     552      data = (Element)dataNode; 
    553553    } 
    554554 
     
    586586   
    587587  public void doPost(HttpServletRequest request, 
    588     HttpServletResponse response) 
     588             HttpServletResponse response) 
    589589    throws ServletException, IOException { 
    590590    doGet(request,response);