1 17 18 19 20 package org.apache.lenya.util; 21 22 import java.util.Enumeration ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import org.apache.cocoon.environment.Request; 27 import org.apache.log4j.Category; 28 29 32 public final class ServletHelper { 33 34 private static Category log = Category.getInstance(ServletHelper.class); 35 36 39 private ServletHelper() { 40 41 } 42 43 48 public static String getWebappURI(Request request) { 49 String context = request.getContextPath(); 50 String requestUri = request.getRequestURI(); 51 return getWebappURI(context, requestUri); 52 } 53 54 60 public static String getWebappURI(String context, String requestUri) { 61 if (context == null) { 62 context = ""; 63 } 64 String url = requestUri.substring(context.length()); 65 if (url.length() > 0 && !url.startsWith("/")) { 66 url = "/" + url; 67 } 68 69 log.debug(" Context prefix: [" + context + "]"); 70 log.debug(" Webapp URL: [" + url + "]"); 71 72 return url; 73 } 74 75 81 public static Map getParameterMap(Request request) { 82 Map requestParameters = new HashMap (); 83 for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { 84 String key = (String ) e.nextElement(); 85 String [] values = request.getParameterValues(key); 86 Object value; 87 if (values.length == 1) { 88 value = values[0]; 89 } 90 else { 91 value = values; 92 } 93 requestParameters.put(key, value); 94 } 95 return requestParameters; 96 } 97 98 } 99 | Popular Tags |