1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.util.filter;
17
18 import java.util.ArrayList;
19 import java.util.Enumeration;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletRequestWrapper;
27
28 import com.isenshi.util.CharUtil;
29
30 public class EncodingRequest extends HttpServletRequestWrapper {
31
32 private Map parameters = new HashMap();
33
34 private Map parameterValues = new HashMap();
35
36 public EncodingRequest(HttpServletRequest request, String encode) {
37 super(request);
38
39 String query = request.getQueryString();
40 if (query == null)
41 return;
42
43 Map tmpParameterValue = new HashMap();
44
45 String[] params = query.split("&");
46 for (int i = 0; i < params.length; i++) {
47 String param = params[i];
48 String[] array = param.split("=");
49 if (array.length > 1) {
50 String value = array[1];
51 value = CharUtil.urlDecode(value, encode);
52 parameters.put(array[0], value);
53 addValue(tmpParameterValue, array[0], value);
54 }
55 }
56 toParameterValues(tmpParameterValue);
57 }
58
59 public String getParameter(String name) {
60 String value = (String) parameters.get(name);
61 if (value == null) {
62 return super.getParameter(name);
63 } else {
64 return value;
65 }
66 }
67
68 public String[] getParameterValues(String name) {
69 String[] values = (String[]) parameterValues.get(name);
70 if (values == null) {
71 return super.getParameterValues(name);
72 } else {
73 return values;
74 }
75 }
76
77 public Map getParameterMap() {
78 Map map = new HashMap();
79 Enumeration enm = getParameterNames();
80
81 while(enm.hasMoreElements()){
82 String key = (String)enm.nextElement();
83 String[] value = getParameterValues(key);
84 map.put(key, value);
85 }
86 return map;
87 }
88
89
90 private void toParameterValues(Map tmpParamValues) {
91 Iterator itr = tmpParamValues.keySet().iterator();
92
93 while (itr.hasNext()) {
94 String name = (String) itr.next();
95 List list = (List) tmpParamValues.get(name);
96 parameterValues.put(name, list.toArray(new String[list.size()]));
97 }
98 }
99
100 private void addValue(Map params, String name, String value) {
101 List list = (List) params.get(name);
102 if (list == null) {
103 list = new ArrayList();
104 params.put(name, list);
105 }
106 list.add(value);
107 }
108
109 }