|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xhtmlrenderer.swing.DelegatingUserAgent
public class DelegatingUserAgent
NaiveUserAgent is a simple implementation of UserAgentCallback which places no restrictions on what
XML, CSS or images are loaded, and reports visited links without any filtering. The most straightforward process
available in the JDK is used to load the resources in question--either using java.io or java.net classes.
The NaiveUserAgent has a small cache for images,
the size of which (number of images) can be passed as a constructor argument. There is no automatic cleaning of
the cache; call shrinkImageCache() to remove the least-accessed elements--for example, you might do this
when a new document is about to be loaded. The NaiveUserAgent is also a DocumentListener; if registered with a
source of document events (like the panel hierarchy), it will respond to the
DocumentListener.documentStarted() call and attempt to shrink its cache.
This class is meant as a starting point--it will work out of the box, but you should really implement your own, tuned to your application's needs.
| Constructor Summary | |
|---|---|
DelegatingUserAgent()
Creates a new instance of NaiveUserAgent with a max image cache of 16 images. |
|
| Method Summary | |
|---|---|
void |
clearImageCache()
Empties the image cache entirely. |
void |
documentLoaded()
Indicates document layout has complete, e.g. |
void |
documentStarted()
Indicates document has been requested (e.g. |
String |
getBaseURL()
Returns the current baseUrl for this class. |
byte[] |
getBinaryResource(String uri)
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. |
CSSResource |
getCSSResource(String uri)
Retrieves the CSS located at the given URI. |
ImageResource |
getImageResource(String uri)
Retrieves the image located at the given URI. |
XMLResource |
getXMLResource(String uri)
Retrieves the XML located at the given URI. |
boolean |
isVisited(String uri)
Returns true if the given URI was visited, meaning it was requested at some point since initialization. |
void |
onLayoutException(Throwable t)
Called when document layout failed with an exception. |
void |
onRenderException(Throwable t)
Called when document render failed with an exception. |
protected InputStream |
resolveAndOpenStream(String uri)
Gets a Reader for the resource identified |
String |
resolveURI(String uri)
Resolves the URI; if absolute, leaves as is, if relative, returns an absolute URI based on the baseUrl for the agent. |
void |
setBaseURL(String uri)
URL relative to which URIs are resolved. |
void |
setImageResourceLoader(ImageResourceLoader loader)
|
void |
setRepaintListener(RepaintListener listener)
|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DelegatingUserAgent()
| Method Detail |
|---|
public void setImageResourceLoader(ImageResourceLoader loader)
public void shrinkImageCache()
public void clearImageCache()
protected InputStream resolveAndOpenStream(String uri)
uri - PARAM
public CSSResource getCSSResource(String uri)
getCSSResource in interface UserAgentCallbackuri - Location of the CSS source.
public ImageResource getImageResource(String uri)
getImageResource in interface UserAgentCallbackuri - Location of the image source.
public XMLResource getXMLResource(String uri)
getXMLResource in interface UserAgentCallbackuri - Location of the XML source.
public byte[] getBinaryResource(String uri)
UserAgentCallbacknull if the resource could not be loaded.
getBinaryResource in interface UserAgentCallbackpublic boolean isVisited(String uri)
isVisited in interface UserAgentCallbackuri - A URI which might have been visited.
public void setBaseURL(String uri)
setBaseURL in interface UserAgentCallbackuri - A URI which anchors other, possibly relative URIs.public String resolveURI(String uri)
resolveURI in interface UserAgentCallbackuri - A URI, possibly relative.
public String getBaseURL()
getBaseURL in interface UserAgentCallbackpublic void documentStarted()
DocumentListener
documentStarted in interface DocumentListenerpublic void documentLoaded()
DocumentListener
documentLoaded in interface DocumentListenerpublic void onLayoutException(Throwable t)
DocumentListenerThrowable objects thrown (except for
ThreadDeath) during layout and not otherwise handled will
be provided to this method. If a DocumentListener has been
defined an XHTML panel, the listener is entirely responsible for
handling the exception. No other action will be taken.
onLayoutException in interface DocumentListenerpublic void onRenderException(Throwable t)
DocumentListenerThrowable objects thrown (except for
ThreadDeath) during render and not otherwise handled will
be provided to this method. If a DocumentListener has been
defined an XHTML panel, the listener is entirely responsible for
handling the exception. No other action will be taken.
onRenderException in interface DocumentListenerpublic void setRepaintListener(RepaintListener listener)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||