org.apache.velocity.tools.view
Class BrowserTool

java.lang.Object
  extended by org.apache.velocity.tools.generic.SafeConfig
      extended by org.apache.velocity.tools.generic.LocaleConfig
          extended by org.apache.velocity.tools.generic.FormatConfig
              extended by org.apache.velocity.tools.view.BrowserTool
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BrowserSnifferTool

@DefaultKey(value="browser")
@InvalidScope(value="application")
public class BrowserTool
extends FormatConfig
implements java.io.Serializable

browser-sniffing tool (session or request scope requested, session scope advised).

Usage:

BrowserTool defines properties that are used to test the client browser, operating system, device, language... Apart from properties related to browser version and language, all properties are booleans.

The following properties are available:

Language properties are filtered by the languagesFilter tool param, if present. If no matching language is found, or if there is no matching language, the tools defaut locale (or the first value of languagesFilter) is returned. Their value is guarantied to belong to the set provided in languagesFilter, if any.

Thanks to Lee Semel (lee@semel.net), the author of the HTTP::BrowserDetect Perl module. See also: * http://www.zytrax.com/tech/web/browser_ids.htm * http://en.wikipedia.org/wiki/User_agent * http://www.user-agents.org/

Since:
VelocityTools 2.0
Version:
$Revision$ $Date$
Author:
Claude Brisson
See Also:
Serialized Form

Field Summary
private  java.lang.String acceptLanguage
           
private static java.util.regex.Pattern fallbackVersion
           
private static java.util.regex.Pattern firefoxVersion
           
private  int geckoMajorVersion
           
private  int geckoMinorVersion
           
private  java.lang.String geckoVersion
           
private static java.util.regex.Pattern genericVersion
           
private static java.util.regex.Pattern ieVersion
           
private  java.util.SortedMap<java.lang.Float,java.util.List<java.lang.String>> languageRangesByQuality
           
private  java.util.List<java.lang.String> languagesFilter
           
protected  org.apache.velocity.runtime.log.Log LOG
           
private  int majorVersion
           
private  int minorVersion
           
private static java.util.regex.Pattern mozillaVersion
           
private  java.lang.String preferredLanguage
           
private static java.util.regex.Pattern quality
           
private static java.util.regex.Pattern safariVersion
           
private static long serialVersionUID
           
private  java.lang.String starLanguageRange
           
private  java.lang.String userAgent
           
private  java.lang.String version
           
 
Fields inherited from class org.apache.velocity.tools.generic.FormatConfig
DEFAULT_FORMAT, FORMAT_KEY
 
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE
 
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY
 
