Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UploadFormParametersWrapper |
|
| 1.5;1.5 |
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 org.apache.hivemind.util.Defense; | |
18 | ||
19 | import javax.servlet.http.HttpServletRequest; | |
20 | import javax.servlet.http.HttpServletRequestWrapper; | |
21 | import java.util.Collections; | |
22 | import java.util.Enumeration; | |
23 | import java.util.Map; | |
24 | ||
25 | /** | |
26 | * {@link javax.servlet.http.HttpServletRequest} wrapper that provides | |
27 | * access to the form field values uploaded in a multipart request. | |
28 | * | |
29 | * @author Howard M. Lewis Ship | |
30 | * @since 4.0 | |
31 | */ | |
32 | public class UploadFormParametersWrapper extends HttpServletRequestWrapper | |
33 | { | |
34 | ||
35 | /** | |
36 | * Map of {@link ValuePart} keyed on parameter name. | |
37 | */ | |
38 | private Map _parameterMap; | |
39 | ||
40 | /** | |
41 | * @param parameterMap | |
42 | * a map whose keys are parameter names and whose values are | |
43 | * arrays of Strings. | |
44 | */ | |
45 | public UploadFormParametersWrapper(HttpServletRequest request, Map parameterMap) | |
46 | { | |
47 | 0 | super(request); |
48 | ||
49 | 0 | Defense.notNull(parameterMap, "parameterMap"); |
50 | ||
51 | // add Parameter from the URL, typically added by JavaScript-URL-manipulation | |
52 | ||
53 | 0 | if (request.getParameterMap() != null) |
54 | { | |
55 | 0 | parameterMap.putAll(request.getParameterMap()); |
56 | } | |
57 | ||
58 | 0 | _parameterMap = Collections.unmodifiableMap(parameterMap ); |
59 | 0 | } |
60 | ||
61 | public String getParameter(String name) | |
62 | { | |
63 | 0 | String[] values = getParameterValues(name); |
64 | ||
65 | 0 | return (values == null || values.length == 0) ? null : values[0]; |
66 | } | |
67 | ||
68 | public Map getParameterMap() | |
69 | { | |
70 | 0 | return _parameterMap; |
71 | } | |
72 | ||
73 | public Enumeration getParameterNames() | |
74 | { | |
75 | 0 | return Collections.enumeration(_parameterMap.keySet()); |
76 | } | |
77 | ||
78 | public String[] getParameterValues(String name) | |
79 | { | |
80 | 0 | return (String[]) _parameterMap.get(name); |
81 | } | |
82 | ||
83 | public String toString() | |
84 | { | |
85 | 0 | return "<UploadFormPartWrapper for " + getRequest() + ">"; |
86 | } | |
87 | } |