org.springframework.batch.admin.web.interceptor
Class ContentTypeInterceptor

java.lang.Object
  extended by org.springframework.web.servlet.handler.HandlerInterceptorAdapter
      extended by org.springframework.batch.admin.web.interceptor.ContentTypeInterceptor
All Implemented Interfaces:
BeanFactoryAware, HandlerInterceptor

public class ContentTypeInterceptor
extends HandlerInterceptorAdapter
implements BeanFactoryAware

Interceptor that looks for an extension on the request path and adds it to the view name if it matches a list provided. This can be used to do simple content negotiation based on request path extensions, as is usual with browsers (the view that is finally resolved could have a different content type than the original request).

Author:
Dave Syer

Constructor Summary
ContentTypeInterceptor()
           
 
Method Summary
 void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
          Compare the extension of the request path (if there is one) with the set provided, and if it matches then add the same extension to the view name, if it is not already present.
 boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
           
 void setBeanFactory(BeanFactory beanFactory)
           
 void setExtensions(Collection<String> extensions)
          A collection of extensions to append to view names.
 
Methods inherited from class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
afterCompletion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentTypeInterceptor

public ContentTypeInterceptor()
Method Detail

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException

setExtensions

public void setExtensions(Collection<String> extensions)
A collection of extensions to append to view names.

Parameters:
extensions - the extensions (e.g. [rss, xml, atom])

preHandle

public boolean preHandle(HttpServletRequest request,
                         HttpServletResponse response,
                         Object handler)
                  throws Exception
Specified by:
preHandle in interface HandlerInterceptor
Overrides:
preHandle in class HandlerInterceptorAdapter
Throws:
Exception

postHandle

public void postHandle(HttpServletRequest request,
                       HttpServletResponse response,
                       Object handler,
                       ModelAndView modelAndView)
                throws Exception
Compare the extension of the request path (if there is one) with the set provided, and if it matches then add the same extension to the view name, if it is not already present.

Specified by:
postHandle in interface HandlerInterceptor
Overrides:
postHandle in class HandlerInterceptorAdapter
Throws:
Exception
See Also:
HandlerInterceptorAdapter.postHandle(HttpServletRequest, HttpServletResponse, Object, ModelAndView)


Copyright © 2011. All Rights Reserved.