All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.web.portlet.handler.ParameterHandlerMapping Maven / Gradle / Ivy

There is a newer version: 5.3.34
Show newest version
/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.portlet.handler;

import java.util.Map;

import javax.portlet.PortletRequest;

import org.springframework.beans.BeansException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

/**
 * 

Implementation of the HandlerMapping interface to map from * a request parameter to request handler beans.

* *

The default name of the parameter is "action", but can be changed using * {@link #setParameterName setParameterName()}.

* *

The bean configuration for this mapping will look somthing like this:

*
 * 	<bean id="parameterHandlerMapping" class="org.springframework.web.portlet.handler.ParameterHandlerMapping">
 * 		<property name="parameterMap">
 * 			<map>
 * 				<entry key="add"><ref bean="addItemHandler"/></entry>
 * 				<entry key="edit"><ref bean="editItemHandler"/></entry>
 * 				<entry key="delete"><ref bean="deleteItemHandler"/></entry>
 * 			</map>
 * 		</property>
 * 	</bean>
 * 
* * @author Rainer Schmitz * @author John A. Lewis * @see ParameterMappingInterceptor * @since 2.0 */ public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping { /** * Default request parameter name to use for mapping to handlers: "action". */ public final static String DEFAULT_PARAMETER_NAME = "action"; private String parameterName = DEFAULT_PARAMETER_NAME; private Map parameterMap; /** * Set the name of the parameter used for mapping to handlers. *

Default is "action". */ public void setParameterName(String parameterName) { Assert.hasText(parameterName, "'parameterName' must not be empty"); this.parameterName = parameterName; } /** * Set a Map with parameters as keys and handler beans or bean names as values. * Convenient for population with bean references. * @param parameterMap map with parameters as keys and beans as values */ public void setParameterMap(Map parameterMap) { this.parameterMap = parameterMap; } /** * Calls the registerHandlers method in addition * to the superclass's initialization. * @see #registerHandlers */ public void initApplicationContext() throws BeansException { super.initApplicationContext(); registerHandlers(this.parameterMap); } /** * Register all handlers specified in the Portlet mode map for the corresponding modes. * @param parameterMap Map with parameter names as keys and handler beans or bean names as values * @throws BeansException if the handler couldn't be registered */ protected void registerHandlers(Map parameterMap) throws BeansException { if (CollectionUtils.isEmpty(parameterMap)) { logger.warn("'parameterMap' is empty on ParameterHandlerMapping"); } else { super.registerHandlers(parameterMap); } } /** * Uses the value of the specified parameter as lookup key. * @see #setParameterName */ protected Object getLookupKey(PortletRequest request) throws Exception { return request.getParameter(this.parameterName); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy