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.List;
25
import java.util.Map;
26
27
import javax.portlet.PortletRequest;
31
32
public class PortletRequestParameterMap extends PortletAbstractMap<String>
33
{
34
private final PortletRequest mPortletRequest;
35
private final Map<String, String> mInternalAttributes;
36
37
public PortletRequestParameterMap(Object request, Map<String, String> internal)
38
39
if (request instanceof PortletRequest)
40
41
mPortletRequest = (PortletRequest) request;
42
if (internal == null)
43
44
mInternalAttributes = Collections.emptyMap();
45
}
46
else
47
48
mInternalAttributes = internal;
49
50
51
52
53
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
54
55
56
57
@Override
58
public String getAttribute(String key)
59
60
if (mPortletRequest != null)
61
62
String value = mInternalAttributes.get(key);
63
if (value != null)
64
65
return value;
66
67
68
return mPortletRequest.getParameter(key);
69
70
71
72
73
74
75
76
77
public void setAttribute(String key, String value)
78
79
throw new UnsupportedOperationException();
80
81
82
83
public void removeAttribute(String key)
84
85
86
87
88
@SuppressWarnings("unchecked")
89
90
public Enumeration<String> getAttributeNames()
91
92
93
94
// merged list of internal parameters & request parameters
95
List<String> attrNames = new ArrayList<String>(5);
96
97
Enumeration<String> requestAttrNames = mPortletRequest.getParameterNames();
98
while (requestAttrNames.hasMoreElements())
99
100
attrNames.add(requestAttrNames.nextElement());
101
102
103
attrNames.addAll(mInternalAttributes.keySet());
104
105
return Collections.enumeration(attrNames);
106
107
108
109
110
111
112