1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.context.servlet; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Enumeration; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.List; |
25 | |
import java.util.Map; |
26 | |
|
27 | |
import javax.servlet.http.HttpServletRequest; |
28 | |
|
29 | |
import org.apache.myfaces.util.AbstractAttributeMap; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public final class RequestHeaderValuesMap extends AbstractAttributeMap<String[]> |
38 | |
{ |
39 | |
private final HttpServletRequest _httpServletRequest; |
40 | 0 | private final Map<String, String[]> _valueCache = new HashMap<String, String[]>(); |
41 | |
|
42 | |
RequestHeaderValuesMap(final HttpServletRequest httpServletRequest) |
43 | 0 | { |
44 | 0 | _httpServletRequest = httpServletRequest; |
45 | 0 | } |
46 | |
|
47 | |
protected String[] getAttribute(final String key) |
48 | |
{ |
49 | 0 | String[] ret = _valueCache.get(key); |
50 | 0 | if (ret == null) |
51 | |
{ |
52 | 0 | _valueCache.put(key, ret = toArray(_httpServletRequest.getHeaders(key))); |
53 | |
} |
54 | |
|
55 | 0 | return ret; |
56 | |
} |
57 | |
|
58 | |
protected void setAttribute(final String key, final String[] value) |
59 | |
{ |
60 | 0 | throw new UnsupportedOperationException("Cannot set HttpServletRequest HeaderValues"); |
61 | |
} |
62 | |
|
63 | |
protected void removeAttribute(final String key) |
64 | |
{ |
65 | 0 | throw new UnsupportedOperationException("Cannot remove HttpServletRequest HeaderValues"); |
66 | |
} |
67 | |
|
68 | |
@SuppressWarnings("unchecked") |
69 | |
protected Enumeration<String> getAttributeNames() |
70 | |
{ |
71 | 0 | return _httpServletRequest.getHeaderNames(); |
72 | |
} |
73 | |
|
74 | |
private String[] toArray(Enumeration<String> e) |
75 | |
{ |
76 | 0 | List<String> ret = new ArrayList<String>(); |
77 | |
|
78 | 0 | while (e.hasMoreElements()) |
79 | |
{ |
80 | 0 | ret.add(e.nextElement()); |
81 | |
} |
82 | |
|
83 | 0 | return ret.toArray(new String[ret.size()]); |
84 | |
} |
85 | |
} |