KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > portlet > multipart > DefaultMultipartActionRequest


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.portlet.multipart;
18
19 import java.util.Collections JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.portlet.ActionRequest;
28
29 import org.springframework.web.multipart.MultipartFile;
30 import org.springframework.web.portlet.util.ActionRequestWrapper;
31
32 /**
33  * Default implementation of the MultipartActionRequest interface.
34  * Provides management of pre-generated parameter values.
35  *
36  * @author Juergen Hoeller
37  * @since 2.0
38  * @see PortletMultipartResolver
39  */

40 public class DefaultMultipartActionRequest extends ActionRequestWrapper implements MultipartActionRequest {
41
42     private Map JavaDoc multipartFiles;
43
44     private final Map JavaDoc multipartParameters;
45
46
47     /**
48      * Wrap the given Portlet ActionRequest in a MultipartActionRequest.
49      * @param request the request to wrap
50      * @param multipartFiles a map of the multipart files
51      * @param multipartParameters a map of the parameters to expose,
52      * with Strings as keys and String arrays as values
53      */

54     public DefaultMultipartActionRequest(ActionRequest request, Map JavaDoc multipartFiles, Map JavaDoc multipartParameters) {
55         super(request);
56         this.multipartFiles = Collections.unmodifiableMap(multipartFiles);
57         this.multipartParameters = multipartParameters;
58     }
59
60
61     public Iterator JavaDoc getFileNames() {
62         return this.multipartFiles.keySet().iterator();
63     }
64
65     public MultipartFile getFile(String JavaDoc name) {
66         return (MultipartFile) this.multipartFiles.get(name);
67     }
68
69     public Map JavaDoc getFileMap() {
70         return this.multipartFiles;
71     }
72
73
74     public Enumeration JavaDoc getParameterNames() {
75         Set JavaDoc paramNames = new HashSet JavaDoc();
76         Enumeration JavaDoc paramEnum = super.getParameterNames();
77         while (paramEnum.hasMoreElements()) {
78             paramNames.add(paramEnum.nextElement());
79         }
80         paramNames.addAll(this.multipartParameters.keySet());
81         return Collections.enumeration(paramNames);
82     }
83
84     public String JavaDoc getParameter(String JavaDoc name) {
85         String JavaDoc[] values = (String JavaDoc[]) this.multipartParameters.get(name);
86         if (values != null) {
87             return (values.length > 0 ? values[0] : null);
88         }
89         return super.getParameter(name);
90     }
91
92     public String JavaDoc[] getParameterValues(String JavaDoc name) {
93         String JavaDoc[] values = (String JavaDoc[]) this.multipartParameters.get(name);
94         if (values != null) {
95             return values;
96         }
97         return super.getParameterValues(name);
98     }
99
100     public Map JavaDoc getParameterMap() {
101         Map JavaDoc paramMap = new HashMap JavaDoc();
102         paramMap.putAll(super.getParameterMap());
103         paramMap.putAll(this.multipartParameters);
104         return paramMap;
105     }
106
107 }
108
Popular Tags