1 16 package com.blandware.atleap.webapp.acegi; 17 18 import javax.servlet.http.Cookie ; 19 import javax.servlet.http.HttpServletRequest ; 20 import java.util.*; 21 22 44 public class SavedRequest { 45 46 49 private ArrayList cookies = new ArrayList(); 50 51 56 public void addCookie(Cookie cookie) { 57 cookies.add(cookie); 58 } 59 60 65 public List getCookies() { 66 return cookies; 67 } 68 69 70 76 private HashMap headers = new HashMap(); 77 78 84 public void addHeader(String name, String value) { 85 ArrayList values = (ArrayList) headers.get(name); 86 if (values == null) { 87 values = new ArrayList(); 88 headers.put(name, values); 89 } 90 values.add(value); 91 } 92 93 98 public Iterator getHeaderNames() { 99 return (headers.keySet().iterator()); 100 } 101 102 108 public Iterator getHeaderValues(String name) { 109 ArrayList values = (ArrayList) headers.get(name); 110 if (values == null) 111 return ((new ArrayList()).iterator()); 112 else 113 return (values.iterator()); 114 } 115 116 117 120 private ArrayList locales = new ArrayList(); 121 122 127 public void addLocale(Locale locale) { 128 locales.add(locale); 129 } 130 131 136 public Iterator getLocales() { 137 return (locales.iterator()); 138 } 139 140 141 144 private String method = null; 145 146 151 public String getMethod() { 152 return (this.method); 153 } 154 155 160 public void setMethod(String method) { 161 this.method = method; 162 } 163 164 165 166 171 private HashMap parameters = new HashMap(); 172 173 179 public void addParameter(String name, String values[]) { 180 parameters.put(name, values); 181 } 182 183 188 public Iterator getParameterNames() { 189 return (parameters.keySet().iterator()); 190 } 191 192 198 public String [] getParameterValues(String name) { 199 return ((String []) parameters.get(name)); 200 } 201 202 207 public Map getParameterMap() { 208 return parameters; 209 } 210 211 212 215 private String queryString = null; 216 217 222 public String getQueryString() { 223 return (this.queryString); 224 } 225 226 231 public void setQueryString(String queryString) { 232 this.queryString = queryString; 233 } 234 235 236 239 private String requestURI = null; 240 241 246 public String getRequestURI() { 247 return (this.requestURI); 248 } 249 250 255 public void setRequestURI(String requestURI) { 256 this.requestURI = requestURI; 257 } 258 259 262 private String pathInfo = null; 263 264 269 public String getPathInfo() { 270 return pathInfo; 271 } 272 273 278 public void setPathInfo(String pathInfo) { 279 this.pathInfo = pathInfo; 280 } 281 282 287 public String getRequestURL() { 288 if (getRequestURI() == null) 289 return null; 290 291 StringBuffer sb = new StringBuffer (getRequestURI()); 292 if (getQueryString() != null) { 296 sb.append('?'); 297 sb.append(getQueryString()); 298 } 299 return sb.toString(); 300 } 301 302 307 public static SavedRequest saveRequest(HttpServletRequest request) { 308 if (request.getRequestURI() == null) 309 return null; 310 311 SavedRequest saved = new SavedRequest(); 313 Cookie cookies[] = request.getCookies(); 314 if (cookies != null) { 315 for (int i = 0; i < cookies.length; i++) 316 saved.addCookie(cookies[i]); 317 } 318 Enumeration names = request.getHeaderNames(); 319 while (names.hasMoreElements()) { 320 String name = (String ) names.nextElement(); 321 Enumeration values = request.getHeaders(name); 322 while (values.hasMoreElements()) { 323 String value = (String ) values.nextElement(); 324 saved.addHeader(name, value); 325 } 326 } 327 Enumeration locales = request.getLocales(); 328 while (locales.hasMoreElements()) { 329 Locale locale = (Locale) locales.nextElement(); 330 saved.addLocale(locale); 331 } 332 Map parameters = request.getParameterMap(); 333 Iterator paramNames = parameters.keySet().iterator(); 334 while (paramNames.hasNext()) { 335 String paramName = (String ) paramNames.next(); 336 String paramValues[] = (String []) parameters.get(paramName); 337 saved.addParameter(paramName, paramValues); 338 } 339 saved.setMethod(request.getMethod()); 340 saved.setQueryString(request.getQueryString()); 341 saved.setRequestURI(request.getRequestURI()); 342 344 return saved; 345 } 346 347 348 } 349 | Popular Tags |