Constructor Summary
BrowserTool()
           
 
Method Summary
private  java.lang.String filterLanguageTag(java.lang.String languageTag)
           
 boolean get(java.lang.String key)
           
 java.lang.String getAcceptLanguage()
           
 boolean getAix()
           
 boolean getAix1()
           
 boolean getAix2()
           
 boolean getAix3()
           
 boolean getAix4()
           
 boolean getAltavista()
           
 boolean getAmaya()
           
 boolean getAmiga()
           
 boolean getAol()
           
 boolean getAol3()
           
 boolean getAol4()
           
 boolean getAol5()
           
 boolean getAol6()
           
 boolean getAolTV()
           
 boolean getAudrey()
           
 boolean getAvantgo()
           
 boolean getBlackberry()
           
 boolean getBsd()
           
 boolean getChrome()
           
 boolean getCss()
           
 boolean getCss1()
           
 boolean getCss2()
           
 boolean getCurl()
           
 boolean getDec()
           
 boolean getDillo()
           
 boolean getDom0()
           
 boolean getDom1()
           
 boolean getDom2()
           
 boolean getDotnet()
           
 boolean getEmacs()
           
 boolean getEpiphany()
           
 boolean getFirefox()
           
 boolean getFreebsd()
           
 boolean getGaleon()
           
 boolean getGecko()
           
 int getGeckoMajorVersion()
           
 int getGeckoMinorVersion()
           
 java.lang.String getGeckoVersion()
           
 boolean getGetright()
           
 boolean getGoogle()
           
 boolean getHotjava()
           
 boolean getHotjava3()
           
 boolean getHotjava3up()
           
 boolean getHpux()
           
 boolean getHpux10()
           
 boolean getHpux9()
           
 boolean getHttpclient()
           
 boolean getIcab()
           
 boolean getIceweasel()
           
 boolean getIe()
           
 boolean getIe3()
           
 boolean getIe4()
           
 boolean getIe4up()
           
 boolean getIe5()
           
 boolean getIe55()
           
 boolean getIe55up()
           
 boolean getIe5up()
           
 boolean getIe6()
           
 boolean getIe6up()
           
 boolean getIe7()
           
 boolean getIe7up()
           
 boolean getIe8()
           
 boolean getIe8up()
           
 boolean getInfoseek()
           
 boolean getIopener()
           
 boolean getIrix()
           
 boolean getIrix5()
           
 boolean getIrix6()
           
 boolean getJava()
           
 boolean getJavascript()
           
 boolean getKmeleon()
           
 boolean getKonqueror()
           
 java.lang.String getLanguagesFilter()
           
 boolean getLinkexchange()
           
 boolean getLinks()
           
 boolean getLinux()
           
 boolean getLobo()
           
 boolean getLotusnotes()
           
 boolean getLwp()
           
 boolean getLycos()
           
 boolean getLynx()
           
 boolean getMac()
           
 boolean getMac68k()
           
 boolean getMacosx()
           
 boolean getMacppc()
           
 int getMajorVersion()
           
 int getMinorVersion()
           
 boolean getMosaic()
           
 boolean getMozilla()
           
 boolean getMpras()
           
 boolean getNav2()
           
 boolean getNav3()
           
 boolean getNav4()
           
 boolean getNav45()
           
 boolean getNav45up()
           
 boolean getNav4up()
           
 boolean getNav6()
           
 boolean getNav6up()
           
 boolean getNavgold()
           
 boolean getNeoplanet()
           
 boolean getNeoplanet2()
           
 boolean getNetscape()
           
 boolean getOpera()
           
 boolean getOpera3()
           
 boolean getOpera4()
           
 boolean getOpera5()
           
 boolean getOpera6()
           
 boolean getOpera7()
           
 boolean getOpera8()
           
 boolean getOpera9()
           
 boolean getOs2()
           
 boolean getPalm()
           
 java.lang.String getPreferredLanguage()
           
 java.util.Locale getPreferredLocale()
           
 boolean getReliant()
           
 boolean getRobot()
           
 boolean getSafari()
           
 boolean getSco()
           
 boolean getScooter()
           
 boolean getSinix()
           
 boolean getSlurp()
           
 boolean getStaroffice()
           
 boolean getSun()
           
 boolean getSun4()
           
 boolean getSun5()
           
 boolean getSuni86()
           
 boolean getUnix()
           
 boolean getUnixware()
           
 java.lang.String getUserAgent()
           
 java.lang.String getVersion()
           
 boolean getVista()
           
 boolean getVMS()
           
 boolean getW3m()
           
 boolean getWap()
           
 boolean getWebcrawler()
           
 boolean getWebTV()
           
 boolean getWget()
           
 boolean getWin16()
           
 boolean getWin2k()
           
 boolean getWin31()
           
 boolean getWin32()
           
 boolean getWin3x()
           
 boolean getWin95()
           
 boolean getWin98()
           
 boolean getWindows()
           
 boolean getWinme()
           
 boolean getWinnt()
           
 boolean getWinxp()
           
 boolean getX11()
           
 boolean getYahoo()
           
private  void parseAcceptLanguage()
           
private  void parseVersion()
           
 void setAcceptLanguage(java.lang.String al)
           
 void setLanguagesFilter(java.lang.String filter)
           
 void setLog(org.apache.velocity.runtime.log.Log log)
          Set log.
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Retrieves the User-Agent header from the request (if any).
 void setUserAgent(java.lang.String ua)
          Sets the User-Agent string to be parsed for info.
private  boolean test(java.lang.String key)
           
 java.lang.String toString()
           
 
Methods inherited from class org.apache.velocity.tools.generic.FormatConfig
configure, getFormat, setFormat
 
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale
 
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

LOG

protected org.apache.velocity.runtime.log.Log LOG

userAgent

private java.lang.String userAgent

version

