Snippet Preview
Snippet HTML Code
1
/* Licensed to the Apache Software Foundation (ASF) under one
2
* or more contributor license agreements. See the NOTICE file
3
* distributed with this work for additional information
4
* regarding copyright ownership. The ASF licenses this file
5
* to you under the Apache License, Version 2.0 (the
6
* "License"); you may not use this file except in compliance
7
* with the License. You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
11
* Unless required by applicable law or agreed to in writing,
12
* software distributed under the License is distributed on an
13
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
* KIND, either express or implied. See the License for the
15
* specific language governing permissions and limitations
16
* under the License.
17
*/
18
19
package org.apache.myfaces.portlet.faces.util.map;
20
21
import java.util.ArrayList;
22
import java.util.Collections;
23
import java.util.Enumeration;
24
import java.util.HashMap;
25
import java.util.List;
26
import java.util.Map;
27
28
import javax.portlet.PortletRequest;
32
33
public class PortletRequestParameterMap extends PortletAbstractMap<String>
34
{
35
private final PortletRequest mPortletRequest;
36
private final Map<String, String> mInternalAttributes;
37
38
public PortletRequestParameterMap(Object request, Map<String, String> internal)
39
40
if (request instanceof PortletRequest)
41
42
mPortletRequest = (PortletRequest) request;
43
if (internal == null)
44
45
mInternalAttributes = Collections.emptyMap();
46
}
47
else
48
49
mInternalAttributes = new HashMap(internal);
50
51
52
53
54
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
55
56
57
58
@Override
59
public String getAttribute(String key)
60
61
if (mPortletRequest != null)
62
63
// Read from the request before the internal ones ass these are the one's
64
// specifically sent by the client.
65
String value = mPortletRequest.getParameter(key);
66
if (value != null)
67
68
return value;
69
70
71
return mInternalAttributes.get(key);
72
73
74
75
76
77
78
79
80
public void setAttribute(String key, String value)
81
82
throw new UnsupportedOperationException();
83
84
85
86
public void removeAttribute(String key)
87
88
89
90
91
@SuppressWarnings("unchecked")
92
93
public Enumeration<String> getAttributeNames()
94
95
96
97
// merged list of internal parameters & request parameters
98
List<String> attrNames = new ArrayList<String>(5);
99
100
Enumeration<String> requestAttrNames = mPortletRequest.getParameterNames();
101
while (requestAttrNames.hasMoreElements())
102
103
attrNames.add(requestAttrNames.nextElement());
104
105
106
attrNames.addAll(mInternalAttributes.keySet());
107
108
return Collections.enumeration(attrNames);
109
110
111
112
113
114
115