Class AbstractUserAgent

java.lang.Object
io.sf.carte.doc.agent.AbstractUserAgent
All Implemented Interfaces:
UserAgent, UserAgent.AgentControl, Serializable
Direct Known Subclasses:
DOMCSSStyleSheetFactory.WrapperUserAgent

public abstract class AbstractUserAgent extends Object implements UserAgent, UserAgent.AgentControl, Serializable
Abstract base class for User Agents, with cookie handling.

See Also:
  • Constructor Details

  • Method Details

    • getOriginPolicy

      protected OriginPolicy getOriginPolicy()
    • setOriginPolicy

      public void setOriginPolicy(OriginPolicy originPolicy)
    • getAgentControl

      public UserAgent.AgentControl getAgentControl()
      Description copied from interface: UserAgent
      Get the control object for this user agent.
      Specified by:
      getAgentControl in interface UserAgent
      Returns:
      the control object for this user agent, or null if this agent has no control.
    • getCookieConfig

      public CookieConfig getCookieConfig()
      Gets the global, useragent-wide default cookie config.
      Specified by:
      getCookieConfig in interface UserAgent.AgentControl
      Returns:
      the default user-agent cookie config.
    • getCookies

      public Set<Cookie> getCookies(String host)
    • getParserFlags

      protected EnumSet<Parser.Flag> getParserFlags()
    • getProperty

      public String getProperty(String propertyName)
      Description copied from interface: UserAgent.AgentControl
      Gets a control property.
      Specified by:
      getProperty in interface UserAgent.AgentControl
      Parameters:
      propertyName - the property name.
      Returns:
      the string representation of the property value, or null if the property is not set.
    • setProperty

      public void setProperty(String propertyName, String value)
      Sets a control property.
      Specified by:
      setProperty in interface UserAgent.AgentControl
      Parameters:
      propertyName - the name of the property to set.
      value - the string representation of the property value.
    • getAuthenticationCredentials

      public AuthenticationCredentials getAuthenticationCredentials(URL url, String realm)
      Gets the authentication credentials for the given URL.
      Specified by:
      getAuthenticationCredentials in interface UserAgent.AgentControl
      Parameters:
      url - the url for which the credential is required.
      realm - the realm name, or null if there is no realm, in which case any valid credential will be returned.
      Returns:
      the authentication credentials, or null if there is none.
    • authenticationCredentials

      public AuthenticationCredentials authenticationCredentials(String host, String realm)
      Gives the credentials for the given hostname and realm, creating a new one if there is none.
      Specified by:
      authenticationCredentials in interface UserAgent.AgentControl
      Parameters:
      host - the host.
      realm - the realm. Cannot be null.
      Returns:
      the credentials.
    • setConnectionTimeout

      public void setConnectionTimeout(int timeout)
      Sets the connection timeout.
      Specified by:
      setConnectionTimeout in interface UserAgent.AgentControl
      Parameters:
      timeout - the connection timeout, in milliseconds. A timeout of 0 means no timeout (the default).
    • isVisitedURL

      public boolean isVisitedURL(URL url)
      Description copied from interface: UserAgent
      Has the provided url been visited by this user agent.
      Specified by:
      isVisitedURL in interface UserAgent
      Parameters:
      url - the URL to test.
      Returns:
      true if the URL was visited by this agent, false if not visited or this agent does not support history.
    • setUseragentId

      public void setUseragentId(String userAgentId)
    • openConnection

      protected URLConnection openConnection(URL url, long creationDate) throws IOException
      Open a URL connection according to the given document creation date.
      Parameters:
      url - the URL to connect to.
      creationDate - the creation date.
      Returns:
      the connection.
      Throws:
      IOException - if an I/O exception occurs opening the connection.
    • createConnection

      protected URLConnection createConnection(URL url) throws IOException
      Opens a connection to the given URL.
      Parameters:
      url - the URL to connect to.
      Returns:
      a URLConnection linking to the URL.
      Throws:
      IOException - if an I/O exception occurs opening the connection.
    • readCookies

      protected void readCookies(HttpURLConnection hcon, long creationDate)