private java.lang.String version

majorVersion

private int majorVersion

minorVersion

private int minorVersion

geckoVersion

private java.lang.String geckoVersion

geckoMajorVersion

private int geckoMajorVersion

geckoMinorVersion

private int geckoMinorVersion

genericVersion

private static java.util.regex.Pattern genericVersion

firefoxVersion

private static java.util.regex.Pattern firefoxVersion

ieVersion

private static java.util.regex.Pattern ieVersion

safariVersion

private static java.util.regex.Pattern safariVersion

mozillaVersion

private static java.util.regex.Pattern mozillaVersion

fallbackVersion

private static java.util.regex.Pattern fallbackVersion

acceptLanguage

private java.lang.String acceptLanguage

languageRangesByQuality

private java.util.SortedMap<java.lang.Float,java.util.List<java.lang.String>> languageRangesByQuality

starLanguageRange

private java.lang.String starLanguageRange

languagesFilter

private java.util.List<java.lang.String> languagesFilter

preferredLanguage

private java.lang.String preferredLanguage

quality

private static java.util.regex.Pattern quality
Constructor Detail

BrowserTool

public BrowserTool()
Method Detail

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Retrieves the User-Agent header from the request (if any).

See Also:
setUserAgent(java.lang.String)

setLog

public void setLog(org.apache.velocity.runtime.log.Log log)
Set log.


setUserAgent

public void setUserAgent(java.lang.String ua)
Sets the User-Agent string to be parsed for info. If null, the string will be empty and everything will return false or null. Otherwise, it will set the whole string to lower case before storing to simplify parsing.


setAcceptLanguage

public void setAcceptLanguage(java.lang.String al)

setLanguagesFilter

public void setLanguagesFilter(java.lang.String filter)

getLanguagesFilter

public java.lang.String getLanguagesFilter()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

get

public boolean get(java.lang.String key)

getUserAgent

public java.lang.String getUserAgent()

getAcceptLanguage

public java.lang.String getAcceptLanguage()

getVersion

public java.lang.String getVersion()

getMajorVersion

public int getMajorVersion()

getMinorVersion

public int getMinorVersion()

getGeckoVersion

public java.lang.String getGeckoVersion()

getGeckoMajorVersion

public int getGeckoMajorVersion()

getGeckoMinorVersion

public int getGeckoMinorVersion()

getGecko

public boolean getGecko()

getFirefox

public boolean getFirefox()

getIceweasel

public boolean getIceweasel()

getGaleon

public boolean getGaleon()

getKmeleon

public boolean getKmeleon()

getEpiphany

public boolean getEpiphany()

getSafari

public boolean getSafari()

getChrome

public boolean getChrome()

getDillo

public boolean getDillo()

getNetscape

public boolean getNetscape()

getNav2

public boolean getNav2()

getNav3

public boolean getNav3()

getNav4

public boolean getNav4()

getNav4up

public boolean getNav4up()

getNav45

public boolean getNav45()

getNav45up

public boolean getNav45up()

getNavgold

public boolean getNavgold()

getNav6

public boolean getNav6()

getNav6up

public boolean getNav6up()

getMozilla

public boolean getMozilla()

getIe

public boolean getIe()

getIe3

public boolean getIe3()

getIe4

public boolean getIe4()

getIe4up

public boolean getIe4up()

getIe5

public boolean getIe5()

getIe5up

public boolean getIe5up()

getIe55

public boolean getIe55()

getIe55up

public boolean getIe55up()

getIe6

public boolean getIe6()

getIe6up

public boolean getIe6up()

getIe7

public boolean getIe7()

getIe7up

public boolean getIe7up()

getIe8

public boolean getIe8()

getIe8up

public boolean getIe8up()

getNeoplanet

public boolean getNeoplanet()

getNeoplanet2

public boolean getNeoplanet2()

getAol

public boolean getAol()

getAol3

public boolean getAol3()

getAol4

public boolean getAol4()

getAol5

public boolean getAol5()

getAol6

public boolean getAol6()

getAolTV

public boolean getAolTV()

getOpera

public boolean getOpera()

getOpera3

public boolean getOpera3()

getOpera4

public boolean getOpera4()

getOpera5

public boolean getOpera5()

