com.ibm.xsp.designer.context
Class XSPUserAgent

java.lang.Object
  extended by com.ibm.xsp.designer.context.XSPUserAgent
All Implemented Interfaces:
java.io.Serializable

public class XSPUserAgent
extends java.lang.Object
implements java.io.Serializable

Utility class to parse the user-agent header variable.

This variable contains the information sent by the client (browser, robot...) and used to identify the client.

See: http://web.archive.org/web/20061217053523/http://en.wikipedia.org/wiki/User_agent

Some Examples:

See Also:
Serialized Form

Field Summary
static int BROWSER_CHROME
           
static int BROWSER_FIREFOX
           
static int BROWSER_IE
           
static int BROWSER_OPERA
           
static int BROWSER_SAFARI
           
static int BROWSER_UNKNOWN
           
 
Constructor Summary
XSPUserAgent(java.lang.String userAgent)
          Constructs a browser identifier with the HTTP request header that contains browser information.
 
Method Summary
 java.lang.String getBrowser()
          Returns a string that represents the browser common name.
 java.lang.String getBrowserVersion()
          Returns the version number as a string.
 double getBrowserVersionNumber()
          Returns the version number converted as a double.
 java.lang.String getUserAgent()
          Get the USER-AGENT string.
 java.lang.String getVersion(java.lang.String entry)
          Get the version for a particular entry.
 double getVersionNumber(java.lang.String entry)
          Get the number version for a particular entry.
 boolean hasEntry(java.lang.String entry)
          Check if an entry is available in the user agent.
 boolean isChrome()
          Check if the browser is Google Chrome.
 boolean isChrome(double min, double max)
          Check if the browser is Chrome within a particular version range.
 boolean isFirefox()
          Check if the browser is Firefox.
 boolean isFirefox(double min, double max)
          Check if the browser is Firefox within a particular version range.
 boolean isIE()
          Check if the browser is Internet Explorer.
 boolean isIE(double min, double max)
          Check if the browser is Internet Explorer within a particular version range.
 boolean isOpera()
          Check if the browser is Opera.
 boolean isOpera(double min, double max)
          Check if the browser is Opera within a particular version range.
 boolean isSafari()
          Check if the browser is Safari.
 boolean isSafari(double min, double max)
          Check if the browser is Safari within a particular version range.
 java.lang.String parseVersion(int pos)
          Extract a version # located at a particular position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BROWSER_UNKNOWN

public static final int BROWSER_UNKNOWN
See Also:
Constant Field Values

BROWSER_FIREFOX

public static final int BROWSER_FIREFOX
See Also:
Constant Field Values

BROWSER_IE

public static final int BROWSER_IE
See Also:
Constant Field Values

BROWSER_OPERA

public static final int BROWSER_OPERA
See Also:
Constant Field Values

BROWSER_SAFARI

public static final int BROWSER_SAFARI
See Also:
Constant Field Values

BROWSER_CHROME

public static final int BROWSER_CHROME
See Also:
Constant Field Values
Constructor Detail

XSPUserAgent

public XSPUserAgent(java.lang.String userAgent)
Constructs a browser identifier with the HTTP request header that contains browser information.

Method Detail

getUserAgent

public java.lang.String getUserAgent()
Get the USER-AGENT string. This method grabs the user-agent value from the request header variable named "user-agent". This string is used to identify the browser, operating system...


hasEntry

public boolean hasEntry(java.lang.String entry)
Check if an entry is available in the user agent.


getVersion

public java.lang.String getVersion(java.lang.String entry)
Get the version for a particular entry. This function scans the user agent and return the version number immediately following the entrye.


getVersionNumber

public double getVersionNumber(java.lang.String entry)
Get the number version for a particular entry. This function convert the version string to a version number, by converting to a double. If the actual version string contains more than one decimal point (ex: 3.0.1), then it ignores the digits after the second decimal point (ex: 3.0)


parseVersion

public java.lang.String parseVersion(int pos)
Extract a version # located at a particular position. This is a utility function that extract a version number located at a particular position. This function ignores all the letters, then space and slash.


getBrowser

public java.lang.String getBrowser()
Returns a string that represents the browser common name. It analyzes the browser based on the user-agent variable and currently recognizes: For all the other browsers, you should analyze the user-agent string


getBrowserVersion

public java.lang.String getBrowserVersion()
Returns the version number as a string. This works if the browser has been properly identified by the class. Only a subset of the browsers are currently reconized.

Returns:
the version number, or an empty string if not applicable

getBrowserVersionNumber

public double getBrowserVersionNumber()
Returns the version number converted as a double. This works if the browser has been properly identified by the class. Only a subset of the browsers are currently reconized. The number is converted to a double from the string, and every digit located after the second decimal point is ignored (ex: 3.0.1 becomes 3.0)

Returns:
the version number, or 0 if not applicable

isFirefox

public boolean isFirefox()
Check if the browser is Firefox.

Returns:
true if the browser is Firefox

isFirefox

public boolean isFirefox(double min,
                         double max)
Check if the browser is Firefox within a particular version range.

Parameters:
min - the minimum accepted version number (inclusive)
max - the maximum accepted version number (inclusive)
Returns:
true if the browser is Firefox

isIE

public boolean isIE()
Check if the browser is Internet Explorer.

Returns:
true if the browser is Internet Explorer

isIE

public boolean isIE(double min,
                    double max)
Check if the browser is Internet Explorer within a particular version range.

Parameters:
min - the minimum accepted version number (inclusive)
max - the maximum accepted version number (inclusive)
Returns:
true if the browser is Internet Explorer

isOpera

public boolean isOpera()
Check if the browser is Opera.

Returns:
true if the browser is Opera

isOpera

public boolean isOpera(double min,
                       double max)
Check if the browser is Opera within a particular version range.

Parameters:
min - the minimum accepted version number (inclusive)
max - the maximum accepted version number (inclusive)
Returns:
true if the browser is Opera

isSafari

public boolean isSafari()
Check if the browser is Safari. For compatibility issue, isSafari() also returns true for a Google Chrome browser.

Returns:
true if the browser is Safari

isSafari

public boolean isSafari(double min,
                        double max)
Check if the browser is Safari within a particular version range. For compatibility issue, isSafari() also returns true for a Google Chrome browser.

Parameters:
min - the minimum accepted version number (inclusive)
max - the maximum accepted version number (inclusive)
Returns:
true if the browser is Safari

isChrome

public boolean isChrome()
Check if the browser is Google Chrome.

Returns:
true if the browser is Chrome

isChrome

public boolean isChrome(double min,
                        double max)
Check if the browser is Chrome within a particular version range.

Parameters:
min - the minimum accepted version number (inclusive)
max - the maximum accepted version number (inclusive)
Returns:
true if the browser is Chrome