01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package org.springframework.webflow.context.portlet;
17:
18: import java.util.Iterator;
19:
20: import javax.portlet.PortletRequest;
21:
22: import org.springframework.binding.collection.CompositeIterator;
23: import org.springframework.binding.collection.StringKeyedMapAdapter;
24: import org.springframework.web.portlet.multipart.MultipartActionRequest;
25: import org.springframework.webflow.core.collection.CollectionUtils;
26:
27: /**
28: * Map backed by the Portlet request parameter map for accessing request local
29: * portlet parameters.
30: *
31: * @author Keith Donald
32: */
33: public class PortletRequestParameterMap extends StringKeyedMapAdapter {
34:
35: /**
36: * The wrapped portlet request.
37: */
38: private PortletRequest request;
39:
40: /**
41: * Create a new map wrapping the parameters of given portlet request.
42: */
43: public PortletRequestParameterMap(PortletRequest request) {
44: this .request = request;
45: }
46:
47: protected Object getAttribute(String key) {
48: if (request instanceof MultipartActionRequest) {
49: MultipartActionRequest multipartRequest = (MultipartActionRequest) request;
50: Object data = multipartRequest.getFileMap().get(key);
51: if (data != null) {
52: return data;
53: }
54: }
55: String[] parameters = request.getParameterValues(key);
56: if (parameters == null) {
57: return null;
58: } else if (parameters.length == 1) {
59: return parameters[0];
60: } else {
61: return parameters;
62: }
63: }
64:
65: protected void setAttribute(String key, Object value) {
66: throw new UnsupportedOperationException(
67: "PortletRequest parameter maps are immutable");
68: }
69:
70: protected void removeAttribute(String key) {
71: throw new UnsupportedOperationException(
72: "PortletRequest parameter maps are immutable");
73: }
74:
75: protected Iterator getAttributeNames() {
76: if (request instanceof MultipartActionRequest) {
77: MultipartActionRequest multipartRequest = (MultipartActionRequest) request;
78: CompositeIterator iterator = new CompositeIterator();
79: iterator.add(multipartRequest.getFileMap().keySet()
80: .iterator());
81: iterator.add(CollectionUtils.toIterator(request
82: .getParameterNames()));
83: return iterator;
84: } else {
85: return CollectionUtils.toIterator(request
86: .getParameterNames());
87: }
88: }
89: }
|