类 BrowserTool
- 所有已实现的接口:
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...
All properties are boolean, excpet those in italic which are strings (and major/minor versions which are integers)
The following properties are available:
- Device: device robot mobile tablet desktop tv
- Features:css3 dom3
- Browser:browser.name browser.majorVersion browser.minorVersion
- Rendering engine: renderingEngine.name renderingEngine.minorVersion renderingEngine.majorVersion
- Operating system: operatingsystem.name operatingsystem.majorVersion operatingsystem.minorVersion
- Specific browser tests:netscape firefox safari MSIE opera links mozilla konqueror chrome
- Specific rendering engine tests:gecko webKit KHTML trident blink edgeHTML presto
- Specific OS tests:windows OSX linux unix BSD android iOS symbian
- Languages: preferredLanguageTag (a string like 'en', 'da', 'en-US', ...), preferredLocale (a java Locale)
- IP address: IPAddress
Language properties are filtered by the languagesFilter tool param, if present, which is here to specify which languages are acceptable on the server side. 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.
Notes on implementation:
- The parsing algorithm is mainly empirical. Used rules are rather generic, so shouldn't need recent updates to be accurate, but accuracy remains far from guaranteed for new devices.
- Parsing should be fast, as the parser only uses a single regex iteration on the user agent string.
- Game consoles, e-readers, etc... are for now classified as mobile devices (but can sometimes be identified by their operating system).
- Needless to say, the frontier between different device types can be very thin...
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/
- https://github.com/OpenDDR
- https://devicemap.apache.org/
- http://www.useragentstring.com/pages/useragentstring.php?name=All
- https://en.wikipedia.org/wiki/Comparison_of_layout_engines_(Cascading_Style_Sheets)
- https://en.wikipedia.org/wiki/Comparison_of_layout_engines_(Document_Object_Model)
- http://www.webapps-online.com/online-tools/user-agent-strings
- https://whichbrowser.net/data/
TODO:
- parse X-Wap-Profile header if present
- parse X-Requested-With header if present
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Revision$ $Date$
- 作者:
- Claude Brisson
- 另请参阅:
-
字段概要
从类继承的字段 org.apache.velocity.tools.generic.FormatConfig
DEFAULT_FORMAT, FORMAT_KEY从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明booleanbooleangetCss3()booleangetDom3()Get the client browser IP address.booleanbooleanbooleanisBlink()booleanisBSD()booleanisChrome()booleanbooleanbooleanbooleanisGecko()booleanisIOS()booleanisKHTML()booleanbooleanisLinks()booleanisLinux()booleanisMobile()booleanbooleanisMSIE()booleanbooleanisOpera()booleanisOSX()booleanisPresto()booleanisRobot()booleanisSafari()booleanbooleanisTablet()booleanbooleanisTV()booleanisUnix()booleanisWebKit()booleanvoidvoidsetLanguagesFilter(String filter) voidsetRequest(jakarta.servlet.http.HttpServletRequest request) Retrieves the User-Agent header from the request (if any).voidSets the User-Agent string to be parsed for info.protected booleantoString()从类继承的方法 org.apache.velocity.tools.view.BrowserToolDeprecatedMethods
getCss, getCss1, getCss2, getDom0, getDom1, getDom2, getDotnet, getGeckoMajorVersion, getGeckoMinorVersion, getGeckoVersion, getIe, getIe3, getIe4, getIe4up, getIe5, getIe55, getIe55up, getIe5up, getIe6, getIe6up, getIe7, getIe7up, getIe8, getIe8up, getJavascript, getMajorVersion, getMinorVersion, getNav2, getNav3, getNav4, getNav45, getNav45up, getNav4up, getNav6, getNav6up, getNavgold, getOpera3, getOpera4, getOpera5, getOpera6, getOpera7, getOpera8, getOpera9, getUserAgent, getVersion, getVista, getWin16, getWin2k, getWin31, getWin32, getWin3x, getWin95, getWin98, getWinme, getWinnt, getWinxp, isAix, isAix1, isAix2, isAix3, isAix4, isAmiga, isBsd, isDec, isEmacs, isFreebsd, isHpux, isHpux10, isHpux9, isIrix, isIrix5, isIrix6, isMac, isMac68k, isMacppc, isMpras, isOs2, isReliant, isSco, isSinix, isSun, isSun4, isSun5, isSuni86, isUnixware, isVMS, isX11从类继承的方法 org.apache.velocity.tools.generic.FormatConfig
configure, getFormat, setFormat从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
构造器详细资料
-
BrowserTool
public BrowserTool()
-
-
方法详细资料
-
setRequest
public void setRequest(jakarta.servlet.http.HttpServletRequest request) Retrieves the User-Agent header from the request (if any).- 参数:
request- servlet request- 另请参阅:
-
setUserAgentString
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.- 参数:
ua- user agent string
-
setAcceptLanguage
-
setLanguagesFilter
-
getLanguagesFilter
-
toString
-
get
-
getUserAgentString
-
getAcceptLanguage
-
getIPAddress
Get the client browser IP address. In the session scope, which is the default, it corresponds to the first seen IP adress.
The tool tries to get the real IP address whenever the request has been proxied.
Please note that the result may be null.
- 返回:
- the IP address as a string
- 从以下版本开始:
- VelocityTools 3.0
-
getDevice
- 返回:
- found device
- 从以下版本开始:
- VelocityTools 3.0
-
isRobot
public boolean isRobot() -
isTablet
public boolean isTablet()- 返回:
- whether found device is a tablet
- 从以下版本开始:
- VelocityTools 3.0
-
isMobile
public boolean isMobile()- 返回:
- whether found device is a mobile device
- 从以下版本开始:
- VelocityTools 3.0
-
isDesktop
public boolean isDesktop()- 返回:
- whether found device is a desktop device
- 从以下版本开始:
- VelocityTools 3.0
-
isTV
public boolean isTV()- 返回:
- whether found device is a TV
- 从以下版本开始:
- VelocityTools 3.0
-
getBrowser
- 指定者:
getBrowser在类中BrowserToolDeprecatedMethods- 返回:
- parsed browser
- 从以下版本开始:
- VelocityTools 3.0
-
getRenderingEngine
- 指定者:
getRenderingEngine在类中BrowserToolDeprecatedMethods- 返回:
- parsed rendering engine
- 从以下版本开始:
- VelocityTools 3.0
-
getOperatingSystem
- 指定者:
getOperatingSystem在类中BrowserToolDeprecatedMethods- 返回:
- parsed operating system
- 从以下版本开始:
- VelocityTools 3.0
-
isGecko
public boolean isGecko()- 指定者:
isGecko在类中BrowserToolDeprecatedMethods
-
isWebKit
public boolean isWebKit() -
isKHTML
public boolean isKHTML() -
isTrident
public boolean isTrident() -
isBlink
public boolean isBlink() -
isEdgeHTML
public boolean isEdgeHTML() -
isPresto
public boolean isPresto() -
isChrome
public boolean isChrome()- 指定者:
isChrome在类中BrowserToolDeprecatedMethods
-
isMSIE
public boolean isMSIE()- 指定者:
isMSIE在类中BrowserToolDeprecatedMethods
-
isFirefox
public boolean isFirefox()- 指定者:
isFirefox在类中BrowserToolDeprecatedMethods
-
isOpera
public boolean isOpera()- 指定者:
isOpera在类中BrowserToolDeprecatedMethods
-
isSafari
public boolean isSafari()- 指定者:
isSafari在类中BrowserToolDeprecatedMethods
-
isNetscape
public boolean isNetscape()- 指定者:
isNetscape在类中BrowserToolDeprecatedMethods
-
isKonqueror
public boolean isKonqueror()- 指定者:
isKonqueror在类中BrowserToolDeprecatedMethods
-
isLinks
public boolean isLinks()- 指定者:
isLinks在类中BrowserToolDeprecatedMethods
-
isMozilla
public boolean isMozilla()- 指定者:
isMozilla在类中BrowserToolDeprecatedMethods
-
isWindows
public boolean isWindows()- 指定者:
isWindows在类中BrowserToolDeprecatedMethods
-
isOSX
public boolean isOSX()- 指定者:
isOSX在类中BrowserToolDeprecatedMethods
-
isLinux
public boolean isLinux()- 指定者:
isLinux在类中BrowserToolDeprecatedMethods
-
isBSD
public boolean isBSD() -
isUnix
public boolean isUnix() -
isAndroid
public boolean isAndroid() -
isIOS
public boolean isIOS() -
isSymbian
public boolean isSymbian() -
isBlackberry
public boolean isBlackberry() -
getCss3
public boolean getCss3() -
getDom3
public boolean getDom3() -
getPreferredLanguage
-
getPreferredLocale
-
test
- 指定者:
test在类中BrowserToolDeprecatedMethods
-