java.lang.Object
io.sf.carte.doc.agent.AbstractUserAgent
- All Implemented Interfaces:
UserAgent
,UserAgent.AgentControl
,Serializable
- Direct Known Subclasses:
DefaultUserAgent
,DOM4JUserAgent
,DOMCSSStyleSheetFactory.WrapperUserAgent
public abstract class AbstractUserAgent
extends Object
implements UserAgent, UserAgent.AgentControl, Serializable
Abstract base class for User Agents, with cookie handling.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.sf.carte.doc.agent.UserAgent
UserAgent.AgentControl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticationCredentials
(String host, String realm) Gives the credentials for the given hostname and realm, creating a new one if there is none.protected URLConnection
createConnection
(URL url) Opens a connection to the given URL.Get the control object for this user agent.getAuthenticationCredentials
(URL url, String realm) Gets the authentication credentials for the given URL.Deprecated, for removal: This API element is subject to removal in a future version.getCookies
(String host) Deprecated, for removal: This API element is subject to removal in a future version.Get the error handler.protected OriginPolicy
protected EnumSet
<Parser.Flag> getProperty
(String propertyName) Gets a control property.boolean
isVisitedURL
(URL url) Has the provided url been visited by this user agent.protected URLConnection
openConnection
(URL url, long creationDate) Open a URL connection according to the given document creation date.protected void
readCookies
(HttpURLConnection hcon, long creationDate) Deprecated, for removal: This API element is subject to removal in a future version.void
setConnectionTimeout
(int timeout) Sets the connection timeout.void
setErrorHandler
(UserAgentErrorHandler handler) Set the error handler.void
setOriginPolicy
(OriginPolicy originPolicy) boolean
setProperty
(String propertyName, String value) Sets a control property.void
setUseragentId
(String userAgentId) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.sf.carte.doc.agent.UserAgent
readURL, setEntityResolver
-
Constructor Details
-
AbstractUserAgent
-
-
Method Details
-
getOriginPolicy
-
setOriginPolicy
-
getAgentControl
Description copied from interface:UserAgent
Get the control object for this user agent.- Specified by:
getAgentControl
in interfaceUserAgent
- Returns:
- the control object for this user agent, or null if this agent has no control.
-
getCookieConfig
Deprecated, for removal: This API element is subject to removal in a future version.Gets the global, useragent-wide default cookie config.- Specified by:
getCookieConfig
in interfaceUserAgent.AgentControl
- Returns:
- null
-
getCookies
Deprecated, for removal: This API element is subject to removal in a future version. -
getErrorHandler
Get the error handler.- Returns:
- the error handler
-
setErrorHandler
Set the error handler.- Parameters:
handler
- the error handler to set
-
getParserFlags
-
getProperty
Description copied from interface:UserAgent.AgentControl
Gets a control property.- Specified by:
getProperty
in interfaceUserAgent.AgentControl
- Parameters:
propertyName
- the property name.- Returns:
- the string representation of the property value, or null if the property is not set.
-
setProperty
Description copied from interface:UserAgent.AgentControl
Sets a control property.If the property is wrong, the user agent should call the method
UserAgentErrorHandler.onWrongPropertyValue(String, String)
.- Specified by:
setProperty
in interfaceUserAgent.AgentControl
- Parameters:
propertyName
- the name of the property to set.value
- the string representation of the property value.- Returns:
true
if the property was set successfully.
-
getAuthenticationCredentials
Gets the authentication credentials for the given URL.- Specified by:
getAuthenticationCredentials
in interfaceUserAgent.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
Gives the credentials for the given hostname and realm, creating a new one if there is none.- Specified by:
authenticationCredentials
in interfaceUserAgent.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 interfaceUserAgent.AgentControl
- Parameters:
timeout
- the connection timeout, in milliseconds. Atimeout
of 0 means no timeout (the default).
-
isVisitedURL
Description copied from interface:UserAgent
Has the provided url been visited by this user agent.- Specified by:
isVisitedURL
in interfaceUserAgent
- 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
-
openConnection
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
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
Deprecated, for removal: This API element is subject to removal in a future version.
-