Changeset 23790
- Timestamp:
- 2011-03-15T16:58:16+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r19984 r23790 19 19 import org.apache.log4j.*; 20 20 21 // Apache Commons 22 import org.apache.commons.lang3.*; 21 23 22 24 /** a servlet to serve the greenstone library - we are using servlets instead … … 43 45 * otherwise DEFAULT_LANG is used*/ 44 46 protected String default_lang= null; 47 48 /** Whether or not client-side XSLT support should be exposed */ 49 protected boolean supports_client_xslt = false; 45 50 46 51 /** The default default - used if a default lang is not specified … … 87 92 String gsdl3_home = config.getInitParameter(GSConstants.GSDL3_HOME); 88 93 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 89 98 this.default_lang = config.getInitParameter(GSConstants.DEFAULT_LANG); 90 99 String sess_expire = config.getInitParameter(GSXML.SESSION_EXPIRATION); 100 91 101 if (sess_expire != null && !sess_expire.equals("")) { 92 102 this.session_expiration = Integer.parseInt(sess_expire); … … 125 135 126 136 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 128 140 if (site_name != null) { 129 141 config_params.put(GSConstants.SITE_NAME, site_name); … … 281 293 String query_string = request.getQueryString(); 282 294 if (query_string!=null){ 283 String[] query_arr = query_string.split("&");295 String[] query_arr = StringUtils.split(query_string, "&"); 284 296 boolean redirect = false; 285 297 String href = null; 286 298 String rl = null; 299 String[] nameval = new String[2]; // Reuse it for memory efficiency purposes 300 287 301 for (int i=0;i<query_arr.length;i++){ 302 288 303 if (query_arr[i].startsWith("el=")){ 289 304 if (query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()).equals("direct")){ … … 292 307 }else if(query_arr[i].startsWith("href=")){ 293 308 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", "\\:"); 298 313 }else if(query_arr[i].startsWith("rl=")){ 299 314 rl = query_arr[i].substring(query_arr[i].indexOf("=")+1,query_arr[i].length()); 300 315 } 301 316 } 317 302 318 //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 303 319 //"rl=0" this is an external link … … 308 324 } 309 325 } 326 310 327 // Nested Diagnostic Configurator to identify the client for 311 312 328 HttpSession session = request.getSession (true); 313 329 session.setMaxInactiveInterval(session_expiration); … … 338 354 output = "html"; // uses html by default 339 355 } 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 341 379 // the request to the receptionist 342 380 Element xml_message = this.doc.createElement (GSXML.MESSAGE_ELEM); 343 381 Element xml_request = GSXML.createBasicRequest (this.doc, GSXML.REQUEST_TYPE_PAGE, "", lang, uid); 344 382 xml_request.setAttribute (GSXML.OUTPUT_ATT, output); 383 345 384 xml_message.appendChild (xml_request); 346 385 … … 464 503 && !name.equals (GSParams.LANGUAGE) 465 504 && !name.equals (GSParams.OUTPUT)) {// we have already dealt with these 466 505 467 506 String value=""; 468 507 String [] values = request.getParameterValues (name); … … 509 548 510 549 // ugly hack to undo : escaping 511 value = value.replaceAll ("%3A", "\\:");550 value = StringUtils.replace(value, "%3A", "\\:"); 512 551 param.setAttribute (GSXML.VALUE_ATT,value); 513 552 xml_param_list.appendChild (param); … … 516 555 } 517 556 518 if (!output.equals ("html")) {557 if (!output.equals("html") && !output.equals("server") && !output.equals("xsltclient")) { 519 558 response.setContentType ("text/xml"); // for now use text 520 559 } … … 584 623 // get all the <a> elements 585 624 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++) { 587 629 Element a = (Element)hrefs.item(i); 588 630 // ugly hack to get rid of : in the args - interferes with session handling … … 590 632 if (!href.equals("")) { 591 633 if (href.indexOf("?")!=-1) { 592 String[] parts = href.split("\\?", -1);593 parts[1] =parts[1].replaceAll(":", "%3A");634 String[] parts = StringUtils.split(href, "\\?", -1); 635 parts[1] = StringUtils.replace(parts[1], ":", "%3A"); 594 636 href = parts[0]+"?"+parts[1]; 595 637 } … … 600 642 // now find any submit bits - get all the <form> elements 601 643 NodeList forms = data.getElementsByTagName("form"); 602 for (int i=0; forms!=null && i<forms.getLength(); i++) { 644 int formscount = forms.getLength(); 645 for (int i=0; forms!=null && i < formscount; i++) { 603 646 Element form = (Element)forms.item(i); 604 647 form.setAttribute("action", response.encodeURL(form.getAttribute("action")));
Note:
See TracChangeset
for help on using the changeset viewer.