|
Project Wonder 2.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object er.extensions.ERXBrowserFactory
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 |
public static final ERXLogger log
protected String _browserClassName
Constructor Detail |
public ERXBrowserFactory()
Method Detail |
public static ERXBrowserFactory factory()
public static void setFactory(ERXBrowserFactory newFactory)
newFactory
- new browser factorypublic String browserClassName()
ERXBrowser
subclass.
The default value is "er.extensions.ERXBasicBrowser"
.
"er.extensions.ERXBasicBrowser"
setBrowserClassName(java.lang.String)
public void setBrowserClassName(String name)
ERXBrowser
subclass.
name
- the name of the ERXBrowser subclass; ignored if nullbrowserClassName()
,
createBrowser(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.webobjects.foundation.NSDictionary)
public ERXBrowser browserMatchingRequest(WORequest request)
"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
public ERXBrowser getBrowserInstance(String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo)
createBrowser
method.
browserName
- stringversion
- stringplatform
- stringuserInfo
- dictionary
public ERXBrowser createBrowser(String browserName, String version, String mozillaVersion, String platform, NSDictionary userInfo)
ERXBrowser
.
If you override it, your implementation should not call super
.
Alternatively, use setBrowserClassName(java.lang.String)
and browserClassName()
.
browserName
- stringversion
- stringmozillaVersion
- stringplatform
- stringuserInfo
- dictionary
ERXBrowser
setBrowserClassName(java.lang.String)
,
browserClassName()
public void retainBrowser(ERXBrowser browser)
browser
- to be retainedpublic void releaseBrowser(ERXBrowser browser)
browser
- to be releasedpublic String browserClassNameForBrowserNamed(String browserName)
browserName
- name of the browser
public String parseBrowserName(String userAgent)
public String parseGeckoVersion(String userAgent)
public String parseVersion(String userAgent)
public String parseMozillaVersion(String userAgent)
public String parsePlatform(String userAgent)
public String parseCPU(String userAgent)
|
Last updated: Do, Dez 9, 2004 12:46 PM CET | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |