You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/09/09 14:06:12 UTC

svn commit: r279747 - /cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java

Author: cziegeler
Date: Fri Sep  9 05:06:08 2005
New Revision: 279747

URL: http://svn.apache.org/viewcvs?rev=279747&view=rev
Log:
Improved request wrapper

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java?rev=279747&r1=279746&r2=279747&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java Fri Sep  9 05:06:08 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004,2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,9 +36,15 @@
  */
 public class ServletRequestImpl extends HttpServletRequestWrapper {
 
-    /** Cache the parameter map */
+    /** Cache the parameter map. */
     protected Map portletParameterMap;
 
+    /** Request object used for {@link #portletParameterMap}. */
+    protected HttpServletRequest cachedRequest;
+
+    /** Original Request. */
+    final protected HttpServletRequest originalRequest;
+
     final protected PortletURLProviderImpl provider;
 
     protected PortletWindow window;
@@ -47,6 +53,7 @@
                               PortletURLProviderImpl provider) {
         super(request);
         this.provider = provider;
+        this.originalRequest = request;
     }
 
     public ServletRequestImpl(HttpServletRequest request,
@@ -55,6 +62,7 @@
         super(request);
         this.provider = provider;
         this.window = window;
+        this.originalRequest = request;
     }
 
     public ServletRequestImpl getRequest(PortletWindow window) {
@@ -62,20 +70,6 @@
     }
 
     /**
-     * @see javax.servlet.http.HttpServletRequest#getQueryString()
-     */
-    public String getQueryString() {
-        return null;
-    }
-
-    /**
-     * @see javax.servlet.http.HttpServletRequest#getRequestURL()
-     */
-    public StringBuffer getRequestURL() {
-        return null;
-    }
-
-    /**
      * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
      */
     public void setCharacterEncoding(String arg0)
@@ -110,7 +104,11 @@
      * @see javax.servlet.ServletRequest#getParameterMap()
      */
     public Map getParameterMap() {
-        // TODO - readd caching
+        HttpServletRequest currentRequest = (HttpServletRequest)this.getRequest();
+        if ( this.portletParameterMap == null
+             || currentRequest != this.cachedRequest ) {
+            this.cachedRequest = currentRequest;
+
             //get control params
             this.portletParameterMap = new HashMap();
 
@@ -132,32 +130,24 @@
                     }
                 }
 
-                //get request params
-            Enumeration parameters = this.getRequest().getParameterNames();
-                while (parameters.hasMoreElements()) {
-                    String paramName = (String) parameters.nextElement();
-                String[] paramValues = this.getRequest().getParameterValues(paramName);
-                String[] values = (String[]) this.portletParameterMap.get(paramName);
-
-                if ( !paramName.startsWith("cocoon-") ) {
-                    if (values != null) {
-                        String[] temp =
-                            new String[paramValues.length + values.length];
-                        System.arraycopy(
-                            paramValues,
-                            0,
-                            temp,
-                            0,
-                            paramValues.length);
-                        System.arraycopy(
-                            values,
-                            0,
-                            temp,
-                            paramValues.length,
-                            values.length);
-                        paramValues = temp;
+                // get request params if the wrapped request is not the Cocoon request
+                if ( currentRequest != this.originalRequest ) {
+                    Enumeration parameters = currentRequest.getParameterNames();
+                    while (parameters.hasMoreElements()) {
+                        String paramName = (String) parameters.nextElement();
+                        String[] paramValues = this.getRequest().getParameterValues(paramName);
+                        String[] values = (String[]) this.portletParameterMap.get(paramName);
+    
+                        if ( !paramName.startsWith("cocoon-") ) {
+                            if (values != null) {
+                                String[] temp = new String[paramValues.length + values.length];
+                                System.arraycopy(paramValues, 0, temp, 0, paramValues.length);
+                                System.arraycopy(values, 0, temp, paramValues.length, values.length);
+                                paramValues = temp;
+                            }
+                            this.portletParameterMap.put(paramName, paramValues);
+                        }
                     }
-                    this.portletParameterMap.put(paramName, paramValues);
                 }
             }
         }
@@ -177,5 +167,91 @@
      */
     public String[] getParameterValues(String name) {
         return (String[]) this.getParameterMap().get(name);
+    }
+    /**
+     * JST-168 PLT.16.3.3 cxxix
+     * @see javax.servlet.ServletRequest#getProtocol()
+     */
+    public String getProtocol() {
+        return null;
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxix
+     * @see javax.servlet.ServletRequest#getRemoteAddr()
+     */
+    public String getRemoteAddr() {
+        return null;
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxix
+     * @see javax.servlet.ServletRequest#getRemoteHost()
+     */
+    public String getRemoteHost() {
+        return null;
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxix
+     * @see javax.servlet.http.HttpServletRequest#getRequestURL()
+     */
+    public StringBuffer getRequestURL() {
+        return null;
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxx
+     * @see javax.servlet.http.HttpServletRequest#getPathInfo()
+     */
+    public String getPathInfo() {
+        String attr = (String)super.getAttribute("javax.servlet.include.path_info");
+        return (attr != null) ? attr : super.getPathInfo();
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxx
+     * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
+     */
+    public String getPathTranslated() {
+        // TODO: Don't know yet how to implement this. 
+        //       A null value is a valid value. 
+        return null;
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxx
+     * @see javax.servlet.http.HttpServletRequest#getQueryString()
+     */
+    public String getQueryString() {
+        String attr = (String)super.getAttribute("javax.servlet.include.query_string");
+        return (attr != null) ? attr : super.getQueryString();
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxx
+     * @see javax.servlet.http.HttpServletRequest#getRequestURI()
+     */
+    public String getRequestURI() {
+        String attr = (String)super.getAttribute("javax.servlet.include.request_uri");
+        return (attr != null) ? attr : super.getRequestURI();
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxx
+     * @see javax.servlet.http.HttpServletRequest#getServletPath()
+     */
+    public String getServletPath() {
+        String attr = (String)super.getAttribute("javax.servlet.include.servlet_path");
+        return (attr != null) ? attr : super.getServletPath();
+    }
+
+    /**
+     * JST-168 PLT.16.3.3 cxxxi
+     * @see javax.servlet.http.HttpServletRequest#getContextPath()
+     */
+    public String getContextPath() {
+        String attr = (String)super.getAttribute("javax.servlet.include.context_path");
+        return (attr != null) ? attr : super.getContextPath();
     }
 }