Polishing
This commit is contained in:
@@ -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.
|
||||
@@ -108,8 +108,7 @@ public interface HandlerInterceptor {
|
||||
* (can also be {@code null})
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
void postHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||
void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
@@ -128,8 +127,7 @@ public interface HandlerInterceptor {
|
||||
* @param ex exception thrown on handler execution, if any
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
void afterCompletion(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
*
|
||||
* <p>This class registers the following {@link HandlerMapping}s:</p>
|
||||
* <ul>
|
||||
* <li>{@link RequestMappingHandlerMapping}
|
||||
* ordered at 0 for mapping requests to annotated controller methods.
|
||||
* <li>{@link BeanNameUrlHandlerMapping}
|
||||
* ordered at 2 to map URL paths to controller bean names.
|
||||
* <li>{@link RequestMappingHandlerMapping}
|
||||
* ordered at 0 for mapping requests to annotated controller methods.
|
||||
* <li>{@link BeanNameUrlHandlerMapping}
|
||||
* ordered at 2 to map URL paths to controller bean names.
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>Note:</strong> Additional HandlerMappings may be registered
|
||||
@@ -96,30 +96,30 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
*
|
||||
* <p>This class registers the following {@link HandlerAdapter}s:
|
||||
* <ul>
|
||||
* <li>{@link RequestMappingHandlerAdapter}
|
||||
* for processing requests with annotated controller methods.
|
||||
* <li>{@link HttpRequestHandlerAdapter}
|
||||
* for processing requests with {@link HttpRequestHandler}s.
|
||||
* <li>{@link SimpleControllerHandlerAdapter}
|
||||
* for processing requests with interface-based {@link Controller}s.
|
||||
* <li>{@link RequestMappingHandlerAdapter}
|
||||
* for processing requests with annotated controller methods.
|
||||
* <li>{@link HttpRequestHandlerAdapter}
|
||||
* for processing requests with {@link HttpRequestHandler}s.
|
||||
* <li>{@link SimpleControllerHandlerAdapter}
|
||||
* for processing requests with interface-based {@link Controller}s.
|
||||
* </ul>
|
||||
*
|
||||
* <p>This class registers the following {@link HandlerExceptionResolver}s:
|
||||
* <ul>
|
||||
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions
|
||||
* through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver} for exceptions annotated
|
||||
* with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring
|
||||
* exception types
|
||||
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions
|
||||
* through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver} for exceptions annotated
|
||||
* with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring
|
||||
* exception types
|
||||
* </ul>
|
||||
*
|
||||
* <p>This class registers an {@link org.springframework.util.AntPathMatcher}
|
||||
* and a {@link org.springframework.web.util.UrlPathHelper} to be used by:
|
||||
* <ul>
|
||||
* <li>the {@link RequestMappingHandlerMapping},
|
||||
* <li>the {@link HandlerMapping} for ViewControllers
|
||||
* <li>and the {@link HandlerMapping} for serving resources
|
||||
* <li>the {@link RequestMappingHandlerMapping},
|
||||
* <li>the {@link HandlerMapping} for ViewControllers
|
||||
* <li>and the {@link HandlerMapping} for serving resources
|
||||
* </ul>
|
||||
* Note that those beans can be configured by using the {@code path-matching} MVC namespace element.
|
||||
*
|
||||
@@ -127,12 +127,12 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
* {@link ExceptionHandlerExceptionResolver} are configured with instances of
|
||||
* the following by default:
|
||||
* <ul>
|
||||
* <li>A {@link ContentNegotiationManager}
|
||||
* <li>A {@link DefaultFormattingConversionService}
|
||||
* <li>A {@link org.springframework.validation.beanvalidation.LocalValidatorFactoryBean}
|
||||
* if a JSR-303 implementation is available on the classpath
|
||||
* <li>A range of {@link HttpMessageConverter}s depending on what 3rd party
|
||||
* libraries are available on the classpath.
|
||||
* <li>A {@link ContentNegotiationManager}
|
||||
* <li>A {@link DefaultFormattingConversionService}
|
||||
* <li>A {@link org.springframework.validation.beanvalidation.LocalValidatorFactoryBean}
|
||||
* if a JSR-303 implementation is available on the classpath
|
||||
* <li>A range of {@link HttpMessageConverter}s depending on what 3rd party
|
||||
* libraries are available on the classpath.
|
||||
* </ul>
|
||||
*
|
||||
* @author Keith Donald
|
||||
@@ -576,10 +576,12 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
if (StringUtils.hasText("bean")) {
|
||||
reference = new RuntimeBeanReference(refElement.getAttribute("bean"),false);
|
||||
list.add(reference);
|
||||
}else if (StringUtils.hasText("parent")){
|
||||
}
|
||||
else if (StringUtils.hasText("parent")){
|
||||
reference = new RuntimeBeanReference(refElement.getAttribute("parent"),true);
|
||||
list.add(reference);
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
parserContext.getReaderContext().error("'bean' or 'parent' attribute is required for <ref> element",
|
||||
parserContext.extractSource(parentElement));
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
/**
|
||||
* Helps with configuring HandlerMappings path matching options such as trailing slash match,
|
||||
* suffix registration, path matcher and path helper.
|
||||
* Configured path matcher and path helper instances are shared for:
|
||||
*
|
||||
* <p>Configured path matcher and path helper instances are shared for:
|
||||
* <ul>
|
||||
* <li>RequestMappings</li>
|
||||
* <li>ViewControllerMappings</li>
|
||||
* <li>ResourcesMappings</li>
|
||||
* <li>RequestMappings</li>
|
||||
* <li>ViewControllerMappings</li>
|
||||
* <li>ResourcesMappings</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Brian Clozel
|
||||
|
||||
@@ -102,45 +102,45 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
*
|
||||
* <p>This class registers the following {@link HandlerMapping}s:</p>
|
||||
* <ul>
|
||||
* <li>{@link RequestMappingHandlerMapping}
|
||||
* ordered at 0 for mapping requests to annotated controller methods.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at 1 to map URL paths directly to view names.
|
||||
* <li>{@link BeanNameUrlHandlerMapping}
|
||||
* ordered at 2 to map URL paths to controller bean names.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet.
|
||||
* <li>{@link RequestMappingHandlerMapping}
|
||||
* ordered at 0 for mapping requests to annotated controller methods.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at 1 to map URL paths directly to view names.
|
||||
* <li>{@link BeanNameUrlHandlerMapping}
|
||||
* ordered at 2 to map URL paths to controller bean names.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests.
|
||||
* <li>{@link HandlerMapping}
|
||||
* ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Registers these {@link HandlerAdapter}s:
|
||||
* <ul>
|
||||
* <li>{@link RequestMappingHandlerAdapter}
|
||||
* for processing requests with annotated controller methods.
|
||||
* <li>{@link HttpRequestHandlerAdapter}
|
||||
* for processing requests with {@link HttpRequestHandler}s.
|
||||
* <li>{@link SimpleControllerHandlerAdapter}
|
||||
* for processing requests with interface-based {@link Controller}s.
|
||||
* <li>{@link RequestMappingHandlerAdapter}
|
||||
* for processing requests with annotated controller methods.
|
||||
* <li>{@link HttpRequestHandlerAdapter}
|
||||
* for processing requests with {@link HttpRequestHandler}s.
|
||||
* <li>{@link SimpleControllerHandlerAdapter}
|
||||
* for processing requests with interface-based {@link Controller}s.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Registers a {@link HandlerExceptionResolverComposite} with this chain of
|
||||
* exception resolvers:
|
||||
* <ul>
|
||||
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions
|
||||
* through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver} for exceptions annotated
|
||||
* with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring
|
||||
* exception types
|
||||
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions
|
||||
* through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver} for exceptions annotated
|
||||
* with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring
|
||||
* exception types
|
||||
* </ul>
|
||||
*
|
||||
* <p>Registers an {@link AntPathMatcher} and a {@link UrlPathHelper}
|
||||
* to be used by:
|
||||
* <ul>
|
||||
* <li>the {@link RequestMappingHandlerMapping},
|
||||
* <li>the {@link HandlerMapping} for ViewControllers
|
||||
* <li>and the {@link HandlerMapping} for serving resources
|
||||
* <li>the {@link RequestMappingHandlerMapping},
|
||||
* <li>the {@link HandlerMapping} for ViewControllers
|
||||
* <li>and the {@link HandlerMapping} for serving resources
|
||||
* </ul>
|
||||
* Note that those beans can be configured with a {@link PathMatchConfigurer}.
|
||||
*
|
||||
@@ -148,12 +148,12 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
* {@link ExceptionHandlerExceptionResolver} are configured with default
|
||||
* instances of the following by default:
|
||||
* <ul>
|
||||
* <li>A {@link ContentNegotiationManager}
|
||||
* <li>A {@link DefaultFormattingConversionService}
|
||||
* <li>A {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean}
|
||||
* if a JSR-303 implementation is available on the classpath
|
||||
* <li>A range of {@link HttpMessageConverter}s depending on the 3rd party
|
||||
* libraries available on the classpath.
|
||||
* <li>a {@link ContentNegotiationManager}
|
||||
* <li>a {@link DefaultFormattingConversionService}
|
||||
* <li>a {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean}
|
||||
* if a JSR-303 implementation is available on the classpath
|
||||
* <li>a range of {@link HttpMessageConverter}s depending on the third-party
|
||||
* libraries available on the classpath.
|
||||
* </ul>
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -439,9 +439,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
* through annotated controller methods. Consider overriding one of these
|
||||
* other more fine-grained methods:
|
||||
* <ul>
|
||||
* <li>{@link #addArgumentResolvers} for adding custom argument resolvers.
|
||||
* <li>{@link #addReturnValueHandlers} for adding custom return value handlers.
|
||||
* <li>{@link #configureMessageConverters} for adding custom message converters.
|
||||
* <li>{@link #addArgumentResolvers} for adding custom argument resolvers.
|
||||
* <li>{@link #addReturnValueHandlers} for adding custom return value handlers.
|
||||
* <li>{@link #configureMessageConverters} for adding custom message converters.
|
||||
* </ul>
|
||||
*/
|
||||
@Bean
|
||||
@@ -763,17 +763,16 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
* A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
|
||||
* <p>Adds the following exception resolvers:
|
||||
* <ul>
|
||||
* <li>{@link ExceptionHandlerExceptionResolver}
|
||||
* for handling exceptions through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver}
|
||||
* for exceptions annotated with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver}
|
||||
* for resolving known Spring exception types
|
||||
* <li>{@link ExceptionHandlerExceptionResolver}
|
||||
* for handling exceptions through @{@link ExceptionHandler} methods.
|
||||
* <li>{@link ResponseStatusExceptionResolver}
|
||||
* for exceptions annotated with @{@link ResponseStatus}.
|
||||
* <li>{@link DefaultHandlerExceptionResolver}
|
||||
* for resolving known Spring exception types
|
||||
* </ul>
|
||||
*/
|
||||
protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
|
||||
exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
|
||||
exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
|
||||
exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
|
||||
if (jackson2Present) {
|
||||
@@ -781,14 +780,15 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
interceptors.add(new JsonViewResponseBodyAdvice());
|
||||
exceptionHandlerExceptionResolver.setResponseBodyAdvice(interceptors);
|
||||
}
|
||||
exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
|
||||
exceptionHandlerExceptionResolver.afterPropertiesSet();
|
||||
exceptionResolvers.add(exceptionHandlerExceptionResolver);
|
||||
|
||||
ResponseStatusExceptionResolver responseStatusExceptionResolver = new ResponseStatusExceptionResolver();
|
||||
responseStatusExceptionResolver.setMessageSource(this.applicationContext);
|
||||
|
||||
exceptionResolvers.add(exceptionHandlerExceptionResolver);
|
||||
exceptionResolvers.add(responseStatusExceptionResolver);
|
||||
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
|
||||
|
||||
exceptionHandlerExceptionResolver.afterPropertiesSet();
|
||||
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -84,9 +84,9 @@ public interface WebMvcConfigurer {
|
||||
* suffix registration, path matcher and path helper.
|
||||
* Configured path matcher and path helper instances are shared for:
|
||||
* <ul>
|
||||
* <li>RequestMappings</li>
|
||||
* <li>ViewControllerMappings</li>
|
||||
* <li>ResourcesMappings</li>
|
||||
* <li>RequestMappings</li>
|
||||
* <li>ViewControllerMappings</li>
|
||||
* <li>ResourcesMappings</li>
|
||||
* </ul>
|
||||
* @since 4.0.3
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
@@ -25,72 +25,64 @@ import org.springframework.web.servlet.support.WebContentGenerator;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
/**
|
||||
* <p>Convenient superclass for controller implementations, using the Template
|
||||
* Method design pattern.</p>
|
||||
*
|
||||
* <p>As stated in the {@link Controller Controller}
|
||||
* interface, a lot of functionality is already provided by certain abstract
|
||||
* base controllers. The AbstractController is one of the most important
|
||||
* abstract base controller providing basic features such as the generation
|
||||
* of caching headers and the enabling or disabling of
|
||||
* supported methods (GET/POST).</p>
|
||||
* <p>Convenient superclass for controller implementations, using the Template Method
|
||||
* design pattern.
|
||||
*
|
||||
* <p><b><a name="workflow">Workflow
|
||||
* (<a href="Controller.html#workflow">and that defined by interface</a>):</b><br>
|
||||
* <ol>
|
||||
* <li>{@link #handleRequest(HttpServletRequest, HttpServletResponse) handleRequest()}
|
||||
* will be called by the DispatcherServlet</li>
|
||||
* <li>Inspection of supported methods (ServletException if request method
|
||||
* is not support)</li>
|
||||
* <li>If session is required, try to get it (ServletException if not found)</li>
|
||||
* <li>Set caching headers if needed according to the cacheSeconds property</li>
|
||||
* <li>Call abstract method {@link #handleRequestInternal(HttpServletRequest, HttpServletResponse) handleRequestInternal()}
|
||||
* (optionally synchronizing around the call on the HttpSession),
|
||||
* which should be implemented by extending classes to provide actual
|
||||
* functionality to return {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects.</li>
|
||||
* <li>{@link #handleRequest(HttpServletRequest, HttpServletResponse) handleRequest()}
|
||||
* will be called by the DispatcherServlet</li>
|
||||
* <li>Inspection of supported methods (ServletException if request method
|
||||
* is not support)</li>
|
||||
* <li>If session is required, try to get it (ServletException if not found)</li>
|
||||
* <li>Set caching headers if needed according to the cacheSeconds property</li>
|
||||
* <li>Call abstract method {@link #handleRequestInternal(HttpServletRequest, HttpServletResponse) handleRequestInternal()}
|
||||
* (optionally synchronizing around the call on the HttpSession),
|
||||
* which should be implemented by extending classes to provide actual
|
||||
* functionality to return {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects.</li>
|
||||
* </ol>
|
||||
* </p>
|
||||
*
|
||||
* <p><b><a name="config">Exposed configuration properties</a>
|
||||
* (<a href="Controller.html#config">and those defined by interface</a>):</b><br>
|
||||
* <table border="1">
|
||||
* <tr>
|
||||
* <td><b>name</b></th>
|
||||
* <td><b>default</b></td>
|
||||
* <td><b>description</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>supportedMethods</td>
|
||||
* <td>GET,POST</td>
|
||||
* <td>comma-separated (CSV) list of methods supported by this controller,
|
||||
* such as GET, POST and PUT</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>requireSession</td>
|
||||
* <td>false</td>
|
||||
* <td>whether a session should be required for requests to be able to
|
||||
* be handled by this controller. This ensures that derived controller
|
||||
* can - without fear of null pointers - call request.getSession() to
|
||||
* retrieve a session. If no session can be found while processing
|
||||
* the request, a ServletException will be thrown</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>cacheSeconds</td>
|
||||
* <td>-1</td>
|
||||
* <td>indicates the amount of seconds to include in the cache header
|
||||
* for the response following on this request. 0 (zero) will include
|
||||
* headers for no caching at all, -1 (the default) will not generate
|
||||
* <i>any headers</i> and any positive number will generate headers
|
||||
* that state the amount indicated as seconds to cache the content</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>synchronizeOnSession</td>
|
||||
* <td>false</td>
|
||||
* <td>whether the call to {@code handleRequestInternal} should be
|
||||
* synchronized around the HttpSession, to serialize invocations
|
||||
* from the same client. No effect if there is no HttpSession.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>name</b></th>
|
||||
* <td><b>default</b></td>
|
||||
* <td><b>description</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>supportedMethods</td>
|
||||
* <td>GET,POST</td>
|
||||
* <td>comma-separated (CSV) list of methods supported by this controller,
|
||||
* such as GET, POST and PUT</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>requireSession</td>
|
||||
* <td>false</td>
|
||||
* <td>whether a session should be required for requests to be able to
|
||||
* be handled by this controller. This ensures that derived controller
|
||||
* can - without fear of null pointers - call request.getSession() to
|
||||
* retrieve a session. If no session can be found while processing
|
||||
* the request, a ServletException will be thrown</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>cacheSeconds</td>
|
||||
* <td>-1</td>
|
||||
* <td>indicates the amount of seconds to include in the cache header
|
||||
* for the response following on this request. 0 (zero) will include
|
||||
* headers for no caching at all, -1 (the default) will not generate
|
||||
* <i>any headers</i> and any positive number will generate headers
|
||||
* that state the amount indicated as seconds to cache the content</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>synchronizeOnSession</td>
|
||||
* <td>false</td>
|
||||
* <td>whether the call to {@code handleRequestInternal} should be
|
||||
* synchronized around the HttpSession, to serialize invocations
|
||||
* from the same client. No effect if there is no HttpSession.
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Rod Johnson
|
||||
|
||||
@@ -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.
|
||||
@@ -30,13 +30,12 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
* <p>Can optionally prepend a {@link #setPrefix prefix} and/or append a
|
||||
* {@link #setSuffix suffix} to build the viewname from the URL filename.
|
||||
*
|
||||
* <p>Find below some examples:
|
||||
*
|
||||
* <p>Find some examples below:
|
||||
* <ol>
|
||||
* <li>{@code "/index" -> "index"}</li>
|
||||
* <li>{@code "/index.html" -> "index"}</li>
|
||||
* <li>{@code "/index.html"} + prefix {@code "pre_"} and suffix {@code "_suf" -> "pre_index_suf"}</li>
|
||||
* <li>{@code "/products/view.html" -> "products/view"}</li>
|
||||
* <li>{@code "/index" -> "index"}</li>
|
||||
* <li>{@code "/index.html" -> "index"}</li>
|
||||
* <li>{@code "/index.html"} + prefix {@code "pre_"} and suffix {@code "_suf" -> "pre_index_suf"}</li>
|
||||
* <li>{@code "/products/view.html" -> "products/view"}</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>Thanks to David Barri for suggesting prefix/suffix support!
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.resource;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
@@ -11,10 +27,11 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link VersionStrategy} implementations.
|
||||
* Supports versions as:
|
||||
*
|
||||
* <p>Supports versions as:
|
||||
* <ul>
|
||||
* <li>prefix in the request path, like "version/static/myresource.js"
|
||||
* <li>file name suffix in the request path, like "static/myresource-version.js"
|
||||
* <li>prefix in the request path, like "version/static/myresource.js"
|
||||
* <li>file name suffix in the request path, like "static/myresource-version.js"
|
||||
* </ul>
|
||||
*
|
||||
* <p>Note: This base class does <i>not</i> provide support for generating the
|
||||
@@ -32,7 +49,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
|
||||
|
||||
|
||||
protected AbstractVersionStrategy(VersionPathStrategy pathStrategy) {
|
||||
Assert.notNull(pathStrategy, "'pathStrategy' is required");
|
||||
Assert.notNull(pathStrategy, "VersionPathStrategy is required");
|
||||
this.pathStrategy = pathStrategy;
|
||||
}
|
||||
|
||||
@@ -66,9 +83,8 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
|
||||
|
||||
private final String prefix;
|
||||
|
||||
|
||||
public PrefixVersionPathStrategy(String version) {
|
||||
Assert.hasText(version, "'version' is required and must not be empty");
|
||||
Assert.hasText(version, "'version' must not be empty");
|
||||
this.prefix = version;
|
||||
}
|
||||
|
||||
@@ -86,9 +102,9 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
|
||||
public String addVersion(String path, String version) {
|
||||
return (this.prefix.endsWith("/") || path.startsWith("/") ? this.prefix + path : this.prefix + "/" + path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File name-based {@code VersionPathStrategy},
|
||||
* e.g. {@code "path/foo-{version}.css"}.
|
||||
@@ -97,7 +113,6 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("-(\\S*)\\.");
|
||||
|
||||
|
||||
@Override
|
||||
public String extractVersion(String requestPath) {
|
||||
Matcher matcher = pattern.matcher(requestPath);
|
||||
|
||||
@@ -40,22 +40,21 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* <p>This transformer:
|
||||
* <ul>
|
||||
* <li>modifies links to match the public URL paths that should be exposed to clients, using
|
||||
* configured {@code ResourceResolver} strategies
|
||||
* <li>appends a comment in the manifest, containing a Hash (e.g. "# Hash: 9de0f09ed7caf84e885f1f0f11c7e326"),
|
||||
* thus changing the content of the manifest in order to trigger an appcache reload in the browser.
|
||||
* <li>modifies links to match the public URL paths that should be exposed to clients,
|
||||
* using configured {@code ResourceResolver} strategies
|
||||
* <li>appends a comment in the manifest, containing a Hash (e.g. "# Hash: 9de0f09ed7caf84e885f1f0f11c7e326"),
|
||||
* thus changing the content of the manifest in order to trigger an appcache reload in the browser.
|
||||
* </ul>
|
||||
*
|
||||
* All files that have the ".manifest" file extension, or the extension given in the constructor, will be transformed
|
||||
* by this class.
|
||||
* All files that have the ".manifest" file extension, or the extension given in the constructor,
|
||||
* will be transformed by this class.
|
||||
*
|
||||
* <p>This hash is computed using the content of the appcache manifest and the content of the linked resources; so
|
||||
* changing a resource linked in the manifest or the manifest itself should invalidate the browser cache.
|
||||
* <p>This hash is computed using the content of the appcache manifest and the content of the linked resources;
|
||||
* so changing a resource linked in the manifest or the manifest itself should invalidate the browser cache.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @see <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline">HTML5 offline
|
||||
* applications spec</a>
|
||||
* @since 4.1
|
||||
* @see <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#offline">HTML5 offline applications spec</a>
|
||||
*/
|
||||
public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
||||
|
||||
@@ -65,6 +64,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AppCacheManifestTransformer.class);
|
||||
|
||||
|
||||
private final Map<String, SectionTransformer> sectionTransformers = new HashMap<String, SectionTransformer>();
|
||||
|
||||
private final String fileExtension;
|
||||
@@ -93,7 +93,9 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
||||
|
||||
|
||||
@Override
|
||||
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
|
||||
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)
|
||||
throws IOException {
|
||||
|
||||
resource = transformerChain.transform(request, resource);
|
||||
|
||||
String filename = resource.getFilename();
|
||||
@@ -128,7 +130,8 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
||||
hashBuilder.appendString(line);
|
||||
}
|
||||
else {
|
||||
contentWriter.write(currentTransformer.transform(line, hashBuilder, resource, transformerChain, request) + "\n");
|
||||
contentWriter.write(
|
||||
currentTransformer.transform(line, hashBuilder, resource, transformerChain, request) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user