This project has retired. For details please refer to its
Attic page.
PortletParamMap xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.portlet.context;
22
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Enumeration;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33 import javax.portlet.PortletRequest;
34
35 import org.apache.tiles.context.MapEntry;
36
37 /***
38 * <p>Private implementation of <code>Map</code> for portlet parameter
39 * name-value.</p>
40 *
41 * @version $Rev: 789695 $ $Date: 2009-06-30 14:43:14 +0200 (mar, 30 giu 2009) $
42 */
43
44 final class PortletParamMap implements Map<String, String> {
45
46
47 /***
48 * Constructor.
49 *
50 * @param request The portlet request to use.
51 */
52 public PortletParamMap(PortletRequest request) {
53 this.request = request;
54 }
55
56
57 /***
58 * The portlet request to use.
59 */
60 private PortletRequest request = null;
61
62
63 /*** {@inheritDoc} */
64 public void clear() {
65 throw new UnsupportedOperationException();
66 }
67
68
69 /*** {@inheritDoc} */
70 public boolean containsKey(Object key) {
71 return (request.getParameter(key(key)) != null);
72 }
73
74
75 /*** {@inheritDoc} */
76 public boolean containsValue(Object value) {
77 Iterator<String> values = values().iterator();
78 while (values.hasNext()) {
79 if (value.equals(values.next())) {
80 return (true);
81 }
82 }
83 return (false);
84 }
85
86
87 /*** {@inheritDoc} */
88 public Set<Map.Entry<String, String>> entrySet() {
89 Set<Map.Entry<String, String>> set = new HashSet<Map.Entry<String, String>>();
90 Enumeration<String> keys = request.getParameterNames();
91 String key;
92 while (keys.hasMoreElements()) {
93 key = keys.nextElement();
94 set.add(new MapEntry<String, String>(key,
95 request.getParameter(key), false));
96 }
97 return (set);
98 }
99
100
101 /*** {@inheritDoc} */
102 public boolean equals(Object o) {
103 PortletRequest otherRequest = ((PortletParamMap) o).request;
104 boolean retValue = true;
105 synchronized (request) {
106 for (Enumeration<String> attribs = request.getParameterNames(); attribs
107 .hasMoreElements()
108 && retValue;) {
109 String parameterName = attribs.nextElement();
110 retValue = request.getParameter(parameterName).equals(
111 otherRequest.getParameter(parameterName));
112 }
113 }
114
115 return retValue;
116 }
117
118
119 /*** {@inheritDoc} */
120 public String get(Object key) {
121 return (request.getParameter(key(key)));
122 }
123
124
125 /*** {@inheritDoc} */
126 public int hashCode() {
127 return (request.hashCode());
128 }
129
130
131 /*** {@inheritDoc} */
132 public boolean isEmpty() {
133 return (size() < 1);
134 }
135
136
137 /*** {@inheritDoc} */
138 public Set<String> keySet() {
139 Set<String> set = new HashSet<String>();
140 Enumeration<String> keys = request.getParameterNames();
141 while (keys.hasMoreElements()) {
142 set.add(keys.nextElement());
143 }
144 return (set);
145 }
146
147
148 /*** {@inheritDoc} */
149 public String put(String key, String value) {
150 throw new UnsupportedOperationException();
151 }
152
153
154 /*** {@inheritDoc} */
155 public void putAll(Map<? extends String, ? extends String> map) {
156 throw new UnsupportedOperationException();
157 }
158
159
160 /*** {@inheritDoc} */
161 public String remove(Object key) {
162 throw new UnsupportedOperationException();
163 }
164
165
166 /*** {@inheritDoc} */
167 public int size() {
168 int n = 0;
169 Enumeration<String> keys = request.getParameterNames();
170 while (keys.hasMoreElements()) {
171 keys.nextElement();
172 n++;
173 }
174 return (n);
175 }
176
177
178 /*** {@inheritDoc} */
179 public Collection<String> values() {
180 List<String> list = new ArrayList<String>();
181 Enumeration<String> keys = request.getParameterNames();
182 while (keys.hasMoreElements()) {
183 list.add(request.getParameter(keys.nextElement()));
184 }
185 return (list);
186 }
187
188
189 /***
190 * Returns the string representation of the key.
191 *
192 * @param key The key.
193 * @return The string representation of the key.
194 * @throws IllegalArgumentException If the key is <code>null</code>.
195 */
196 private String key(Object key) {
197 if (key == null) {
198 throw new IllegalArgumentException();
199 } else if (key instanceof String) {
200 return ((String) key);
201 } else {
202 return (key.toString());
203 }
204 }
205
206
207 }