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.bind;
18:
19: import javax.servlet.ServletRequest;
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
40: MutablePropertyValues {
41:
42: /** Default prefix separator */
43: public static final String DEFAULT_PREFIX_SEPARATOR = "_";
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 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(
63: ServletRequest request, String prefix) {
64: this (request, prefix, DEFAULT_PREFIX_SEPARATOR);
65: }
66:
67: /**
68: * Create new ServletRequestPropertyValues supplying both prefix and
69: * prefix separator.
70: * @param request HTTP request
71: * @param prefix the prefix for parameters (the full prefix will
72: * consist of this plus the separator)
73: * @param prefixSeparator separator delimiting prefix (e.g. "spring")
74: * and the rest of the parameter name ("param1", "param2")
75: */
76: public ServletRequestParameterPropertyValues(
77: ServletRequest request, String prefix,
78: String prefixSeparator) {
79: super(WebUtils.getParametersStartingWith(request,
80: (prefix != null) ? prefix + prefixSeparator : null));
81: }
82:
83: }
|