org.lobobrowser.html.test
public class SimpleUserAgentContext extends java.lang.Object implements UserAgentContext
UserAgentContext
.
This class is provided for user convenience.
Usually this class should be extended in order to provide appropriate
user agent information and more robust content loading routines.
Its setters can be called to modify certain user agent defaults.Constructor and Description |
---|
SimpleUserAgentContext() |
Modifier and Type | Method and Description |
---|---|
HttpRequest |
createHttpRequest()
Creates a
SimpleHttpRequest instance. |
java.lang.String |
getAppCodeName()
Returns the application "code name." This implementation
returns the value of a local field.
|
java.lang.String |
getAppMinorVersion()
Gets the "minor version" of the application.
|
java.lang.String |
getAppName()
Gets the application name.
|
java.lang.String |
getAppVersion()
Gets the major application version.
|
java.lang.String |
getBrowserLanguage()
Get the browser language.
|
java.lang.String |
getCookie(java.net.URL url)
This implementation uses the default
java.net.CookieHandler ,
if any, to get cookie information for the given URL. |
java.lang.String |
getPlatform()
Returns the value of Java property
os.name . |
java.lang.String |
getProduct() |
protected java.net.Proxy |
getProxy()
Gets the connection proxy used in requests created
by
createHttpRequest() by default. |
int |
getScriptingOptimizationLevel()
Gets the Rhino optimization level.
|
java.security.Policy |
getSecurityPolicy()
Returns
null . |
java.lang.String |
getUserAgent()
Gets the User-Agent string.
|
java.lang.String |
getVendor() |
boolean |
isCookieEnabled()
This implementation returns true if and only if
java.net.CookieHandler.getDefault()
is returning a non-null value. |
boolean |
isExternalCSSEnabled()
Determines whether external CSS loading should be enabled.
|
boolean |
isMedia(java.lang.String mediaName)
This implementation returns true for certain media names,
such as
screen . |
boolean |
isScriptingEnabled()
Determines whether scripting should be enabled.
|
void |
setAppCodeName(java.lang.String appCodeName)
Sets the application code name normally returned by
getAppCodeName() . |
void |
setAppMinorVersion(java.lang.String appMinorVersion)
Sets the value normally returned by
getAppMinorVersion() . |
void |
setAppName(java.lang.String appName)
Sets the value normally returned by
getAppName() . |
void |
setAppVersion(java.lang.String appVersion)
Sets the value normally returned by
getAppVersion() . |
void |
setCookie(java.net.URL url,
java.lang.String cookieSpec)
This method uses the default CookieHandler, if one is available,
to set a cookie value.
|
void |
setExternalCSSEnabled(boolean enabled)
Sets the value normally returned by
isExternalCSSEnabled() . |
void |
setProduct(java.lang.String product) |
void |
setProxy(java.net.Proxy proxy)
Sets the value of the proxy normally returned by
getProxy() . |
void |
setScriptingEnabled(boolean enable)
Sets the value normally returned by
isScriptingEnabled() . |
void |
setScriptingOptimizationLevel(int level)
Sets the value normally returned by
getScriptingOptimizationLevel() . |
void |
setUserAgent(java.lang.String userAgent)
Sets the value normally returned by
getUserAgent() . |
void |
setVendor(java.lang.String vendor) |
public boolean isMedia(java.lang.String mediaName)
screen
.isMedia
in interface UserAgentContext
mediaName
- Media name, which
may be screen
, tty
, etc. (See HTML Specification).public HttpRequest createHttpRequest()
SimpleHttpRequest
instance.
The HttpRequest
object returned by this method is
used to load images, scripts, style sheets, and to implement
the Javascript XMLHttpRequest class.
Override if a custom mechanism to make requests is needed.createHttpRequest
in interface UserAgentContext
protected java.net.Proxy getProxy()
createHttpRequest()
by default. This implementation returns
the value of a local field.setProxy(java.net.Proxy)
public void setProxy(java.net.Proxy proxy)
getProxy()
.proxy
- A java.net.Proxy
instance.public java.lang.String getAppCodeName()
getAppCodeName
in interface UserAgentContext
setAppCodeName(String)
public void setAppCodeName(java.lang.String appCodeName)
getAppCodeName()
.appCodeName
- An application "code name."public java.lang.String getAppMinorVersion()
getAppMinorVersion
in interface UserAgentContext
setAppMinorVersion(String)
public void setAppMinorVersion(java.lang.String appMinorVersion)
getAppMinorVersion()
.appMinorVersion
- The application's "minor version."public java.lang.String getAppName()
getAppName
in interface UserAgentContext
setAppName(String)
public void setAppName(java.lang.String appName)
getAppName()
.appName
- The application name.public java.lang.String getAppVersion()
getAppVersion
in interface UserAgentContext
setAppVersion(String)
public void setAppVersion(java.lang.String appVersion)
getAppVersion()
.appVersion
- The application version.public java.lang.String getBrowserLanguage()
getBrowserLanguage
in interface UserAgentContext
public java.lang.String getPlatform()
os.name
.
It may be overridden to provide a different value.getPlatform
in interface UserAgentContext
public java.lang.String getUserAgent()
getUserAgent
in interface UserAgentContext
setUserAgent(String)
public void setUserAgent(java.lang.String userAgent)
getUserAgent()
.userAgent
- A User-Agent string.public boolean isCookieEnabled()
java.net.CookieHandler.getDefault()
is returning a non-null value. The method may
be overridden to provide an alternative means
of determining cookie enabling state.isCookieEnabled
in interface UserAgentContext
public java.lang.String getCookie(java.net.URL url)
java.net.CookieHandler
,
if any, to get cookie information for the given URL. If no cookie handler
is available, this method returns the empty string.getCookie
in interface UserAgentContext
public boolean isScriptingEnabled()
true
.isScriptingEnabled
in interface UserAgentContext
setScriptingEnabled(boolean)
public void setScriptingEnabled(boolean enable)
isScriptingEnabled()
.enable
- A boolean value.public void setCookie(java.net.URL url, java.lang.String cookieSpec)
setCookie
in interface UserAgentContext
cookieSpec
- Specification of cookies, as they
would appear in the Set-Cookie
header value of HTTP.public java.security.Policy getSecurityPolicy()
null
. This method must be overridden
if JavaScript code is untrusted.getSecurityPolicy
in interface UserAgentContext
public int getScriptingOptimizationLevel()
-1
.getScriptingOptimizationLevel
in interface UserAgentContext
setScriptingOptimizationLevel(int)
public void setScriptingOptimizationLevel(int level)
getScriptingOptimizationLevel()
.level
- A Rhino optimization level.public java.lang.String getVendor()
getVendor
in interface UserAgentContext
public void setVendor(java.lang.String vendor)
public java.lang.String getProduct()
getProduct
in interface UserAgentContext
public void setProduct(java.lang.String product)
public boolean isExternalCSSEnabled()
true
.isExternalCSSEnabled
in interface UserAgentContext
setExternalCSSEnabled(boolean)
public void setExternalCSSEnabled(boolean enabled)
isExternalCSSEnabled()
.enabled
- A boolean value.