01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of 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,
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;
20: import java.util.Enumeration;
21: import java.util.HashMap;
22: import java.util.HashSet;
23: import java.util.Map;
24: import java.util.Set;
25:
26: import javax.servlet.http.HttpServletRequest;
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
38: AbstractMultipartHttpServletRequest {
39:
40: private final Map multipartParameters;
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 request, Map multipartFiles,
51: Map multipartParameters) {
52:
53: super (request);
54: setMultipartFiles(multipartFiles);
55: this .multipartParameters = multipartParameters;
56: }
57:
58: public Enumeration getParameterNames() {
59: Set paramNames = new HashSet();
60: Enumeration 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 getParameter(String name) {
69: String[] values = (String[]) 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[] getParameterValues(String name) {
77: String[] values = (String[]) this .multipartParameters.get(name);
78: if (values != null) {
79: return values;
80: }
81: return super .getParameterValues(name);
82: }
83:
84: public Map getParameterMap() {
85: Map paramMap = new HashMap();
86: paramMap.putAll(super.getParameterMap());
87: paramMap.putAll(this.multipartParameters);
88: return paramMap;
89: }
90:
91: }
|