001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.portlet.bind;
018
019import javax.portlet.PortletRequest;
020
021import org.springframework.beans.MutablePropertyValues;
022import org.springframework.web.portlet.util.PortletUtils;
023
024/**
025 * PropertyValues implementation created from parameters in a PortletRequest.
026 * Can look for all property values beginning with a certain prefix and
027 * prefix separator (default is "_").
028 *
029 * <p>For example, with a prefix of "spring", "spring_param1" and
030 * "spring_param2" result in a Map with "param1" and "param2" as keys.
031 *
032 * <p>This class is not immutable to be able to efficiently remove property
033 * values that should be ignored for binding.
034 *
035 * @author Juergen Hoeller
036 * @author John A. Lewis
037 * @since 2.0
038 * @see org.springframework.web.portlet.util.PortletUtils#getParametersStartingWith
039 */
040@SuppressWarnings("serial")
041public class PortletRequestParameterPropertyValues extends MutablePropertyValues {
042
043        /** Default prefix separator */
044        public static final String DEFAULT_PREFIX_SEPARATOR = "_";
045
046
047        /**
048         * Create new PortletRequestPropertyValues using no prefix
049         * (and hence, no prefix separator).
050         * @param request portlet request
051         */
052        public PortletRequestParameterPropertyValues(PortletRequest request) {
053                this(request, null, null);
054        }
055
056        /**
057         * Create new PortletRequestPropertyValues using the given prefix and
058         * the default prefix separator (the underscore character "_").
059         * @param request portlet request
060         * @param prefix the prefix for parameters (the full prefix will
061         * consist of this plus the separator)
062         * @see #DEFAULT_PREFIX_SEPARATOR
063         */
064        public PortletRequestParameterPropertyValues(PortletRequest request, String prefix) {
065                this(request, prefix, DEFAULT_PREFIX_SEPARATOR);
066        }
067
068        /**
069         * Create new PortletRequestPropertyValues supplying both prefix and
070         * prefix separator.
071         * @param request portlet request
072         * @param prefix the prefix for parameters (the full prefix will
073         * consist of this plus the separator)
074         * @param prefixSeparator separator delimiting prefix (e.g. "spring")
075         * and the rest of the parameter name ("param1", "param2")
076         */
077        public PortletRequestParameterPropertyValues(PortletRequest request, String prefix, String prefixSeparator) {
078                super(PortletUtils.getParametersStartingWith(
079                                request, (prefix != null ? prefix + prefixSeparator : null)));
080        }
081
082}