You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/08/25 17:41:31 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/util ServletHelper.java

andreas     2003/08/25 08:41:31

  Modified:    src/java/org/apache/lenya/util ServletHelper.java
  Log:
  added getParameterMap() method
  
  Revision  Changes    Path
  1.2       +40 -3     cocoon-lenya/src/java/org/apache/lenya/util/ServletHelper.java
  
  Index: ServletHelper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/util/ServletHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHelper.java	23 Jul 2003 19:18:17 -0000	1.1
  +++ ServletHelper.java	25 Aug 2003 15:41:31 -0000	1.2
  @@ -55,12 +55,25 @@
   */
   package org.apache.lenya.util;
   
  +import java.util.Enumeration;
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.cocoon.environment.Request;
   
   /**
  + * Servlet utility class.
  + * 
    * @author andreas
    */
  -public class ServletHelper {
  +public final class ServletHelper {
  +
  +    /**
  +     * Ctor.
  +     */
  +    private ServletHelper() {
  +
  +    }
   
       /**
        * Returns the URL inside the web application (without the context prefix). 
  @@ -74,5 +87,29 @@
           }
           String url = request.getRequestURI().substring(context.length());
           return url;
  -    } 
  +    }
  +
  +    /**
  +     * Converts the request parameters to a map.
  +     * If a key is mapped to multiple parameters, a string array is used as the value.
  +     * @param request The request.
  +     * @return A map.
  +     */
  +    public static Map getParameterMap(Request request) {
  +        Map requestParameters = new HashMap();
  +        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
  +            String key = (String) e.nextElement();
  +            String[] values = request.getParameterValues(key);
  +            Object value;
  +            if (values.length == 1) {
  +                value = values[0];
  +            }
  +            else {
  +                value = values;
  +            }
  +            requestParameters.put(key, value);
  +        }
  +        return requestParameters;
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org