KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > multipart > support > DefaultMultipartHttpServletRequest


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.multipart.support;
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.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 /**
29  * Default implementation of the MultipartHttpServletRequest interface.
30  * Provides management of pre-generated parameter values.
31  *
32  * @author Trevor D. Cook
33  * @author Juergen Hoeller
34  * @since 29.09.2003
35  * @see org.springframework.web.multipart.MultipartResolver
36  */

37 public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpServletRequest {
38
39     private final Map JavaDoc multipartParameters;
40
41
42     /**
43      * Wrap the given HttpServletRequest in a MultipartHttpServletRequest.
44      * @param request the servlet request to wrap
45      * @param multipartFiles a map of the multipart files
46      * @param multipartParameters a map of the parameters to expose,
47      * with Strings as keys and String arrays as values
48      */

49     public DefaultMultipartHttpServletRequest(
50             HttpServletRequest JavaDoc request, Map JavaDoc multipartFiles, Map JavaDoc multipartParameters) {
51
52         super(request);
53         setMultipartFiles(multipartFiles);
54         this.multipartParameters = multipartParameters;
55     }
56
57
58     public Enumeration JavaDoc getParameterNames() {
59         Set JavaDoc paramNames = new HashSet JavaDoc();
60         Enumeration JavaDoc paramEnum = super.getParameterNames();
61         while (paramEnum.hasMoreElements()) {
62             paramNames.add(paramEnum.nextElement());
63         }
64         paramNames.addAll(this.multipartParameters.keySet());
65         return Collections.enumeration(paramNames);
66     }
67
68     public String JavaDoc getParameter(String JavaDoc name) {
69         String JavaDoc[] values = (String JavaDoc[]) this.multipartParameters.get(name);
70         if (values != null) {
71             return (values.length > 0 ? values[0] : null);
72         }
73         return super.getParameter(name);
74     }
75
76     public String JavaDoc[] getParameterValues(String JavaDoc name) {
77         String JavaDoc[] values = (String JavaDoc[]) this.multipartParameters.get(name);
78         if (values != null) {
79             return values;
80         }
81         return super.getParameterValues(name);
82     }
83
84     public Map JavaDoc getParameterMap() {
85         Map JavaDoc paramMap = new HashMap JavaDoc();
86         paramMap.putAll(super.getParameterMap());
87         paramMap.putAll(this.multipartParameters);
88         return paramMap;
89     }
90
91 }
92
Popular Tags