Package org.faceless.publisher.resource
Class MemoryURLConnectionFactory
java.lang.Object
org.faceless.publisher.resource.MemoryURLConnectionFactory
- All Implemented Interfaces:
URLConnectionFactory
A general purpose URLConnectionFactory which can be used to map particular
URLs to a preloaded byte array, known as a "Blob" (after the same term in
web browsers).
An instance of this can be used to override any URL - it can be added to the
ReportFactory
or a single
Report
by calling the getURLConnectionFactories()
method on either class. If it is to override URLs that would be handled normally, eg "http"
or "file" URLs, it should be put at the start of the list to ensure it has the highest-priority.
MemoryURLConnectionFactory factory = new MemoryURLConnectionFactory();
Map<URL2,AbstractBlob> map = factory.getMap();
ByteBuffer data = ...; // your data, from any source
URL2 url = URL2.parse("https://example.com/foo");
Blob blob = new Blob(url, MediaType.parse("text/html"), data, 0);
map.put(blob.getURL(), blob);
Report report = reportfactory.createReport();
report.getURLConnectionFactories().add(0, myhandler);
report.load(...);
-
Constructor Summary
ConstructorDescriptionCreate a new MemoryURLConnectionFactoryMemoryURLConnectionFactory
(Map<? extends URL2, ? extends AbstractBlob> map) Create a new MemoryURLConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptioncreateEgressFilter
(EgressFilter parent) Create an EgressFilter that wraps the supplied EgressFilter, but makes exceptions for the URLs retrieved from memory this URLConnectionFactorygetMap()
Return the Map of URLs to {link AbstractBlob} values.getURLConnection
(URL2 uri, ReportFactory reportFactory) Return a URLConnection for the specified URI, or null if not possible with this factory.boolean
Return true if the supplied URL (which will be loadable by this Factory) should be considered trusted.boolean
Return true if this URLConnectionFactory supports the specified URL.toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.faceless.publisher.resource.URLConnectionFactory
close, getExpiry, getURLConnectionProcessors, isUnchanged, setURLConnectionProcessors
-
Constructor Details
-
MemoryURLConnectionFactory
public MemoryURLConnectionFactory()Create a new MemoryURLConnectionFactory -
MemoryURLConnectionFactory
Create a new MemoryURLConnectionFactory. The supplied map will be copied to the map returned bygetMap()
- Parameters:
map
- the map to copy to the internal map.
-
-
Method Details
-
getURLConnection
Description copied from interface:URLConnectionFactory
Return a URLConnection for the specified URI, or null if not possible with this factory.- Specified by:
getURLConnection
in interfaceURLConnectionFactory
- Parameters:
uri
- the URIreportFactory
- the ReportFactory that owns this connection- Throws:
IOException
-
supports
Return true if this URLConnectionFactory supports the specified URL. This returns true if the URL is a key in the map returned bygetMap()
- Specified by:
supports
in interfaceURLConnectionFactory
- Parameters:
url
- the URL
-
getMap
Return the Map of URLs to {link AbstractBlob} values. The returned map can be edited in thread-safe way without synchronization, and all keys and values must be non0null. -
toString
-
isTrusted
Description copied from interface:URLConnectionFactory
Return true if the supplied URL (which will be loadable by this Factory) should be considered trusted. The default implementation returns false.- Specified by:
isTrusted
in interfaceURLConnectionFactory
- See Also:
-
createEgressFilter
Create an EgressFilter that wraps the supplied EgressFilter, but makes exceptions for the URLs retrieved from memory this URLConnectionFactory- Parameters:
parent
- the EgressFilter to defer to- Returns:
- a new EgressFilter
- Since:
- 1.4
-