use of net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver in project OsmAnd-tools by osmandapp.
the class NativeSwingRendering method loadRuleStorage.
public void loadRuleStorage(String path, String renderingProperties) throws IOException, XmlPullParserException, SAXException {
final LinkedHashMap<String, String> renderingConstants = new LinkedHashMap<String, String>();
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
@Override
public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref) throws XmlPullParserException, IOException {
RenderingRulesStorage depends = new RenderingRulesStorage(name, renderingConstants);
depends.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream(name + ".render.xml"), ref);
return depends;
}
};
if (path == null || path.equals("default.render.xml")) {
loadRenderingAttributes(RenderingRulesStorage.class.getResourceAsStream("default.render.xml"), renderingConstants);
storage = new RenderingRulesStorage("default", renderingConstants);
storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("default.render.xml"), resolver);
} else {
InputStream is = null;
InputStream is2 = null;
if (new File(path).exists()) {
is = new FileInputStream(new File(path));
is2 = new FileInputStream(new File(path));
} else {
is = RenderingRulesStorage.class.getResourceAsStream(path);
is2 = RenderingRulesStorage.class.getResourceAsStream(path);
}
if (is == null) {
throw new IllegalArgumentException("Can't find rendering style '" + path + "'");
}
loadRenderingAttributes(is, renderingConstants);
storage = new RenderingRulesStorage("default", renderingConstants);
storage.parseRulesFromXmlInputStream(is2, resolver);
is.close();
is2.close();
}
renderingProps = new HashMap<String, String>();
String[] props = renderingProperties.split(",");
for (String s : props) {
int i = s.indexOf('=');
if (i > 0) {
String key = s.substring(0, i).trim();
String value = s.substring(i + 1).trim();
if (value.contains(";")) {
value = value.substring(0, value.indexOf(';'));
}
renderingProps.put(key, value);
}
}
initRenderingRulesStorage(storage);
}
use of net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver in project Osmand by osmandapp.
the class RendererRegistry method loadRenderer.
// private static boolean USE_PRECOMPILED_STYLE = false;
private RenderingRulesStorage loadRenderer(String name, final Map<String, RenderingRulesStorage> loadedRenderers, final Map<String, String> renderingConstants) throws IOException, XmlPullParserException {
// if ((name.equals(DEFAULT_RENDER) || name.equalsIgnoreCase("default")) && USE_PRECOMPILED_STYLE) {
// RenderingRulesStorage rrs = new RenderingRulesStorage("", null);
// new DefaultRenderingRulesStorage().createStyle(rrs);
// log.info("INIT rendering from class");
// return rrs;
// }
InputStream is = getInputStream(name);
if (is == null) {
return null;
}
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(is, "UTF-8");
int tok;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
String tagName = parser.getName();
if (tagName.equals("renderingConstant")) {
if (!renderingConstants.containsKey(parser.getAttributeValue("", "name"))) {
renderingConstants.put(parser.getAttributeValue("", "name"), parser.getAttributeValue("", "value"));
}
}
}
}
} finally {
is.close();
}
// parse content
is = getInputStream(name);
final RenderingRulesStorage main = new RenderingRulesStorage(name, renderingConstants);
loadedRenderers.put(name, main);
try {
main.parseRulesFromXmlInputStream(is, new RenderingRulesStorageResolver() {
@Override
public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref) throws XmlPullParserException {
// reload every time to propogate rendering constants
if (loadedRenderers.containsKey(name)) {
// $NON-NLS-1$
log.warn("Circular dependencies found " + name);
}
RenderingRulesStorage dep = null;
try {
dep = loadRenderer(name, loadedRenderers, renderingConstants);
} catch (IOException e) {
// $NON-NLS-1$
log.warn("Dependent renderer not found : " + e.getMessage(), e);
}
if (dep == null) {
// $NON-NLS-1$
log.warn("Dependent renderer not found : " + name);
}
return dep;
}
});
} finally {
is.close();
}
if (rendererLoadedEventListener != null)
rendererLoadedEventListener.onRendererLoaded(name, main, getInputStream(name));
return main;
}
use of net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver in project Osmand by osmandapp.
the class RenderingRulesStoragePrinter method main.
public static void main(String[] args) throws XmlPullParserException, IOException {
RenderingRulesStorage.STORE_ATTTRIBUTES = true;
// InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml");
String defaultFile = "/Users/victorshcherb/osmand/repos/resources/rendering_styles/default.render.xml";
if (args.length > 0) {
defaultFile = args[0];
}
String outputPath = ".";
if (args.length > 1) {
outputPath = args[1];
}
String name = "Style";
Map<String, String> renderingConstants = new LinkedHashMap<String, String>();
InputStream is = new FileInputStream(defaultFile);
// buggy attributes
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(is, "UTF-8");
int tok;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
String tagName = parser.getName();
if (tagName.equals("renderingConstant")) {
if (!renderingConstants.containsKey(parser.getAttributeValue("", "name"))) {
renderingConstants.put(parser.getAttributeValue("", "name"), parser.getAttributeValue("", "value"));
}
}
}
}
} finally {
is.close();
}
is = new FileInputStream(defaultFile);
RenderingRulesStorage storage = new RenderingRulesStorage("default", renderingConstants);
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
@Override
public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref) throws XmlPullParserException, IOException {
RenderingRulesStorage depends = new RenderingRulesStorage(name, null);
depends.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream(name + ".render.xml"), ref);
return depends;
}
};
storage.parseRulesFromXmlInputStream(is, resolver);
new RenderingRulesStoragePrinter().printJavaFile(outputPath, name, storage);
}
Aggregations