Package org.lobobrowser.html.test
Class SimpleUserAgentContext
- java.lang.Object
-
- org.lobobrowser.html.test.SimpleUserAgentContext
-
- All Implemented Interfaces:
UserAgentContext
public class SimpleUserAgentContext extends java.lang.Object implements UserAgentContext
Simple implementation ofUserAgentContext. 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 Constructor Description SimpleUserAgentContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestcreateHttpRequest()Creates aSimpleHttpRequestinstance.java.lang.StringgetAppCodeName()Returns the application "code name." This implementation returns the value of a local field.java.lang.StringgetAppMinorVersion()Gets the "minor version" of the application.java.lang.StringgetAppName()Gets the application name.java.lang.StringgetAppVersion()Gets the major application version.java.lang.StringgetBrowserLanguage()Get the browser language.java.lang.StringgetCookie(java.net.URL url)This implementation uses the defaultjava.net.CookieHandler, if any, to get cookie information for the given URL.java.lang.StringgetPlatform()Returns the value of Java propertyos.name.java.lang.StringgetProduct()protected java.net.ProxygetProxy()Gets the connection proxy used in requests created bycreateHttpRequest()by default.intgetScriptingOptimizationLevel()Gets the Rhino optimization level.java.security.PolicygetSecurityPolicy()Returnsnull.java.lang.StringgetUserAgent()Gets the User-Agent string.java.lang.StringgetVendor()booleanisCookieEnabled()This implementation returns true if and only ifjava.net.CookieHandler.getDefault()is returning a non-null value.booleanisExternalCSSEnabled()Determines whether external CSS loading should be enabled.booleanisMedia(java.lang.String mediaName)This implementation returns true for certain media names, such asscreen.booleanisScriptingEnabled()Determines whether scripting should be enabled.voidsetAppCodeName(java.lang.String appCodeName)Sets the application code name normally returned bygetAppCodeName().voidsetAppMinorVersion(java.lang.String appMinorVersion)Sets the value normally returned bygetAppMinorVersion().voidsetAppName(java.lang.String appName)Sets the value normally returned bygetAppName().voidsetAppVersion(java.lang.String appVersion)Sets the value normally returned bygetAppVersion().voidsetCookie(java.net.URL url, java.lang.String cookieSpec)This method uses the default CookieHandler, if one is available, to set a cookie value.voidsetExternalCSSEnabled(boolean enabled)Sets the value normally returned byisExternalCSSEnabled().voidsetProduct(java.lang.String product)voidsetProxy(java.net.Proxy proxy)Sets the value of the proxy normally returned bygetProxy().voidsetScriptingEnabled(boolean enable)Sets the value normally returned byisScriptingEnabled().voidsetScriptingOptimizationLevel(int level)Sets the value normally returned bygetScriptingOptimizationLevel().voidsetUserAgent(java.lang.String userAgent)Sets the value normally returned bygetUserAgent().voidsetVendor(java.lang.String vendor)
-
-
-
Method Detail
-
isMedia
public boolean isMedia(java.lang.String mediaName)
This implementation returns true for certain media names, such asscreen.- Specified by:
isMediain interfaceUserAgentContext- Parameters:
mediaName- Media name, which may bescreen,tty, etc. (See HTML Specification).
-
createHttpRequest
public HttpRequest createHttpRequest()
Creates aSimpleHttpRequestinstance. TheHttpRequestobject 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:
createHttpRequestin interfaceUserAgentContext
-
getProxy
protected java.net.Proxy getProxy()
Gets the connection proxy used in requests created bycreateHttpRequest()by default. This implementation returns the value of a local field.- See Also:
setProxy(java.net.Proxy)
-
setProxy
public void setProxy(java.net.Proxy proxy)
Sets the value of the proxy normally returned bygetProxy().- Parameters:
proxy- Ajava.net.Proxyinstance.
-
getAppCodeName
public java.lang.String getAppCodeName()
Returns the application "code name." This implementation returns the value of a local field.- Specified by:
getAppCodeNamein interfaceUserAgentContext- See Also:
setAppCodeName(String)
-
setAppCodeName
public void setAppCodeName(java.lang.String appCodeName)
Sets the application code name normally returned bygetAppCodeName().- Parameters:
appCodeName- An application "code name."
-
getAppMinorVersion
public java.lang.String getAppMinorVersion()
Gets the "minor version" of the application. This implementation returns the value of a local field.- Specified by:
getAppMinorVersionin interfaceUserAgentContext- See Also:
setAppMinorVersion(String)
-
setAppMinorVersion
public void setAppMinorVersion(java.lang.String appMinorVersion)
Sets the value normally returned bygetAppMinorVersion().- Parameters:
appMinorVersion- The application's "minor version."
-
getAppName
public java.lang.String getAppName()
Gets the application name. This implementation returns the value of a local field.- Specified by:
getAppNamein interfaceUserAgentContext- See Also:
setAppName(String)
-
setAppName
public void setAppName(java.lang.String appName)
Sets the value normally returned bygetAppName().- Parameters:
appName- The application name.
-
getAppVersion
public java.lang.String getAppVersion()
Gets the major application version. This implementation returns the value of a local field.- Specified by:
getAppVersionin interfaceUserAgentContext- See Also:
setAppVersion(String)
-
setAppVersion
public void setAppVersion(java.lang.String appVersion)
Sets the value normally returned bygetAppVersion().- Parameters:
appVersion- The application version.
-
getBrowserLanguage
public java.lang.String 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:
getBrowserLanguagein interfaceUserAgentContext
-
getPlatform
public java.lang.String getPlatform()
Returns the value of Java propertyos.name. It may be overridden to provide a different value.- Specified by:
getPlatformin interfaceUserAgentContext
-
getUserAgent
public java.lang.String getUserAgent()
Gets the User-Agent string. This implementation returns the value of a local field.- Specified by:
getUserAgentin interfaceUserAgentContext- See Also:
setUserAgent(String)
-
setUserAgent
public void setUserAgent(java.lang.String userAgent)
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:
isCookieEnabledin interfaceUserAgentContext
-
getCookie
public java.lang.String getCookie(java.net.URL url)
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:
getCookiein interfaceUserAgentContext
-
isScriptingEnabled
public boolean isScriptingEnabled()
Determines whether scripting should be enabled. This implementation returns the value of a local field defaulting totrue.- Specified by:
isScriptingEnabledin interfaceUserAgentContext- See Also:
setScriptingEnabled(boolean)
-
setScriptingEnabled
public void setScriptingEnabled(boolean enable)
Sets the value normally returned byisScriptingEnabled().- Parameters:
enable- A boolean value.
-
setCookie
public 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.- Specified by:
setCookiein interfaceUserAgentContextcookieSpec- Specification of cookies, as they would appear in the Set-Cookie header value of HTTP.
-
getSecurityPolicy
public java.security.Policy getSecurityPolicy()
Returnsnull. This method must be overridden if JavaScript code is untrusted.- Specified by:
getSecurityPolicyin interfaceUserAgentContext
-
getScriptingOptimizationLevel
public int getScriptingOptimizationLevel()
Gets the Rhino optimization level. This implementation returns the value of a local field defaulting to-1.- Specified by:
getScriptingOptimizationLevelin interfaceUserAgentContext- See Also:
setScriptingOptimizationLevel(int)
-
setScriptingOptimizationLevel
public void setScriptingOptimizationLevel(int level)
Sets the value normally returned bygetScriptingOptimizationLevel().- Parameters:
level- A Rhino optimization level.
-
getVendor
public java.lang.String getVendor()
- Specified by:
getVendorin interfaceUserAgentContext
-
setVendor
public void setVendor(java.lang.String vendor)
-
getProduct
public java.lang.String getProduct()
- Specified by:
getProductin interfaceUserAgentContext
-
setProduct
public void setProduct(java.lang.String product)
-
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:
isExternalCSSEnabledin interfaceUserAgentContext- See Also:
setExternalCSSEnabled(boolean)
-
setExternalCSSEnabled
public void setExternalCSSEnabled(boolean enabled)
Sets the value normally returned byisExternalCSSEnabled().- Parameters:
enabled- A boolean value.
-
-