Polishing

This commit is contained in:
Juergen Hoeller
2016-08-10 14:20:42 +02:00
parent a4b6682c3e
commit 59a24b406a
25 changed files with 154 additions and 152 deletions

View File

@@ -47,14 +47,13 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
*
* @author Rossen Stoyanchev
* @since 3.1
*
* @see DefaultServletHandlerConfigurer
*/
public class ResourceHandlerRegistry {
private final ServletContext servletContext;
private final ApplicationContext appContext;
private final ApplicationContext applicationContext;
private final ContentNegotiationManager contentNegotiationManager;
@@ -69,26 +68,30 @@ public class ResourceHandlerRegistry {
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext,
ContentNegotiationManager contentNegotiationManager) {
Assert.notNull(applicationContext, "ApplicationContext is required");
this.appContext = applicationContext;
this.applicationContext = applicationContext;
this.servletContext = servletContext;
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Add a resource handler for serving static resources based on the specified URL path patterns.
* The handler will be invoked for every incoming request that matches to one of the specified path patterns.
* @return A {@link ResourceHandlerRegistration} to use to further configure the registered resource handler.
* Add a resource handler for serving static resources based on the specified URL path
* patterns. The handler will be invoked for every incoming request that matches to
* one of the specified path patterns.
* @return A {@link ResourceHandlerRegistration} to use to further configure the
* registered resource handler
*/
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {
ResourceHandlerRegistration registration = new ResourceHandlerRegistration(this.appContext, pathPatterns);
ResourceHandlerRegistration registration =
new ResourceHandlerRegistration(this.applicationContext, pathPatterns);
this.registrations.add(registration);
return registration;
}
/**
* Whether a resource handler has already been registered for the given pathPattern.
* Whether a resource handler has already been registered for the given path pattern.
*/
public boolean hasMappingForPattern(String pathPattern) {
for (ResourceHandlerRegistration registration : this.registrations) {
@@ -100,8 +103,9 @@ public class ResourceHandlerRegistry {
}
/**
* Specify the order to use for resource handling relative to other {@link HandlerMapping}s configured in
* the Spring MVC application context. The default value used is {@code Integer.MAX_VALUE-1}.
* Specify the order to use for resource handling relative to other {@link HandlerMapping}s
* configured in the Spring MVC application context.
* <p>The default value used is {@code Integer.MAX_VALUE-1}.
*/
public ResourceHandlerRegistry setOrder(int order) {
this.order = order;
@@ -109,10 +113,11 @@ public class ResourceHandlerRegistry {
}
/**
* Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
* Return a handler mapping with the mapped resource handlers; or {@code null} in case
* of no registrations.
*/
protected AbstractHandlerMapping getHandlerMapping() {
if (registrations.isEmpty()) {
if (this.registrations.isEmpty()) {
return null;
}
@@ -121,13 +126,13 @@ public class ResourceHandlerRegistry {
for (String pathPattern : registration.getPathPatterns()) {
ResourceHttpRequestHandler handler = registration.getRequestHandler();
handler.setServletContext(this.servletContext);
handler.setApplicationContext(this.appContext);
handler.setApplicationContext(this.applicationContext);
handler.setContentNegotiationManager(this.contentNegotiationManager);
try {
handler.afterPropertiesSet();
}
catch (Exception e) {
throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
catch (Exception ex) {
throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
}
urlMap.put(pathPattern, handler);
}

View File

@@ -275,7 +275,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
if (this.resourceHttpMessageConverter == null) {
this.resourceHttpMessageConverter = new ResourceHttpMessageConverter();
}
if(this.resourceRegionHttpMessageConverter == null) {
if (this.resourceRegionHttpMessageConverter == null) {
this.resourceRegionHttpMessageConverter = new ResourceRegionHttpMessageConverter();
}
}
@@ -372,7 +372,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
try {
List<HttpRange> httpRanges = inputMessage.getHeaders().getRange();
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
if(httpRanges.size() == 1) {
if (httpRanges.size() == 1) {
ResourceRegion resourceRegion = httpRanges.get(0).toResourceRegion(resource);
this.resourceRegionHttpMessageConverter.write(resourceRegion, mediaType, outputMessage);
}

View File

@@ -181,8 +181,8 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
try {
pageContext.getOut().print(url);
}
catch (IOException e) {
throw new JspException(e);
catch (IOException ex) {
throw new JspException(ex);
}
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -25,8 +25,8 @@ import org.springframework.util.StringUtils;
/**
* Convenient super class for many html tags that render content using the databinding
* features of the {@link AbstractHtmlElementTag AbstractHtmlElementTag}. The only thing sub tags
* need to do is override {@link #renderDefaultContent(TagWriter)}.
* features of the {@link AbstractHtmlElementTag AbstractHtmlElementTag}. The only thing
* sub-tags need to do is override {@link #renderDefaultContent(TagWriter)}.
*
* @author Rob Harrop
* @author Juergen Hoeller
@@ -136,8 +136,8 @@ public abstract class AbstractHtmlElementBodyTag extends AbstractHtmlElementTag
try {
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
catch (IOException e) {
throw new JspException("Unable to write buffered body content.", e);
catch (IOException ex) {
throw new JspException("Unable to write buffered body content.", ex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.view.tiles3;
import java.util.Locale;
@@ -46,8 +47,8 @@ public class SpringLocaleResolver extends DefaultLocaleResolver {
return RequestContextUtils.getLocale(servletRequest);
}
}
catch (NotAServletEnvironmentException e) {
// Ignore
catch (NotAServletEnvironmentException ex) {
// ignore
}
return super.resolveLocale(request);
}