ERXBrowserFactory Class Reference

Collaboration diagram for ERXBrowserFactory:

Collaboration graph
[legend]

List of all members.

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()


Detailed Description

All WebObjects applications have exactly one 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]

 

Constructor & Destructor Documentation

Public browser constructor.


Member Function Documentation

NSMutableDictionary _browserPool (  )  [private]

String _browserString ( String  userAgent  )  [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]

String _versionString ( String  userAgent  )  [private]

String browserClassName (  ) 

Returns the name of the ERXBrowser subclass. The default value is "er.extensions.appserver.ERXBasicBrowser".

Returns:
the name of the ERXBrowser subclass; default to "er.extensions.appserver.ERXBasicBrowser"
See also:
setBrowserClassName

String browserClassNameForBrowserNamed ( String  browserName  ) 

Adds the option to use multiple different ERXBrowser subclasses depending on the name of the browser.

Parameters:
browserName name of the browser
Returns:
ERXBrowser subclass class name

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.

Parameters:
request WORequest
Returns:
a shared browser object

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.

Parameters:
browserName string
version string
mozillaVersion string
platform string
userInfo dictionary
Returns:
new browser object that is a concrete subclass of ERXBrowser
See also:
setBrowserClassName

browserClassName

static ERXBrowserFactory factory (  )  [static]

Gets the singleton browser factory object.

Returns:
browser factory

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.

Parameters:
browserName string
version string
mozillaVersion string
platform string
userInfo dictionary
Returns:
a shared browser object

boolean isRobot ( String  userAgent  )  [private]

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  ) 

Decrements the retain count for a given browser object.

Parameters:
browser to be released

synchronized void retainBrowser ( ERXBrowser  browser  ) 

Retains a given browser object.

Parameters:
browser to be retained

void setBrowserClassName ( String  name  ) 

Sets the name of the ERXBrowser subclass.

Parameters:
name the name of the ERXBrowser subclass; ignored if null
See also:
browserClassName

createBrowser

static void setFactory ( ERXBrowserFactory  newFactory  )  [static]

Sets the browser factory used to create browser objects.

Parameters:
newFactory new browser factory


Member Data Documentation

Caches the browser class name

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

final Logger log = Logger.getLogger(ERXBrowserFactory.class) [static]

logging support

final NSMutableArray<Pattern> robotExpressions = new NSMutableArray() [static, private]

Expressions that define a robot


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:01 2012 for Project Wonder by  doxygen 1.5.8