getOpera6

public boolean getOpera6()

getOpera7

public boolean getOpera7()

getOpera8

public boolean getOpera8()

getOpera9

public boolean getOpera9()

getHotjava

public boolean getHotjava()

getHotjava3

public boolean getHotjava3()

getHotjava3up

public boolean getHotjava3up()

getLobo

public boolean getLobo()

getHttpclient

public boolean getHttpclient()

getAmaya

public boolean getAmaya()

getCurl

public boolean getCurl()

getStaroffice

public boolean getStaroffice()

getIcab

public boolean getIcab()

getLotusnotes

public boolean getLotusnotes()

getKonqueror

public boolean getKonqueror()

getLynx

public boolean getLynx()

getLinks

public boolean getLinks()

getW3m

public boolean getW3m()

getWebTV

public boolean getWebTV()

getMosaic

public boolean getMosaic()

getWget

public boolean getWget()

getGetright

public boolean getGetright()

getLwp

public boolean getLwp()

getYahoo

public boolean getYahoo()

getGoogle

public boolean getGoogle()

getJava

public boolean getJava()

getAltavista

public boolean getAltavista()

getScooter

public boolean getScooter()

getLycos

public boolean getLycos()

getInfoseek

public boolean getInfoseek()

getWebcrawler

public boolean getWebcrawler()

getLinkexchange

public boolean getLinkexchange()

getSlurp

public boolean getSlurp()

getRobot

public boolean getRobot()

getBlackberry

public boolean getBlackberry()

getAudrey

public boolean getAudrey()

getIopener

public boolean getIopener()

getAvantgo

public boolean getAvantgo()

getPalm

public boolean getPalm()

getWap

public boolean getWap()

getWin16

public boolean getWin16()

getWin3x

public boolean getWin3x()

getWin31

public boolean getWin31()

getWin95

public boolean getWin95()

getWin98

public boolean getWin98()

getWinnt

public boolean getWinnt()

getWin2k

public boolean getWin2k()

getWinxp

public boolean getWinxp()

getVista

public boolean getVista()

getDotnet

public boolean getDotnet()

getWinme

public boolean getWinme()

getWin32

public boolean getWin32()

getWindows

public boolean getWindows()

getMac

public boolean getMac()

getMacosx

public boolean getMacosx()

getMac68k

public boolean getMac68k()

getMacppc

public boolean getMacppc()

getAmiga

public boolean getAmiga()

getEmacs

public boolean getEmacs()

getOs2

public boolean getOs2()

getSun

public boolean getSun()

getSun4

public boolean getSun4()

getSun5

public boolean getSun5()

getSuni86

public boolean getSuni86()

getIrix

public boolean getIrix()

getIrix5

public boolean getIrix5()

getIrix6

public boolean getIrix6()

getHpux

public boolean getHpux()

getHpux9

public boolean getHpux9()

getHpux10

public boolean getHpux10()

getAix

public boolean getAix()

getAix1

public boolean getAix1()

getAix2

public boolean getAix2()

getAix3

public boolean getAix3()

getAix4

public boolean getAix4()

getLinux

public boolean getLinux()

getSco

public boolean getSco()

getUnixware

public boolean getUnixware()

getMpras

public boolean getMpras()

getReliant

public boolean getReliant()

getDec

public boolean getDec()

getSinix

public boolean getSinix()

getFreebsd

public boolean getFreebsd()

getBsd

public boolean getBsd()

getX11

public boolean getX11()

getUnix

public boolean getUnix()

getVMS

public boolean getVMS()

getCss

public boolean getCss()

getCss1

public boolean getCss1()

getCss2

public boolean getCss2()

getDom0

public boolean getDom0()

getDom1

public boolean getDom1()

getDom2

public boolean getDom2()

getJavascript

public boolean getJavascript()

getPreferredLanguage

public java.lang.String getPreferredLanguage()

getPreferredLocale

public java.util.Locale getPreferredLocale()

test

private boolean test(java.lang.String key)

parseVersion

private void parseVersion()

parseAcceptLanguage

private void parseAcceptLanguage()

filterLanguageTag

private java.lang.String filterLanguageTag(java.lang.String languageTag)


Copyright (c) 2003-2007 Apache Software Foundation