
Public Member Functions | |
| String | browserClassName () |
| String | browserClassNameForBrowserNamed (String browserName) |
| ERXBrowser | browserMatchingRequest (WORequest request) |
| synchronized ERXBrowser | createBrowser (String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo) |
| ERXBrowserFactory () | |
| synchronized ERXBrowser | getBrowserInstance (String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo) |
| String | parseBrowserName (String userAgent) |
| String | parseCPU (String userAgent) |
| String | parseGeckoVersion (String userAgent) |
| String | parseMozillaVersion (String userAgent) |
| String | parsePlatform (String userAgent) |
| String | parseVersion (String userAgent) |
| synchronized void | releaseBrowser (ERXBrowser browser) |
| synchronized void | retainBrowser (ERXBrowser browser) |
| void | setBrowserClassName (String name) |
Static Public Member Functions | |
| static ERXBrowserFactory | factory () |
| static void | setFactory (ERXBrowserFactory newFactory) |
Static Public Attributes | |
| static final Logger | log = Logger.getLogger(ERXBrowserFactory.class) |
Protected Attributes | |
| String | _browserClassName |
Private Member Functions | |
| NSMutableDictionary | _browserPool () |
| String | _browserString (String userAgent) |
| String | _computeKey (String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo) |
| String | _computeKey (ERXBrowser browser) |
| ERXBrowser | _createBrowserWithClassName (String className, String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException |
| ERXMutableInteger | _decrementReferenceCounterForKey (String key) |
| ERXMutableInteger | _incrementReferenceCounterForKey (String key) |
| NSMutableDictionary | _referenceCounters () |
| String | _versionString (String userAgent) |
| boolean | isRobot (String userAgent) |
Private Attributes | |
| NSMutableDictionary | _browserPool |
| NSMutableDictionary | _referenceCounters |
Static Private Attributes | |
| static final NSMutableDictionary | _cache = ERXMutableDictionary.synchronizedDictionary() |
| static final String | _DEFAULT_BROWSER_CLASS_NAME = ERXBasicBrowser.class.getName() |
| static ERXBrowserFactory | _factory |
| static final NSMutableArray < Pattern > | robotExpressions = new NSMutableArray() |
ERXBrowserFactory instance. Its primary role is to manage ERXBrowser objects. It provides facility to parse "user-agent" HTTP header and to create an appropriate browser object. It also maintains the browser pool to store shared ERXBrowser objects. Since ERXBrowser object is immutable, it can be safely shared between sessions and ERXBrowserFactory tries to have only one instance of ERXBrowser for each kind of web browsers.
The primary method called by ERXSession and ERXDirectAction is browserMatchingRequest which takes a WORequest as the parameter and returns a shared instance of browser object. You actually wouldn't have to call this function by yourself because ERXSession and ERXDirectAction provide browser method that returns a browser object for the current request for you.
Note that ERXSession and ERXDirectAction call ERXBrowserFactory's retainBrowser and releaseBrowser to put the browser object to the browser pool when it is created and to remove the browser object from the pool when it is no longer referred from sessions and direct actions. ERXSession and ERXDirectAction automatically handle this and you do not have to call these methods from your code.
The current implementation of the parsers support variety of Web browsers in the market such as Internet Explorer (IE), OmniWeb, Netscape, iCab and Opera, versions between 2.0 and 7.0.
To customize the parsers for "user-agent" HTTP header, subclass ERXBrowserFactory and override methods like parseBrowserName, parseVersion, parseMozillaVersion and parsePlatForm. Then put the following statement into the application's constructor.
ERXBrowserFactory.setFactory(new SubClassOfERXBrowserFactory());
If you want to use your own subclass of ERXBrowser, put the follwoing statement into the application's constructor.
ERXBrowserFactory.factory().setBrowserClassName("NameOfTheSubClassOfERXBrowser")
This implementation is tested with the following browsers (or "user-agent" strings) Please ask the guy (tatsuyak@mac.com) for WOUnitTest test cases.
Mac OS X ---------------------------------------------------------------------------------- iCab 2.8.1 Mozilla/4.5 (compatible; iCab 2.8.1; Macintosh; I; PPC) IE 5.21 Mozilla/4.0 (compatible; MSIE 5.21; Mac_PowerPC) Netscape 7.0b1 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0rc2) Gecko/20020512 Netscape/7.0b1 Netscape 6.2.3 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3 OmniWeb 4.1-v422 Mozilla/4.5 (compatible; OmniWeb/4.1-v422; Mac_PowerPC) Safari 1.0b(v48) Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/48 (like Gecko) Safari/48 iPhone 1.0 Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3
Windows 2000 ---------------------------------------------------------------------------------- IE 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) IE 5.5 Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) Netscape 6.2.3 Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3 Netscape 4.79 Mozilla/4.79 [en] (Windows NT 5.0; U) Opera 6.04 Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.04 [en]
Public browser constructor.
| NSMutableDictionary _browserPool | ( | ) | [private] |
| String _computeKey | ( | String | browserName, | |
| String | version, | |||
| String | mozillaVersion, | |||
| String | platform, | |||
| NSDictionary | userInfo | |||
| ) | [private] |
| String _computeKey | ( | ERXBrowser | browser | ) | [private] |
| ERXBrowser _createBrowserWithClassName | ( | String | className, | |
| String | browserName, | |||
| String | version, | |||
| String | mozillaVersion, | |||
| String | platform, | |||
| NSDictionary | userInfo | |||
| ) | throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException [private] |
| ERXMutableInteger _decrementReferenceCounterForKey | ( | String | key | ) | [private] |
| ERXMutableInteger _incrementReferenceCounterForKey | ( | String | key | ) | [private] |
| NSMutableDictionary _referenceCounters | ( | ) | [private] |
| String browserClassName | ( | ) |
Returns the name of the ERXBrowser subclass. The default value is "er.extensions.appserver.ERXBasicBrowser".
"er.extensions.appserver.ERXBasicBrowser" Adds the option to use multiple different ERXBrowser subclasses depending on the name of the browser.
| browserName | name of the browser |
| ERXBrowser browserMatchingRequest | ( | WORequest | request | ) |
Gets a shared browser object for given request. Parses "user-agent" string in the request and gets the appropiate browser object.
This is the primary method to call from application logics, and once you get a browser object, you are responsible to call retainBrowser to keep the browser object in the browser pool.
You are also required to call releaseBrowser to release the browser from the pool when it is no longer needed.
| request | WORequest |
| synchronized ERXBrowser createBrowser | ( | String | browserName, | |
| String | version, | |||
| String | mozillaVersion, | |||
| String | platform, | |||
| NSDictionary | userInfo | |||
| ) |
Creates a new browser object for given parameters. Override this method if you need to provide your own subclass of ERXBrowser. If you override it, your implementation should not call super.
Alternatively, use setBrowserClassName and browserClassName.
| browserName | string | |
| version | string | |
| mozillaVersion | string | |
| platform | string | |
| userInfo | dictionary |
ERXBrowser | static ERXBrowserFactory factory | ( | ) | [static] |
Gets the singleton browser factory object.
| synchronized ERXBrowser getBrowserInstance | ( | String | browserName, | |
| String | version, | |||
| String | mozillaVersion, | |||
| String | platform, | |||
| NSDictionary | userInfo | |||
| ) |
Gets a shared browser object from browser pool. If such browser object does not exist, this method will create one by using createBrowser method.
| browserName | string | |
| version | string | |
| mozillaVersion | string | |
| platform | string | |
| userInfo | dictionary |
| boolean isRobot | ( | String | userAgent | ) | [private] |
| synchronized void releaseBrowser | ( | ERXBrowser | browser | ) |
Decrements the retain count for a given browser object.
| browser | to be released |
| synchronized void retainBrowser | ( | ERXBrowser | browser | ) |
Retains a given browser object.
| browser | to be retained |
| void setBrowserClassName | ( | String | name | ) |
Sets the name of the ERXBrowser subclass.
| name | the name of the ERXBrowser subclass; ignored if null |
| static void setFactory | ( | ERXBrowserFactory | newFactory | ) | [static] |
Sets the browser factory used to create browser objects.
| newFactory | new browser factory |
String _browserClassName [protected] |
Caches the browser class name
NSMutableDictionary _browserPool [private] |
final NSMutableDictionary _cache = ERXMutableDictionary.synchronizedDictionary() [static, private] |
Mapping of UAs to browsers
final String _DEFAULT_BROWSER_CLASS_NAME = ERXBasicBrowser.class.getName() [static, private] |
holds the default browser class name
ERXBrowserFactory _factory [static, private] |
Caches a reference to the browser factory
NSMutableDictionary _referenceCounters [private] |
final NSMutableArray<Pattern> robotExpressions = new NSMutableArray() [static, private] |
Expressions that define a robot
1.5.8