cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r279746 - /cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
Date Fri, 09 Sep 2005 12:02:06 GMT
Author: cziegeler
Date: Fri Sep  9 05:02:02 2005
New Revision: 279746

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

Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java?rev=279746&r1=279745&r2=279746&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/pluto/servlet/ServletRequestImpl.java
Fri Sep  9 05:02:02 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,54 +104,50 @@
      * @see javax.servlet.ServletRequest#getParameterMap()
      */
     public Map getParameterMap() {
-        // TODO - readd caching
-        // get control params
-        this.portletParameterMap = new HashMap();
-
-        if (this.provider != null
-            && this.provider.getPortletWindow().equals(this.window)) {
-            // get render parameters
-            Iterator i = this.provider.getParameters().entrySet().iterator();
-            while (i.hasNext()) {
-                Map.Entry entry = (Map.Entry) i.next();
-                // convert simple values to string arrays
-                if (entry.getValue() instanceof String) {
-                    this.portletParameterMap.put(
-                        entry.getKey(),
-                        new String[] {(String) entry.getValue()});
-                } else {
-                    this.portletParameterMap.put(
-                        entry.getKey(),
-                        entry.getValue());
+        HttpServletRequest currentRequest = (HttpServletRequest)this.getRequest();
+        if ( this.portletParameterMap == null
+             || currentRequest != this.cachedRequest ) {
+            this.cachedRequest = currentRequest;
+
+            // get control params
+            this.portletParameterMap = new HashMap();
+
+            if (this.provider != null
+                && this.provider.getPortletWindow().equals(this.window)) {
+                // get render parameters
+                Iterator i = this.provider.getParameters().entrySet().iterator();
+                while (i.hasNext()) {
+                    Map.Entry entry = (Map.Entry) i.next();
+                    // convert simple values to string arrays
+                    if (entry.getValue() instanceof String) {
+                         this.portletParameterMap.put(
+                             entry.getKey(),
+                             new String[] {(String) entry.getValue()});
+                    } else {
+                        this.portletParameterMap.put(
+                            entry.getKey(),
+                            entry.getValue());
+                    }
                 }
-            }
 
-            //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);
                 }
             }
         }
@@ -178,4 +168,89 @@
     public String[] getParameterValues(String name) {
         return (String[]) this.getParameterMap().get(name);
     }
-}
\ No newline at end of file
+    /**
+     * 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();
+    }
+}



Mime
View raw message