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;
29
30
import javax.portlet.faces.Bridge;
31
import javax.portlet.faces.BridgeUtil;
35
36
public class PortletRequestParameterMap extends PortletAbstractMap<String>
37
{
38
private final PortletRequest mPortletRequest;
39
private final Map<String, String> mInternalAttributes;
40
private Map<String,String[]> mPrivateParameters;
41
42
public PortletRequestParameterMap(Object request, Map<String, String> internal)
43
44
if (request instanceof PortletRequest)
45
46
mPortletRequest = (PortletRequest) request;
47
if (internal == null)
48
49
mInternalAttributes = Collections.emptyMap();
50
}
51
else
52
53
mInternalAttributes = new HashMap(internal);;
54
55
56
57
58
throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
59
60
61
62
@Override
63
public String getAttribute(String key)
64
65
if (mPortletRequest != null)
66
67
if (mPrivateParameters == null)
68
69
mPrivateParameters = getPrivateParameterMap();
70
71
String[] params = mPrivateParameters.get(key);
72
if (params != null)
73
74
return params[0];
75
76
77
// Now try the internal/temp parameters (part of the views querystring)
78
79
return mInternalAttributes.get(key);
80
81
82
83
84
85
86
87
88
89
90
public void setAttribute(String key, String value)
91
92
throw new UnsupportedOperationException();
93
94
95
96
public void removeAttribute(String key)
97
98
99
100
101
@SuppressWarnings("unchecked")
102
103
public Enumeration<String> getAttributeNames()
104
105
106
107
// merged list of internal parameters & request parameters
108
List<String> attrNames = new ArrayList<String>(5);
109
110
111
112
113
114
attrNames.addAll(mPrivateParameters.keySet());
115
attrNames.addAll(mInternalAttributes.keySet());
116
117
return Collections.enumeration(attrNames);
118
119
120
121
122
123
124
125
private Map<String,String[]> getPrivateParameterMap()
126
127
// Some portlet containers (WebSphere) claim submitted (form) data aren't private parameters
128
// during an action/resource request -- instead they are all regular params -- to workaround
129
// this indicate that during an action/resource all non-public params are private params
130
131
Map <String, String[]> privateParams = mPortletRequest.getPrivateParameterMap();;
132
if ((BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.ACTION_PHASE ||
133
BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RESOURCE_PHASE))
134
135
Map<String, String[]> allParams = mPortletRequest.getParameterMap();
136
Map<String, String[]> publicParams = mPortletRequest.getPublicParameterMap();
137
138
if (publicParams.size() == 0)
139
140
privateParams = allParams;
141
142
else if (allParams.size() != (privateParams.size() + publicParams.size()))
143
144
// Construct the non-Public param Map by excluding those which are public
145
// from the overall set. This works around issue that some portlet
146
// containers think getPrivateParameters should return the private
147
// render parameters -- and hence its empty during an action. (WebSphere 6.1 is one case)
148
privateParams = (Map<String, String[]>) new HashMap(allParams);
149
for (Map.Entry<String, String[]> entry : publicParams.entrySet())
150
151
privateParams.remove(entry.getKey());
152
153
154
155
156
return privateParams;
157
158