Top Description Methods
com.openhtmltopdf.extend

public Interface UserAgentCallback

Known Direct Implementers
com.openhtmltopdf.swing.NaiveUserAgent
Imports
com.openhtmltopdf.outputdevice.helper.ExternalResourceType, com.openhtmltopdf.resource.CSSResource, .ImageResource, .XMLResource

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.

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 com.openhtmltopdf.swing.NaiveUserAgent.

Author
Torbjoern Gannholm

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the base uri, possibly in the implementations private uri-space
getBaseURL
()

public default byte[]
public byte[]
getBinaryResource(String uri, ExternalResourceType type)

Retrieves a binary resource located at a given URI and returns its contents as a byte array or null if the resource could not be loaded.

public default CSSResource

Returns:

A CSSResource for the content at the URI.
getCSSResource
(String
Location of the CSS
uri
)

Retrieves the CSS at the given URI.

public CSSResource
public default ImageResource

Returns:

An ImageResource for the content at the URI.
getImageResource
(String
Location of the image
uri
)

Retrieves the Image at the given URI.

public ImageResource
public default XMLResource
public XMLResource

Returns:

A XMLResource for the content at the URI.
getXMLResource
(String
Location of the XML
uri
,
ExternalResourceType
Either xhtml or svg.
type
)

Retrieves the XML at the given URI.

public boolean

Returns:

The visited value
isVisited
(String
A URI which may have been visited by this user agent.
uri
)

Normally, returns true if the user agent has visited this URI.

public String

Returns:

the full uri in uri-spaces known to the current implementation.
resolveURI
(String
an absolute or relative (to baseURL) uri to be resolved.
uri
)

Used to find a uri that may be relative to the BaseURL.

public String
resolveUri(String baseUri, String uri)

public void
setBaseURL(String
A URL against which relative references can be resolved.
url
)

Does not need to be a correct URL, only an identifier that the implementation can resolve.

Method Detail

getBaseURLback to summary
public String getBaseURL()
Returns:String

the base uri, possibly in the implementations private uri-space

getBinaryResourceback to summary
public default byte[] getBinaryResource(String uri)
Annotations
@Deprecated
getBinaryResourceback to summary
public byte[] getBinaryResource(String uri, ExternalResourceType type)

Retrieves a binary resource located at a given URI and returns its contents as a byte array or null if the resource could not be loaded.

getCSSResourceback to summary
public default CSSResource getCSSResource(String uri)

Retrieves the CSS at the given URI. This is a synchronous call.

Parameters
uri:String

Location of the CSS

Returns:CSSResource

A CSSResource for the content at the URI.

getCSSResourceback to summary
public CSSResource getCSSResource(String uri, ExternalResourceType type)
getImageResourceback to summary
public default ImageResource getImageResource(String uri)

Retrieves the Image at the given URI. This is a synchronous call.

Parameters
uri:String

Location of the image

Returns:ImageResource

An ImageResource for the content at the URI.

getImageResourceback to summary
public ImageResource getImageResource(String uri, ExternalResourceType type)
getXMLResourceback to summary
public default XMLResource getXMLResource(String uri)
Annotations
@Deprecated
getXMLResourceback to summary
public XMLResource getXMLResource(String uri, ExternalResourceType type)

Retrieves the XML at the given URI. This is a synchronous call.

Parameters
uri:String

Location of the XML

type:ExternalResourceType

Either xhtml or svg.

Returns:XMLResource

A XMLResource for the content at the URI.

isVisitedback to summary
public boolean isVisited(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:String

A URI which may have been visited by this user agent.

Returns:boolean

The visited value

resolveURIback to summary
public String resolveURI(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:String

an absolute or relative (to baseURL) uri to be resolved.

Returns:String

the full uri in uri-spaces known to the current implementation.

resolveUriback to summary
public String resolveUri(String baseUri, String uri)
setBaseURLback to summary
public void setBaseURL(String url)

Does not need to be a correct URL, only an identifier that the implementation can resolve.

Parameters
url:String

A URL against which relative references can be resolved.