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.Serializable
Analyse 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/- Version:
- $Revision: 110060 $
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Browser.BrowserName
static class
Browser.OS
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.oro.text.regex.Pattern
botPattern
static java.lang.String
botPatternStr
protected java.lang.String
browserName
protected java.lang.String
browserVersion
protected boolean
isAndroid
protected boolean
isBlackberry
protected boolean
isChrome
protected boolean
isChromeFrame
protected boolean
isEdge
protected boolean
isFirefox
protected boolean
isIE
protected boolean
isIE10
protected boolean
isIE11
protected boolean
isIE11plus
protected boolean
isIE5
protected boolean
isIE55
protected boolean
isIE6
protected boolean
isIE7
protected boolean
isIE8
protected boolean
isIE9
protected boolean
isIEMobile
protected boolean
isIMode
protected boolean
isIPad
protected boolean
isIPhone
protected boolean
isModernBrowser
protected boolean
isOldBrowser
protected boolean
isOpera
protected boolean
isOperaMini
protected boolean
isRobot
protected boolean
isSafari
protected java.lang.String
platform
static java.lang.String
REVISION
protected java.lang.String
userAgent
All 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 void
checkDevice(javax.servlet.http.HttpServletRequest request)
static boolean
ereg(java.lang.String regexp, java.lang.String str)
static boolean
eregi(java.lang.String regexp, java.lang.String str)
java.lang.String
getBrowserName()
java.lang.String
getBrowserShortName()
java.lang.String
getBrowserVersion()
java.lang.String
getDeviceCPU()
int
getDeviceScreenDepth()
int
getDeviceScreenHeight()
int
getDeviceScreenWidth()
java.lang.String
getPlatform()
java.lang.String
getUserAgent()
static double
getVersion(java.lang.String browserVersion)
static void
init(java.lang.String botPatternStr)
Initialise a Robot pattern matching a given regexpboolean
isAndroid()
boolean
isChrome()
boolean
isChromeFrame()
boolean
isDeviceDescribed()
boolean
isEdge()
boolean
isFirefox()
boolean
isIE()
boolean
isIE10()
boolean
isIE11()
boolean
isIE5()
boolean
isIE55()
boolean
isIE6()
boolean
isIE6Only()
boolean
isIE7()
boolean
isIE8()
boolean
isIE9()
boolean
isIEMobile()
boolean
isIMode()
boolean
isIPad()
boolean
isIPhone()
boolean
isKnownBrowser()
boolean
isModernBrowser()
boolean
isOldBrowser()
boolean
isOpera()
boolean
isOperaMini()
boolean
isPDA()
boolean
isRobot()
boolean
isSafari()
boolean
isSmallDevice()
Returns true if the user-client is hosted on a small device such as a PDA or an i-mode cell phone.static void
main(java.lang.String[] args)
void
setBrowserName(java.lang.String browserName)
void
setBrowserVersion(java.lang.String browserVersion)
void
setFirefox(boolean isFirefox)
void
setIE5(boolean isIE5)
void
setIE55(boolean isIE55)
void
setIMode(boolean isIMode)
void
setModernBrowser(boolean isModernBrowser)
void
setOldBrowser(boolean isOldBrowser)
void
setPlatform(java.lang.String platform)
void
setRobot(boolean isRobot)
void
setUserAgent(java.lang.String userAgent)
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 needleboolean
supportCSS3()
java.lang.String
toString()
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
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:
toString
in 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()
-
-