Package org.lobobrowser.html.test
Class SimpleUserAgentContext
java.lang.Object
org.lobobrowser.html.test.SimpleUserAgentContext
- All Implemented Interfaces:
UserAgentContext
Simple implementation of
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates aSimpleHttpRequest
instance.Returns the application "code name." This implementation returns the value of a local field.Gets the "minor version" of the application.Gets the application name.Gets the major application version.Get the browser language.This implementation uses the defaultjava.net.CookieHandler
, if any, to get cookie information for the given URL.Returns the value of Java propertyos.name
.protected Proxy
getProxy()
Gets the connection proxy used in requests created bycreateHttpRequest()
by default.int
Gets the Rhino optimization level.Returnsnull
.Gets the User-Agent string.boolean
This implementation returns true if and only ifjava.net.CookieHandler.getDefault()
is returning a non-null value.boolean
Determines whether external CSS loading should be enabled.boolean
This implementation returns true for certain media names, such asscreen
.boolean
Determines whether scripting should be enabled.void
setAppCodeName
(String appCodeName) Sets the application code name normally returned bygetAppCodeName()
.void
setAppMinorVersion
(String appMinorVersion) Sets the value normally returned bygetAppMinorVersion()
.void
setAppName
(String appName) Sets the value normally returned bygetAppName()
.void
setAppVersion
(String appVersion) Sets the value normally returned bygetAppVersion()
.void
This method uses the default CookieHandler, if one is available, to set a cookie value.void
setExternalCSSEnabled
(boolean enabled) Sets the value normally returned byisExternalCSSEnabled()
.void
setProduct
(String product) void
Sets the value of the proxy normally returned bygetProxy()
.void
setScriptingEnabled
(boolean enable) Sets the value normally returned byisScriptingEnabled()
.void
setScriptingOptimizationLevel
(int level) Sets the value normally returned bygetScriptingOptimizationLevel()
.void
setUserAgent
(String userAgent) Sets the value normally returned bygetUserAgent()
.void
-
Constructor Details
-
SimpleUserAgentContext
public SimpleUserAgentContext()
-
-
Method Details
-
isMedia
This implementation returns true for certain media names, such asscreen
.- Specified by:
isMedia
in interfaceUserAgentContext
- Parameters:
mediaName
- Media name, which may bescreen
,tty
, etc. (See HTML Specification).
-
createHttpRequest
Creates aSimpleHttpRequest
instance. TheHttpRequest
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.- Specified by:
createHttpRequest
in interfaceUserAgentContext
-
getProxy
Gets the connection proxy used in requests created bycreateHttpRequest()
by default. This implementation returns the value of a local field.- See Also:
-
setProxy
Sets the value of the proxy normally returned bygetProxy()
.- Parameters:
proxy
- Ajava.net.Proxy
instance.
-
getAppCodeName
Returns the application "code name." This implementation returns the value of a local field.- Specified by:
getAppCodeName
in interfaceUserAgentContext
- See Also:
-
setAppCodeName
Sets the application code name normally returned bygetAppCodeName()
.- Parameters:
appCodeName
- An application "code name."
-
getAppMinorVersion
Gets the "minor version" of the application. This implementation returns the value of a local field.- Specified by:
getAppMinorVersion
in interfaceUserAgentContext
- See Also:
-
setAppMinorVersion
Sets the value normally returned bygetAppMinorVersion()
.- Parameters:
appMinorVersion
- The application's "minor version."
-
getAppName
Gets the application name. This implementation returns the value of a local field.- Specified by:
getAppName
in interfaceUserAgentContext
- See Also:
-
setAppName
Sets the value normally returned bygetAppName()
.- Parameters:
appName
- The application name.
-
getAppVersion
Gets the major application version. This implementation returns the value of a local field.- Specified by:
getAppVersion
in interfaceUserAgentContext
- See Also:
-
setAppVersion
Sets the value normally returned bygetAppVersion()
.- Parameters:
appVersion
- The application version.
-
getBrowserLanguage
Get the browser language. This implementation returns the language of the default locale. It may be overridden to provide a different value.- Specified by:
getBrowserLanguage
in interfaceUserAgentContext
-
getPlatform
Returns the value of Java propertyos.name
. It may be overridden to provide a different value.- Specified by:
getPlatform
in interfaceUserAgentContext
-
getUserAgent
Gets the User-Agent string. This implementation returns the value of a local field.- Specified by:
getUserAgent
in interfaceUserAgentContext
- See Also:
-
setUserAgent
Sets the value normally returned bygetUserAgent()
.- Parameters:
userAgent
- A User-Agent string.
-
isCookieEnabled
public boolean isCookieEnabled()This implementation returns true if and only ifjava.net.CookieHandler.getDefault()
is returning a non-null value. The method may be overridden to provide an alternative means of determining cookie enabling state.- Specified by:
isCookieEnabled
in interfaceUserAgentContext
-
getCookie
This implementation uses the defaultjava.net.CookieHandler
, if any, to get cookie information for the given URL. If no cookie handler is available, this method returns the empty string.- Specified by:
getCookie
in interfaceUserAgentContext
-
isScriptingEnabled
public boolean isScriptingEnabled()Determines whether scripting should be enabled. This implementation returns the value of a local field defaulting totrue
.- Specified by:
isScriptingEnabled
in interfaceUserAgentContext
- See Also:
-
setScriptingEnabled
public void setScriptingEnabled(boolean enable) Sets the value normally returned byisScriptingEnabled()
.- Parameters:
enable
- A boolean value.
-
setCookie
This method uses the default CookieHandler, if one is available, to set a cookie value.- Specified by:
setCookie
in interfaceUserAgentContext
cookieSpec
- Specification of cookies, as they would appear in the Set-Cookie header value of HTTP.
-
getSecurityPolicy
Returnsnull
. This method must be overridden if JavaScript code is untrusted.- Specified by:
getSecurityPolicy
in interfaceUserAgentContext
-
getScriptingOptimizationLevel
public int getScriptingOptimizationLevel()Gets the Rhino optimization level. This implementation returns the value of a local field defaulting to-1
.- Specified by:
getScriptingOptimizationLevel
in interfaceUserAgentContext
- See Also:
-
setScriptingOptimizationLevel
public void setScriptingOptimizationLevel(int level) Sets the value normally returned bygetScriptingOptimizationLevel()
.- Parameters:
level
- A Rhino optimization level.
-
getVendor
- Specified by:
getVendor
in interfaceUserAgentContext
-
setVendor
-
getProduct
- Specified by:
getProduct
in interfaceUserAgentContext
-
setProduct
-
isExternalCSSEnabled
public boolean isExternalCSSEnabled()Determines whether external CSS loading should be enabled. This implementation returns the value of a local field defaulting totrue
.- Specified by:
isExternalCSSEnabled
in interfaceUserAgentContext
- See Also:
-
setExternalCSSEnabled
public void setExternalCSSEnabled(boolean enabled) Sets the value normally returned byisExternalCSSEnabled()
.- Parameters:
enabled
- A boolean value.
-