EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style
This commit is contained in:
@@ -20,10 +20,10 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletException;
|
||||
@@ -45,7 +45,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.i18n.SimpleLocaleContext;
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.core.OrderComparator;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
@@ -262,16 +261,16 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
private PortletMultipartResolver multipartResolver;
|
||||
|
||||
/** List of HandlerMappings used by this portlet */
|
||||
private List handlerMappings;
|
||||
private List<HandlerMapping> handlerMappings;
|
||||
|
||||
/** List of HandlerAdapters used by this portlet */
|
||||
private List handlerAdapters;
|
||||
private List<HandlerAdapter> handlerAdapters;
|
||||
|
||||
/** List of HandlerExceptionResolvers used by this portlet */
|
||||
private List handlerExceptionResolvers;
|
||||
private List<HandlerExceptionResolver> handlerExceptionResolvers;
|
||||
|
||||
/** List of ViewResolvers used by this portlet */
|
||||
private List viewResolvers;
|
||||
private List<ViewResolver> viewResolvers;
|
||||
|
||||
|
||||
/**
|
||||
@@ -371,8 +370,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
*/
|
||||
private void initMultipartResolver(ApplicationContext context) {
|
||||
try {
|
||||
this.multipartResolver = (PortletMultipartResolver)
|
||||
context.getBean(MULTIPART_RESOLVER_BEAN_NAME, PortletMultipartResolver.class);
|
||||
this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, PortletMultipartResolver.class);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
|
||||
}
|
||||
@@ -396,19 +394,18 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
this.handlerMappings = null;
|
||||
|
||||
if (this.detectAllHandlerMappings) {
|
||||
// Find all HandlerMappings in the ApplicationContext,
|
||||
// including ancestor contexts.
|
||||
Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
// Find all HandlerMappings in the ApplicationContext, including ancestor contexts.
|
||||
Map<String, HandlerMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
context, HandlerMapping.class, true, false);
|
||||
if (!matchingBeans.isEmpty()) {
|
||||
this.handlerMappings = new ArrayList(matchingBeans.values());
|
||||
this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
|
||||
// We keep HandlerMappings in sorted order.
|
||||
Collections.sort(this.handlerMappings, new OrderComparator());
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Object hm = context.getBean(HANDLER_MAPPING_BEAN_NAME, HandlerMapping.class);
|
||||
HandlerMapping hm = context.getBean(HANDLER_MAPPING_BEAN_NAME, HandlerMapping.class);
|
||||
this.handlerMappings = Collections.singletonList(hm);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
@@ -435,19 +432,18 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
this.handlerAdapters = null;
|
||||
|
||||
if (this.detectAllHandlerAdapters) {
|
||||
// Find all HandlerAdapters in the ApplicationContext,
|
||||
// including ancestor contexts.
|
||||
Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
// Find all HandlerAdapters in the ApplicationContext, including ancestor contexts.
|
||||
Map<String, HandlerAdapter> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
context, HandlerAdapter.class, true, false);
|
||||
if (!matchingBeans.isEmpty()) {
|
||||
this.handlerAdapters = new ArrayList(matchingBeans.values());
|
||||
this.handlerAdapters = new ArrayList<HandlerAdapter>(matchingBeans.values());
|
||||
// We keep HandlerAdapters in sorted order.
|
||||
Collections.sort(this.handlerAdapters, new OrderComparator());
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Object ha = context.getBean(HANDLER_ADAPTER_BEAN_NAME, HandlerAdapter.class);
|
||||
HandlerAdapter ha = context.getBean(HANDLER_ADAPTER_BEAN_NAME, HandlerAdapter.class);
|
||||
this.handlerAdapters = Collections.singletonList(ha);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
@@ -474,19 +470,18 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
this.handlerExceptionResolvers = null;
|
||||
|
||||
if (this.detectAllHandlerExceptionResolvers) {
|
||||
// Find all HandlerExceptionResolvers in the ApplicationContext,
|
||||
// including ancestor contexts.
|
||||
Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
// Find all HandlerExceptionResolvers in the ApplicationContext, including ancestor contexts.
|
||||
Map<String, HandlerExceptionResolver> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
context, HandlerExceptionResolver.class, true, false);
|
||||
if (!matchingBeans.isEmpty()) {
|
||||
this.handlerExceptionResolvers = new ArrayList(matchingBeans.values());
|
||||
this.handlerExceptionResolvers = new ArrayList<HandlerExceptionResolver>(matchingBeans.values());
|
||||
// We keep HandlerExceptionResolvers in sorted order.
|
||||
Collections.sort(this.handlerExceptionResolvers, new OrderComparator());
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Object her = context.getBean(
|
||||
HandlerExceptionResolver her = context.getBean(
|
||||
HANDLER_EXCEPTION_RESOLVER_BEAN_NAME, HandlerExceptionResolver.class);
|
||||
this.handlerExceptionResolvers = Collections.singletonList(her);
|
||||
}
|
||||
@@ -514,19 +509,18 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
this.viewResolvers = null;
|
||||
|
||||
if (this.detectAllViewResolvers) {
|
||||
// Find all ViewResolvers in the ApplicationContext,
|
||||
// including ancestor contexts.
|
||||
Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
// Find all ViewResolvers in the ApplicationContext, including ancestor contexts.
|
||||
Map<String, ViewResolver> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
context, ViewResolver.class, true, false);
|
||||
if (!matchingBeans.isEmpty()) {
|
||||
this.viewResolvers = new ArrayList(matchingBeans.values());
|
||||
this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.values());
|
||||
// We keep ViewResolvers in sorted order.
|
||||
Collections.sort(this.viewResolvers, new OrderComparator());
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Object vr = context.getBean(VIEW_RESOLVER_BEAN_NAME, ViewResolver.class);
|
||||
ViewResolver vr = context.getBean(VIEW_RESOLVER_BEAN_NAME, ViewResolver.class);
|
||||
this.viewResolvers = Collections.singletonList(vr);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
@@ -552,11 +546,10 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
* @param context the current Portlet ApplicationContext
|
||||
* @param strategyInterface the strategy interface
|
||||
* @return the corresponding strategy object
|
||||
* @throws BeansException if initialization failed
|
||||
* @see #getDefaultStrategies
|
||||
*/
|
||||
protected Object getDefaultStrategy(ApplicationContext context, Class strategyInterface) throws BeansException {
|
||||
List strategies = getDefaultStrategies(context, strategyInterface);
|
||||
protected <T> T getDefaultStrategy(ApplicationContext context, Class<T> strategyInterface) {
|
||||
List<T> strategies = getDefaultStrategies(context, strategyInterface);
|
||||
if (strategies.size() != 1) {
|
||||
throw new BeanInitializationException(
|
||||
"DispatcherPortlet needs exactly 1 strategy for interface [" + strategyInterface.getName() + "]");
|
||||
@@ -573,42 +566,36 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
* @param context the current Portlet ApplicationContext
|
||||
* @param strategyInterface the strategy interface
|
||||
* @return the List of corresponding strategy objects
|
||||
* @throws BeansException if initialization failed
|
||||
*/
|
||||
protected List getDefaultStrategies(ApplicationContext context, Class strategyInterface) throws BeansException {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> List<T> getDefaultStrategies(ApplicationContext context, Class<T> strategyInterface) {
|
||||
String key = strategyInterface.getName();
|
||||
List strategies = null;
|
||||
String value = defaultStrategies.getProperty(key);
|
||||
if (value != null) {
|
||||
String[] classNames = StringUtils.commaDelimitedListToStringArray(value);
|
||||
strategies = new ArrayList(classNames.length);
|
||||
for (int i = 0; i < classNames.length; i++) {
|
||||
String className = classNames[i];
|
||||
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15 && className.indexOf("Annotation") != -1) {
|
||||
// Skip Java 5 specific strategies when running on JDK 1.4...
|
||||
continue;
|
||||
}
|
||||
List<T> strategies = new ArrayList<T>(classNames.length);
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
Class clazz = ClassUtils.forName(className, DispatcherPortlet.class.getClassLoader());
|
||||
Object strategy = createDefaultStrategy(context, clazz);
|
||||
strategies.add(strategy);
|
||||
strategies.add((T) strategy);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new BeanInitializationException(
|
||||
"Could not find DispatcherPortlet's default strategy class [" + className +
|
||||
"] for interface [" + key + "]", ex);
|
||||
"] for interface [" + key + "]", ex);
|
||||
}
|
||||
catch (LinkageError err) {
|
||||
throw new BeanInitializationException(
|
||||
"Error loading DispatcherPortlet's default strategy class [" + className +
|
||||
"] for interface [" + key + "]: problem with class file or dependent class", err);
|
||||
"] for interface [" + key + "]: problem with class file or dependent class", err);
|
||||
}
|
||||
}
|
||||
return strategies;
|
||||
}
|
||||
else {
|
||||
strategies = Collections.EMPTY_LIST;
|
||||
return new LinkedList<T>();
|
||||
}
|
||||
return strategies;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -767,7 +754,6 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
logger.debug("Bound render request context to thread: " + request);
|
||||
}
|
||||
|
||||
RenderRequest processedRequest = request;
|
||||
HandlerExecutionChain mappedHandler = null;
|
||||
int interceptorIndex = -1;
|
||||
|
||||
@@ -790,9 +776,9 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
}
|
||||
|
||||
// Determine handler for the current request.
|
||||
mappedHandler = getHandler(processedRequest, false);
|
||||
mappedHandler = getHandler(request, false);
|
||||
if (mappedHandler == null || mappedHandler.getHandler() == null) {
|
||||
noHandlerFound(processedRequest, response);
|
||||
noHandlerFound(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -801,8 +787,8 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
if (interceptors != null) {
|
||||
for (int i = 0; i < interceptors.length; i++) {
|
||||
HandlerInterceptor interceptor = interceptors[i];
|
||||
if (!interceptor.preHandleRender(processedRequest, response, mappedHandler.getHandler())) {
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
|
||||
if (!interceptor.preHandleRender(request, response, mappedHandler.getHandler())) {
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, null);
|
||||
return;
|
||||
}
|
||||
interceptorIndex = i;
|
||||
@@ -811,13 +797,13 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
|
||||
// Actually invoke the handler.
|
||||
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
|
||||
mv = ha.handleRender(processedRequest, response, mappedHandler.getHandler());
|
||||
mv = ha.handleRender(request, response, mappedHandler.getHandler());
|
||||
|
||||
// Apply postHandle methods of registered interceptors.
|
||||
if (interceptors != null) {
|
||||
for (int i = interceptors.length - 1; i >= 0; i--) {
|
||||
HandlerInterceptor interceptor = interceptors[i];
|
||||
interceptor.postHandleRender(processedRequest, response, mappedHandler.getHandler(), mv);
|
||||
interceptor.postHandleRender(request, response, mappedHandler.getHandler(), mv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -832,7 +818,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
|
||||
// Did the handler return a view to render?
|
||||
if (mv != null && !mv.isEmpty()) {
|
||||
render(mv, processedRequest, response);
|
||||
render(mv, request, response);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -842,19 +828,19 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
}
|
||||
|
||||
// Trigger after-completion for successful outcome.
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, null);
|
||||
}
|
||||
|
||||
catch (Exception ex) {
|
||||
// Trigger after-completion for thrown exception.
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, ex);
|
||||
throw ex;
|
||||
}
|
||||
catch (Error err) {
|
||||
PortletException ex =
|
||||
new PortletException("Error occured during request processing: " + err.getMessage(), err);
|
||||
// Trigger after-completion for thrown exception.
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
|
||||
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@@ -918,12 +904,10 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
return handler;
|
||||
}
|
||||
|
||||
Iterator it = this.handlerMappings.iterator();
|
||||
while (it.hasNext()) {
|
||||
HandlerMapping hm = (HandlerMapping) it.next();
|
||||
for (HandlerMapping hm : this.handlerMappings) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Testing handler map [" + hm + "] in DispatcherPortlet with name '" +
|
||||
getPortletName() + "'");
|
||||
logger.debug(
|
||||
"Testing handler map [" + hm + "] in DispatcherPortlet with name '" + getPortletName() + "'");
|
||||
}
|
||||
handler = hm.getHandler(request);
|
||||
if (handler != null) {
|
||||
@@ -961,9 +945,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
* This is a fatal error.
|
||||
*/
|
||||
protected HandlerAdapter getHandlerAdapter(Object handler) throws PortletException {
|
||||
Iterator it = this.handlerAdapters.iterator();
|
||||
while (it.hasNext()) {
|
||||
HandlerAdapter ha = (HandlerAdapter) it.next();
|
||||
for (HandlerAdapter ha : this.handlerAdapters) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Testing handler adapter [" + ha + "]");
|
||||
}
|
||||
@@ -1070,11 +1052,6 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
view = (View) viewObject;
|
||||
}
|
||||
|
||||
if (view == null) {
|
||||
throw new PortletException("Could not resolve view with name '" + mv.getViewName() +
|
||||
"' in portlet with name '" + getPortletName() + "'");
|
||||
}
|
||||
|
||||
// Set the content type on the response if needed and if possible.
|
||||
// The Portlet spec requires the content type to be set on the RenderResponse;
|
||||
// it's not sufficient to let the View set it on the ServletResponse.
|
||||
@@ -1111,8 +1088,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||
* @see ViewResolver#resolveViewName
|
||||
*/
|
||||
protected View resolveViewName(String viewName, Map model, RenderRequest request) throws Exception {
|
||||
for (Iterator it = this.viewResolvers.iterator(); it.hasNext();) {
|
||||
ViewResolver viewResolver = (ViewResolver) it.next();
|
||||
for (ViewResolver viewResolver : this.viewResolvers) {
|
||||
View view = viewResolver.resolveViewName(viewName, request.getLocale());
|
||||
if (view != null) {
|
||||
return view;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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.
|
||||
@@ -290,15 +290,15 @@ public class ModelAndView {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer("ModelAndView: ");
|
||||
StringBuilder result = new StringBuilder("ModelAndView: ");
|
||||
if (isReference()) {
|
||||
buf.append("reference to view with name '").append(this.view).append("'");
|
||||
result.append("reference to view with name '").append(this.view).append("'");
|
||||
}
|
||||
else {
|
||||
buf.append("materialized View is [").append(this.view).append(']');
|
||||
result.append("materialized View is [").append(this.view).append(']');
|
||||
}
|
||||
buf.append("; model is ").append(this.model);
|
||||
return buf.toString();
|
||||
result.append("; model is ").append(this.model);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ public abstract class AbstractRefreshablePortletApplicationContext extends Abstr
|
||||
beanFactory.registerResolvableDependency(PortletConfig.class, this.portletConfig);
|
||||
|
||||
PortletApplicationContextUtils.registerPortletApplicationScopes(beanFactory);
|
||||
PortletApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.portletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.web.portlet.context;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
@@ -127,4 +131,38 @@ public abstract class PortletApplicationContextUtils {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register web-specific environment beans with the given BeanFactory,
|
||||
* as used by the Portlet ApplicationContext.
|
||||
* @param bf the BeanFactory to configure
|
||||
* @param pc the PortletContext that we're running within
|
||||
*/
|
||||
static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, PortletContext pc) {
|
||||
if (!bf.containsBean(WebApplicationContext.CONTEXT_PROPERTIES_BEAN_NAME)) {
|
||||
Map<String, String> parameterMap = new HashMap<String, String>();
|
||||
if (pc != null) {
|
||||
Enumeration paramNameEnum = pc.getInitParameterNames();
|
||||
while (paramNameEnum.hasMoreElements()) {
|
||||
String paramName = (String) paramNameEnum.nextElement();
|
||||
parameterMap.put(paramName, pc.getInitParameter(paramName));
|
||||
}
|
||||
}
|
||||
bf.registerSingleton(WebApplicationContext.CONTEXT_PROPERTIES_BEAN_NAME,
|
||||
Collections.unmodifiableMap(parameterMap));
|
||||
}
|
||||
|
||||
if (!bf.containsBean(WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME)) {
|
||||
Map<String, Object> attributeMap = new HashMap<String, Object>();
|
||||
if (pc != null) {
|
||||
Enumeration attrNameEnum = pc.getAttributeNames();
|
||||
while (attrNameEnum.hasMoreElements()) {
|
||||
String attrName = (String) attrNameEnum.nextElement();
|
||||
attributeMap.put(attrName, pc.getAttribute(attrName));
|
||||
}
|
||||
}
|
||||
bf.registerSingleton(WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME,
|
||||
Collections.unmodifiableMap(attributeMap));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,18 +17,14 @@
|
||||
package org.springframework.web.portlet.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.AbstractRequestAttributes;
|
||||
import org.springframework.web.context.request.DestructionCallbackBindingListener;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.portlet.util.PortletUtils;
|
||||
|
||||
@@ -52,18 +48,20 @@ import org.springframework.web.portlet.util.PortletUtils;
|
||||
public class PortletRequestAttributes extends AbstractRequestAttributes {
|
||||
|
||||
/**
|
||||
* We'll create a lot of these objects, so we don't want a new logger every time.
|
||||
* Constant identifying the {@link String} prefixed to the name of a
|
||||
* destruction callback when it is stored in a {@link PortletSession}.
|
||||
*/
|
||||
private static final Log logger = LogFactory.getLog(PortletRequestAttributes.class);
|
||||
public static final String DESTRUCTION_CALLBACK_NAME_PREFIX =
|
||||
PortletRequestAttributes.class.getName() + ".DESTRUCTION_CALLBACK.";
|
||||
|
||||
|
||||
private final PortletRequest request;
|
||||
|
||||
private volatile PortletSession session;
|
||||
|
||||
private final Map sessionAttributesToUpdate = new HashMap();
|
||||
private final Map<String, Object> sessionAttributesToUpdate = new HashMap<String, Object>();
|
||||
|
||||
private final Map globalSessionAttributesToUpdate = new HashMap();
|
||||
private final Map<String, Object> globalSessionAttributesToUpdate = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -222,6 +220,18 @@ public class PortletRequestAttributes extends AbstractRequestAttributes {
|
||||
}
|
||||
}
|
||||
|
||||
public Object resolveReference(String key) {
|
||||
if (REFERENCE_REQUEST.equals(key)) {
|
||||
return this.request;
|
||||
}
|
||||
else if (REFERENCE_SESSION.equals(key)) {
|
||||
return getSession(true);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return getSession(true).getId();
|
||||
}
|
||||
@@ -240,9 +250,8 @@ public class PortletRequestAttributes extends AbstractRequestAttributes {
|
||||
this.session = this.request.getPortletSession(false);
|
||||
synchronized (this.sessionAttributesToUpdate) {
|
||||
if (this.session != null) {
|
||||
for (Iterator it = this.sessionAttributesToUpdate.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String name = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : this.sessionAttributesToUpdate.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object newValue = entry.getValue();
|
||||
Object oldValue = this.session.getAttribute(name);
|
||||
if (oldValue == newValue) {
|
||||
@@ -254,9 +263,8 @@ public class PortletRequestAttributes extends AbstractRequestAttributes {
|
||||
}
|
||||
synchronized (this.globalSessionAttributesToUpdate) {
|
||||
if (this.session != null) {
|
||||
for (Iterator it = this.globalSessionAttributesToUpdate.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String name = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : this.globalSessionAttributesToUpdate.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object newValue = entry.getValue();
|
||||
Object oldValue = this.session.getAttribute(name, PortletSession.APPLICATION_SCOPE);
|
||||
if (oldValue == newValue) {
|
||||
@@ -274,10 +282,9 @@ public class PortletRequestAttributes extends AbstractRequestAttributes {
|
||||
* @param callback the callback to be executed for destruction
|
||||
*/
|
||||
private void registerSessionDestructionCallback(String name, Runnable callback) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Could not register destruction callback [" + callback + "] for attribute '" + name +
|
||||
"' for session scope because Portlet API 1.0 does not support session attribute callbacks");
|
||||
}
|
||||
PortletSession session = getSession(true);
|
||||
session.setAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name,
|
||||
new DestructionCallbackBindingListener(callback));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -108,7 +108,7 @@ public class PortletRequestHandledEvent extends RequestHandledEvent {
|
||||
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("portlet=[").append(this.portletName).append("]; ");
|
||||
sb.append(super.getShortDescription());
|
||||
return sb.toString();
|
||||
@@ -116,7 +116,7 @@ public class PortletRequestHandledEvent extends RequestHandledEvent {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("portlet=[").append(this.portletName).append("]; ");
|
||||
sb.append("mode=[").append(this.portletMode).append("]; ");
|
||||
sb.append("type=[").append(this.requestType).append("]; ");
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.portlet.context;
|
||||
import java.security.Principal;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletSession;
|
||||
@@ -82,7 +81,8 @@ public class PortletWebRequest extends PortletRequestAttributes implements Nativ
|
||||
return getRequest().getParameterValues(paramName);
|
||||
}
|
||||
|
||||
public Map getParameterMap() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
return getRequest().getParameterMap();
|
||||
}
|
||||
|
||||
@@ -121,19 +121,19 @@ public class PortletWebRequest extends PortletRequestAttributes implements Nativ
|
||||
|
||||
public String getDescription(boolean includeClientInfo) {
|
||||
PortletRequest request = getRequest();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("context=").append(request.getContextPath());
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("context=").append(request.getContextPath());
|
||||
if (includeClientInfo) {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
buffer.append(";session=").append(session.getId());
|
||||
result.append(";session=").append(session.getId());
|
||||
}
|
||||
String user = getRequest().getRemoteUser();
|
||||
if (StringUtils.hasLength(user)) {
|
||||
buffer.append(";user=").append(user);
|
||||
result.append(";user=").append(user);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -144,6 +144,7 @@ public class StaticPortletApplicationContext extends StaticApplicationContext
|
||||
beanFactory.registerResolvableDependency(PortletConfig.class, this.portletConfig);
|
||||
|
||||
PortletApplicationContextUtils.registerPortletApplicationScopes(beanFactory);
|
||||
PortletApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.portletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.portlet.multipart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
@@ -26,10 +25,8 @@ import org.apache.commons.fileupload.FileUpload;
|
||||
import org.apache.commons.fileupload.FileUploadBase;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.portlet.PortletFileUpload;
|
||||
import org.apache.commons.fileupload.portlet.PortletRequestContext;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
import org.springframework.web.multipart.MultipartException;
|
||||
import org.springframework.web.multipart.commons.CommonsFileUploadSupport;
|
||||
@@ -39,7 +36,7 @@ import org.springframework.web.portlet.util.PortletUtils;
|
||||
/**
|
||||
* {@link PortletMultipartResolver} implementation for
|
||||
* <a href="http://jakarta.apache.org/commons/fileupload">Jakarta Commons FileUpload</a>
|
||||
* 1.1 or above. Commons FileUpload 1.2 or above is recommended.
|
||||
* 1.2 or above.
|
||||
*
|
||||
* <p>Provides "maxUploadSize", "maxInMemorySize" and "defaultEncoding" settings as
|
||||
* bean properties (inherited from {@link CommonsFileUploadSupport}). See corresponding
|
||||
@@ -61,9 +58,6 @@ import org.springframework.web.portlet.util.PortletUtils;
|
||||
public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport
|
||||
implements PortletMultipartResolver, PortletContextAware {
|
||||
|
||||
private final boolean commonsFileUpload12Present =
|
||||
ClassUtils.hasMethod(PortletFileUpload.class, "isMultipartContent", new Class[] {ActionRequest.class});
|
||||
|
||||
private boolean resolveLazily = false;
|
||||
|
||||
|
||||
@@ -122,11 +116,8 @@ public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport
|
||||
if (request == null) {
|
||||
return false;
|
||||
}
|
||||
else if (commonsFileUpload12Present) {
|
||||
return PortletFileUpload.isMultipartContent(request);
|
||||
}
|
||||
else {
|
||||
return PortletFileUpload.isMultipartContent(new PortletRequestContext(request));
|
||||
return PortletFileUpload.isMultipartContent(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user