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.portlet.bind;
18:
19: import javax.portlet.PortletRequest;
20:
21: import org.springframework.beans.MutablePropertyValues;
22: import org.springframework.web.portlet.util.PortletUtils;
23:
24: /**
25: * PropertyValues implementation created from parameters in a PortletRequest.
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 Juergen Hoeller
36: * @author John A. Lewis
37: * @since 2.0
38: * @see org.springframework.web.portlet.util.PortletUtils#getParametersStartingWith
39: */
40: public class PortletRequestParameterPropertyValues extends
41: MutablePropertyValues {
42:
43: /** Default prefix separator */
44: public static final String DEFAULT_PREFIX_SEPARATOR = "_";
45:
46: /**
47: * Create new PortletRequestPropertyValues using no prefix
48: * (and hence, no prefix separator).
49: * @param request portlet request
50: */
51: public PortletRequestParameterPropertyValues(PortletRequest request) {
52: this (request, null, null);
53: }
54:
55: /**
56: * Create new PortletRequestPropertyValues using the given prefix and
57: * the default prefix separator (the underscore character "_").
58: * @param request portlet request
59: * @param prefix the prefix for parameters (the full prefix will
60: * consist of this plus the separator)
61: * @see #DEFAULT_PREFIX_SEPARATOR
62: */
63: public PortletRequestParameterPropertyValues(
64: PortletRequest request, String prefix) {
65: this (request, prefix, DEFAULT_PREFIX_SEPARATOR);
66: }
67:
68: /**
69: * Create new PortletRequestPropertyValues supplying both prefix and
70: * prefix separator.
71: * @param request portlet request
72: * @param prefix the prefix for parameters (the full prefix will
73: * consist of this plus the separator)
74: * @param prefixSeparator separator delimiting prefix (e.g. "spring")
75: * and the rest of the parameter name ("param1", "param2")
76: */
77: public PortletRequestParameterPropertyValues(
78: PortletRequest request, String prefix,
79: String prefixSeparator) {
80: super(PortletUtils.getParametersStartingWith(request,
81: (prefix != null) ? prefix + prefixSeparator : null));
82: }
83:
84: }
|