Class SimpleUserAgentContext

  • All Implemented Interfaces:
    UserAgentContext

    public class SimpleUserAgentContext
    extends java.lang.Object
    implements 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 Detail

      • SimpleUserAgentContext

        public SimpleUserAgentContext()
    • Method Detail

      • isMedia

        public boolean isMedia​(java.lang.String mediaName)
        This implementation returns true for certain media names, such as screen.
        Specified by:
        isMedia in interface UserAgentContext
        Parameters:
        mediaName - Media name, which may be screen, tty, etc. (See HTML Specification).
      • createHttpRequest

        public HttpRequest createHttpRequest()
        Creates a 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.
        Specified by:
        createHttpRequest in interface UserAgentContext
      • getProxy

        protected java.net.Proxy getProxy()
        Gets the connection proxy used in requests created by createHttpRequest() 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 by getProxy().
        Parameters:
        proxy - A java.net.Proxy instance.
      • setAppCodeName

        public void setAppCodeName​(java.lang.String appCodeName)
        Sets the application code name normally returned by getAppCodeName().
        Parameters:
        appCodeName - An application "code name."
      • setAppMinorVersion

        public void setAppMinorVersion​(java.lang.String appMinorVersion)
        Sets the value normally returned by getAppMinorVersion().
        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:
        getAppName in interface UserAgentContext
        See Also:
        setAppName(String)
      • setAppName

        public void setAppName​(java.lang.String appName)
        Sets the value normally returned by getAppName().
        Parameters:
        appName - The application name.
      • setAppVersion

        public void setAppVersion​(java.lang.String appVersion)
        Sets the value normally returned by getAppVersion().
        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:
        getBrowserLanguage in interface UserAgentContext
      • getPlatform

        public java.lang.String getPlatform()
        Returns the value of Java property os.name. It may be overridden to provide a different value.
        Specified by:
        getPlatform in interface UserAgentContext
      • setUserAgent

        public void setUserAgent​(java.lang.String userAgent)
        Sets the value normally returned by getUserAgent().
        Parameters:
        userAgent - A User-Agent string.
      • isCookieEnabled

        public boolean isCookieEnabled()
        This implementation returns true if and only if 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.
        Specified by:
        isCookieEnabled in interface UserAgentContext
      • getCookie

        public 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. If no cookie handler is available, this method returns the empty string.
        Specified by:
        getCookie in interface UserAgentContext
      • setScriptingEnabled

        public void setScriptingEnabled​(boolean enable)
        Sets the value normally returned by isScriptingEnabled().
        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:
        setCookie in interface UserAgentContext
        cookieSpec - Specification of cookies, as they would appear in the Set-Cookie header value of HTTP.
      • getSecurityPolicy

        public java.security.Policy getSecurityPolicy()
        Returns null. This method must be overridden if JavaScript code is untrusted.
        Specified by:
        getSecurityPolicy in interface UserAgentContext
      • setScriptingOptimizationLevel

        public void setScriptingOptimizationLevel​(int level)
        Sets the value normally returned by getScriptingOptimizationLevel().
        Parameters:
        level - A Rhino optimization level.
      • setVendor

        public void setVendor​(java.lang.String vendor)
      • setProduct

        public void setProduct​(java.lang.String product)
      • setExternalCSSEnabled

        public void setExternalCSSEnabled​(boolean enabled)
        Sets the value normally returned by isExternalCSSEnabled().
        Parameters:
        enabled - A boolean value.