Class 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/
    See Also:
    Serialized Form
    • 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
    • Constructor Detail

      • Browser

        public Browser​(javax.servlet.http.HttpServletRequest request,
                       boolean checkRemoteHost)
    • 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 regexp
        str - 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 regexp
        str - 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 String
        needle - 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 class java.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()