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
ConstructorsConstructorDescriptionCreate a new MemoryURLConnectionFactoryMemoryURLConnectionFactory(Map<? extends URL2, ? extends AbstractBlob> map) Create a new MemoryURLConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptiongetMap()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.booleanisEgressRequired(URL2 url) Return true if egress is potentially required to retrieve this URL.booleanReturn true if the supplied URL (which will be loadable by this Factory) should be considered trusted.booleanReturn true if this URLConnectionFactory supports the specified URL.toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:URLConnectionFactoryReturn a URLConnection for the specified URI, or null if not possible with this factory.- Specified by:
getURLConnectionin 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:
supportsin interfaceURLConnectionFactory- Parameters:
url- the URL- Returns:
- whether the URL is supported by this factory
-
isEgressRequired
Description copied from interface:URLConnectionFactoryReturn true if egress is potentially required to retrieve this URL. There is a default implementation which returns true.- Specified by:
isEgressRequiredin interfaceURLConnectionFactory- Parameters:
url- the URI- Returns:
- whether egress is required
-
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:URLConnectionFactoryReturn true if the supplied URL (which will be loadable by this Factory) should be considered trusted. The default implementation returns false.- Specified by:
isTrustedin interfaceURLConnectionFactory- See Also:
-