1 15 package org.jahia.services.applications; 16 17 import java.io.PrintWriter ; 18 import java.io.StringWriter ; 19 import java.net.MalformedURLException ; 20 import java.net.URL ; 21 import java.net.URLDecoder ; 22 import java.security.Principal ; 23 import java.util.Collections ; 24 import java.util.Enumeration ; 25 import java.util.Hashtable ; 26 import java.util.List ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 30 import javax.servlet.RequestDispatcher ; 31 import javax.servlet.ServletContext ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletRequestWrapper ; 34 import javax.servlet.http.HttpSession ; 35 36 import org.apache.log4j.Logger; 37 import org.jahia.exceptions.JahiaException; 38 import org.jahia.exceptions.JahiaSessionExpirationException; 39 import org.jahia.params.ParamBean; 40 import org.jahia.registries.ServicesRegistry; 41 import org.jahia.security.license.LicenseConstants; 42 import org.jahia.services.usermanager.GenericPrincipal; 43 import org.jahia.services.usermanager.JahiaGroup; 44 import org.jahia.services.usermanager.JahiaUser; 45 46 63 64 public class ServletIncludeRequestWrapper extends HttpServletRequestWrapper { 65 66 private static Logger logger = Logger.getLogger(ServletIncludeRequestWrapper.class); 67 68 private String emulatedContextPath; 69 private URL emulatedURL; 70 private String emulatedMethod; 71 private Map parameters = new Hashtable (); 72 private boolean parsed = false; 73 private HttpSessionWrapper sessionWrapper; 74 private PersistantServletRequest appRequest; 75 private final ParamBean jahiaParams; 76 private String contextIdentifier; 78 private String emulatedServletPath = ""; 79 private String emulatedPathInfo = ""; 80 private String initialRequestURI = ""; 83 private boolean applicationCacheOn = true; 84 private long applicationCacheExpirationDelay = -1; 85 private boolean inheritJahiaSessionAttributes = false; 86 private boolean hideRequestParameter = false; 87 88 112 public ServletIncludeRequestWrapper(HttpServletRequest httpServletRequest, 113 String emulURL, String emulContextPath, String emulMethod, 114 PersistantServletRequest applicationRequest, String contextID, 115 boolean fullScreenActivated, boolean inheritJahiaSessionAttr, 116 ParamBean jParams) { 117 super(httpServletRequest); 118 initialRequestURI = super.getRequestURI(); 119 emulatedContextPath = emulContextPath; 120 emulatedMethod = emulMethod; 121 appRequest = applicationRequest; 122 jahiaParams = jParams; 123 contextIdentifier = contextID; 124 this.inheritJahiaSessionAttributes = inheritJahiaSessionAttr; 125 parsed = false; 126 129 setAttribute("originalRequest", getRequest()); 131 try { 132 133 String URLPort; 134 if (jahiaParams.getRealRequest().getServerPort() == 80) { 135 URLPort = ""; 136 } else { 137 Integer conv = new Integer (jahiaParams.getRealRequest() 138 .getServerPort()); 139 URLPort = ":" + conv.toString(); 140 } 141 142 URL contextURL = new URL (jahiaParams 143 .getRealRequest().getScheme() 144 + "://" 145 + jahiaParams.getRealRequest().getServerName() 146 + URLPort + "/"); 147 158 emulatedURL = new URL (contextURL, emulURL); 159 160 httpServletRequest.setAttribute("org.portletapi.portal", "true"); 161 162 httpServletRequest.setAttribute("org.portletapi.contextid", 163 contextID); 164 if (fullScreenActivated) { 165 httpServletRequest.setAttribute("org.portletapi.fullscreen", 166 "true"); 167 } else { 168 httpServletRequest.setAttribute("org.portletapi.fullscreen", 169 "false"); 170 } 171 httpServletRequest.setAttribute("org.jahia.sitekey", jParams 172 .getSiteKey()); 173 httpServletRequest.setAttribute("org.jahia.siteurl", jParams 174 .getSiteURL()); 175 httpServletRequest.setAttribute("org.jahia.siteid", Integer 176 .toString(jParams.getSiteID())); 177 httpServletRequest.setAttribute("org.jahia.pageid", Integer 178 .toString(jParams.getPageID())); 179 httpServletRequest.setAttribute("org.jahia.operationmode", jParams 180 .getOperationMode()); 181 186 httpServletRequest.setAttribute("org.jahia.license.licenseType", 187 new Integer (LicenseConstants.PROJODA_LICENSE_TYPE)); 188 189 this.hideRequestParameter = (!applicationRequest.getUniqueIDStr() 190 .equalsIgnoreCase( 191 jParams.getRealRequest().getParameter("appid"))); 192 193 parseParameters(httpServletRequest); 194 parseEmulatedURL(URLDecode(emulURL)); 195 } catch (MalformedURLException mue) { 196 logger.debug("Malformed URL", mue); 197 emulatedURL = null; 198 } catch (JahiaException je) { 199 logger 200 .debug("JahiaException in constructor of request wrapper", je); 201 emulatedURL = null; 202 } 203 logger.debug("emulatedURL value : [" + emulatedURL + "]"); 204 logger 205 .debug("super.requestURI value : [" + super.getRequestURI() + "]"); 206 logger.debug("initial requestURI value : [" + initialRequestURI + "]"); 207 208 } 209 210 221 public boolean hasRequestURIChanged() { 222 238 239 if (!super.getRequestURI().equals(initialRequestURI)) { 240 if (logger.isDebugEnabled()){ 241 logger.debug("Request URI Has changed ! emulatedURI=" 242 + initialRequestURI + ", super.getRequestURI()=" 243 + super.getRequestURI()); 244 if (this.emulatedURL != null) { 245 logger.debug(",emulatedURL=" + this.emulatedURL.toString()); 246 } 247 if (super.getRequestURL() != null) { 248 logger.debug(", super.getRequestURL()=" + super.getRequestURL() 249 + "\n"); 250 } else { 251 logger.debug(", super.getRequestURL()=null\n"); 252 } 253 } 254 261 262 this.initialRequestURI = super.getRequestURI(); 263 if (this.appRequest != null) { 264 updateEmulatedValues(); 266 this.parsed = false; 267 this.hideRequestParameter = false; 268 parseParameters(this); 269 } 270 return true; 271 } 272 273 return false; 274 } 275 276 private void updateEmulatedValues() { 277 try { 278 String URLPort; 279 if (getServerPort() == 80) { 280 URLPort = ""; 281 } else { 282 Integer conv = new Integer (getServerPort()); 283 URLPort = ":" + conv.toString(); 284 } 285 286 StringBuffer newRequestURL = new StringBuffer (super.getRequestURI()); 287 String queryString = (String ) getAttribute(RequestDispatcherWrapper.INCLUDE_QUERY_STRING); 288 if (queryString == null) { 289 queryString = (String ) getAttribute(RequestDispatcherWrapper.FORWARD_QUERY_STRING); 290 } 291 if (queryString == null) { 292 queryString = super.getQueryString(); 293 } 294 295 if (queryString != null && !"".equals(queryString.trim())) { 296 newRequestURL.append("?"); 297 newRequestURL.append(queryString); 298 } 299 300 URL contextURL = new URL (getScheme() + "://" 301 + getServerName() + URLPort + "/"); 302 emulatedURL = new URL (contextURL, newRequestURL.toString()); 303 parseEmulatedURL(newRequestURL.toString()); 304 305 if (queryString != null) { 306 logger.info("Parsing query string [" + queryString + "]"); 308 if (parameters == null) { 309 parameters = new Hashtable (); 310 } 311 312 parseStringParameters(parameters, queryString, 313 getCharacterEncoding(), false); 314 } 315 } catch (Throwable t) { 318 logger.debug("Error updating emulated values", t); 319 } 320 } 321 322 329 private void parseEmulatedURL(String url) throws JahiaException { 330 if (url == null) { 331 String errMsg = "App emulated URL is null !"; 332 throw new JahiaException(errMsg, errMsg, 333 JahiaException.ERROR_SEVERITY, JahiaException.APPLICATION_ERROR); 334 } 335 336 int pos = url.indexOf(appRequest.getContext()); 337 if (pos == -1) { 338 String errMsg = "App emulated URL doesn't contains the application context path !"; 339 throw new JahiaException(errMsg, errMsg, 340 JahiaException.ERROR_SEVERITY, JahiaException.APPLICATION_ERROR); 341 } 342 343 String path = url.substring(pos + appRequest.getContext().length()); 344 int pos2 = path.indexOf("?"); 345 346 String servletMappingPattern = appRequest.getServletMappingPattern(); 348 if (servletMappingPattern != null) { 349 if (servletMappingPattern.equals("/")) { 350 this.emulatedServletPath = ""; 352 this.emulatedPathInfo = ""; 353 } else if (servletMappingPattern.startsWith("/") 354 && servletMappingPattern.endsWith("/*")) { 355 this.emulatedServletPath = servletMappingPattern.substring(0, 357 servletMappingPattern.length() - 2); 358 359 if (pos2 == -1) { 360 this.emulatedPathInfo = path; 361 } else { 362 this.emulatedPathInfo = path.substring(0, pos2); 363 } 364 365 if (this.emulatedPathInfo.startsWith(this.emulatedServletPath)) { 370 this.emulatedPathInfo = this.emulatedPathInfo 371 .substring(this.emulatedServletPath.length()); 372 } 373 374 } else if (servletMappingPattern.startsWith("*.")) { 375 int pathSepPos = path.lastIndexOf("/"); 377 int pos3 = -1; 378 if (pathSepPos != -1) { 379 pos3 = path.indexOf(servletMappingPattern.substring(1), 380 pathSepPos); 381 } else { 382 pos3 = path.indexOf(servletMappingPattern.substring(1)); 383 } 384 if (pos3 != -1) { 385 this.emulatedServletPath = path.substring(0, pos3 386 + servletMappingPattern.length() - 1); 387 if (pos2 == -1) { 388 this.emulatedPathInfo = path; 389 } else { 390 this.emulatedPathInfo = path.substring(0, pos2); 391 } 392 if (this.emulatedPathInfo 393 .startsWith(this.emulatedServletPath)) { 394 this.emulatedPathInfo = this.emulatedPathInfo 395 .substring(this.emulatedServletPath.length()); 396 } 397 } 398 } else if (!servletMappingPattern.equals("")) { 399 this.emulatedServletPath = servletMappingPattern; 401 pos = path.indexOf(this.emulatedServletPath); 402 if (pos2 == -1) { 403 this.emulatedPathInfo = path; 404 } else { 405 this.emulatedPathInfo = path.substring(0, pos2); 406 } 407 if (this.emulatedPathInfo.startsWith(this.emulatedServletPath)) { 408 this.emulatedPathInfo = this.emulatedPathInfo 409 .substring(this.emulatedServletPath.length()); 410 } 411 } else { 412 if (appRequest.getWebAppType() == PersistantServletRequest.JSP_TYPE) { 413 if (pos2 == -1) { 415 this.emulatedServletPath = path; 416 } else { 417 this.emulatedServletPath = path.substring(0, pos2); 418 } 419 this.emulatedPathInfo = ""; 420 } 421 } 422 } else { 423 this.emulatedServletPath = ""; 424 this.emulatedPathInfo = ""; 425 } 426 427 if (this.emulatedPathInfo != null) { 428 int sessionIDPos = this.emulatedPathInfo 431 .lastIndexOf(";jsessionid="); 432 if (sessionIDPos != -1) { 433 this.emulatedPathInfo = this.emulatedPathInfo.substring(0, 435 sessionIDPos); 436 logger.debug("Removed session ID marker from end of path info"); 437 } 438 } 439 440 if (logger.isDebugEnabled()) { 441 logger.debug("url = [" + url + "]"); 442 logger.debug("emulated servlet path = [" + this.emulatedServletPath 443 + "]"); 444 logger 445 .debug("emulated path info = [" + this.emulatedPathInfo + "]"); 446 logger.debug("super.requestURI value : [" + super.getRequestURI() 447 + "]"); 448 logger.debug("initial requestURI value : [" + initialRequestURI 449 + "]"); 450 } 451 } 452 453 460 public ServletIncludeRequestWrapper(HttpServletRequest httpServletRequest, 461 ParamBean jParams) { 462 super(httpServletRequest); 463 emulatedContextPath = super.getContextPath(); 464 emulatedMethod = null; 465 emulatedURL = null; 466 jahiaParams = jParams; 467 } 468 469 public String getRemoteUser() { 470 if (emulatedURL != null) { 471 JahiaUser user = jahiaParams.getUser(); 472 if (user != null) { 473 return user.getUsername(); 476 } else { 477 return ""; 478 } 479 } else { 480 return super.getRemoteUser(); 481 } 482 } 483 484 487 public Principal getUserPrincipal() { 488 if (emulatedURL != null) { 489 JahiaUser user = jahiaParams.getUser(); 490 491 if (user != null) { 492 493 GenericPrincipal gPrincipal = new GenericPrincipal(user); 494 return gPrincipal; 495 496 } else { 497 return null; 498 } 499 500 } else { 501 return super.getUserPrincipal(); 502 } 503 } 504 505 515 516 public RequestDispatcher getRequestDispatcher(String path) { 517 logger.debug("path = [" + path + "]"); 518 if (emulatedURL != null) { 519 ServletContext dispatchedContext = jahiaParams.getContext() 520 .getContext(emulatedContextPath); 521 if (dispatchedContext == null) { 522 logger.debug("Error getting request context " 523 + emulatedContextPath + " for app " 524 + appRequest.getName()); 525 return null; 526 } 527 528 RequestDispatcher sessionDispatcher = dispatchedContext 530 .getRequestDispatcher(path); 531 return sessionDispatcher; 532 } else { 533 return super.getRequestDispatcher(path); 534 } 535 } 536 537 public boolean isUserInRole(String role) { 538 if (emulatedURL != null) { 540 if (jahiaParams == null) { 541 logger.debug("Jahia Params is null, exiting immediately..."); 542 return false; 543 } 544 JahiaUser user = jahiaParams.getUser(); 545 if (user != null) { 546 if (appRequest == null) { 547 logger 548 .debug("Null application request object, exiting isUserInRole..."); 549 return false; 550 } 551 if (appRequest.getApplicationBean() == null) { 552 logger 553 .debug("Null application bean object, exiting isUserInRole..."); 554 return false; 555 } 556 JahiaGroup roleGroup = ServicesRegistry.getInstance() 558 .getJahiaGroupManagerService().lookupGroup( 559 0, 560 appRequest.getApplicationBean().getID() + "_" 561 + contextIdentifier + "_" + role); 562 if (roleGroup != null) { 563 if (roleGroup.isMember(user) == true) { 564 logger.debug("User [" + user.getUsername() 565 + "] is a member of role [" 566 + roleGroup.getName() + "]"); 567 return true; } else { 570 logger.debug("User [" + user.getUsername() 571 + "] is NOT a member of role [" 572 + roleGroup.getName() + "]"); 573 return false; } 575 } else { 576 logger.debug("Role [" 577 + appRequest.getApplicationBean().getID() + "_" 578 + contextIdentifier + "_" + role 579 + "] not found in Jahia's groups!"); 580 return false; } 582 } else { 583 logger.debug("No user logged, ignoring call !"); 584 return false; 585 } 586 } else { 587 logger.debug("Using servlet API standard call..."); 589 return super.isUserInRole(role); 590 } 591 } 592 593 public void setContextPath(String newPath) { 594 logger.debug("setContextPath(" + newPath + ")"); 595 } 597 598 public String getContextPath() { 599 String contextPath = super.getContextPath(); 600 if (emulatedURL != null) { 601 if (hasRequestURIChanged()) { 602 return contextPath; 603 } 604 } 605 logger.debug(" super.getContextPath=[" + contextPath + "]"); 606 logger.debug("emulatedContextPath = [" + emulatedContextPath + "]"); 607 return emulatedContextPath; 608 } 609 610 private static String decode(String value, String encoding, 611 boolean urlParameters) { 612 if (value != null 613 && (value.indexOf('%') >= 0 || value.indexOf('+') >= 0)) { 614 try { 615 if (urlParameters) 616 value = URLDecode(value); 617 else 618 value = URLDecoder.decode(value, encoding); 619 } catch (Throwable t) { 620 logger.debug("Error during decoding", t); 621 } 622 } 623 return value; 624 } 625 626 645 public static void removeStringParameters(Map map, String data, 646 String encoding, boolean urlParameters) { 647 if (data == null || data.length() == 0) 648 return; 649 650 652 StringParser parser = new StringParser(data); 654 boolean first = true; 655 int nameStart = 0; 656 int nameEnd = 0; 657 int valueStart = 0; 658 int valueEnd = 0; 659 String name = null; 660 String value = null; 661 662 while (true) { 664 if (first) 666 first = false; 667 else 668 parser.advance(); 669 670 nameStart = parser.getIndex(); 671 nameEnd = parser.findChar('='); 672 parser.advance(); 673 valueStart = parser.getIndex(); 674 valueEnd = parser.findChar('&'); 675 name = parser.extract(nameStart, nameEnd); 676 value = parser.extract(valueStart, valueEnd); 677 678 if (name.length() < 1) 680 break; 681 682 name = decode(name, encoding, urlParameters); 684 value = decode(value, encoding, urlParameters); 685 686 map.remove(name); 688 } 689 } 690 691 713 public static void parseStringParameters(Map map, String data, 714 String encoding, boolean urlParameters) { 715 716 if ((data == null) || (data.length() < 1)) 717 return; 718 719 721 StringParser parser = new StringParser(data); 723 boolean first = true; 724 int nameStart = 0; 725 int nameEnd = 0; 726 int valueStart = 0; 727 int valueEnd = 0; 728 String name = null; 729 String value = null; 730 731 while (true) { 733 if (first) 735 first = false; 736 else 737 parser.advance(); 738 nameStart = parser.getIndex(); 739 nameEnd = parser.findChar('='); 740 parser.advance(); 741 valueStart = parser.getIndex(); 742 valueEnd = parser.findChar('&'); 743 name = parser.extract(nameStart, nameEnd); 744 value = parser.extract(valueStart, valueEnd); 745 746 if (name.length() < 1) 748 break; 749 750 name = decode(name, encoding, urlParameters); 753 value = decode(value, encoding, urlParameters); 754 755 map.put(name, value); 758 } 759 } 760 761 769 protected void parseParameters(HttpServletRequest originalRequest) { 770 771 773 if (parsed) 774 return; 775 776 Map results = parameters; 777 if (results == null) 778 results = new Hashtable (); 779 780 785 if (!this.hideRequestParameter) { 786 Enumeration paramNames = originalRequest.getParameterNames(); 787 while (paramNames.hasMoreElements()) { 788 String paramName = (String ) paramNames.nextElement(); 789 results.put(paramName, originalRequest 790 .getParameterValues(paramName)); 791 } 792 } 793 794 String encoding = originalRequest.getCharacterEncoding(); 798 removeStringParameters(results, originalRequest.getQueryString(), 799 encoding, true); 800 801 String queryString = emulatedURL.getQuery(); 803 if (queryString != null && queryString.length() != 0) { 805 try { 806 parseStringParameters(results, queryString, encoding, true); 807 } catch (Throwable t) { 808 logger.debug("Error parsing URL parameters !"); 809 } 810 } 811 812 822 parsed = true; 823 parameters = results; 824 } 825 826 836 public static String URLDecode(String str) throws IllegalArgumentException { 837 838 if (str == null) 839 return (null); 840 841 StringBuffer dec = new StringBuffer (); 842 int pos = 0; 843 int len = str.length(); 844 dec.ensureCapacity(str.length()); 845 846 while (pos < len) { 847 int lookahead; 849 for (lookahead = pos; lookahead < len; lookahead++) { 851 char ch = str.charAt(lookahead); 852 if ((ch == '+') || (ch == '%')) 853 break; 854 } 855 856 if (lookahead > pos) { 858 dec.append(str.substring(pos, lookahead)); 859 pos = lookahead; 860 } 861 862 if (pos >= len) 864 break; 865 866 char meta = str.charAt(pos); 868 if (meta == '+') { 869 dec.append(' '); 870 pos++; 871 } else if (meta == '%') { 872 try { 873 dec.append((char) Integer.parseInt(str.substring(pos + 1, 874 pos + 3), 16)); 875 } catch (NumberFormatException e) { 876 throw new IllegalArgumentException ("Invalid hexadecimal '" 877 + str.substring(pos + 1, pos + 3) 878 + " in URLencoded string"); 879 } catch (StringIndexOutOfBoundsException e) { 880 throw new IllegalArgumentException ( 881 "Invalid unescaped '%' in URLcoded string"); 882 } 883 pos += 3; 884 } 885 } 886 return (dec.toString()); 887 888 } 889 890 public String getRequestURI() { 891 892 String requestURI = super.getRequestURI(); 893 logger.debug(" super.getRequestURI()=[" + requestURI + "]"); 894 895 if (emulatedURL != null) { 896 if (hasRequestURIChanged()) { 897 return requestURI; 898 } 899 900 String requestURL = getContextPath(); 901 if (appRequest.getWebAppType() == PersistantServletRequest.SERVLET_TYPE) { 902 if (this.emulatedServletPath.length() > 0) { 903 if (!this.emulatedServletPath.startsWith("/")) { 904 requestURL += "/"; 905 } 906 requestURL += this.emulatedServletPath; 907 } 908 requestURL += this.emulatedPathInfo; 909 } else { 910 if (!appRequest.getservletsrc().startsWith("/")) { 911 requestURL += "/"; 912 } 913 requestURL += appRequest.getservletsrc(); 914 } 915 917 logger.debug("emulated requestURI = [" + requestURL + "]"); 918 return requestURL; 920 } else { 921 return super.getRequestURI(); 922 } 923 } 924 925 public StringBuffer getRequestURL() { 926 StringBuffer requestURL = super.getRequestURL(); 927 String reqURL = ""; 928 if (requestURL != null) { 929 reqURL = requestURL.toString(); 930 } 931 String emulURL = ""; 932 if (emulatedURL != null) { 933 emulURL = emulatedURL.toString(); 934 } 935 logger.debug(" super.getRequestURL()=[" + reqURL + "], emulatedURL=" 936 + emulURL); 937 938 if (emulatedURL != null) { 939 if (hasRequestURIChanged()) { 940 return requestURL; 941 } 942 946 logger.debug("emulated requestURL = [" + emulatedURL + "]"); 947 return new StringBuffer (emulatedURL.toString()); 948 } else { 949 return super.getRequestURL(); 950 } 951 } 952 953 public String getServletPath() { 954 String servletPath = super.getServletPath(); 955 String pathInfo = super.getPathInfo(); 956 logger.debug("super.getServletPath()=[" + servletPath + "]"); 957 logger 958 .debug("emulated servlet path [" + this.emulatedServletPath + "]"); 959 logger.debug("while super.getPathInfo()=[" + pathInfo + "]"); 960 961 if (emulatedURL != null) { 962 963 if (hasRequestURIChanged()) { 964 logger 965 .debug("Request URI has changed, returning super.getServletPath=[" 966 + servletPath + "]"); 967 return servletPath; 968 } 970 971 975 if (servletPath.endsWith(".jsp")) { 976 982 logger.debug("JSP servlet path (" + servletPath 983 + ") detected, returning server path..."); 984 985 this.emulatedServletPath = servletPath; 986 if (super.getPathInfo() != null) { 987 this.emulatedPathInfo = super.getPathInfo(); 988 } else { 989 this.emulatedPathInfo = ""; 990 } 991 992 if (super.getMethod() != null) { 993 this.emulatedMethod = super.getMethod(); 994 } else { 995 this.emulatedMethod = ""; 996 } 997 return servletPath; 998 } 999 1000 logger.debug("emulated servlet path [" + this.emulatedServletPath 1001 + "]"); 1002 return this.emulatedServletPath; 1003 } 1004 1005 return super.getServletPath(); 1006 1007 } 1008 1009 public String getQueryString() { 1010 String queryString = super.getQueryString(); 1011 logger.debug("super.getQueryString()=[" + queryString + "]"); 1012 if (emulatedURL != null) { 1013 if (hasRequestURIChanged()) { 1014 return queryString; 1015 } 1016 1017 logger.debug("getQueryString() = [" + emulatedURL.getQuery() + "]"); 1018 return emulatedURL.getQuery(); 1019 } else { 1020 return super.getQueryString(); 1021 } 1022 } 1023 1024 public String getPathTranslated() { 1025 if (emulatedURL != null) { 1026 logger.debug("getPathTranslated() = [" + super.getPathTranslated() 1027 + "]"); 1028 return super.getPathTranslated(); 1029 } else { 1030 return super.getPathTranslated(); 1031 } 1032 } 1033 1034 public Locale getLocale() { 1035 Locale loc; 1036 if (emulatedURL != null || jahiaParams != null) 1037 loc = jahiaParams.getLocale(); 1038 else 1039 loc = super.getLocale(); 1040 logger.debug("getLocale() = [" + loc + "]"); 1041 return loc; 1042 } 1043 1044 public Enumeration getLocales() { 1045 if (emulatedURL != null) { 1046 List locales; 1047 try { 1048 locales = jahiaParams.getLocales(); 1049 } catch (Throwable ex) { 1050 logger.debug("error getting locales", ex); 1051 locales = Collections.singletonList(Locale.getDefault()); 1052 } 1053 logger.debug("getLocale() = [" + locales + "]"); 1054 return Collections.enumeration(locales); 1055 } else { 1056 logger.debug("getLocale() = [" + super.getLocales() + "]"); 1057 return super.getLocales(); 1058 } 1059 } 1060 1061 public String getPathInfo() { 1062 String pathInfo = super.getPathInfo(); 1063 logger.debug("super.getPathInfo()=[" + pathInfo + "]"); 1064 1065 if (emulatedURL == null) { 1066 logger.debug("getPathInfo() = [" + pathInfo + "]"); 1067 return pathInfo; 1068 } else { 1069 if (hasRequestURIChanged()) { 1070 return pathInfo; 1071 } 1072 logger.debug("getPathInfo() emulated pathInfo = [" 1073 + this.emulatedPathInfo + "]"); 1074 return this.emulatedPathInfo; 1075 } 1076 } 1077 1078 public String getParameter(String name) { 1079 if (emulatedURL != null && !hasRequestURIChanged()) { 1081 if (parameters == null) { 1082 } 1084 1085 Object objValue = parameters.get(name); 1086 if (objValue == null) { 1087 return null; 1089 } 1090 Class classValue = objValue.getClass(); 1091 1092 if (classValue.isArray()) { 1093 1094 String [] value = (String []) parameters.get(name); 1095 if (value == null) { 1096 return null; 1097 } else { 1098 } 1101 1102 return value[0]; 1104 } else { 1105 String value = (String ) objValue; 1106 return value; 1108 } 1109 } else { 1110 return super.getParameter(name); 1113 } 1114 } 1115 1116 public Enumeration getParameterNames() { 1117 if (emulatedURL != null && !hasRequestURIChanged()) { 1119 return new Hashtable (parameters).keys(); 1120 } else { 1121 return super.getParameterNames(); 1122 } 1123 } 1124 1125 public String [] getParameterValues(String name) { 1126 logger.debug("getParameterValues(" + name + ")"); 1127 if (emulatedURL != null && !hasRequestURIChanged()) { 1128 1129 Object objValue = parameters.get(name); 1130 if (objValue == null) { 1131 return null; 1133 } 1134 Class classValue = objValue.getClass(); 1135 1136 if (classValue.isArray()) { 1137 1138 String [] value = (String []) parameters.get(name); 1139 return value; 1140 } else { 1141 String value = (String ) objValue; 1142 String [] valueArray = { value }; 1144 return valueArray; 1145 } 1146 1147 1152 } else { 1153 return super.getParameterValues(name); 1154 } 1155 } 1156 1157 public Map getParameterMap() { 1158 if (emulatedURL != null && !hasRequestURIChanged()) { 1159 logger.debug("getParameterMap()"); 1160 return Collections.unmodifiableMap(parameters); 1161 } else { 1162 return super.getParameterMap(); 1163 } 1164 } 1165 1166 public void setAttribute(String name, Object o) { 1167 if (o != null) { 1168 if (name.equals("javax.servlet.jsp.jspException")) { 1170 StringWriter sw = new StringWriter (); 1172 PrintWriter pw = new PrintWriter (sw); 1173 Throwable t = (Throwable ) o; 1174 t.printStackTrace(pw); 1175 logger.debug("Exception : " + sw.toString()); 1176 } 1177 } 1178 String objValue = "null"; 1179 if (o != null) { 1180 objValue = objValue.toString(); 1181 } 1182 logger.debug("setAttribute(" + name + ", " + objValue + ")"); 1183 1184 if (emulatedURL != null) { 1185 if ("org.jahia.portletapi.CacheExpirationDelay".equals(name)) { 1190 Long delay = (Long ) o; 1191 applicationCacheExpirationDelay = delay.longValue(); 1192 if (applicationCacheExpirationDelay == 0) { 1193 applicationCacheOn = false; 1194 } 1195 } else { 1196 super.setAttribute(name, o); 1197 } 1198 } else { 1199 super.setAttribute(name, o); 1200 } 1201 1202 } 1203 1204 public void removeAttribute(String name) { 1205 logger.debug("removeAttribute(" + name + ")"); 1206 super.removeAttribute(name); 1207 } 1208 1209 public Object getAttribute(String name) { 1210 logger.debug("getAttribute(" + name + ")"); 1211 if (super.getAttribute(name) == null) { 1212 if ("org.portletapi.userlist".equals(name)) { 1213 super.setAttribute("org.portletapi.userlist", appRequest 1214 .getAppContextUsers()); 1215 } 1216 } 1217 return super.getAttribute(name); 1218 } 1219 1220 public HttpSession getSession(boolean create) { 1221 if (emulatedURL != null) { 1222 if (sessionWrapper == null) { 1224 try { 1225 sessionWrapper = new HttpSessionWrapper(jahiaParams 1226 .getSession(create), appRequest.getApplicationBean() 1227 .getName(), contextIdentifier, 1228 inheritJahiaSessionAttributes); 1229 } catch (JahiaSessionExpirationException ex) { 1230 logger.debug("Session exception, create=" + create, ex); 1231 return null; 1232 } 1233 1234 } 1235 return sessionWrapper; 1236 } else { 1237 return super.getSession(create); 1239 } 1240 } 1241 1242 public HttpSession getSession() { 1243 return getSession(true); 1244 } 1245 1246 public String getMethod() { 1247 if (emulatedURL != null) { 1248 return emulatedMethod; 1249 } else { 1250 return super.getMethod(); 1251 } 1252 } 1253 1254 public PersistantServletRequest getPersistantServletRequest() { 1255 return this.appRequest; 1256 } 1257 1258 public boolean isApplicationCacheOn() { 1259 return applicationCacheOn; 1260 } 1261 1262 public long getApplicationCacheExpirationDelay() { 1263 return applicationCacheExpirationDelay; 1264 } 1265 1266} | Popular Tags |