KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > multipart > UploadFormParametersWrapper


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 JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
23
24 import org.apache.hivemind.util.Defense;
25
26 /**
27  * {@link javax.servlet.http.HttpServletRequest}  wrapper that provides access to the form
28  * 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 JavaDoc
34 {
35     /**
36      * Map of {@link ValuePart} keyed on parameter name.
37      */

38     private Map JavaDoc _parameterMap;
39
40     /**
41      * @param parameterMap
42      * a map whose keys are parameter names and whose values are arrays of Strings.
43      */

44     public UploadFormParametersWrapper(HttpServletRequest JavaDoc request, Map JavaDoc parameterMap)
45     {
46         super(request);
47
48         Defense.notNull(parameterMap, "parameterMap");
49
50         _parameterMap = Collections.unmodifiableMap(parameterMap);
51     }
52
53     public String JavaDoc getParameter(String JavaDoc name)
54     {
55         String JavaDoc[] values = getParameterValues(name);
56
57         return (values == null || values.length == 0) ? null : values[0];
58     }
59
60     public Map JavaDoc getParameterMap()
61     {
62         return _parameterMap;
63     }
64
65     public Enumeration JavaDoc getParameterNames()
66     {
67         return Collections.enumeration(_parameterMap.keySet());
68     }
69
70     public String JavaDoc[] getParameterValues(String JavaDoc name)
71     {
72         return (String JavaDoc[]) _parameterMap.get(name);
73     }
74
75     public String JavaDoc toString()
76     {
77         return "<UploadFormPartWrapper for " + getRequest() + ">";
78     }
79 }
Popular Tags