Polishing

(cherry picked from commit 2675ce7)
This commit is contained in:
Juergen Hoeller
2014-11-22 18:05:35 +01:00
parent f6e1856276
commit 7f1e5a49a4
4 changed files with 54 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -45,6 +45,7 @@ public abstract class FreeMarkerTemplateUtils {
*/
public static String processTemplateIntoString(Template template, Object model)
throws IOException, TemplateException {
StringWriter result = new StringWriter();
template.process(model, result);
return result.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
@@ -28,9 +28,9 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
/**
* FreeMarker TemplateLoader adapter that loads via a Spring ResourceLoader.
* Used by FreeMarkerConfigurationFactory for any resource loader path that
* cannot be resolved to a java.io.File.
* FreeMarker {@link TemplateLoader} adapter that loads via a Spring {@link ResourceLoader}.
* Used by {@link FreeMarkerConfigurationFactory} for any resource loader path that cannot
* be resolved to a {@link java.io.File}.
*
* @author Juergen Hoeller
* @since 14.03.2004
@@ -63,6 +63,7 @@ public class SpringTemplateLoader implements TemplateLoader {
}
}
public Object findTemplateSource(String name) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Looking for FreeMarker template with name [" + name + "]");
@@ -84,7 +85,6 @@ public class SpringTemplateLoader implements TemplateLoader {
}
}
public long getLastModified(Object templateSource) {
Resource resource = (Resource) templateSource;
try {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -36,11 +36,13 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
private int order = Ordered.LOWEST_PRECEDENCE;
public AbstractHandlerMethodAdapter() {
// no restriction of HTTP methods by default
super(false);
}
/**
* Specify the order value for this HandlerAdapter bean.
* <p>Default value is {@code Integer.MAX_VALUE}, meaning that it's non-ordered.
@@ -54,49 +56,47 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
return this.order;
}
/**
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
*
* This implementation expects the handler to be an {@link HandlerMethod}.
* @param handler the handler instance to check
* @return whether or not this adapter can adapt the given handler
*/
public final boolean supports(Object handler) {
return handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler);
return (handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler));
}
/**
* Given a handler method, return whether or not this adapter can support it.
*
* @param handlerMethod the handler method to check
* @return whether or not this adapter can adapt the given method
*/
protected abstract boolean supportsInternal(HandlerMethod handlerMethod);
/**
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
* This implementation expects the handler to be an {@link HandlerMethod}.
*/
public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
return handleInternal(request, response, (HandlerMethod) handler);
}
/**
* Use the given handler method to handle the request.
*
* @param request current HTTP request
* @param response current HTTP response
* @param handlerMethod handler method to use. This object must have previously been passed to the
* {@link #supportsInternal(HandlerMethod)} this interface, which must have returned {@code true}.
* @return ModelAndView object with the name of the view and the required model data, or {@code null} if
* the request has been handled directly
* @return ModelAndView object with the name of the view and the required model data,
* or {@code null} if the request has been handled directly
* @throws Exception in case of errors
*/
protected abstract ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response,
HandlerMethod handlerMethod) throws Exception;
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception;
/**
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
* This implementation expects the handler to be an {@link HandlerMethod}.
*/
public final long getLastModified(HttpServletRequest request, Object handler) {
return getLastModifiedInternal(request, (HandlerMethod) handler);
@@ -104,10 +104,10 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
/**
* Same contract as for {@link javax.servlet.http.HttpServlet#getLastModified(HttpServletRequest)}.
*
* @param request current HTTP request
* @param handlerMethod handler method to use
* @return the lastModified value for the given handler
*/
protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod);
}

View File

@@ -137,9 +137,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
private Long asyncRequestTimeout;
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[] {};
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[0];
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[] {};
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[0];
private boolean ignoreDefaultModelOnRedirect = false;
@@ -168,21 +168,18 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
/**
* Default constructor.
*/
public RequestMappingHandlerAdapter() {
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316
stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316
this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
this.messageConverters.add(new ByteArrayHttpMessageConverter());
this.messageConverters.add(stringHttpMessageConverter);
this.messageConverters.add(new SourceHttpMessageConverter<Source>());
this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
/**
* Provide resolvers for custom argument types. Custom resolvers are ordered
* after built-in ones. To override the built-in support for argument
@@ -305,6 +302,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return modelAndViewResolvers;
}
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
* If not set, the default constructor is used.
*/
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Provide the converters to use in argument resolvers and return value
* handlers that support reading and/or writing to the body of the
@@ -314,19 +319,11 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
this.messageConverters = messageConverters;
}
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
* If not set, the default constructor is used.
*/
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Return the configured message body converters.
*/
public List<HttpMessageConverter<?>> getMessageConverters() {
return messageConverters;
return this.messageConverters;
}
/**
@@ -338,10 +335,10 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the configured WebBindingInitializer, or {@code null}.
* Return the configured WebBindingInitializer, or {@code null} if none.
*/
public WebBindingInitializer getWebBindingInitializer() {
return webBindingInitializer;
return this.webBindingInitializer;
}
/**
@@ -460,9 +457,8 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* {@inheritDoc}
* <p>A {@link ConfigurableBeanFactory} is expected for resolving
* expressions in method argument default values.
* A {@link ConfigurableBeanFactory} is expected for resolving expressions
* in method argument default values.
*/
public void setBeanFactory(BeanFactory beanFactory) {
if (beanFactory instanceof ConfigurableBeanFactory) {
@@ -471,12 +467,13 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the owning factory of this bean instance, or {@code null}.
* Return the owning factory of this bean instance, or {@code null} if none.
*/
protected ConfigurableBeanFactory getBeanFactory() {
return this.beanFactory;
}
public void afterPropertiesSet() {
if (this.argumentResolvers == null) {
List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
@@ -634,6 +631,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
}
/**
* Always return {@code true} since any method argument and return value
* type will be processed in some way. A method argument not recognized
@@ -647,17 +645,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return true;
}
/**
* This implementation always returns -1. An {@code @RequestMapping}
* method can calculate the lastModified value, call
* {@link WebRequest#checkNotModified(long)}, and return {@code null}
* if the result of that call is {@code true}.
*/
@Override
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
return -1;
}
@Override
protected final ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
@@ -686,8 +673,19 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the {@link SessionAttributesHandler} instance for the given
* handler type, never {@code null}.
* This implementation always returns -1. An {@code @RequestMapping} method can
* calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
* and return {@code null} if the result of that call is {@code true}.
*/
@Override
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
return -1;
}
/**
* Return the {@link SessionAttributesHandler} instance for the given handler type
* (never {@code null}).
*/
private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handlerMethod) {
Class<?> handlerType = handlerMethod.getBeanType();