Changeset 18223

Show
Ignore:
Timestamp:
17.12.2008 14:17:05 (10 years ago)
Author:
oranfry
Message:

fixed tabbing in this file

Files:
1 modified

Legend:

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

    r16938 r18223  
    3939  /** the receptionist to send messages to */ 
    4040  protected Receptionist recept=null; 
     41 
    4142  /** the default language - is specified by setting a servlet param, 
    4243   * otherwise DEFAULT_LANG is used*/ 
    4344  protected String default_lang= null; 
     45 
    4446  /** The default default - used if a default lang is not specified 
    4547   * in the servlet params */ 
    4648  protected final String DEFAULT_LANG = "en"; 
     49 
    4750  /** container Document to create XML Nodes */ 
    4851  protected Document doc=null; 
     52 
    4953  /** a converter class to parse XML and create Docs */ 
    5054  protected XMLConverter converter=null; 
     55 
    5156  /** the cgi stuff - the Receptionist can add new args to this 
    5257   * 
     
    7883    // disable preferences - does this work anyway?? 
    7984    //System.setProperty("java.util.prefs.PreferencesFactory", "org.greenstone.gsdl3.util.DisabledPreferencesFactory"); 
    80      
    8185     
    8286    String library_name = config.getInitParameter(GSConstants.LIBRARY_NAME); 
     
    247251    protected void cleanupCache(String coll_name) { 
    248252      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 
    252257    protected Hashtable getParamsTable() { 
    253258      return coll_name_params_table; 
    254259    } 
     260 
    255261    public void valueBound(HttpSessionBindingEvent event) { 
    256262      // Do nothing 
     
    262268      } 
    263269    } 
     270 
    264271    public int tableSize() { 
    265272      return (coll_name_params_table == null)? 0 : coll_name_params_table.size(); 
    266273    } 
    267   } 
    268    
    269   public void doGet (HttpServletRequest request, 
    270             HttpServletResponse response) 
     274 
     275  } 
     276   
     277  public void doGet (HttpServletRequest request, HttpServletResponse response) 
    271278    throws ServletException, IOException { 
    272279    logUsageInfo (request); 
     
    279286      String rl = null; 
    280287      for (int i=0;i<query_arr.length;i++){ 
    281     if (query_arr[i].startsWith("el")){ 
    282       if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){ 
    283         redirect = true; 
    284       } 
    285     }else if(query_arr[i].startsWith("href")){ 
    286       href = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 
    287       href = href.replaceAll("%2f", "/"); 
    288       href = href.replaceAll("%7e", "~"); 
    289       href = href.replaceAll("%3f", "?"); 
    290       href = href.replaceAll("%3A", "\\:"); 
    291     }else if(query_arr[i].startsWith("rl")){ 
    292       rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 
    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        } 
    294301      } 
    295302      //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 
     
    297304      //"rl=1" this is an internal link 
    298305      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     response.setContentType("text/xml"); 
    300     response.sendRedirect(href); 
     306        response.setContentType("text/xml"); 
     307        response.sendRedirect(href); 
    301308      } 
    302309    } 
     
    357364      String coll = request.getParameter(GSParams.SYSTEM_CLUSTER); 
    358365      if (coll != null && !coll.equals("")) { 
    359     clean_all = false; 
    360     clean_collection = coll; 
     366        clean_all = false; 
     367        clean_collection = coll; 
    361368      } else { 
    362     // check other system types 
    363     if (subaction.equals("a") || subaction.equals("d")) { 
    364       String module_name = request.getParameter("sn"); 
    365       if (module_name != null && !module_name.equals("")) { 
    366         clean_all = false; 
    367         clean_collection = module_name; 
    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        } 
    370377      } 
    371378      if (clean_all) { 
    372     session_ids_table = new Hashtable();  
    373     session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 
     379        session_ids_table = new Hashtable();  
     380        session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 
    374381      } else { 
    375     // just clean up info for clean_collection 
    376     ArrayList cache_list = new ArrayList(session_ids_table.values()); 
    377     for (int i=0; i<cache_list.size(); i++) { 
    378       UserSessionCache cache = (UserSessionCache)cache_list.get(i); 
    379       cache.cleanupCache(clean_collection); 
    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     
    382389      } 
    383390 
     
    390397    } 
    391398     
    392     //  logger.info("should_cache= " + should_cache); 
     399    // logger.info("should_cache= " + should_cache); 
    393400 
    394401    //clear the collection-specific cache in the session, since we have no way to know whether this session is  
     
    398405      String name = (String)attributeNames.nextElement(); 
    399406      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); 
    403411      } 
    404412    } 
     
    408416      cache_key = "0000000000"; 
    409417    } 
    410      
     418     
    411419    UserSessionCache session_cache = null; 
    412420    Hashtable param_table = null;     
     
    415423    if (should_cache == true && cache_key != null && !cache_key.equals("")) { 
    416424      if (session_ids_table.containsKey(sid)) { 
    417     session_cache = (UserSessionCache)session_ids_table.get(sid); 
    418     param_table = session_cache.getParamsTable(); 
    419     logger.info("collections in table: " + tableToString(param_table)); 
    420     if (param_table.containsKey(cache_key)) { 
    421       //logger.info("existing table: " + collection); 
    422       table = (Hashtable)param_table.get(cache_key); 
    423     } else { 
    424       table = new Hashtable(); 
    425       param_table.put(cache_key, table); 
    426       //logger.info("new table: " + collection); 
    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        } 
    428436      } else { 
    429     param_table = new Hashtable(); 
    430     table = new Hashtable(); 
    431     param_table.put(cache_key, table); 
    432     session_cache = new UserSessionCache(sid, param_table); 
    433     session_ids_table.put(sid, session_cache); 
    434     session.setAttribute(GSXML.USER_SESSION_CACHE_ATT, session_cache); 
    435     //logger.info("new session id"); 
     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"); 
    436444      } 
    437445    } 
     
    446454      xml_request.setAttribute (GSXML.ACTION_ATT, action); 
    447455      if (subaction != null) { 
    448     xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 
     456        xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 
    449457      } 
    450458       
     
    457465      while(params.hasMoreElements ()) { 
    458466        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 
    463472          String value=""; 
    464473          String [] values = request.getParameterValues (name); 
     
    471480          // either add it to the param list straight away, or save it to the session and add it later 
    472481          if (this.params.shouldSave (name) && table != null) { 
    473           table.put(name, value);                     
     482            table.put(name, value); 
    474483          } else { 
    475484            Element param = this.doc.createElement (GSXML.PARAM_ELEM); 
     
    483492      // do we need to do this? why not just put from table into param list 
    484493      if (table != null) { 
    485     Enumeration keys = table.keys (); 
    486     while(keys.hasMoreElements ()) { 
    487       String name = (String)keys.nextElement(); 
    488       session.setAttribute(name, (String)table.get(name)); 
    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        } 
    490499      } 
    491500       
     
    496505         
    497506        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 
    501511          Element param = this.doc.createElement (GSXML.PARAM_ELEM); 
    502512          param.setAttribute (GSXML.NAME_ATT, name); 
    503513          String value =  GSXML.xmlSafe ((String)session.getAttribute (name)); 
     514 
    504515          // ugly hack to undo : escaping 
    505516          value = value.replaceAll ("%3A", "\\:"); 
     
    521532     
    522533    displaySize(session_ids_table); 
    523 } 
     534 
     535  } //end of doGet(HttpServletRequest, HttpServletResponse) 
    524536 
    525537  //a debugging method 
     
    536548    ArrayList cache_list = new ArrayList(table.values()); 
    537549    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(); 
    539551    } 
    540552    logger.info("Number of sessions : total number of cached collection info = " + table.size() + " : " + num_cached_coll); 
    541   }   
     553  } 
     554 
    542555  /** merely a debugging method! */ 
    543556  private String tableToString(Hashtable table) { 
     
    604617  } 
    605618   
    606   public void doPost(HttpServletRequest request, 
    607              HttpServletResponse response) 
     619  public void doPost(HttpServletRequest request, HttpServletResponse response) 
    608620    throws ServletException, IOException { 
     621 
    609622    doGet(request,response); 
    610623     
    611624  } 
     625 
    612626}