1. /*
  2. * Copyright 2002-2004 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. package org.springframework.web.bind;
  17. import javax.servlet.ServletRequest;
  18. import org.springframework.beans.MutablePropertyValues;
  19. import org.springframework.web.util.WebUtils;
  20. /**
  21. * PropertyValues implementation created from parameters in a ServletRequest.
  22. * Looks for all property values beginning with a certain prefix
  23. * and prefix separator.
  24. *
  25. * <p>This class is not immutable to be able to efficiently remove property
  26. * values that should be ignored for binding.
  27. *
  28. * @author Rod Johnson
  29. * @author Juergen Hoeller
  30. * @version $Id: ServletRequestParameterPropertyValues.java,v 1.4 2004/03/18 02:46:15 trisberg Exp $
  31. */
  32. public class ServletRequestParameterPropertyValues extends MutablePropertyValues {
  33. /** Default prefix separator */
  34. public static final String DEFAULT_PREFIX_SEPARATOR = "_";
  35. /**
  36. * Create new ServletRequestPropertyValues using no prefix
  37. * (and hence, no prefix separator).
  38. * @param request HTTP Request
  39. */
  40. public ServletRequestParameterPropertyValues(ServletRequest request) {
  41. this(request, null, null);
  42. }
  43. /**
  44. * Create new ServletRequestPropertyValues using the default prefix
  45. * separator and the given prefix (the underscore character "_").
  46. * @param request HTTP Request
  47. * @param prefix prefix for properties
  48. */
  49. public ServletRequestParameterPropertyValues(ServletRequest request, String prefix) {
  50. this(request, prefix, DEFAULT_PREFIX_SEPARATOR);
  51. }
  52. /**
  53. * Create new ServletRequestPropertyValues supplying both prefix and prefix separator.
  54. * @param request HTTP Request
  55. * @param prefix prefix for properties
  56. * @param prefixSeparator Separator delimiting prefix (e.g. user) from property name
  57. * (e.g. age) to build a request parameter name such as user_age
  58. */
  59. public ServletRequestParameterPropertyValues(ServletRequest request, String prefix, String prefixSeparator) {
  60. super(WebUtils.getParametersStartingWith(request, (prefix != null) ? prefix + prefixSeparator : null));
  61. }
  62. }