Interface UserAgentCallback
-
- All Known Implementing Classes:
ITextUserAgent
,NaiveUserAgent
public interface UserAgentCallback
To be implemented by any user agent using the panel. "User agent" is a term defined by the W3C in the documentation for XHTML and CSS; in most cases, you can think of this as the rendering component for a browser.
This interface defines a simple callback mechanism for Flying Saucer to interact with a user agent. The FS toolkit provides a default implementation for this interface which in most cases you can leave as is. You can provide your own UserAgentCallback when constructing an
XHTMLPanel
orBasicPanel
.The user agent in this case is responsible for retrieving external resources. For privacy reasons, if using the library in an application that can access URIs in an unrestricted fashion, you may decide to restrict access to XML, CSS or images retrieved from external sources; that's one of the purposes of the UAC.
To understand how to create your own UAC, it's best to look at some of the implemetations shipped with the library, like the
NaiveUserAgent
.- Author:
- Torbjörn Gannholm
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
getBaseURL()
byte[]
getBinaryResource(java.lang.String uri)
Retrieves a binary resource located at a given URI and returns its contents as a byte array ornull
if the resource could not be loaded.CSSResource
getCSSResource(java.lang.String uri)
Retrieves the CSS at the given URI.ImageResource
getImageResource(java.lang.String uri)
Retrieves the Image at the given URI.XMLResource
getXMLResource(java.lang.String uri)
Retrieves the XML at the given URI.boolean
isVisited(java.lang.String uri)
Normally, returns true if the user agent has visited this URI.java.lang.String
resolveURI(java.lang.String uri)
Used to find a uri that may be relative to the BaseURL.void
setBaseURL(java.lang.String url)
Does not need to be a correct URL, only an identifier that the implementation can resolve.
-
-
-
Method Detail
-
getCSSResource
CSSResource getCSSResource(java.lang.String uri)
Retrieves the CSS at the given URI. This is a synchronous call.- Parameters:
uri
- Location of the CSS- Returns:
- A CSSResource for the content at the URI.
-
getImageResource
ImageResource getImageResource(java.lang.String uri)
Retrieves the Image at the given URI. This is a synchronous call.- Parameters:
uri
- Location of the image- Returns:
- An ImageResource for the content at the URI.
-
getXMLResource
XMLResource getXMLResource(java.lang.String uri)
Retrieves the XML at the given URI. This is a synchronous call.- Parameters:
uri
- Location of the XML- Returns:
- A XMLResource for the content at the URI.
-
getBinaryResource
byte[] getBinaryResource(java.lang.String uri)
Retrieves a binary resource located at a given URI and returns its contents as a byte array ornull
if the resource could not be loaded.
-
isVisited
boolean isVisited(java.lang.String uri)
Normally, returns true if the user agent has visited this URI. UserAgent should consider if it should answer truthfully or not for privacy reasons.- Parameters:
uri
- A URI which may have been visited by this user agent.- Returns:
- The visited value
-
setBaseURL
void setBaseURL(java.lang.String url)
Does not need to be a correct URL, only an identifier that the implementation can resolve.- Parameters:
url
- A URL against which relative references can be resolved.
-
getBaseURL
java.lang.String getBaseURL()
- Returns:
- the base uri, possibly in the implementations private uri-space
-
resolveURI
java.lang.String resolveURI(java.lang.String uri)
Used to find a uri that may be relative to the BaseURL. The returned value will always only be used via methods in the same implementation of this interface, therefore may be a private uri-space.- Parameters:
uri
- an absolute or relative (to baseURL) uri to be resolved.- Returns:
- the full uri in uri-spaces known to the current implementation.
-
-