public abstract class NaiveUserAgent extends Object implements UserAgentCallback, DocumentListener
NaiveUserAgent is a simple implementation of UserAgentCallback which places no restrictions on what
XML, CSS or images are loaded.
The NaiveUserAgent has a simple per-run cache for images so that the same image is not embedded in a document multiple times.
| Modifier and Type | Class and Description |
|---|---|
static class |
NaiveUserAgent.ClassPathStream |
static class |
NaiveUserAgent.ClassPathStreamFactory |
static class |
NaiveUserAgent.DataUriFactory |
static class |
NaiveUserAgent.DefaultAccessController |
static class |
NaiveUserAgent.DefaultHttpStream |
static class |
NaiveUserAgent.DefaultHttpStreamFactory |
static class |
NaiveUserAgent.DefaultUriResolver |
| Modifier and Type | Field and Description |
|---|---|
protected Map<ExternalResourceControlPriority,BiPredicate<String,ExternalResourceType>> |
_accessControllers |
protected String |
_baseUri |
protected LinkedHashMap<String,ImageResource> |
_imageCache
a (simple) cache
This is only useful for the one run.
|
protected Map<String,FSStreamFactory> |
_protocolsStreamFactory |
protected FSUriResolver |
_resolver |
protected FSUriResolver |
DEFAULT_URI_RESOLVER |
| Constructor and Description |
|---|
NaiveUserAgent() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkAccessAllowed(String uriOrResolved,
ExternalResourceType type,
ExternalResourceControlPriority priority) |
void |
clearImageCache()
Deprecated.
|
void |
documentLoaded()
Deprecated.
|
void |
documentStarted()
Deprecated.
|
protected String |
extractProtocol(String uri) |
String |
getBaseURL()
Returns the current baseUrl for this class.
|
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. |
CSSResource |
getCSSResource(String uri,
ExternalResourceType type)
Retrieves the CSS located at the given URI.
|
FSUriResolver |
getDefaultUriResolver() |
static byte[] |
getEmbeddedBase64Image(String imageDataUri)
Get the binary content of an embedded base 64 image.
|
abstract ImageResource |
getImageResource(String uri,
ExternalResourceType type) |
protected FSStreamFactory |
getProtocolFactory(String protocol) |
XMLResource |
getXMLResource(String uri,
ExternalResourceType type)
Retrieves the XML located at the given URI.
|
protected boolean |
hasProtocolFactory(String protocol) |
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)
Deprecated.
|
void |
onRenderException(Throwable t)
Deprecated.
|
protected Reader |
openReader(String uri)
Gets a reader for the identified resource by a resolved URI.
|
protected InputStream |
openStream(String uri)
Gets a InputStream for the resource identified by a resolved URI.
|
protected String |
readAll(Reader reader) |
String |
resolveURI(String uri)
Used to find a uri that may be relative to the BaseURL.
|
String |
resolveUri(String baseUri,
String uri) |
void |
setAccessController(ExternalResourceControlPriority prio,
BiPredicate<String,ExternalResourceType> controller) |
void |
setBaseURL(String uri)
URL relative to which URIs are resolved.
|
void |
setProtocolsStreamFactory(Map<String,FSStreamFactory> protocolsStreamFactory) |
void |
setUriResolver(FSUriResolver resolver) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetBinaryResource, getCSSResource, getImageResource, getXMLResourceprotected final LinkedHashMap<String,ImageResource> _imageCache
protected final FSUriResolver DEFAULT_URI_RESOLVER
protected final Map<ExternalResourceControlPriority,BiPredicate<String,ExternalResourceType>> _accessControllers
protected FSUriResolver _resolver
protected String _baseUri
protected Map<String,FSStreamFactory> _protocolsStreamFactory
public static byte[] getEmbeddedBase64Image(String imageDataUri)
imageDataUri - URI of the embedded imagepublic void setProtocolsStreamFactory(Map<String,FSStreamFactory> protocolsStreamFactory)
public void setUriResolver(FSUriResolver resolver)
public FSUriResolver getDefaultUriResolver()
@Deprecated public void clearImageCache()
protected FSStreamFactory getProtocolFactory(String protocol)
protected boolean hasProtocolFactory(String protocol)
protected String extractProtocol(String uri) throws URISyntaxException
URISyntaxExceptionprotected InputStream openStream(String uri)
protected Reader openReader(String uri)
protected String readAll(Reader reader) throws IOException
IOExceptionpublic CSSResource getCSSResource(String uri, ExternalResourceType type)
getCSSResource in interface UserAgentCallbackuri - Location of the CSS source.public abstract ImageResource getImageResource(String uri, ExternalResourceType type)
getImageResource in interface UserAgentCallbackpublic XMLResource getXMLResource(String uri, ExternalResourceType type)
getXMLResource in interface UserAgentCallbackuri - Location of the XML source.type - Either xhtml or svg.public byte[] getBinaryResource(String uri, ExternalResourceType type)
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 setAccessController(ExternalResourceControlPriority prio, BiPredicate<String,ExternalResourceType> controller)
public boolean checkAccessAllowed(String uriOrResolved, ExternalResourceType type, ExternalResourceControlPriority priority)
public String getBaseURL()
getBaseURL in interface UserAgentCallbackpublic void setBaseURL(String uri)
setBaseURL in interface UserAgentCallbackuri - A URI which anchors other, possibly relative URIs.@Deprecated public void documentStarted()
DocumentListenerdocumentStarted in interface DocumentListener@Deprecated public void documentLoaded()
DocumentListenerdocumentLoaded in interface DocumentListener@Deprecated public 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 DocumentListener@Deprecated public 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 String resolveURI(String uri)
UserAgentCallbackresolveURI in interface UserAgentCallbackuri - an absolute or relative (to baseURL) uri to be resolved.public String resolveUri(String baseUri, String uri)
resolveUri in interface UserAgentCallbackCopyright © 2004–2025. All rights reserved.