Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
UploadFormParametersWrapper |
|
| 1.0;1 |
1 | // Copyright 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.multipart; |
|
16 | ||
17 | import java.util.Collections; |
|
18 | import java.util.Enumeration; |
|
19 | import java.util.Map; |
|
20 | ||
21 | import javax.servlet.http.HttpServletRequest; |
|
22 | import javax.servlet.http.HttpServletRequestWrapper; |
|
23 | ||
24 | import org.apache.hivemind.util.Defense; |
|
25 | ||
26 | /** |
|
27 | * {@link javax.servlet.http.HttpServletRequest} wrapper that provides |
|
28 | * access to the form field values uploaded in a multipart request. |
|
29 | * |
|
30 | * @author Howard M. Lewis Ship |
|
31 | * @since 4.0 |
|
32 | */ |
|
33 | public class UploadFormParametersWrapper extends HttpServletRequestWrapper |
|
34 | { |
|
35 | ||
36 | /** |
|
37 | * Map of {@link ValuePart} keyed on parameter name. |
|
38 | */ |
|
39 | private Map _parameterMap; |
|
40 | ||
41 | /** |
|
42 | * @param parameterMap |
|
43 | * a map whose keys are parameter names and whose values are |
|
44 | * arrays of Strings. |
|
45 | */ |
|
46 | public UploadFormParametersWrapper(HttpServletRequest request, |
|
47 | Map parameterMap) |
|
48 | { |
|
49 | 5 | super(request); |
50 | ||
51 | 5 | Defense.notNull(parameterMap, "parameterMap"); |
52 | ||
53 | 5 | _parameterMap = Collections.unmodifiableMap(parameterMap); |
54 | 5 | } |
55 | ||
56 | public String getParameter(String name) |
|
57 | { |
|
58 | 2 | String[] values = getParameterValues(name); |
59 | ||
60 | 2 | return (values == null || values.length == 0) ? null : values[0]; |
61 | } |
|
62 | ||
63 | public Map getParameterMap() |
|
64 | { |
|
65 | 1 | return _parameterMap; |
66 | } |
|
67 | ||
68 | public Enumeration getParameterNames() |
|
69 | { |
|
70 | 1 | return Collections.enumeration(_parameterMap.keySet()); |
71 | } |
|
72 | ||
73 | public String[] getParameterValues(String name) |
|
74 | { |
|
75 | 3 | return (String[]) _parameterMap.get(name); |
76 | } |
|
77 | ||
78 | public String toString() |
|
79 | { |
|
80 | 0 | return "<UploadFormPartWrapper for " + getRequest() + ">"; |
81 | } |
|
82 | } |