KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > context > portlet > PortletRequestParameterMap


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, 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 JavaDoc;
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 JavaDoc getAttribute(String JavaDoc key) {
48         if (request instanceof MultipartActionRequest) {
49             MultipartActionRequest multipartRequest = (MultipartActionRequest)request;
50             Object JavaDoc data = multipartRequest.getFileMap().get(key);
51             if (data != null) {
52                 return data;
53             }
54         }
55         String JavaDoc[] 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 JavaDoc key, Object JavaDoc value) {
66         throw new UnsupportedOperationException JavaDoc("PortletRequest parameter maps are immutable");
67     }
68
69     protected void removeAttribute(String JavaDoc key) {
70         throw new UnsupportedOperationException JavaDoc("PortletRequest parameter maps are immutable");
71     }
72
73     protected Iterator JavaDoc getAttributeNames() {
74         if (request instanceof MultipartActionRequest) {
75             MultipartActionRequest multipartRequest = (MultipartActionRequest)request;
76             CompositeIterator iterator = new CompositeIterator();
77             iterator.add(multipartRequest.getFileMap().keySet().iterator());
78             iterator.add(CollectionUtils.toIterator(request.getParameterNames()));
79             return iterator;
80         }
81         else {
82             return CollectionUtils.toIterator(request.getParameterNames());
83         }
84     }
85 }
Popular Tags