Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-27 00:27:52 +00:00
parent 6bbc966a21
commit b0790bf5e7
248 changed files with 2374 additions and 3208 deletions

View File

@@ -972,8 +972,8 @@ public class DispatcherPortlet extends FrameworkPortlet {
throws Exception {
ModelAndView exMv = null;
for (Iterator it = this.handlerExceptionResolvers.iterator(); exMv == null && it.hasNext();) {
HandlerExceptionResolver resolver = (HandlerExceptionResolver) it.next();
for (Iterator<HandlerExceptionResolver> it = this.handlerExceptionResolvers.iterator(); exMv == null && it.hasNext();) {
HandlerExceptionResolver resolver = it.next();
exMv = resolver.resolveException(request, response, handler, ex);
}
if (exMv != null) {

View File

@@ -91,7 +91,7 @@ public class ModelAndView {
* (Objects). Model entries may not be <code>null</code>, but the
* model Map may be <code>null</code> if there is no model data.
*/
public ModelAndView(String viewName, Map model) {
public ModelAndView(String viewName, Map<String, ?> model) {
this.view = viewName;
if (model != null) {
getModelMap().addAllAttributes(model);
@@ -105,7 +105,7 @@ public class ModelAndView {
* (Objects). Model entries may not be <code>null</code>, but the
* model Map may be <code>null</code> if there is no model data.
*/
public ModelAndView(Object view, Map model) {
public ModelAndView(Object view, Map<String, ?> model) {
this.view = view;
if (model != null) {
getModelMap().addAllAttributes(model);
@@ -193,7 +193,7 @@ public class ModelAndView {
* Return the model map. May return <code>null</code>.
* Called by DispatcherPortlet for evaluation of the model.
*/
protected Map getModelInternal() {
protected Map<String, Object> getModelInternal() {
return this.model;
}
@@ -211,7 +211,7 @@ public class ModelAndView {
* Return the model map. Never returns <code>null</code>.
* To be called by application code for modifying the model.
*/
public Map getModel() {
public Map<String, Object> getModel() {
return getModelMap();
}
@@ -245,7 +245,7 @@ public class ModelAndView {
* @see ModelMap#addAllAttributes(Map)
* @see #getModelMap()
*/
public ModelAndView addAllObjects(Map modelMap) {
public ModelAndView addAllObjects(Map<String, ?> modelMap) {
getModelMap().addAllAttributes(modelMap);
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -73,12 +73,12 @@ public class PortletContextResourcePatternResolver extends PathMatchingResourceP
* @see javax.portlet.PortletContext#getResourcePaths
*/
@Override
protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
if (rootDirResource instanceof PortletContextResource) {
PortletContextResource pcResource = (PortletContextResource) rootDirResource;
PortletContext pc = pcResource.getPortletContext();
String fullPattern = pcResource.getPath() + subPattern;
Set result = new HashSet();
Set<Resource> result = new HashSet<Resource>();
doRetrieveMatchingPortletContextResources(pc, fullPattern, pcResource.getPath(), result);
return result;
}
@@ -98,11 +98,11 @@ public class PortletContextResourcePatternResolver extends PathMatchingResourceP
* @see javax.portlet.PortletContext#getResourcePaths
*/
protected void doRetrieveMatchingPortletContextResources(
PortletContext portletContext, String fullPattern, String dir, Set result) throws IOException {
PortletContext portletContext, String fullPattern, String dir, Set<Resource> result) throws IOException {
Set candidates = portletContext.getResourcePaths(dir);
if (candidates != null) {
boolean dirDepthNotFixed = (fullPattern.indexOf("**") != -1);
boolean dirDepthNotFixed = fullPattern.contains("**");
for (Iterator it = candidates.iterator(); it.hasNext();) {
String currPath = (String) it.next();
if (currPath.endsWith("/") &&

View File

@@ -18,12 +18,10 @@ package org.springframework.web.portlet.handler;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletRequest;
import org.springframework.beans.BeansException;
@@ -40,11 +38,11 @@ import org.springframework.util.Assert;
* @see #getLookupKey(javax.portlet.PortletRequest)
* @see #registerHandler(Object, Object)
*/
public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapping {
public abstract class AbstractMapBasedHandlerMapping<K> extends AbstractHandlerMapping {
private boolean lazyInitHandlers = false;
private final Map handlerMap = new HashMap();
private final Map<K, Object> handlerMap = new HashMap<K, Object>();
/**
@@ -67,18 +65,20 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
* @see #getLookupKey
*/
@Override
@SuppressWarnings("unchecked")
protected Object getHandlerInternal(PortletRequest request) throws Exception {
Object lookupKey = getLookupKey(request);
K lookupKey = getLookupKey(request);
Object handler = this.handlerMap.get(lookupKey);
if (handler != null && logger.isDebugEnabled()) {
logger.debug("Key [" + lookupKey + "] -> handler [" + handler + "]");
}
if (handler instanceof Map) {
Map predicateMap = (Map) handler;
List predicates = new LinkedList(predicateMap.keySet());
Map<PortletRequestMappingPredicate, Object> predicateMap =
(Map<PortletRequestMappingPredicate, Object>) handler;
List<PortletRequestMappingPredicate> predicates =
new LinkedList<PortletRequestMappingPredicate>(predicateMap.keySet());
Collections.sort(predicates);
for (Iterator it = predicates.iterator(); it.hasNext();) {
PortletRequestMappingPredicate predicate = (PortletRequestMappingPredicate) it.next();
for (PortletRequestMappingPredicate predicate : predicates) {
if (predicate.match(request)) {
return predicateMap.get(predicate);
}
@@ -94,7 +94,7 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
* @return the lookup key (never <code>null</code>)
* @throws Exception if key computation failed
*/
protected abstract Object getLookupKey(PortletRequest request) throws Exception;
protected abstract K getLookupKey(PortletRequest request) throws Exception;
/**
@@ -102,10 +102,9 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
* @param handlerMap Map with lookup keys as keys and handler beans or bean names as values
* @throws BeansException if the handler couldn't be registered
*/
protected void registerHandlers(Map handlerMap) throws BeansException {
protected void registerHandlers(Map<K, ?> handlerMap) throws BeansException {
Assert.notNull(handlerMap, "Handler Map must not be null");
for (Iterator it = handlerMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
for (Map.Entry<K, ?> entry : handlerMap.entrySet()) {
registerHandler(entry.getKey(), entry.getValue());
}
}
@@ -118,7 +117,7 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
* @throws BeansException if the handler couldn't be registered
* @throws IllegalStateException if there is a conflicting handler registered
*/
protected void registerHandler(Object lookupKey, Object handler) throws BeansException, IllegalStateException {
protected void registerHandler(K lookupKey, Object handler) throws BeansException, IllegalStateException {
registerHandler(lookupKey, handler, null);
}
@@ -132,7 +131,8 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
* @throws BeansException if the handler couldn't be registered
* @throws IllegalStateException if there is a conflicting handler registered
*/
protected void registerHandler(Object lookupKey, Object handler, PortletRequestMappingPredicate predicate)
@SuppressWarnings("unchecked")
protected void registerHandler(K lookupKey, Object handler, PortletRequestMappingPredicate predicate)
throws BeansException, IllegalStateException {
Assert.notNull(lookupKey, "Lookup key must not be null");
@@ -158,9 +158,10 @@ public abstract class AbstractMapBasedHandlerMapping extends AbstractHandlerMapp
else {
if (predicate != null) {
// Add the handler to the predicate map.
Map predicateMap = (Map) mappedHandler;
Map<PortletRequestMappingPredicate, Object> predicateMap =
(Map<PortletRequestMappingPredicate, Object>) mappedHandler;
if (predicateMap == null) {
predicateMap = new LinkedHashMap();
predicateMap = new LinkedHashMap<PortletRequestMappingPredicate, Object>();
this.handlerMap.put(lookupKey, predicateMap);
}
predicateMap.put(predicate, resolvedHandler);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -17,12 +17,10 @@
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 {@link org.springframework.web.portlet.HandlerMapping}
@@ -51,7 +49,7 @@ import org.springframework.util.CollectionUtils;
* @since 2.0
* @see ParameterMappingInterceptor
*/
public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping {
public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping<String> {
/**
* Default request parameter name to use for mapping to handlers: "action".
@@ -61,7 +59,7 @@ public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping {
private String parameterName = DEFAULT_PARAMETER_NAME;
private Map parameterMap;
private Map<String, ?> parameterMap;
/**
@@ -78,7 +76,7 @@ public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping {
* Convenient for population with bean references.
* @param parameterMap map with parameters as keys and beans as values
*/
public void setParameterMap(Map parameterMap) {
public void setParameterMap(Map<String, ?> parameterMap) {
this.parameterMap = parameterMap;
}
@@ -94,28 +92,12 @@ public class ParameterHandlerMapping extends AbstractMapBasedHandlerMapping {
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
*/
@Override
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
*/
@Override
protected Object getLookupKey(PortletRequest request) throws Exception {
protected String getLookupKey(PortletRequest request) throws Exception {
return request.getParameter(this.parameterName);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -17,14 +17,13 @@
package org.springframework.web.portlet.handler;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import org.springframework.beans.BeansException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@@ -48,9 +47,9 @@ import org.springframework.util.CollectionUtils;
* @author John A. Lewis
* @since 2.0
*/
public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping {
public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping<PortletMode> {
private final Map portletModeMap = new HashMap();
private final Map<String, Object> portletModeMap = new HashMap<String, Object>();
/**
@@ -58,7 +57,7 @@ public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping {
* @param mappings properties with PortletMode names as keys and bean names as values
*/
public void setMappings(Properties mappings) {
this.portletModeMap.putAll(mappings);
CollectionUtils.mergePropertiesIntoMap(mappings, this.portletModeMap);
}
/**
@@ -66,7 +65,7 @@ public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping {
* Convenient for population with bean references.
* @param portletModeMap map with PortletMode names as keys and beans or bean names as values
*/
public void setPortletModeMap(Map portletModeMap) {
public void setPortletModeMap(Map<String, ?> portletModeMap) {
this.portletModeMap.putAll(portletModeMap);
}
@@ -79,27 +78,17 @@ public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping {
@Override
public void initApplicationContext() throws BeansException {
super.initApplicationContext();
registerHandlers(this.portletModeMap);
registerHandlersByMode(this.portletModeMap);
}
/**
* Register all handlers specified in the Portlet mode map for the corresponding modes.
* @param portletModeMap Map with mode names as keys and handler beans or bean names as values
* @throws BeansException if the handler couldn't be registered
*/
@Override
protected void registerHandlers(Map portletModeMap) throws BeansException {
if (CollectionUtils.isEmpty(portletModeMap)) {
logger.warn("Neither 'portletModeMap' nor 'mappings' set on PortletModeHandlerMapping");
}
else {
for (Iterator it = portletModeMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String modeKey = (String) entry.getKey();
PortletMode mode = new PortletMode(modeKey);
Object handler = entry.getValue();
registerHandler(mode, handler);
}
protected void registerHandlersByMode(Map<String, Object> portletModeMap) {
Assert.notNull(portletModeMap, "'portletModeMap' must not be null");
for (Map.Entry<String, Object> entry : portletModeMap.entrySet()) {
registerHandler(new PortletMode(entry.getKey()), entry.getValue());
}
}
@@ -108,7 +97,7 @@ public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping {
* Uses the current PortletMode as lookup key.
*/
@Override
protected Object getLookupKey(PortletRequest request) throws Exception {
protected PortletMode getLookupKey(PortletRequest request) throws Exception {
return request.getPortletMode();
}

View File

@@ -17,17 +17,13 @@
package org.springframework.web.portlet.handler;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import org.springframework.beans.BeansException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
/**
* Implementation of the {@link org.springframework.web.portlet.HandlerMapping}
@@ -82,7 +78,7 @@ import org.springframework.util.ObjectUtils;
* @since 2.0
* @see ParameterMappingInterceptor
*/
public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerMapping {
public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerMapping<PortletModeParameterLookupKey> {
/**
* Default request parameter name to use for mapping to handlers: "action".
@@ -92,11 +88,11 @@ public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerM
private String parameterName = DEFAULT_PARAMETER_NAME;
private Map portletModeParameterMap;
private Map<String, Map<String, ?>> portletModeParameterMap;
private boolean allowDuplicateParameters = false;
private final Set parametersUsed = new HashSet();
private final Set<String> parametersUsed = new HashSet<String>();
/**
@@ -114,7 +110,7 @@ public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerM
* <p>Convenient for population with bean references.
* @param portletModeParameterMap two-level map of portlet modes and parameters to handler beans
*/
public void setPortletModeParameterMap(Map portletModeParameterMap) {
public void setPortletModeParameterMap(Map<String, Map<String, ?>> portletModeParameterMap) {
this.portletModeParameterMap = portletModeParameterMap;
}
@@ -140,45 +136,28 @@ public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerM
@Override
public void initApplicationContext() throws BeansException {
super.initApplicationContext();
registerHandlers(this.portletModeParameterMap);
registerHandlersByModeAndParameter(this.portletModeParameterMap);
}
/**
* Register all handlers specified in the Portlet mode map for the corresponding modes.
* @param portletModeParameterMap Map with mode names as keys and parameter Maps as values
* @throws BeansException if the handler couldn't be registered
*/
@Override
protected void registerHandlers(Map portletModeParameterMap) throws BeansException {
if (CollectionUtils.isEmpty(portletModeParameterMap)) {
logger.warn("'portletModeParameterMap' not set on PortletModeParameterHandlerMapping");
}
else {
for (Iterator it = portletModeParameterMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String modeKey = (String) entry.getKey();
PortletMode mode = new PortletMode(modeKey);
Object parameterMap = entry.getValue();
if (!(parameterMap instanceof Map)) {
throw new IllegalArgumentException(
"The value for the portlet mode must be a Map of parameter Strings to handler Objects");
}
registerHandler(mode, (Map) parameterMap);
}
protected void registerHandlersByModeAndParameter(Map<String, Map<String, ?>> portletModeParameterMap) {
Assert.notNull(portletModeParameterMap, "'portletModeParameterMap' must not be null");
for (Map.Entry<String, Map<String, ?>> entry : portletModeParameterMap.entrySet()) {
PortletMode mode = new PortletMode(entry.getKey());
registerHandler(mode, entry.getValue());
}
}
/**
* Register all handlers specified in the given parameter map.
* @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 registerHandler(PortletMode mode, Map parameterMap) throws BeansException {
for (Iterator it = parameterMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String parameter = (String) entry.getKey();
Object handler = entry.getValue();
registerHandler(mode, parameter, handler);
protected void registerHandler(PortletMode mode, Map<String, ?> parameterMap) {
for (Map.Entry<String, ?> entry : parameterMap.entrySet()) {
registerHandler(mode, entry.getKey(), entry.getValue());
}
}
@@ -202,10 +181,9 @@ public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerM
}
this.parametersUsed.add(parameter);
registerHandler(new LookupKey(mode, parameter), handler);
registerHandler(new PortletModeParameterLookupKey(mode, parameter), handler);
}
/**
* Returns a lookup key that combines the current PortletMode and the current
* value of the specified parameter.
@@ -213,49 +191,10 @@ public class PortletModeParameterHandlerMapping extends AbstractMapBasedHandlerM
* @see #setParameterName
*/
@Override
protected Object getLookupKey(PortletRequest request) throws Exception {
protected PortletModeParameterLookupKey getLookupKey(PortletRequest request) throws Exception {
PortletMode mode = request.getPortletMode();
String parameter = request.getParameter(this.parameterName);
return new LookupKey(mode, parameter);
}
/**
* Internal class used as lookup key, combining PortletMode and parameter value.
*/
private static class LookupKey {
private final PortletMode mode;
private final String parameter;
public LookupKey(PortletMode portletMode, String parameter) {
this.mode = portletMode;
this.parameter = parameter;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof LookupKey)) {
return false;
}
LookupKey otherKey = (LookupKey) other;
return (this.mode.equals(otherKey.mode) &&
ObjectUtils.nullSafeEquals(this.parameter, otherKey.parameter));
}
@Override
public int hashCode() {
return (this.mode.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.parameter));
}
@Override
public String toString() {
return "Portlet mode '" + this.mode + "', parameter '" + this.parameter + "'";
}
return new PortletModeParameterLookupKey(mode, parameter);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2002-2008 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 javax.portlet.PortletMode;
import org.springframework.util.ObjectUtils;
/**
* Internal class used as lookup key, combining PortletMode and parameter value.
*
* @author Juergen Hoeller
*/
class PortletModeParameterLookupKey {
private final PortletMode mode;
private final String parameter;
public PortletModeParameterLookupKey(PortletMode portletMode, String parameter) {
this.mode = portletMode;
this.parameter = parameter;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof PortletModeParameterLookupKey)) {
return false;
}
PortletModeParameterLookupKey otherKey = (PortletModeParameterLookupKey) other;
return (this.mode.equals(otherKey.mode) &&
ObjectUtils.nullSafeEquals(this.parameter, otherKey.parameter));
}
@Override
public int hashCode() {
return (this.mode.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.parameter));
}
@Override
public String toString() {
return "Portlet mode '" + this.mode + "', parameter '" + this.parameter + "'";
}
}

View File

@@ -20,6 +20,7 @@ import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.PortletContext;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadBase;
@@ -113,12 +114,7 @@ public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport
public boolean isMultipart(ActionRequest request) {
if (request == null) {
return false;
}
else {
return PortletFileUpload.isMultipartContent(request);
}
return (request != null && PortletFileUpload.isMultipartContent(request));
}
public MultipartActionRequest resolveMultipart(final ActionRequest request) throws MultipartException {
@@ -146,11 +142,12 @@ public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport
* @return the parsing result
* @throws MultipartException if multipart resolution failed.
*/
@SuppressWarnings("unchecked")
protected MultipartParsingResult parseRequest(ActionRequest request) throws MultipartException {
String encoding = determineEncoding(request);
FileUpload fileUpload = prepareFileUpload(encoding);
try {
List fileItems = ((PortletFileUpload) fileUpload).parseRequest(request);
List<FileItem> fileItems = ((PortletFileUpload) fileUpload).parseRequest(request);
return parseFileItems(fileItems, encoding);
}
catch (FileUploadBase.SizeLimitExceededException ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.portlet.ActionRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -39,22 +38,24 @@ import org.springframework.web.portlet.util.ActionRequestWrapper;
*/
public class DefaultMultipartActionRequest extends ActionRequestWrapper implements MultipartActionRequest {
private Map multipartFiles;
private Map<String, MultipartFile> multipartFiles;
private Map multipartParameters;
private Map<String, String[]> multipartParameters;
/**
* Wrap the given Portlet ActionRequest in a MultipartActionRequest.
* @param request the request to wrap
* @param multipartFiles a map of the multipart files
* @param multipartParameters a map of the parameters to expose,
* @param mpFiles a map of the multipart files
* @param mpParams a map of the parameters to expose,
* with Strings as keys and String arrays as values
*/
public DefaultMultipartActionRequest(ActionRequest request, Map multipartFiles, Map multipartParameters) {
public DefaultMultipartActionRequest(
ActionRequest request, Map<String, MultipartFile> mpFiles, Map<String, String[]> mpParams) {
super(request);
setMultipartFiles(multipartFiles);
setMultipartParameters(multipartParameters);
setMultipartFiles(mpFiles);
setMultipartParameters(mpParams);
}
/**
@@ -66,25 +67,25 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
}
public Iterator getFileNames() {
public Iterator<String> getFileNames() {
return getMultipartFiles().keySet().iterator();
}
public MultipartFile getFile(String name) {
return (MultipartFile) getMultipartFiles().get(name);
return getMultipartFiles().get(name);
}
public Map getFileMap() {
public Map<String, MultipartFile> getFileMap() {
return getMultipartFiles();
}
@Override
public Enumeration getParameterNames() {
Set paramNames = new HashSet();
public Enumeration<String> getParameterNames() {
Set<String> paramNames = new HashSet<String>();
Enumeration paramEnum = super.getParameterNames();
while (paramEnum.hasMoreElements()) {
paramNames.add(paramEnum.nextElement());
paramNames.add((String) paramEnum.nextElement());
}
paramNames.addAll(getMultipartParameters().keySet());
return Collections.enumeration(paramNames);
@@ -92,7 +93,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
@Override
public String getParameter(String name) {
String[] values = (String[]) getMultipartParameters().get(name);
String[] values = getMultipartParameters().get(name);
if (values != null) {
return (values.length > 0 ? values[0] : null);
}
@@ -101,7 +102,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
@Override
public String[] getParameterValues(String name) {
String[] values = (String[]) getMultipartParameters().get(name);
String[] values = getMultipartParameters().get(name);
if (values != null) {
return values;
}
@@ -109,8 +110,9 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
}
@Override
public Map getParameterMap() {
Map paramMap = new HashMap();
@SuppressWarnings("unchecked")
public Map<String, String[]> getParameterMap() {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.putAll(super.getParameterMap());
paramMap.putAll(getMultipartParameters());
return paramMap;
@@ -121,7 +123,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
* Set a Map with parameter names as keys and MultipartFile objects as values.
* To be invoked by subclasses on initialization.
*/
protected final void setMultipartFiles(Map multipartFiles) {
protected final void setMultipartFiles(Map<String, MultipartFile> multipartFiles) {
this.multipartFiles = Collections.unmodifiableMap(multipartFiles);
}
@@ -130,7 +132,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
* lazily initializing it if necessary.
* @see #initializeMultipart()
*/
protected Map getMultipartFiles() {
protected Map<String, MultipartFile> getMultipartFiles() {
if (this.multipartFiles == null) {
initializeMultipart();
}
@@ -141,7 +143,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
* Set a Map with parameter names as keys and String array objects as values.
* To be invoked by subclasses on initialization.
*/
protected final void setMultipartParameters(Map multipartParameters) {
protected final void setMultipartParameters(Map<String, String[]> multipartParameters) {
this.multipartParameters = multipartParameters;
}
@@ -150,7 +152,7 @@ public class DefaultMultipartActionRequest extends ActionRequestWrapper implemen
* lazily initializing it if necessary.
* @see #initializeMultipart()
*/
protected Map getMultipartParameters() {
protected Map<String, String[]> getMultipartParameters() {
if (this.multipartParameters == null) {
initializeMultipart();
}

View File

@@ -49,7 +49,9 @@ import org.springframework.web.portlet.util.PortletUtils;
* @see #setCommandClass
* @see #setCommandName
* @see #setValidator
* @deprecated as of Spring 3.0, in favor of annotated controllers
*/
@Deprecated
public abstract class AbstractCommandController extends BaseCommandController {
/**

View File

@@ -243,7 +243,9 @@ import org.springframework.web.portlet.handler.PortletSessionRequiredException;
* @see #showForm(RenderRequest, RenderResponse, BindException)
* @see SimpleFormController
* @see AbstractWizardFormController
* @deprecated as of Spring 3.0, in favor of annotated controllers
*/
@Deprecated
public abstract class AbstractFormController extends BaseCommandController {
/**

View File

@@ -17,9 +17,7 @@
package org.springframework.web.portlet.mvc;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
@@ -83,7 +81,9 @@ import org.springframework.web.portlet.util.PortletUtils;
* @see #validatePage
* @see #processFinish
* @see #processCancel
* @deprecated as of Spring 3.0, in favor of annotated controllers
*/
@Deprecated
public abstract class AbstractWizardFormController extends AbstractFormController {
/**
@@ -480,10 +480,9 @@ public abstract class AbstractWizardFormController extends AbstractFormControlle
*/
protected void setTargetRenderParameter(ActionRequest request, ActionResponse response) {
try {
Iterator it = PortletUtils.getParametersStartingWith(request, PARAM_TARGET).entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String param = PARAM_TARGET + (String) entry.getKey();
Map<String, Object> params = PortletUtils.getParametersStartingWith(request, PARAM_TARGET);
for (Map.Entry<String, Object> entry : params.entrySet()) {
String param = PARAM_TARGET + entry.getKey();
Object value = entry.getValue();
if (logger.isDebugEnabled()) {
logger.debug("Setting target render parameter [" + param + "]");

View File

@@ -138,7 +138,9 @@ import org.springframework.web.portlet.handler.PortletSessionRequiredException;
* @author Juergen Hoeller
* @author John A. Lewis
* @since 2.0
* @deprecated as of Spring 3.0, in favor of annotated controllers
*/
@Deprecated
public abstract class BaseCommandController extends AbstractController {
/**

View File

@@ -132,7 +132,9 @@ import org.springframework.web.portlet.ModelAndView;
* @author Juergen Hoeller
* @author Rob Harrop
* @since 2.0
* @deprecated as of Spring 3.0, in favor of annotated controllers
*/
@Deprecated
public class SimpleFormController extends AbstractFormController {
private String formView;

View File

@@ -19,15 +19,11 @@ package org.springframework.web.portlet.mvc.annotation;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.ReflectionUtils;
@@ -77,7 +73,7 @@ import org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping;
* @see RequestMapping
* @see AnnotationMethodHandlerAdapter
*/
public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapping {
public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapping<PortletMode> {
/**
* Calls the <code>registerHandlers</code> method in addition
@@ -99,10 +95,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
String[] beanNames = context.getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
Class<?> handlerType = context.getType(beanName);
ListableBeanFactory bf = (context instanceof ConfigurableApplicationContext ?
((ConfigurableApplicationContext) context).getBeanFactory() : context);
GenericBeanFactoryAccessor bfa = new GenericBeanFactoryAccessor(bf);
RequestMapping mapping = bfa.findAnnotationOnBean(beanName, RequestMapping.class);
RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
if (mapping != null) {
String[] modeKeys = mapping.value();
String[] params = mapping.params();
@@ -167,7 +160,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp
* Uses the current PortletMode as lookup key.
*/
@Override
protected Object getLookupKey(PortletRequest request) throws Exception {
protected PortletMode getLookupKey(PortletRequest request) throws Exception {
return request.getPortletMode();
}

View File

@@ -276,17 +276,11 @@ public abstract class PortletUtils {
* @param request current portlet request
* @param attributes the attributes Map
*/
public static void exposeRequestAttributes(PortletRequest request, Map attributes) {
public static void exposeRequestAttributes(PortletRequest request, Map<String, ?> attributes) {
Assert.notNull(request, "Request must not be null");
Assert.notNull(attributes, "attributes Map must not be null");
Iterator it = attributes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
if (!(entry.getKey() instanceof String)) {
throw new IllegalArgumentException(
"Invalid key [" + entry.getKey() + "] in attributes Map - only Strings allowed as attribute keys");
}
request.setAttribute((String) entry.getKey(), entry.getValue());
Assert.notNull(attributes, "Attributes Map must not be null");
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
request.setAttribute(entry.getKey(), entry.getValue());
}
}
@@ -345,10 +339,10 @@ public abstract class PortletUtils {
* @see javax.portlet.PortletRequest#getParameterValues
* @see javax.portlet.PortletRequest#getParameterMap
*/
public static Map getParametersStartingWith(PortletRequest request, String prefix) {
public static Map<String, Object> getParametersStartingWith(PortletRequest request, String prefix) {
Assert.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map params = new TreeMap();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}