View Javadoc

1   /*
2    * Copyright 1999-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.chain.web.portlet;
17  
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Enumeration;
22  import java.util.HashSet;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Set;
27  import javax.portlet.PortletRequest;
28  
29  
30  /***
31   * <p>Private implementation of <code>Map</code> for portlet parameter
32   * name-values[].</p>
33   *
34   * @author Craig R. McClanahan
35   * @version $Revision: 1.3 $ $Date: 2004/02/25 00:01:06 $
36   */
37  
38  final class PortletParamValuesMap implements Map {
39  
40  
41      public PortletParamValuesMap(PortletRequest request) {
42          this.request = request;
43      }
44  
45  
46      private PortletRequest request = null;
47  
48  
49      public void clear() {
50          throw new UnsupportedOperationException();
51      }
52  
53  
54      public boolean containsKey(Object key) {
55          return (request.getParameter(key(key)) != null);
56      }
57  
58  
59      public boolean containsValue(Object value) {
60          Iterator values = values().iterator();
61          while (values.hasNext()) {
62              if (value.equals(values.next())) {
63                  return (true);
64              }
65          }
66          return (false);
67      }
68  
69  
70      public Set entrySet() {
71          Set set = new HashSet();
72          Enumeration keys = request.getParameterNames();
73          while (keys.hasMoreElements()) {
74              set.add(request.getParameterValues((String) keys.nextElement()));
75          }
76          return (set);
77      }
78  
79  
80      public boolean equals(Object o) {
81          return (request.equals(o));
82      }
83  
84  
85      public Object get(Object key) {
86          return (request.getParameterValues(key(key)));
87      }
88  
89  
90      public int hashCode() {
91          return (request.hashCode());
92      }
93  
94  
95      public boolean isEmpty() {
96          return (size() < 1);
97      }
98  
99  
100     public Set keySet() {
101         Set set = new HashSet();
102         Enumeration keys = request.getParameterNames();
103         while (keys.hasMoreElements()) {
104             set.add(keys.nextElement());
105         }
106         return (set);
107     }
108 
109 
110     public Object put(Object key, Object value) {
111         throw new UnsupportedOperationException();
112     }
113 
114 
115     public void putAll(Map map) {
116         throw new UnsupportedOperationException();
117     }
118 
119 
120     public Object remove(Object key) {
121         throw new UnsupportedOperationException();
122     }
123 
124 
125     public int size() {
126         int n = 0;
127         Enumeration keys = request.getParameterNames();
128         while (keys.hasMoreElements()) {
129             keys.nextElement();
130             n++;
131         }
132         return (n);
133     }
134 
135 
136     public Collection values() {
137         List list = new ArrayList();
138         Enumeration keys = request.getParameterNames();
139         while (keys.hasMoreElements()) {
140             list.add(request.getParameterValues((String) keys.nextElement()));
141         }
142         return (list);
143     }
144 
145 
146     private String key(Object key) {
147         if (key == null) {
148             throw new IllegalArgumentException();
149         } else if (key instanceof String) {
150             return ((String) key);
151         } else {
152             return (key.toString());
153         }
154     }
155 
156 
157 }