1 17 package servletunit.struts; 18 19 import org.apache.cactus.ServletURL; 20 import org.apache.cactus.server.HttpServletRequestWrapper; 21 22 import java.util.*; 23 24 31 public class StrutsRequestWrapper extends HttpServletRequestWrapper { 32 33 private String pathInfo; 34 private String servletPath; 35 private Map parameters; 36 37 public StrutsRequestWrapper(HttpServletRequestWrapper request) { 38 super(request,new ServletURL(request.getServerName(),request.getContextPath(),request.getServletPath(),request.getPathInfo(),request.getQueryString())); 39 parameters = new HashMap(); 40 } 41 42 public void setPathInfo(String pathInfo) { 43 this.pathInfo = pathInfo; 44 } 45 46 public String getPathInfo() { 47 if (this.pathInfo == null) 48 return super.getPathInfo(); 49 else 50 return this.pathInfo; 51 } 52 53 public void setServletPath(String servletPath) { 54 this.servletPath = servletPath; 55 } 56 57 public String getServletPath() { 58 if (this.servletPath == null) 59 return super.getServletPath(); 60 else 61 return this.servletPath; 62 } 63 64 65 public String getParameter(String name) { 66 String [] result = getParameterValues(name); 67 if ((result != null) && (result.length > 0)) { 68 return result[0]; 69 } else 70 return null; 71 } 72 73 public String [] getParameterValues(String name) { 74 Object result = super.getParameterValues(name); 75 if ((result == null) && (parameters.containsKey(name))) { 76 result = parameters.get(name); 77 if (!(result instanceof String [])) { 78 String [] resultArray = { result.toString() }; 79 result = resultArray; 80 } 81 } 82 return (String []) result; 83 } 84 85 public Enumeration getParameterNames() { 86 Enumeration superNames = super.getParameterNames(); 87 List nameList = new ArrayList(parameters.keySet()); 88 while (superNames.hasMoreElements()) { 89 nameList.add(superNames.nextElement()); 90 } 91 return Collections.enumeration(nameList); 92 } 93 94 public void addParameter(String name, String value) { 95 if ((super.getParameter(name) == null) && (name != null) && (value != null)) 96 parameters.put(name,value); 97 } 98 99 public void addParameter(String name, String [] values) { 100 if ((super.getParameter(name) == null) && (name != null) && (values != null)) 101 parameters.put(name,values); 102 } 103 104 public Map getParameterMap() { 105 Map result = new HashMap(); 106 result.putAll(super.getParameterMap()); 107 result.putAll(parameters); 108 return result; 109 } 110 111 public void clearRequestParameters() { 112 this.parameters.clear(); 113 } 115 116 } 117 118 119
| Popular Tags
|