Hello all,
for usage in c:geo I have the need to use custom themes with mapsforge where I don't have any resource available as File (neither the xml render scheme itself nor the resource files it references to) but can only provide inputstreams for all of this.
Class org.mapsforge.map.rendertheme.StreamRenderTheme solves half the problem because it allows providing the xml render scheme as InputStream. However, it still requires all references (file) resources in the xml to be referenced as File using a relative file path.
My idea is to provide an optional "custom" InputStream provider which receives a string (the resource string from XML scheme) and returns the InputStream for this ressource. E.g. new constructor of StreamRenderTheme may look like this:
public interface ResourceProvider {
InputStream get(final String src);
}
/**
* @param relativePathPrefix the prefix for all relative resource paths.
* @param inputStream an input stream containing valid render theme XML data.
* @param resourceProvider provides inputstreams for resource src
*/
public StreamRenderTheme(String relativePathPrefix, InputStream inputStream, ResourceProvider resourceProvider) {
...
}
This resourceProvider can be passed through RenderThemeHandler, Area/Line/... etc until XmlUtils.createInputStream() and used there like this:
/**
* Create InputStream from assets, file or jar resource.
* <p/>
* If the resource has not a location prefix, then the search order is (file, assets, jar).
*/
private static InputStream createInputStream(GraphicFactory graphicFactory, String relativePathPrefix, String src, ResourceProvider resourceProvider) throws IOException {
InputStream inputStream;
if (resourceProvider != null) {
inputStream = resourceProvider.get(src);
if (inputStream != null) {
return inputStream;
}
}
...(continue with already existing code
if (src.startsWith(PREFIX_ASSETS)) {
...
What do you think about this? This would really help me out. If ok I can code this up and provide a PR for this.