org.eclipse.jetty.servlets
Class UserAgentFilter

java.lang.Object
  extended by org.eclipse.jetty.servlets.UserAgentFilter
All Implemented Interfaces:
Filter
Direct Known Subclasses:
GzipFilter

public class UserAgentFilter
extends Object
implements Filter

User Agent Filter.

This filter allows efficient matching of user agent strings for downstream or extended filters to use for browser specific logic.

The filter is configured with the following init parameters:

attribute
If set, then the request attribute of this name is set with the matched user agent string
cacheSize
The size of the user-agent cache, used to avoid reparsing of user agent strings. The entire cache is flushed when this size is reached
userAgent
A regex Pattern to extract the essential elements of the user agent. The concatenation of matched pattern groups is used as the user agent name
An example value for pattern is (?:Mozilla[^\(]*\(compatible;\s*+([^;]*);.*)|(?:.*?([^\s]+/[^\s]+).*). These two pattern match the common compatibility user-agent strings and extract the real user agent, failing that, the first element of the agent string is returned.


Constructor Summary
UserAgentFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
           
 String getUserAgent(ServletRequest request)
           
 String getUserAgent(String ua)
          Get UserAgent.
 void init(FilterConfig filterConfig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserAgentFilter

public UserAgentFilter()
Method Detail

destroy

public void destroy()
Specified by:
destroy in interface Filter

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
              throws IOException,
                     ServletException
Specified by:
doFilter in interface Filter
Throws:
IOException
ServletException

init

public void init(FilterConfig filterConfig)
          throws ServletException
Specified by:
init in interface Filter
Throws:
ServletException

getUserAgent

public String getUserAgent(ServletRequest request)

getUserAgent

public String getUserAgent(String ua)
Get UserAgent. The configured agent patterns are used to match against the passed user agent string. If any patterns match, the concatenation of pattern groups is returned as the user agent string. Match results are cached.

Parameters:
ua - A user agent string
Returns:
The matched pattern groups or the original user agent string


Copyright © 1995-2011 Mort Bay Consulting. All Rights Reserved.