Ignore:
Timestamp:
2011-05-09T14:37:04+12:00 (13 years ago)
Author:
sjm84
Message:

Updating this branch to match the latest Greenstone3 changes

Location:
main/branches/64_bit_Greenstone/greenstone3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone3

  • main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r19984 r24007  
    1919import org.apache.log4j.*;
    2020
     21// Apache Commons
     22import org.apache.commons.lang3.*;
    2123
    2224/** a servlet to serve the greenstone library - we are using servlets instead
     
    4345   * otherwise DEFAULT_LANG is used*/
    4446  protected String default_lang= null;
     47 
     48  /** Whether or not client-side XSLT support should be exposed */
     49  protected boolean supports_client_xslt = false;
    4550
    4651  /** The default default - used if a default lang is not specified
     
    8792    String gsdl3_home = config.getInitParameter(GSConstants.GSDL3_HOME);
    8893    String interface_name = config.getInitParameter(GSConstants.INTERFACE_NAME);
     94   
     95    String allowXslt = (String)config.getInitParameter(GSConstants.ALLOW_CLIENT_SIDE_XSLT);
     96    supports_client_xslt = allowXslt != null && allowXslt.equals("true");
     97   
    8998    this.default_lang = config.getInitParameter(GSConstants.DEFAULT_LANG);
    9099    String sess_expire = config.getInitParameter(GSXML.SESSION_EXPIRATION);
     100   
    91101    if (sess_expire != null && !sess_expire.equals("")) {
    92102      this.session_expiration = Integer.parseInt(sess_expire);
     
    125135   
    126136    config_params.put(GSConstants.LIBRARY_NAME, library_name);
    127     config_params.put(GSConstants.INTERFACE_NAME, interface_name);
     137    config_params.put(GSConstants.INTERFACE_NAME, interface_name); 
     138    config_params.put(GSConstants.ALLOW_CLIENT_SIDE_XSLT, supports_client_xslt);
     139   
    128140    if (site_name != null) {
    129141      config_params.put(GSConstants.SITE_NAME, site_name);
     
    281293    String query_string = request.getQueryString();
    282294    if (query_string!=null){
    283       String[] query_arr = query_string.split("&");
     295      String[] query_arr = StringUtils.split(query_string, "&");
    284296      boolean redirect = false;
    285297      String href = null;
    286298      String rl = null;
     299      String[] nameval = new String[2]; // Reuse it for memory efficiency purposes 
     300
    287301      for (int i=0;i<query_arr.length;i++){
     302
    288303        if (query_arr[i].startsWith("el=")){
    289304          if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){
     
    292307        }else if(query_arr[i].startsWith("href=")){
    293308          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", "\\:");
     309          href = StringUtils.replace(href, "%2f", "/");
     310          href = StringUtils.replace(href, "%7e", "~");
     311          href = StringUtils.replace(href, "%3f", "?");
     312          href = StringUtils.replace(href, "%3A", "\\:");
    298313        }else if(query_arr[i].startsWith("rl=")){
    299314          rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length());
    300315        }
    301316      }
     317
    302318      //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
    303319      //"rl=0" this is an external link
     
    308324      }
    309325    }
     326   
    310327    // Nested Diagnostic Configurator to identify the client for
    311    
    312328    HttpSession session = request.getSession (true);
    313329    session.setMaxInactiveInterval(session_expiration);
     
    338354      output = "html"; // uses html by default
    339355    }
    340    
     356   
     357    // If server output, force a switch to traditional interface
     358    //output = (output.equals("server")) ? "html" : output;
     359   
     360    // Force change the output mode if client-side XSLT is supported - server vs. client
     361    // BUT only if the library allows client-side transforms   
     362    if(supports_client_xslt) {
     363        // MUST be done before the xml_message is built
     364        Cookie[] cookies = request.getCookies();
     365        Cookie xsltCookie = null;
     366       
     367        // The client has cookies enabled and a value set - use it!
     368        if(cookies != null) {
     369            for(Cookie c : cookies) {
     370                if(c.getName().equals("supportsXSLT")) {
     371                    xsltCookie = c;
     372                    break;
     373                }
     374            }
     375            output = (xsltCookie != null && xsltCookie.getValue().equals("true") && output.equals("html")) ? "xsltclient" : output;
     376        }
     377    }
     378   
    341379    // the request to the receptionist
    342380    Element xml_message = this.doc.createElement (GSXML.MESSAGE_ELEM);
    343381    Element xml_request = GSXML.createBasicRequest (this.doc, GSXML.REQUEST_TYPE_PAGE, "", lang, uid);
    344382    xml_request.setAttribute (GSXML.OUTPUT_ATT, output);
     383   
    345384    xml_message.appendChild (xml_request);
    346385   
     
    464503          && !name.equals (GSParams.LANGUAGE)
    465504          && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these
    466 
     505         
    467506          String value="";
    468507          String [] values = request.getParameterValues (name);
     
    509548
    510549          // ugly hack to undo : escaping
    511           value = value.replaceAll ("%3A", "\\:");
     550          value = StringUtils.replace(value, "%3A", "\\:");
    512551          param.setAttribute (GSXML.VALUE_ATT,value);
    513552          xml_param_list.appendChild (param);
     
    516555    }
    517556     
    518     if (!output.equals ("html")) {
     557    if (!output.equals("html") && !output.equals("server") && !output.equals("xsltclient")) {
    519558      response.setContentType ("text/xml"); // for now use text
    520559    }
     
    584623        // get all the <a> elements
    585624        NodeList hrefs = data.getElementsByTagName("a");
    586         for (int i=0; hrefs!=null && i<hrefs.getLength(); i++) {
     625        // Instead of calculating each iteration...
     626        int hrefscount = hrefs.getLength();
     627
     628        for (int i=0; hrefs!=null && i < hrefscount; i++) {
    587629          Element a = (Element)hrefs.item(i);
    588630          // ugly hack to get rid of : in the args - interferes with session handling
     
    590632          if (!href.equals("")) {
    591633            if (href.indexOf("?")!=-1) {
    592               String[] parts = href.split("\\?", -1);
    593               parts[1]=parts[1].replaceAll(":", "%3A");
    594               href = parts[0]+"?"+parts[1];
     634              String[] parts = StringUtils.split(href, "\\?", -1);
     635              if (parts.length == 1)
     636              {
     637                parts[0] = StringUtils.replace(parts[0], ":", "%3A");
     638                href = "?"+parts[0];
     639              }
     640              else
     641              {
     642                parts[1] = StringUtils.replace(parts[1], ":", "%3A");
     643                href = parts[0]+"?"+parts[1];
     644              }
     645             
    595646            }
    596647            a.setAttribute("href", response.encodeURL(href));
     
    600651        // now find any submit bits - get all the <form> elements
    601652        NodeList forms = data.getElementsByTagName("form");
    602         for (int i=0; forms!=null && i<forms.getLength(); i++) {
     653        int formscount = forms.getLength();
     654        for (int i=0; forms!=null && i < formscount; i++) {
    603655          Element form = (Element)forms.item(i);
    604656          form.setAttribute("action", response.encodeURL(form.getAttribute("action")));
Note: See TracChangeset for help on using the changeset viewer.