first bunch of backports from 3.1 M2 to 3.0.6
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -22,6 +22,7 @@ import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.multipart.MultipartRequest;
|
||||
import org.springframework.web.portlet.util.PortletUtils;
|
||||
|
||||
/**
|
||||
* Special {@link org.springframework.validation.DataBinder} to perform data binding
|
||||
@@ -105,8 +106,8 @@ public class PortletRequestDataBinder extends WebDataBinder {
|
||||
*/
|
||||
public void bind(PortletRequest request) {
|
||||
MutablePropertyValues mpvs = new PortletRequestParameterPropertyValues(request);
|
||||
if (request instanceof MultipartRequest) {
|
||||
MultipartRequest multipartRequest = (MultipartRequest) request;
|
||||
MultipartRequest multipartRequest = PortletUtils.getNativeRequest(request, MultipartRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
|
||||
}
|
||||
doBind(mpvs);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,13 +23,12 @@ import java.util.Map;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.portlet.filter.PortletRequestWrapper;
|
||||
import javax.portlet.filter.PortletResponseWrapper;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.portlet.util.PortletUtils;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.web.context.request.WebRequest} adapter
|
||||
@@ -79,40 +78,12 @@ public class PortletWebRequest extends PortletRequestAttributes implements Nativ
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeRequest(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
PortletRequest request = getRequest();
|
||||
while (request != null) {
|
||||
if (requiredType.isInstance(request)) {
|
||||
return (T) request;
|
||||
}
|
||||
else if (request instanceof PortletRequestWrapper) {
|
||||
request = ((PortletRequestWrapper) request).getRequest();
|
||||
}
|
||||
else {
|
||||
request = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return PortletUtils.getNativeRequest(getRequest(), requiredType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeResponse(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
PortletResponse response = getResponse();
|
||||
while (response != null) {
|
||||
if (requiredType.isInstance(response)) {
|
||||
return (T) response;
|
||||
}
|
||||
else if (response instanceof PortletResponseWrapper) {
|
||||
response = ((PortletResponseWrapper) response).getResponse();
|
||||
}
|
||||
else {
|
||||
response = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return PortletUtils.getNativeResponse(getResponse(), requiredType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -32,6 +32,9 @@ import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.portlet.ResourceResponse;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.filter.PortletRequestWrapper;
|
||||
import javax.portlet.filter.PortletResponseWrapper;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -276,6 +279,48 @@ public abstract class PortletUtils {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an appropriate request object of the specified type, if available,
|
||||
* unwrapping the given request as far as necessary.
|
||||
* @param request the portlet request to introspect
|
||||
* @param requiredType the desired type of request object
|
||||
* @return the matching request object, or <code>null</code> if none
|
||||
* of that type is available
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getNativeRequest(PortletRequest request, Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
if (requiredType.isInstance(request)) {
|
||||
return (T) request;
|
||||
}
|
||||
else if (request instanceof PortletRequestWrapper) {
|
||||
return getNativeRequest(((PortletRequestWrapper) request).getRequest(), requiredType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an appropriate response object of the specified type, if available,
|
||||
* unwrapping the given response as far as necessary.
|
||||
* @param response the portlet response to introspect
|
||||
* @param requiredType the desired type of response object
|
||||
* @return the matching response object, or <code>null</code> if none
|
||||
* of that type is available
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getNativeResponse(PortletResponse response, Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
if (requiredType.isInstance(response)) {
|
||||
return (T) response;
|
||||
}
|
||||
else if (response instanceof PortletResponseWrapper) {
|
||||
return getNativeResponse(((PortletResponseWrapper) response).getResponse(), requiredType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the given Map as request attributes, using the keys as attribute names
|
||||
* and the values as corresponding attribute values. Keys must be Strings.
|
||||
@@ -293,7 +338,7 @@ public abstract class PortletUtils {
|
||||
/**
|
||||
* Retrieve the first cookie with the given name. Note that multiple
|
||||
* cookies can have the same name but different paths or domains.
|
||||
* @param request current servlet request
|
||||
* @param request current portlet request
|
||||
* @param name cookie name
|
||||
* @return the first cookie with the given name, or <code>null</code> if none is found
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user