org.weborganic.bastille.web.filter
Class DetectBrowserFilter

java.lang.Object
  extended by org.weborganic.bastille.web.filter.DetectBrowserFilter
All Implemented Interfaces:
javax.servlet.Filter

public final class DetectBrowserFilter
extends Object
implements javax.servlet.Filter

A Simpler filter class for redirect URL based on User-Agent to different URL.

Configuration

Sample config in Web Configuration (web.xml)

 <filter>
    <filter-name>MobileFilter</filter-name>
    <filter-class>org.weborganic.bastille.web.filter.DetectBrowserFilter</filter-class>
     <init-param>
       <param-name>mobile</param-name>
       <param-value>http://m.pbs.gov.au</param-value>
     </init-param>
     <init-param>
       <param-name>normal</param-name>
       <param-value>http://www.pbs.gov.au</param-value>
    </init-param>
  </filter>
 
 

Since:
0.6.13

Constructor Summary
DetectBrowserFilter()
           
 
Method Summary
 void destroy()
          
 void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          
 void doHTTPFilter(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, javax.servlet.FilterChain chain)
          Do the filtering for a HTTP request.
 void init(javax.servlet.FilterConfig config)
          Initialises the filter.
static boolean isMobile(String userAgent)
          Indicates whether the specified user agent is a mobile device or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DetectBrowserFilter

public DetectBrowserFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Initialises the filter.

This servlet accepts the following initialisation parameters:

Both parameters MUST be valid URLs.

Specified by:
init in interface javax.servlet.Filter
Parameters:
config - The filter configuration.
Throws:
javax.servlet.ServletException

destroy

public void destroy()

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest req,
                     javax.servlet.ServletResponse res,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

doHTTPFilter

public void doHTTPFilter(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse res,
                         javax.servlet.FilterChain chain)
                  throws javax.servlet.ServletException,
                         IOException
Do the filtering for a HTTP request.

Parameters:
req - The HTTP servlet request.
res - The HTTP servlet response.
chain - The filter chain.
Throws:
IOException - Should an error occurs while writing the response.
javax.servlet.ServletException - If thrown by the filter chain.

isMobile

public static boolean isMobile(String userAgent)
Indicates whether the specified user agent is a mobile device or not.

Parameters:
userAgent - The User-Agent HTTP header string.
Returns:
true if the user agent string matches that of a mobile device; false otherwise.
See Also:
Detect Mobile Browser | Open source mobile phone detection