📄 servletincluderequestwrapper.java
字号:
if (meta == '+') { dec.append(' '); pos++; } else if (meta == '%') { try { dec.append((char) Integer.parseInt (str.substring(pos+1, pos+3), 16)); } catch (NumberFormatException e) { throw new IllegalArgumentException ("Invalid hexadecimal '" + str.substring(pos+1, pos+3) + " in URLencoded string"); } catch (StringIndexOutOfBoundsException e) { throw new IllegalArgumentException ("Invalid unescaped '%' in URLcoded string"); } pos += 3; } } return (dec.toString()); } public String getRequestURI() { String requestURI = super.getRequestURI(); JahiaConsole.println("RequestWrapper", "super.getRequestURI()=[" + requestURI + "]"); if (emulatedURL != null) { if ( hasRequestURIChanged() ){ return requestURI; } String requestURL = getContextPath(); if ( appRequest.getWebAppType() == PersistantServletRequest.SERVLET_TYPE ){ if ( this.emulatedServletPath.length()>0 ){ if ( !this.emulatedServletPath.startsWith("/") ){ requestURL += "/"; } requestURL += this.emulatedServletPath; } requestURL += this.emulatedPathInfo; } else { if ( !appRequest.getservletsrc().startsWith("/") ){ requestURL += "/"; } requestURL += appRequest.getservletsrc(); } JahiaConsole.println("RequestWrapper", "emulated requestURI = [" + requestURL + "]"); //return getContextPath()+ "/" + appRequest.getServletName(); return requestURL; } else { return super.getRequestURI(); } } public StringBuffer getRequestURL() { StringBuffer requestURL = super.getRequestURL(); JahiaConsole.println("RequestWrapper", " super.getRequestURL()=[" + requestURL.toString() + "]"); if (emulatedURL != null) { if ( hasRequestURIChanged() ){ return requestURL; } JahiaConsole.println("RequestWrapper", "emulated requestURL = [" + super.getRequestURL() + "]"); return super.getRequestURL(); } else { return super.getRequestURL(); } } public String getServletPath() { String serverPath = super.getServletPath(); String pathInfo = super.getPathInfo(); JahiaConsole.println("RequestWrapper", "super.getServletPath()=[" + serverPath + "]"); JahiaConsole.println("RequestWrapper", "emulated servlet path [" + this.emulatedServletPath + "]"); JahiaConsole.println("RequestWrapper", "while super.getPathInfo()=[" + pathInfo + "]"); if (hasRequestURIChanged()) { JahiaConsole.println("RequestWrapper", "Request URI has changed, returning emulatedServletPath=[" + serverPath + "]"); emulatedServletPath = serverPath; } if (emulatedURL != null) { /* JahiaConsole.println("RequestWrapper", "getServletPath() = [" + appRequest.getName() + "]"); */ if (serverPath.endsWith(".jsp")) { /** @todo remove this hack that was introduced to make internal * app redirection to JSP work. Must find a better way to * detect this. This will fail if we try to redirect to a JSP * directly (or maybe it works but not guaranteed. */ JahiaConsole.println("RequestWrapper", "JSP servlet path ("+ serverPath + ") detected, returning server path..."); return serverPath; } JahiaConsole.println("RequestWrapper", "emulated servlet path [" + this.emulatedServletPath + "]"); return this.emulatedServletPath; } return super.getServletPath(); } public String getQueryString() { String queryString = super.getQueryString(); JahiaConsole.println("RequestWrapper", "super.getQueryString()=[" + queryString + "]"); if (emulatedURL != null) { if ( hasRequestURIChanged() ){ return queryString; } JahiaConsole.println("RequestWrapper", "getQueryString() = [" + emulatedURL.getQuery() + "]"); return emulatedURL.getQuery(); } else { return super.getQueryString(); } } public String getPathTranslated() { if (emulatedURL != null) { JahiaConsole.println("RequestWrapper", "getPathTranslated() = [" + super.getPathTranslated() + "]"); return super.getPathTranslated(); } else { return super.getPathTranslated(); } }// public Locale getLocale() {// if (emulatedURL != null) {// JahiaConsole.println("RequestWrapper", "getLocale() = [" + super.getLocale() + "]");// return this.jahiaParams.getLocale();// } else {// return super.getLocale();// }// }//// public Enumeration getLocales() {// if (emulatedURL != null) {// JahiaConsole.println("RequestWrapper", "getLocale() = [" + super.getLocales() + "]");// Vector v = new Vector();// try {// Iterator iterator = this.jahiaParams.getLocales().iterator();// while ( iterator.hasNext() ){// v.add(iterator.next());// }// } catch (Throwable t ){// JahiaConsole.printe("error getting locales",t);// }// return v.elements();// } else {// return super.getLocales();// }// } public String getPathInfo() { String pathInfo = super.getPathInfo(); JahiaConsole.println("RequestWrapper", "super.getPathInfo()=[" + pathInfo + "]"); if (emulatedURL == null) { JahiaConsole.println("RequestWrapper", "getPathInfo() = [" + pathInfo + "]"); return pathInfo; } else { if ( hasRequestURIChanged() ){ return pathInfo; } JahiaConsole.println("RequestWrapper", "getPathInfo() emulated pathInfo = [" + this.emulatedPathInfo + "]"); return this.emulatedPathInfo ; } } public String getParameter(String name) { // JahiaConsole.println("RequestWrapper", "RequestWrapper.Entering getParameter("+name+")..."); if (emulatedURL != null && !hasRequestURIChanged() ) { if (parameters == null) { //JahiaConsole.println("RequestWrapper", "Error : parameter Object not found !"); } Object objValue = parameters.get(name); if (objValue == null) { //JahiaConsole.println("RequestWrapper", "Warning : parameter ["+name+"] not found !"); return null; } Class classValue = objValue.getClass(); if (classValue.isArray()) { String[] value = (String[]) parameters.get(name); if (value == null) { return null; } else { // JahiaConsole.println("RequestWrapper", "Array detected. Parameter = " + value.toString()); } // JahiaConsole.println("RequestWrapper", "Array detected. Result = [" + value[0] + "]"); return value[0]; } else { String value = (String) objValue; // JahiaConsole.println("RequestWrapper", "String detected. Result = [" + value + "]"); return value; } } else { // JahiaConsole.println("RequestWrapper", "Result from parent = [" + super.getParameter(name) + "]"); return super.getParameter(name); } } public Enumeration getParameterNames() { // JahiaConsole.println("RequestWrapper", "started"); if (emulatedURL != null && !hasRequestURIChanged()) { return new Hashtable(parameters).keys(); } else { return super.getParameterNames(); } } public String[] getParameterValues(String name) { JahiaConsole.println("RequestWrapper", "getParameterValues("+name+")"); if (emulatedURL != null && !hasRequestURIChanged()) { Object objValue = parameters.get(name); if (objValue == null) { //JahiaConsole.println("RequestWrapper", "Warning : parameter ["+name+"] not found !"); return null; } Class classValue = objValue.getClass(); if (classValue.isArray()) { String[] value = (String[]) parameters.get(name); return value; } else { String value = (String) objValue; // JahiaConsole.println("RequestWrapper", "String detected. Result = [" + value + "]"); String[] valueArray = {value}; return valueArray; } /* String[] x = (String[]) parameters.get(name); JahiaConsole.println("RequestWrapper", "getParameterValues("+name+") : values :[" + x[0] + "]"); return x; */ } else { return super.getParameterValues(name); } } public Map getParameterMap() { if (emulatedURL != null && !hasRequestURIChanged()) { JahiaConsole.println("RequestWrapper", "getParameterMap()"); return copyMap(parameters); } else { return super.getParameterMap(); } } public void setAttribute(String name, Object o) { if (o != null) { // JahiaConsole.println("RequestWrapper", "setAttribute(" + name + "," + o.toString() + ")"); if (name.equals("javax.servlet.jsp.jspException")) { // let's print out the exception... StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Throwable t = (Throwable) o; t.printStackTrace(pw); JahiaConsole.println("RequestWrapper", "Exception : " + sw.toString()); } } if (emulatedURL != null) { // Note : we used to have here some code to deactivate setting // of include parameters, but this was resolved by using a NamedDispatcher // that doesn't set these. These caused problems with Tomcat's implementation // of JSP dispatching that checked for the include attributes. if ("org.jahia.portletapi.CacheExpirationDelay".equals(name)) { Long delay = (Long) o; applicationCacheExpirationDelay = delay.longValue(); if (applicationCacheExpirationDelay == 0) { applicationCacheOn = false; } } else { super.setAttribute(name, o); } } else { super.setAttribute(name, o); } } public void removeAttribute(String name) { JahiaConsole.println("RequestWrapper", "removeAttribute("+name+")"); super.removeAttribute(name); } public Object getAttribute(String name) { JahiaConsole.println("RequestWrapper", "getAttribute("+name+")"); return super.getAttribute(name); } public HttpSession getSession (boolean create) { if (emulatedURL != null) { // JahiaConsole.println("RequestWrapper", "getEmulatedSession"); if (sessionWrapper == null) { try { sessionWrapper = new HttpSessionWrapper(jahiaParams.getSession(), appRequest.getApplicationBean().getName(), contextIdentifier, inheritJahiaSessionAttributes); } catch (JahiaSessionExpirationException ex) { return null; } } return sessionWrapper; } else { // JahiaConsole.println("RequestWrapper", "getSession"); return super.getSession(create); } } public HttpSession getSession() { return getSession(true); } public String getMethod() { if (emulatedURL != null) { return emulatedMethod; } else { return super.getMethod(); } } public PersistantServletRequest getPersistantServletRequest(){ return this.appRequest; } public boolean isApplicationCacheOn() { return applicationCacheOn; } public long getApplicationCacheExpirationDelay() { return applicationCacheExpirationDelay; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -