Package com.openhtmltopdf.swing
Class DelegatingUserAgent
java.lang.Object
com.openhtmltopdf.swing.NaiveUserAgent
com.openhtmltopdf.swing.DelegatingUserAgent
- All Implemented Interfaces:
DocumentListener,UserAgentCallback
public class DelegatingUserAgent extends NaiveUserAgent
-
Nested Class Summary
Nested classes/interfaces inherited from class com.openhtmltopdf.swing.NaiveUserAgent
NaiveUserAgent.DefaultHttpStream, NaiveUserAgent.DefaultHttpStreamFactory, NaiveUserAgent.DefaultUriResolver -
Field Summary
Fields inherited from class com.openhtmltopdf.swing.NaiveUserAgent
_baseUri, _imageCache, _protocolsStreamFactory, _resolver, DEFAULT_URI_RESOLVER -
Constructor Summary
Constructors Constructor Description DelegatingUserAgent()Creates a new instance of NaiveUserAgent with a max image cache of 16 images. -
Method Summary
Modifier and Type Method Description voidclearImageCache()Empties the image cache entirely.voiddocumentLoaded()Indicates document layout has complete, e.g.voiddocumentStarted()Indicates document has been requested (e.g.StringgetBaseURL()Returns the current baseUrl for this class.ImageResourcegetImageResource(String uri)Retrieves the image located at the given URI.voidonLayoutException(Throwable t)Called when document layout failed with an exception.voidonRenderException(Throwable t)Called when document render failed with an exception.StringresolveURI(String uri)Resolves the URI; if absolute, leaves as is, if relative, returns an absolute URI based on the baseUrl for the agent.voidsetBaseURL(String uri)URL relative to which URIs are resolved.voidsetImageResourceLoader(ImageResourceLoader loader)voidsetRepaintListener(RepaintListener listener)voidshrinkImageCache()If the image cache has more items than the limit specified for this class, the least-recently used will be dropped from cache until it reaches the desired size.Methods inherited from class com.openhtmltopdf.swing.NaiveUserAgent
getBinaryResource, getCSSResource, getDefaultUriResolver, getProtocolFactory, getXMLResource, hasProtocolFactory, isVisited, openReader, openStream, readAll, resolveUri, setProtocolsStreamFactory, setUriResolver
-
Constructor Details
-
DelegatingUserAgent
public DelegatingUserAgent()Creates a new instance of NaiveUserAgent with a max image cache of 16 images.
-
-
Method Details
-
setImageResourceLoader
-
shrinkImageCache
public void shrinkImageCache()If the image cache has more items than the limit specified for this class, the least-recently used will be dropped from cache until it reaches the desired size. -
clearImageCache
public void clearImageCache()Empties the image cache entirely.- Overrides:
clearImageCachein classNaiveUserAgent
-
getImageResource
Retrieves the image located at the given URI. It's assumed the URI does point to an image--the URI will be accessed (using java.io or java.net), opened, read and then passed into the JDK image-parsing routines. The result is packed up into an ImageResource for later consumption.- Specified by:
getImageResourcein interfaceUserAgentCallback- Overrides:
getImageResourcein classNaiveUserAgent- Parameters:
uri- Location of the image source.- Returns:
- An ImageResource containing the image.
-
setBaseURL
URL relative to which URIs are resolved.- Specified by:
setBaseURLin interfaceUserAgentCallback- Overrides:
setBaseURLin classNaiveUserAgent- Parameters:
uri- A URI which anchors other, possibly relative URIs.
-
resolveURI
Resolves the URI; if absolute, leaves as is, if relative, returns an absolute URI based on the baseUrl for the agent.- Specified by:
resolveURIin interfaceUserAgentCallback- Overrides:
resolveURIin classNaiveUserAgent- Parameters:
uri- A URI, possibly relative.- Returns:
- A URI as String, resolved, or null if there was an exception (for example if the URI is malformed).
-
getBaseURL
Returns the current baseUrl for this class.- Specified by:
getBaseURLin interfaceUserAgentCallback- Overrides:
getBaseURLin classNaiveUserAgent- Returns:
- the base uri, possibly in the implementations private uri-space
-
documentStarted
public void documentStarted()Description copied from interface:DocumentListenerIndicates document has been requested (e.g. a new document is going to be loaded). This will be called before any activity takes place for the document.- Specified by:
documentStartedin interfaceDocumentListener- Overrides:
documentStartedin classNaiveUserAgent
-
documentLoaded
public void documentLoaded()Description copied from interface:DocumentListenerIndicates document layout has complete, e.g. document is fully "loaded" for display; this is not a callback for the document source (e.g. XML) being loaded. This method will be called on every layout run (including, for example, after panel resizes).- Specified by:
documentLoadedin interfaceDocumentListener- Overrides:
documentLoadedin classNaiveUserAgent
-
onLayoutException
Description copied from interface:DocumentListenerCalled when document layout failed with an exception. AllThrowableobjects thrown (except forThreadDeath) during layout and not otherwise handled will be provided to this method. If aDocumentListenerhas been defined an XHTML panel, the listener is entirely responsible for handling the exception. No other action will be taken.- Specified by:
onLayoutExceptionin interfaceDocumentListener- Overrides:
onLayoutExceptionin classNaiveUserAgent
-
onRenderException
Description copied from interface:DocumentListenerCalled when document render failed with an exception. AllThrowableobjects thrown (except forThreadDeath) during render and not otherwise handled will be provided to this method. If aDocumentListenerhas been defined an XHTML panel, the listener is entirely responsible for handling the exception. No other action will be taken.- Specified by:
onRenderExceptionin interfaceDocumentListener- Overrides:
onRenderExceptionin classNaiveUserAgent
-
setRepaintListener
-