1 40 package org.dspace.app.webui.util; 41 42 import java.util.Enumeration ; 43 import java.util.HashMap ; 44 import java.util.Iterator ; 45 import java.util.Map ; 46 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.http.HttpServletRequestWrapper ; 49 50 58 public class RequestInfo 59 { 60 61 private Map originalParameterMap; 62 63 64 private String originalMethod; 65 66 67 private String originalQueryString; 68 69 76 public RequestInfo(HttpServletRequest request) 77 { 78 originalParameterMap = new HashMap (request.getParameterMap()); 79 originalMethod = request.getMethod(); 80 originalQueryString = request.getQueryString(); 81 } 82 83 93 public HttpServletRequest wrapRequest(HttpServletRequest request) 94 { 95 return new MyWrapper(request); 96 } 97 98 102 class MyWrapper extends HttpServletRequestWrapper 103 { 104 public MyWrapper(HttpServletRequest request) 105 { 106 super(request); 107 } 108 109 public String getParameter(String name) 111 { 112 String [] vals = (String []) originalParameterMap.get(name); 113 114 if (vals == null) 115 { 116 return super.getParameter(name); 119 } 120 else 121 { 122 return vals[0]; 123 } 124 } 125 126 public Map getParameterMap() 127 { 128 return originalParameterMap; 129 } 130 131 public Enumeration getParameterNames() 132 { 133 Iterator i = originalParameterMap.keySet().iterator(); 134 135 return new EnumIterator(i); 136 } 137 138 public String [] getParameterValues(String name) 139 { 140 return ((String []) originalParameterMap.get(name)); 141 } 142 143 public String getMethod() 144 { 145 return originalMethod; 146 } 147 148 public String getQueryString() 149 { 150 return originalQueryString; 151 } 152 153 160 class EnumIterator implements Enumeration 161 { 162 private Iterator iterator; 163 164 public EnumIterator(Iterator i) 165 { 166 iterator = i; 167 } 168 169 public boolean hasMoreElements() 170 { 171 return iterator.hasNext(); 172 } 173 174 public Object nextElement() 175 { 176 return iterator.next(); 177 } 178 } 179 } 180 } 181 | Popular Tags |