Project Wonder 2.0

er.extensions
Class ERXBrowserFactory

java.lang.Object
  extended byer.extensions.ERXBrowserFactory

public class ERXBrowserFactory
extends Object

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 retailnBrowser 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
 
 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]

 


Field Summary
protected  String _browserClassName
          Caches the browser class name
static ERXLogger log
          logging support
 
Constructor Summary
ERXBrowserFactory()
          Public browser constructor.
 
Method Summary
 String browserClassName()
          Returns the name of the ERXBrowser subclass.
 String browserClassNameForBrowserNamed(String browserName)
          Adds the option to use multiple different ERXBrowser subclasses depending on the name of the browser.
 ERXBrowser browserMatchingRequest(WORequest request)
          Gets a shared browser object for given request.
 ERXBrowser createBrowser(String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo)
          Creates a new browser object for given parameters.
static ERXBrowserFactory factory()
          Gets the singleton browser factory object.
 ERXBrowser getBrowserInstance(String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo)
          Gets a shared browser object from browser pool.
 String parseBrowserName(String userAgent)
           
 String parseCPU(String userAgent)
           
 String parseGeckoVersion(String userAgent)
           
 String parseMozillaVersion(String userAgent)
           
 String parsePlatform(String userAgent)
           
 String parseVersion(String userAgent)
           
 void releaseBrowser(ERXBrowser browser)
          Decrements the retain count for a given browser object.
 void retainBrowser(ERXBrowser browser)
          Retains a given browser object.
 void setBrowserClassName(String name)
          Sets the name of the ERXBrowser subclass.
static void setFactory(ERXBrowserFactory newFactory)
          Sets the browser factory used to create browser objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


_browserClassName

protected String _browserClassName
Caches the browser class name

Constructor Detail

ERXBrowserFactory

public ERXBrowserFactory()
Public browser constructor.

Method Detail

factory

public static ERXBrowserFactory factory()
Gets the singleton browser factory object.

Returns:
browser factory

setFactory

public static void setFactory(ERXBrowserFactory newFactory)
Sets the browser factory used to create browser objects.

Parameters:
newFactory - new browser factory

browserClassName

public String browserClassName()
Returns the name of the ERXBrowser subclass. The default value is "er.extensions.ERXBasicBrowser".

Returns:
the name of the ERXBrowser subclass; default to "er.extensions.ERXBasicBrowser"
See Also:
setBrowserClassName(java.lang.String)

setBrowserClassName

public 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(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.webobjects.foundation.NSDictionary)

browserMatchingRequest

public 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

getBrowserInstance

public 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
platform - string
userInfo - dictionary
Returns:
a shared browser object

createBrowser

public 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(java.lang.String) 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(java.lang.String), browserClassName()

retainBrowser

public void retainBrowser(ERXBrowser browser)
Retains a given browser object.

Parameters:
browser - to be retained

releaseBrowser

public void releaseBrowser(ERXBrowser browser)
Decrements the retain count for a given browser object.

Parameters:
browser - to be released

browserClassNameForBrowserNamed

public 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

parseBrowserName

public String parseBrowserName(String userAgent)

parseGeckoVersion

public String parseGeckoVersion(String userAgent)

parseVersion

public String parseVersion(String userAgent)

parseMozillaVersion

public String parseMozillaVersion(String userAgent)

parsePlatform

public String parsePlatform(String userAgent)

parseCPU

public String parseCPU(String userAgent)

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.