From 0a0709441cc9b0d3d2fa565676f65d1a35d6f125 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 17:12:09 +0200 Subject: [PATCH] Fix rendering rule storage --- .../osmand/render/RenderingRulesStorage.java | 51 +++++++++++++++++-- .../render/RenderingRulesStoragePrinter.java | 2 +- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java index 7d8dad381b..1c9214f660 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -18,6 +17,7 @@ import java.util.Map.Entry; import java.util.Stack; import net.osmand.PlatformUtil; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; @@ -183,6 +183,23 @@ public class RenderingRulesStorage { } } + private class XmlTreeSequence { + XmlTreeSequence parent; + String seqOrder; + Map attrsMap = new LinkedHashMap(); + String name; + List children = new ArrayList(); + + private void process(RenderingRulesHandler handler, int el) throws XmlPullParserException, IOException { + // TODO create new attrsMap and replace #SEQ -> el + handler.startElement(attrsMap, name); + for(XmlTreeSequence s : children) { + s.process(handler, el); + } + handler.endElement(name); + } + } + private class RenderingRulesHandler { private final XmlPullParser parser; private int state; @@ -200,14 +217,40 @@ public class RenderingRulesStorage { Map attrsMap = new LinkedHashMap(); parser.setInput(is, "UTF-8"); int tok; + XmlTreeSequence currentSeqElement = null; while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { -// String seq = parser.getAttributeValue("", "seq"); attrsMap.clear(); parseAttributes(parser, attrsMap); - startElement(attrsMap, parser.getName()); + String name = parser.getName(); + if (!Algorithms.isEmpty(parser.getAttributeValue("", "seq")) || currentSeqElement != null) { + XmlTreeSequence seq = new XmlTreeSequence(); + seq.name = name; + seq.attrsMap = attrsMap; + seq.parent = currentSeqElement; + if (currentSeqElement == null) { + seq.seqOrder = parser.getAttributeValue("", "seq"); + } else { + currentSeqElement.children.add(seq); + seq.seqOrder = currentSeqElement.seqOrder; + } + currentSeqElement = seq; + } else { + startElement(attrsMap, name); + } } else if (tok == XmlPullParser.END_TAG) { - endElement(parser.getName()); + if(currentSeqElement == null) { + endElement(parser.getName()); + } else { + XmlTreeSequence process = currentSeqElement; + currentSeqElement = currentSeqElement.parent; + if (currentSeqElement == null) { + // Here we process sequence element + for(int i = 1; i < 5; i++) { + process.process(this, i); + } + } + } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java index 5948bcb5e1..86d0c2cb73 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java @@ -21,7 +21,7 @@ import org.xmlpull.v1.XmlPullParserException; public class RenderingRulesStoragePrinter { public static void main(String[] args) throws XmlPullParserException, IOException { - RenderingRulesStorage.STORE_ATTTRIBUTES = true; + RenderingRulesStorage.STORE_ATTRIBUTES = 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) {