Package com.jalios.util
Class Browser
- java.lang.Object
-
- com.jalios.util.Browser
-
- All Implemented Interfaces:
java.io.Serializable
public class Browser extends java.lang.Object implements java.io.SerializableAnalyse the user agent of a http request to determine full information about the client's browser. Can be slow, store in session attribute! Browser Detection: http://www.apptools.com/phptools/browser/source.php Robot detection: http://sitemesh.dev.java.net/- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBrowser.BrowserNamestatic classBrowser.OS
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.oro.text.regex.PatternbotPatternstatic java.lang.StringbotPatternStrprotected java.lang.StringbrowserNameprotected java.lang.StringbrowserVersionprotected booleanisAndroidprotected booleanisBlackberryprotected booleanisChromeprotected booleanisChromeFrameprotected booleanisEdgeprotected booleanisFirefoxprotected booleanisIEprotected booleanisIE10protected booleanisIE11protected booleanisIE11plusprotected booleanisIE5protected booleanisIE55protected booleanisIE6protected booleanisIE7protected booleanisIE8protected booleanisIE9protected booleanisIEMobileprotected booleanisIModeprotected booleanisIPadprotected booleanisIPhoneprotected booleanisModernBrowserprotected booleanisOldBrowserprotected booleanisOperaprotected booleanisOperaMiniprotected booleanisRobotprotected booleanisSafariprotected java.lang.Stringplatformprotected java.lang.StringuserAgentAll known robot user-agent headers (list can be found here).
-
Constructor Summary
Constructors Constructor Description Browser(javax.servlet.http.HttpServletRequest request, boolean checkRemoteHost)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckDevice(javax.servlet.http.HttpServletRequest request)static booleanereg(java.lang.String regexp, java.lang.String str)static booleaneregi(java.lang.String regexp, java.lang.String str)java.lang.StringgetBrowserName()java.lang.StringgetBrowserShortName()java.lang.StringgetBrowserVersion()java.lang.StringgetDeviceCPU()intgetDeviceScreenDepth()intgetDeviceScreenHeight()intgetDeviceScreenWidth()java.lang.StringgetPlatform()java.lang.StringgetUserAgent()static doublegetVersion(java.lang.String browserVersion)static voidinit(java.lang.String botPatternStr)Initialise a Robot pattern matching a given regexpbooleanisAndroid()booleanisChrome()booleanisChromeFrame()booleanisDeviceDescribed()booleanisEdge()booleanisFirefox()booleanisIE()booleanisIE10()booleanisIE11()booleanisIE5()booleanisIE55()booleanisIE6()booleanisIE6Only()booleanisIE7()booleanisIE8()booleanisIE9()booleanisIEMobile()booleanisIMode()booleanisIPad()booleanisIPhone()booleanisKnownBrowser()booleanisModernBrowser()booleanisOldBrowser()booleanisOpera()booleanisOperaMini()booleanisPDA()booleanisRobot()booleanisSafari()booleanisSmallDevice()Returns true if the user-client is hosted on a small device such as a PDA or an i-mode cell phone.static voidmain(java.lang.String[] args)voidsetBrowserName(java.lang.String browserName)voidsetBrowserVersion(java.lang.String browserVersion)voidsetFirefox(boolean isFirefox)voidsetIE5(boolean isIE5)voidsetIE55(boolean isIE55)voidsetIMode(boolean isIMode)voidsetModernBrowser(boolean isModernBrowser)voidsetOldBrowser(boolean isOldBrowser)voidsetPlatform(java.lang.String platform)voidsetRobot(boolean isRobot)voidsetUserAgent(java.lang.String userAgent)static java.lang.Stringstristr(java.lang.String haystack, java.lang.String needle)Return the substring of the given haystack starting from the first occurence of the needlebooleansupportCSS3()java.lang.StringtoString()
-
-
-
Field Detail
-
userAgent
protected java.lang.String userAgent
All known robot user-agent headers (list can be found here).NOTE: To avoid bad detection:
- Robots with ID of 2 letters only were removed
- Robot called "webs" were removed
- directhit was changed in direct_hit (its real id)
-
platform
protected java.lang.String platform
-
browserName
protected java.lang.String browserName
-
browserVersion
protected java.lang.String browserVersion
-
isIE
protected boolean isIE
-
isIE11plus
protected boolean isIE11plus
-
isIE11
protected boolean isIE11
-
isIE10
protected boolean isIE10
-
isIE9
protected boolean isIE9
-
isIE8
protected boolean isIE8
-
isIE7
protected boolean isIE7
-
isIE6
protected boolean isIE6
-
isIE55
protected boolean isIE55
-
isIE5
protected boolean isIE5
-
isIEMobile
protected boolean isIEMobile
-
isFirefox
protected boolean isFirefox
-
isOpera
protected boolean isOpera
-
isOperaMini
protected boolean isOperaMini
-
isSafari
protected boolean isSafari
-
isIPhone
protected boolean isIPhone
-
isIPad
protected boolean isIPad
-
isBlackberry
protected boolean isBlackberry
-
isAndroid
protected boolean isAndroid
-
isModernBrowser
protected boolean isModernBrowser
-
isOldBrowser
protected boolean isOldBrowser
-
isChrome
protected boolean isChrome
-
isChromeFrame
protected boolean isChromeFrame
-
isEdge
protected boolean isEdge
-
isRobot
protected boolean isRobot
-
isIMode
protected boolean isIMode
-
botPattern
protected static org.apache.oro.text.regex.Pattern botPattern
-
botPatternStr
public static java.lang.String botPatternStr
-
-
Method Detail
-
init
public static void init(java.lang.String botPatternStr)
Initialise a Robot pattern matching a given regexp- Parameters:
botPatternStr- a regular expression that will be used against UserAgent string to detect robot
-
checkDevice
protected void checkDevice(javax.servlet.http.HttpServletRequest request)
-
getDeviceCPU
public java.lang.String getDeviceCPU()
- Returns:
- the device CPU
- Since:
- jcms-5.5.0
-
getDeviceScreenWidth
public int getDeviceScreenWidth()
- Returns:
- the device screen width
- Since:
- jcms-5.5.0
-
getDeviceScreenHeight
public int getDeviceScreenHeight()
- Returns:
- the device screen height
- Since:
- jcms-5.5.0
-
getDeviceScreenDepth
public int getDeviceScreenDepth()
- Returns:
- the device screen depth
- Since:
- jcms-5.5.0
-
isPDA
public boolean isPDA()
- Returns:
- true if the browser is hosted on a PDA
- Since:
- jcms-5.5.0
-
isSmallDevice
public boolean isSmallDevice()
Returns true if the user-client is hosted on a small device such as a PDA or an i-mode cell phone.- Returns:
- true if the user-client is hosted on a small device.
- Since:
- jcms-5.6.0
-
isDeviceDescribed
public boolean isDeviceDescribed()
- Returns:
- true if device info are provided
- Since:
- jcms-5.5.0
-
eregi
public static boolean eregi(java.lang.String regexp, java.lang.String str)- Parameters:
regexp- the regexpstr- the String- Returns:
- true if th eregexp match
- Since:
- jcms-5.0.0
-
ereg
public static boolean ereg(java.lang.String regexp, java.lang.String str)- Parameters:
regexp- the regexpstr- the String- Returns:
- true if the regexp match with case insansitive
- Since:
- jcms-5.0.0
-
stristr
public static java.lang.String stristr(java.lang.String haystack, java.lang.String needle)Return the substring of the given haystack starting from the first occurence of the needle- Parameters:
haystack- the Stringneedle- the first occurence- Returns:
- the substring
- Since:
- jcms-5.0.0
-
getVersion
public static double getVersion(java.lang.String browserVersion)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
getBrowserName
public java.lang.String getBrowserName()
-
setBrowserName
public void setBrowserName(java.lang.String browserName)
-
getBrowserVersion
public java.lang.String getBrowserVersion()
-
setBrowserVersion
public void setBrowserVersion(java.lang.String browserVersion)
-
getBrowserShortName
public java.lang.String getBrowserShortName()
-
isFirefox
public boolean isFirefox()
-
setFirefox
public void setFirefox(boolean isFirefox)
-
isIE
public boolean isIE()
-
isIE5
public boolean isIE5()
-
setIE5
public void setIE5(boolean isIE5)
-
isIE55
public boolean isIE55()
-
setIE55
public void setIE55(boolean isIE55)
-
isIE6
public boolean isIE6()
- Returns:
- true if browser was detected as Internet Explorer version 6 or greater
-
isIE6Only
public boolean isIE6Only()
- Returns:
- true if browser was detected Internet Explorer version 6 exactly
-
isIE7
public boolean isIE7()
- Returns:
- true if browser was detected as Internet Explorer version 7 or greater
-
isEdge
public boolean isEdge()
- Returns:
- true if browser was detected as Microsoft Edge
-
isIE11
public boolean isIE11()
- Returns:
- true if browser was detected as Internet Explorer version 11 or greater
-
isIE10
public boolean isIE10()
- Returns:
- true if browser was detected as Internet Explorer version 10 or greater
-
isIE9
public boolean isIE9()
- Returns:
- true if browser was detected as Internet Explorer version 9 or greater
-
isIE8
public boolean isIE8()
- Returns:
- true if browser was detected as Internet Explorer version 8 or greater
-
isIEMobile
public boolean isIEMobile()
-
isChromeFrame
public boolean isChromeFrame()
-
isOpera
public boolean isOpera()
-
isOperaMini
public boolean isOperaMini()
-
isChrome
public boolean isChrome()
-
isSafari
public boolean isSafari()
-
isIPhone
public boolean isIPhone()
-
isIPad
public boolean isIPad()
-
isAndroid
public boolean isAndroid()
-
isModernBrowser
public boolean isModernBrowser()
-
setModernBrowser
public void setModernBrowser(boolean isModernBrowser)
-
isOldBrowser
public boolean isOldBrowser()
-
setOldBrowser
public void setOldBrowser(boolean isOldBrowser)
-
isKnownBrowser
public boolean isKnownBrowser()
-
isRobot
public boolean isRobot()
-
setRobot
public void setRobot(boolean isRobot)
-
isIMode
public boolean isIMode()
- Returns:
- true if this Browser is a i-mode capable browser.
-
setIMode
public void setIMode(boolean isIMode)
-
getPlatform
public java.lang.String getPlatform()
-
setPlatform
public void setPlatform(java.lang.String platform)
-
getUserAgent
public java.lang.String getUserAgent()
-
setUserAgent
public void setUserAgent(java.lang.String userAgent)
-
supportCSS3
public boolean supportCSS3()
-
-