@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -46,40 +46,47 @@ 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 List<ResourceHandlerRegistration> registrations = new ArrayList<ResourceHandlerRegistration>();
|
||||
|
||||
private int order = Integer.MAX_VALUE -1;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new resource handler registry for the given application context.
|
||||
* @param applicationContext the Spring application context
|
||||
* @param servletContext the corresponding Servlet context
|
||||
*/
|
||||
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
|
||||
Assert.notNull(applicationContext, "ApplicationContext is required");
|
||||
this.appContext = applicationContext;
|
||||
this.applicationContext = applicationContext;
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -91,8 +98,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;
|
||||
@@ -100,10 +108,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;
|
||||
}
|
||||
|
||||
@@ -112,12 +121,12 @@ public class ResourceHandlerRegistry {
|
||||
for (String pathPattern : registration.getPathPatterns()) {
|
||||
ResourceHttpRequestHandler handler = registration.getRequestHandler();
|
||||
handler.setServletContext(this.servletContext);
|
||||
handler.setApplicationContext(this.appContext);
|
||||
handler.setApplicationContext(this.applicationContext);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user