KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > bind > ServletRequestParameterPropertyValues


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.bind;
18
19 import javax.servlet.ServletRequest JavaDoc;
20
21 import org.springframework.beans.MutablePropertyValues;
22 import org.springframework.web.util.WebUtils;
23
24 /**
25  * PropertyValues implementation created from parameters in a ServletRequest.
26  * Can look for all property values beginning with a certain prefix and
27  * prefix separator (default is "_").
28  *
29  * <p>For example, with a prefix of "spring", "spring_param1" and
30  * "spring_param2" result in a Map with "param1" and "param2" as keys.
31  *
32  * <p>This class is not immutable to be able to efficiently remove property
33  * values that should be ignored for binding.
34  *
35  * @author Rod Johnson
36  * @author Juergen Hoeller
37  * @see org.springframework.web.util.WebUtils#getParametersStartingWith
38  */

39 public class ServletRequestParameterPropertyValues extends MutablePropertyValues {
40
41     /** Default prefix separator */
42     public static final String JavaDoc DEFAULT_PREFIX_SEPARATOR = "_";
43
44
45     /**
46      * Create new ServletRequestPropertyValues using no prefix
47      * (and hence, no prefix separator).
48      * @param request HTTP request
49      */

50     public ServletRequestParameterPropertyValues(ServletRequest JavaDoc request) {
51         this(request, null, null);
52     }
53
54     /**
55      * Create new ServletRequestPropertyValues using the given prefix and
56      * the default prefix separator (the underscore character "_").
57      * @param request HTTP request
58      * @param prefix the prefix for parameters (the full prefix will
59      * consist of this plus the separator)
60      * @see #DEFAULT_PREFIX_SEPARATOR
61      */

62     public ServletRequestParameterPropertyValues(ServletRequest JavaDoc request, String JavaDoc prefix) {
63         this(request, prefix, DEFAULT_PREFIX_SEPARATOR);
64     }
65
66     /**
67      * Create new ServletRequestPropertyValues supplying both prefix and
68      * prefix separator.
69      * @param request HTTP request
70      * @param prefix the prefix for parameters (the full prefix will
71      * consist of this plus the separator)
72      * @param prefixSeparator separator delimiting prefix (e.g. "spring")
73      * and the rest of the parameter name ("param1", "param2")
74      */

75     public ServletRequestParameterPropertyValues(ServletRequest JavaDoc request, String JavaDoc prefix, String JavaDoc prefixSeparator) {
76         super(WebUtils.getParametersStartingWith(
77                 request, (prefix != null) ? prefix + prefixSeparator : null));
78     }
79
80 }
81
Popular Tags