org.riotfamily.website.filter
Class BotSessionFilter

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.riotfamily.website.filter.BotSessionFilter
All Implemented Interfaces:
Filter, BeanNameAware, DisposableBean, InitializingBean, ServletContextAware

public class BotSessionFilter
extends OncePerRequestFilter

Filter that prevents URLs from being encoded if the request is originated by search engine robot/crawler.

Since:
6.4
Author:
Felix Gnass [fgnass at neteye dot de]

Field Summary
static String DEFAULT_BOT_PATTERN
           
 
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
BotSessionFilter()
           
 
Method Summary
protected  void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
          Passes the request on to the filter chain using a response wrapper that prevents URLs from being encoded.
protected  boolean isBot(HttpServletRequest request)
          Returns true if the botPattern is found in the User-Agent header.
 void setPattern(String pattern)
          Sets the regular expression that is used to check whether a User-Agent belongs to a robot/spider/crawler.
protected  boolean shouldNotFilter(HttpServletRequest request)
          Skips the filtering if a session id was requested using a cookie or the User-Agent header does not look like the one of a robot.
 
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName
 
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BOT_PATTERN

public static final String DEFAULT_BOT_PATTERN
See Also:
Constant Field Values
Constructor Detail

BotSessionFilter

public BotSessionFilter()
Method Detail

setPattern

public void setPattern(String pattern)
Sets the regular expression that is used to check whether a User-Agent belongs to a robot/spider/crawler. The pattern does not need to match the whole User-Agent header, it is checked whether the patter is included within the string. Note that the pattern is case sensitive and the header is converted to lower case before the pattern is checked. The default is bot|crawler|spider.


shouldNotFilter

protected boolean shouldNotFilter(HttpServletRequest request)
Skips the filtering if a session id was requested using a cookie or the User-Agent header does not look like the one of a robot.

Overrides:
shouldNotFilter in class OncePerRequestFilter

isBot

protected boolean isBot(HttpServletRequest request)
Returns true if the botPattern is found in the User-Agent header. Note that the header is converted to lower case before the regular expression is checked.


doFilterInternal

protected final void doFilterInternal(HttpServletRequest request,
                                      HttpServletResponse response,
                                      FilterChain filterChain)
                               throws ServletException,
                                      IOException
Passes the request on to the filter chain using a response wrapper that prevents URLs from being encoded.

Specified by:
doFilterInternal in class OncePerRequestFilter
Throws:
ServletException
IOException