source: josm/trunk/scripts/SyncEditorLayerIndex.java@ 19449

Last change on this file since 19449 was 19449, checked in by stoecker, 4 weeks ago

better output to find the position

  • Property svn:eol-style set to native
File size: 72.0 KB
RevLine 
[7726]1// License: GPL. For details, see LICENSE file.
[18989]2
[15034]3import static java.nio.charset.StandardCharsets.UTF_8;
[15033]4
5import java.io.BufferedReader;
[16098]6import java.io.BufferedWriter;
[15033]7import java.io.IOException;
8import java.io.OutputStreamWriter;
[16098]9import java.io.Writer;
[15033]10import java.lang.reflect.Field;
[15163]11import java.net.MalformedURLException;
12import java.net.URL;
[16098]13import java.nio.charset.Charset;
[15034]14import java.nio.file.Files;
15import java.nio.file.Paths;
[15033]16import java.text.DecimalFormat;
17import java.text.ParseException;
18import java.text.SimpleDateFormat;
19import java.util.ArrayList;
20import java.util.Arrays;
21import java.util.Calendar;
22import java.util.Collection;
23import java.util.Collections;
24import java.util.Date;
25import java.util.HashMap;
26import java.util.LinkedList;
27import java.util.List;
28import java.util.Locale;
29import java.util.Map;
30import java.util.Map.Entry;
31import java.util.Objects;
[15082]32import java.util.Set;
[15692]33import java.util.function.BiConsumer;
[15082]34import java.util.function.Function;
[15033]35import java.util.regex.Matcher;
36import java.util.regex.Pattern;
37import java.util.stream.Collectors;
38
39import org.openstreetmap.gui.jmapviewer.Coordinate;
40import org.openstreetmap.josm.data.Preferences;
41import org.openstreetmap.josm.data.imagery.ImageryInfo;
42import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
43import org.openstreetmap.josm.data.imagery.Shape;
44import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
[15478]45import org.openstreetmap.josm.data.preferences.JosmUrls;
[15033]46import org.openstreetmap.josm.data.projection.Projections;
[16650]47import org.openstreetmap.josm.data.sources.SourceInfo;
[15033]48import org.openstreetmap.josm.data.validation.routines.DomainValidator;
49import org.openstreetmap.josm.io.imagery.ImageryReader;
50import org.openstreetmap.josm.spi.preferences.Config;
[15439]51import org.openstreetmap.josm.tools.ImageProvider;
[15692]52import org.openstreetmap.josm.tools.JosmRuntimeException;
[15034]53import org.openstreetmap.josm.tools.Logging;
[15033]54import org.openstreetmap.josm.tools.OptionParser;
55import org.openstreetmap.josm.tools.OptionParser.OptionCount;
56import org.openstreetmap.josm.tools.ReflectionUtils;
[18208]57import org.openstreetmap.josm.tools.Utils;
[15033]58import org.xml.sax.SAXException;
59
[18989]60import jakarta.json.Json;
61import jakarta.json.JsonArray;
62import jakarta.json.JsonNumber;
63import jakarta.json.JsonObject;
64import jakarta.json.JsonReader;
65import jakarta.json.JsonString;
66import jakarta.json.JsonValue;
67
[7726]68/**
[11854]69 * Compare and analyse the differences of the editor layer index and the JOSM imagery list.
[7726]70 * The goal is to keep both lists in sync.
[18801]71 * <p>
72 * The <a href="https://github.com/osmlab/editor-layer-index">editor layer index</a> project
73 * provides also a version in the JOSM format, but the GEOJSON is the original source format, so we read that.
74 * <p>
75 * For running, the main JOSM binary needs to be in classpath, e.g.
76 * <p>
77 * {@code $ java -cp ../dist/josm-custom.jar SyncEditorLayerIndex}
78 * <p>
79 * Add option {@code -h} to show the available command line flags.
[7726]80 */
[15037]81@SuppressWarnings("unchecked")
[15033]82public class SyncEditorLayerIndex {
[14019]83
[15034]84 private static final int MAXLEN = 140;
85
[15033]86 private List<ImageryInfo> josmEntries;
87 private JsonArray eliEntries;
[19137]88 private JsonArray idEntries;
89 private JsonArray rapidEntries;
[7726]90
[15034]91 private final Map<String, JsonObject> eliUrls = new HashMap<>();
[19137]92 private final Map<String, JsonObject> idUrls = new HashMap<>();
93 private final Map<String, JsonObject> rapidUrls = new HashMap<>();
[15034]94 private final Map<String, ImageryInfo> josmUrls = new HashMap<>();
95 private final Map<String, ImageryInfo> josmMirrors = new HashMap<>();
96 private static final Map<String, String> oldproj = new HashMap<>();
97 private static final List<String> ignoreproj = new LinkedList<>();
[7726]98
[15033]99 private static String eliInputFile = "imagery_eli.geojson";
[19137]100 private static String idInputFile = "imagery_id.geojson";
101 private static String rapidInputFile = "imagery_rapid.geojson";
[15033]102 private static String josmInputFile = "imagery_josm.imagery.xml";
103 private static String ignoreInputFile = "imagery_josm.ignores.txt";
[16098]104 private static Writer outputStream;
[15033]105 private static String optionOutput;
106 private static boolean optionShorten;
107 private static boolean optionNoSkip;
108 private static boolean optionXhtmlBody;
109 private static boolean optionXhtml;
110 private static String optionEliXml;
111 private static String optionJosmXml;
112 private static String optionEncoding;
113 private static boolean optionNoEli;
[19106]114 private final Map<String, String> skip = new HashMap<>();
115 private final Map<String, String> skipStart = new HashMap<>();
[7726]116
117 /**
118 * Main method.
[15033]119 * @param args program arguments
120 * @throws IOException if any I/O error occurs
121 * @throws ReflectiveOperationException if any reflective operation error occurs
122 * @throws SAXException if any SAX error occurs
[7726]123 */
[15033]124 public static void main(String[] args) throws IOException, SAXException, ReflectiveOperationException {
125 Locale.setDefault(Locale.ROOT);
[15034]126 parseCommandLineArguments(args);
[15478]127 Config.setUrlsProvider(JosmUrls.getInstance());
[15033]128 Preferences pref = new Preferences(JosmBaseDirectories.getInstance());
129 Config.setPreferencesInstance(pref);
130 pref.init(false);
131 SyncEditorLayerIndex script = new SyncEditorLayerIndex();
132 script.setupProj();
133 script.loadSkip();
134 script.start();
135 script.loadJosmEntries();
136 if (optionJosmXml != null) {
[16098]137 try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionJosmXml), UTF_8)) {
138 script.printentries(script.josmEntries, writer);
[15034]139 }
[11964]140 }
[15033]141 script.loadELIEntries();
[19137]142 script.loadELIUsers();
[15033]143 if (optionEliXml != null) {
[16098]144 try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionEliXml), UTF_8)) {
145 script.printentries(script.eliEntries, writer);
[15034]146 }
[11964]147 }
[15033]148 script.checkInOneButNotTheOther();
149 script.checkCommonEntries();
150 script.end();
151 if (outputStream != null) {
152 outputStream.close();
[9505]153 }
[7726]154 }
[9653]155
[7726]156 /**
[15033]157 * Displays help on the console
158 */
159 private static void showHelp() {
160 System.out.println(getHelp());
161 System.exit(0);
162 }
163
164 static String getHelp() {
165 return "usage: java -cp build SyncEditorLayerIndex\n" +
166 "-c,--encoding <encoding> output encoding (defaults to UTF-8 or cp850 on Windows)\n" +
[15034]167 "-e,--eli_input <eli_input> Input file for the editor layer index (geojson). " +
168 "Default is imagery_eli.geojson (current directory).\n" +
[19137]169 "-d,--id_input <id_input> Input file for the id index (geojson). " +
170 "Default is imagery_id.geojson (current directory).\n" +
[15033]171 "-h,--help show this help\n" +
172 "-i,--ignore_input <ignore_input> Input file for the ignore list. Default is imagery_josm.ignores.txt (current directory).\n" +
[15034]173 "-j,--josm_input <josm_input> Input file for the JOSM imagery list (xml). " +
174 "Default is imagery_josm.imagery.xml (current directory).\n" +
[19137]175 "-m,--noeli don't show output for ELI, Rapid or iD problems\n" +
[15033]176 "-n,--noskip don't skip known entries\n" +
177 "-o,--output <output> Output file, - prints to stdout (default: -)\n" +
178 "-p,--elixml <elixml> ELI entries for use in JOSM as XML file (incomplete)\n" +
179 "-q,--josmxml <josmxml> JOSM entries reoutput as XML file (incomplete)\n" +
[19137]180 "-r,--rapid_input <rapid_input> Input file for the rapid index (geojson). " +
181 "Default is imagery_rapid.geojson (current directory).\n" +
[15033]182 "-s,--shorten shorten the output, so it is easier to read in a console window\n" +
183 "-x,--xhtmlbody create XHTML body for display in a web page\n" +
184 "-X,--xhtml create XHTML for display in a web page\n";
185 }
186
187 /**
[7726]188 * Parse command line arguments.
[15033]189 * @param args program arguments
[15034]190 * @throws IOException in case of I/O error
[7726]191 */
[15034]192 static void parseCommandLineArguments(String[] args) throws IOException {
[15033]193 new OptionParser("JOSM/ELI synchronization script")
194 .addFlagParameter("help", SyncEditorLayerIndex::showHelp)
195 .addShortAlias("help", "h")
196 .addArgumentParameter("output", OptionCount.OPTIONAL, x -> optionOutput = x)
197 .addShortAlias("output", "o")
198 .addArgumentParameter("eli_input", OptionCount.OPTIONAL, x -> eliInputFile = x)
199 .addShortAlias("eli_input", "e")
[19137]200 .addArgumentParameter("id_input", OptionCount.OPTIONAL, x -> idInputFile = x)
201 .addShortAlias("id_input", "d")
202 .addArgumentParameter("rapid_input", OptionCount.OPTIONAL, x -> rapidInputFile = x)
203 .addShortAlias("rapid_input", "r")
[15033]204 .addArgumentParameter("josm_input", OptionCount.OPTIONAL, x -> josmInputFile = x)
205 .addShortAlias("josm_input", "j")
206 .addArgumentParameter("ignore_input", OptionCount.OPTIONAL, x -> ignoreInputFile = x)
207 .addShortAlias("ignore_input", "i")
208 .addFlagParameter("shorten", () -> optionShorten = true)
209 .addShortAlias("shorten", "s")
210 .addFlagParameter("noskip", () -> optionNoSkip = true)
211 .addShortAlias("noskip", "n")
212 .addFlagParameter("xhtmlbody", () -> optionXhtmlBody = true)
213 .addShortAlias("xhtmlbody", "x")
214 .addFlagParameter("xhtml", () -> optionXhtml = true)
215 .addShortAlias("xhtml", "X")
216 .addArgumentParameter("elixml", OptionCount.OPTIONAL, x -> optionEliXml = x)
217 .addShortAlias("elixml", "p")
218 .addArgumentParameter("josmxml", OptionCount.OPTIONAL, x -> optionJosmXml = x)
219 .addShortAlias("josmxml", "q")
220 .addFlagParameter("noeli", () -> optionNoEli = true)
221 .addShortAlias("noeli", "m")
222 .addArgumentParameter("encoding", OptionCount.OPTIONAL, x -> optionEncoding = x)
223 .addShortAlias("encoding", "c")
224 .parseOptionsOrExit(Arrays.asList(args));
[7726]225
[15034]226 if (optionOutput != null && !"-".equals(optionOutput)) {
[16098]227 outputStream = Files.newBufferedWriter(Paths.get(optionOutput), optionEncoding != null ? Charset.forName(optionEncoding) : UTF_8);
[15033]228 } else if (optionEncoding != null) {
229 outputStream = new OutputStreamWriter(System.out, optionEncoding);
[7726]230 }
231 }
232
[13530]233 void setupProj() {
[15033]234 oldproj.put("EPSG:3359", "EPSG:3404");
235 oldproj.put("EPSG:3785", "EPSG:3857");
236 oldproj.put("EPSG:31297", "EPGS:31287");
237 oldproj.put("EPSG:31464", "EPSG:31468");
238 oldproj.put("EPSG:54004", "EPSG:3857");
239 oldproj.put("EPSG:102100", "EPSG:3857");
240 oldproj.put("EPSG:102113", "EPSG:3857");
241 oldproj.put("EPSG:900913", "EPGS:3857");
242 ignoreproj.add("EPSG:4267");
243 ignoreproj.add("EPSG:5221");
244 ignoreproj.add("EPSG:5514");
245 ignoreproj.add("EPSG:32019");
246 ignoreproj.add("EPSG:102066");
247 ignoreproj.add("EPSG:102067");
248 ignoreproj.add("EPSG:102685");
249 ignoreproj.add("EPSG:102711");
[13530]250 }
251
[15033]252 void loadSkip() throws IOException {
[19106]253 final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)}}} *\\|\\|");
[16098]254 try (BufferedReader fr = Files.newBufferedReader(Paths.get(ignoreInputFile), UTF_8)) {
[15033]255 String line;
[11238]256
[15033]257 while ((line = fr.readLine()) != null) {
258 Matcher res = pattern.matcher(line);
259 if (res.matches()) {
[15850]260 String s = res.group(2);
[15851]261 if (s.endsWith("...")) {
[15850]262 s = s.substring(0, s.length() - 3);
263 if ("Ignore".equals(res.group(1))) {
264 skipStart.put(s, "green");
265 } else {
266 skipStart.put(s, "darkgoldenrod");
267 }
[15851]268 } else {
[15850]269 if ("Ignore".equals(res.group(1))) {
270 skip.put(s, "green");
271 } else {
272 skip.put(s, "darkgoldenrod");
273 }
274 }
[11238]275 }
276 }
[11234]277 }
[11238]278 }
[9653]279
[15692]280 void myprintlnfinal(String s) {
[15033]281 if (outputStream != null) {
[15692]282 try {
[19139]283 outputStream.write(s + System.lineSeparator());
[15692]284 } catch (IOException e) {
285 throw new JosmRuntimeException(e);
286 }
[9658]287 } else {
[15033]288 System.out.println(s);
[9658]289 }
290 }
291
[15850]292 String isSkipString(String s) {
293 if (skip.containsKey(s))
294 return skip.get(s);
295 for (Entry<String, String> str : skipStart.entrySet()) {
[15878]296 if (s.startsWith(str.getKey())) {
297 skipStart.remove(str.getKey());
[15850]298 return str.getValue();
[15878]299 }
[15850]300 }
301 return null;
302 }
[15851]303
[15692]304 void myprintln(String s) {
[15850]305 String color;
[18801]306 final String escaped = s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
[15850]307 if ((color = isSkipString(s)) != null) {
[15033]308 skip.remove(s);
309 if (optionXhtmlBody || optionXhtml) {
[15034]310 s = "<pre style=\"margin:3px;color:"+color+"\">"
[18801]311 + escaped +"</pre>";
[9658]312 }
[15033]313 if (!optionNoSkip) {
314 return;
[9662]315 }
[15034]316 } else if (optionXhtmlBody || optionXhtml) {
[15850]317 color =
[15033]318 s.startsWith("***") ? "black" :
319 ((s.startsWith("+ ") || s.startsWith("+++ ELI")) ? "blue" :
320 (s.startsWith("#") ? "indigo" :
[18382]321 (s.startsWith("!") ? "orange" :
322 (s.startsWith("~") ? "red" : "brown"))));
[18801]323 s = "<pre style=\"margin:3px;color:"+color+"\">"+ escaped +"</pre>";
[9505]324 }
[15033]325 if ((s.startsWith("+ ") || s.startsWith("+++ ELI") || s.startsWith("#")) && optionNoEli) {
326 return;
[11965]327 }
[15033]328 myprintlnfinal(s);
[9658]329 }
330
[15692]331 void start() {
[15033]332 if (optionXhtml) {
[15034]333 myprintlnfinal(
334 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
335 myprintlnfinal(
336 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"+
337 "<title>JOSM - ELI differences</title></head><body>\n");
[9505]338 }
339 }
[9653]340
[15692]341 void end() {
[15033]342 for (String s : skip.keySet()) {
343 myprintln("+++ Obsolete skip entry: " + s);
[9658]344 }
[15878]345 for (String s : skipStart.keySet()) {
346 myprintln("+++ Obsolete skip entry: " + s + "...");
347 }
[15033]348 if (optionXhtml) {
349 myprintlnfinal("</body></html>\n");
[9658]350 }
351 }
352
[15033]353 void loadELIEntries() throws IOException {
[16098]354 try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(eliInputFile), UTF_8))) {
[15033]355 eliEntries = jr.readObject().getJsonArray("features");
356 }
[9653]357
[15033]358 for (JsonValue e : eliEntries) {
359 String url = getUrlStripped(e);
[9653]360 if (url.contains("{z}")) {
[15878]361 myprintln("+++ ELI-URL uses {z} instead of {zoom}: "+getDescription(e));
[15034]362 url = url.replace("{z}", "{zoom}");
[9653]363 }
[11582]364 if (eliUrls.containsKey(url)) {
[15033]365 myprintln("+++ ELI-URL is not unique: "+url);
[9505]366 } else {
[15033]367 eliUrls.put(url, e.asJsonObject());
[9505]368 }
[15033]369 JsonArray s = e.asJsonObject().get("properties").asJsonObject().getJsonArray("available_projections");
370 if (s != null) {
371 String urlLc = url.toLowerCase(Locale.ENGLISH);
372 List<String> old = new LinkedList<>();
373 for (JsonValue p : s) {
374 String proj = ((JsonString) p).getString();
375 if (oldproj.containsKey(proj) || ("CRS:84".equals(proj) && !urlLc.contains("version=1.3"))) {
376 old.add(proj);
[13530]377 }
378 }
[15033]379 if (!old.isEmpty()) {
380 myprintln("+ ELI Projections "+String.join(", ", old)+" not useful: "+getDescription(e));
[13530]381 }
382 }
[7726]383 }
[15033]384 myprintln("*** Loaded "+eliEntries.size()+" entries (ELI). ***");
[7726]385 }
[19139]386
[19137]387 void loadELIUsers() throws IOException {
388 try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(idInputFile), UTF_8))) {
389 idEntries = jr.readArray();
390 }
391 for (JsonValue e : idEntries) {
392 String url = getUrlStripped(e);
393 if (!eliUrls.containsKey(url))
394 myprintln("+++ iD-URL not in ELI: "+url);
395 idUrls.put(url, e.asJsonObject());
396 }
397 myprintln("*** Loaded "+idEntries.size()+" entries (iD). ***");
398 try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(rapidInputFile), UTF_8))) {
[19213]399 rapidEntries = jr.readObject().getJsonArray("imagery");
[19137]400 }
401 for (JsonValue e : rapidEntries) {
402 String url = getUrlStripped(e);
403 if (!eliUrls.containsKey(url))
404 myprintln("+++ Rapid-URL not in ELI: "+url);
405 rapidUrls.put(url, e.asJsonObject());
406 }
407 myprintln("*** Loaded "+rapidEntries.size()+" entries (Rapid). ***");
408 }
[15033]409
410 String cdata(String s) {
411 return cdata(s, false);
[11968]412 }
[7726]413
[15033]414 String cdata(String s, boolean escape) {
415 if (escape) {
416 return s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
[15712]417 } else if (s.matches(".*[<>&].*"))
[15033]418 return "<![CDATA["+s+"]]>";
419 return s;
420 }
421
422 String maininfo(Object entry, String offset) {
423 String t = getType(entry);
424 String res = offset + "<type>"+t+"</type>\n";
425 res += offset + "<url>"+cdata(getUrl(entry))+"</url>\n";
426 if (getMinZoom(entry) != null)
427 res += offset + "<min-zoom>"+getMinZoom(entry)+"</min-zoom>\n";
428 if (getMaxZoom(entry) != null)
429 res += offset + "<max-zoom>"+getMaxZoom(entry)+"</max-zoom>\n";
430 if ("wms".equals(t)) {
431 List<String> p = getProjections(entry);
432 if (p != null) {
433 res += offset + "<projections>\n";
[15034]434 for (String c : p) {
[15033]435 res += offset + " <code>"+c+"</code>\n";
[15034]436 }
[15033]437 res += offset + "</projections>\n";
[11975]438 }
[11967]439 }
[15033]440 return res;
[11967]441 }
[12061]442
[16098]443 void printentries(List<?> entries, Writer stream) throws IOException {
[15033]444 DecimalFormat df = new DecimalFormat("#.#######");
445 df.setRoundingMode(java.math.RoundingMode.CEILING);
446 stream.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
447 stream.write("<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n");
448 for (Object e : entries) {
[13536]449 stream.write(" <entry"
[15034]450 + ("eli-best".equals(getQuality(e)) ? " eli-best=\"true\"" : "")
451 + (getOverlay(e) ? " overlay=\"true\"" : "")
[15033]452 + ">\n");
453 String t;
[19375]454 if (!Utils.isStripEmpty(t = getName(e)))
[15033]455 stream.write(" <name>"+cdata(t, true)+"</name>\n");
[19375]456 if (!Utils.isStripEmpty(t = getId(e)))
[15033]457 stream.write(" <id>"+t+"</id>\n");
[19375]458 if (!Utils.isStripEmpty(t = getCategory(e)))
[15033]459 stream.write(" <category>"+t+"</category>\n");
[19375]460 if (!Utils.isStripEmpty(t = getDate(e)))
[15033]461 stream.write(" <date>"+t+"</date>\n");
[19375]462 if (!Utils.isStripEmpty(t = getCountryCode(e)))
[15033]463 stream.write(" <country-code>"+t+"</country-code>\n");
464 if ((getDefault(e)))
465 stream.write(" <default>true</default>\n");
466 stream.write(maininfo(e, " "));
[19375]467 if (!Utils.isStripEmpty(t = getAttributionText(e)))
[15033]468 stream.write(" <attribution-text mandatory=\"true\">"+cdata(t, true)+"</attribution-text>\n");
[19375]469 if (!Utils.isStripEmpty(t = getAttributionUrl(e)))
[15033]470 stream.write(" <attribution-url>"+cdata(t)+"</attribution-url>\n");
[19375]471 if (!Utils.isStripEmpty(t = getLogoImage(e)))
[15033]472 stream.write(" <logo-image>"+cdata(t, true)+"</logo-image>\n");
[19375]473 if (!Utils.isStripEmpty(t = getLogoUrl(e)))
[15033]474 stream.write(" <logo-url>"+cdata(t)+"</logo-url>\n");
[19375]475 if (!Utils.isStripEmpty(t = getTermsOfUseText(e)))
[15033]476 stream.write(" <terms-of-use-text>"+cdata(t, true)+"</terms-of-use-text>\n");
[19375]477 if (!Utils.isStripEmpty(t = getTermsOfUseUrl(e)))
[15033]478 stream.write(" <terms-of-use-url>"+cdata(t)+"</terms-of-use-url>\n");
[19375]479 if (!Utils.isStripEmpty(t = getPermissionReferenceUrl(e)))
[15033]480 stream.write(" <permission-ref>"+cdata(t)+"</permission-ref>\n");
[19375]481 if (!Utils.isStripEmpty(t = getPrivacyPolicyUrl(e)))
[16127]482 stream.write(" <privacy-policy-url>"+cdata(t)+"</privacy-policy-url>\n");
[15033]483 if ((getValidGeoreference(e)))
484 stream.write(" <valid-georeference>true</valid-georeference>\n");
[19375]485 if (!Utils.isStripEmpty(t = getIcon(e)))
[15033]486 stream.write(" <icon>"+cdata(t)+"</icon>\n");
487 for (Entry<String, String> d : getDescriptions(e).entrySet()) {
[19137]488 stream.write(" <description lang=\""+d.getKey()+"\">"+cdata(d.getValue(), true)+"</description>\n");
[11975]489 }
[15033]490 for (ImageryInfo m : getMirrors(e)) {
491 stream.write(" <mirror>\n"+maininfo(m, " ")+" </mirror>\n");
[11967]492 }
[15033]493 double minlat = 1000;
494 double minlon = 1000;
495 double maxlat = -1000;
496 double maxlon = -1000;
497 String shapes = "";
498 String sep = "\n ";
[13771]499 try {
[15033]500 for (Shape s: getShapes(e)) {
501 shapes += " <shape>";
502 int i = 0;
503 for (Coordinate p: s.getPoints()) {
504 double lat = p.getLat();
505 double lon = p.getLon();
506 if (lat > maxlat) maxlat = lat;
507 if (lon > maxlon) maxlon = lon;
508 if (lat < minlat) minlat = lat;
509 if (lon < minlon) minlon = lon;
[15034]510 if ((i++ % 3) == 0) {
[15033]511 shapes += sep + " ";
[13771]512 }
[15033]513 shapes += "<point lat='"+df.format(lat)+"' lon='"+df.format(lon)+"'/>";
[11964]514 }
[15033]515 shapes += sep + "</shape>\n";
[11964]516 }
[19106]517 } catch (IllegalArgumentException illegalArgumentException) {
518 Logging.trace(illegalArgumentException);
[11964]519 }
[15033]520 if (!shapes.isEmpty()) {
[15034]521 stream.write(" <bounds min-lat='"+df.format(minlat)
522 +"' min-lon='"+df.format(minlon)
523 +"' max-lat='"+df.format(maxlat)
524 +"' max-lon='"+df.format(maxlon)+"'>\n");
[15033]525 stream.write(shapes + " </bounds>\n");
[11964]526 }
[15033]527 stream.write(" </entry>\n");
[11964]528 }
[15033]529 stream.write("</imagery>\n");
530 stream.close();
[11964]531 }
532
[15033]533 void loadJosmEntries() throws IOException, SAXException, ReflectiveOperationException {
534 try (ImageryReader reader = new ImageryReader(josmInputFile)) {
535 josmEntries = reader.parse();
536 }
[9667]537
[15033]538 for (ImageryInfo e : josmEntries) {
[18989]539 if (!e.isValid()) {
540 myprintln("~~~ JOSM-Entry missing fields (" + String.join(", ", e.getMissingFields()) + "): " + getDescription(e));
541 }
[19375]542 if (Utils.isStripEmpty(getUrl(e))) {
[18382]543 myprintln("~~~ JOSM-Entry without URL: " + getDescription(e));
[15033]544 continue;
[14554]545 }
[19375]546 if (Utils.isStripEmpty(e.getDate()) && e.getDate() != null) {
[18382]547 myprintln("~~~ JOSM-Entry with empty Date: " + getDescription(e));
[16373]548 continue;
549 }
[19375]550 if (Utils.isStripEmpty(getName(e))) {
[18382]551 myprintln("~~~ JOSM-Entry without Name: " + getDescription(e));
[15033]552 continue;
[14554]553 }
[15033]554 String url = getUrlStripped(e);
[9658]555 if (url.contains("{z}")) {
[18382]556 myprintln("~~~ JOSM-URL uses {z} instead of {zoom}: "+getDescription(e));
[15034]557 url = url.replace("{z}", "{zoom}");
[9658]558 }
[9505]559 if (josmUrls.containsKey(url)) {
[18382]560 myprintln("~~~ JOSM-URL is not unique: "+url);
[9505]561 } else {
[15033]562 josmUrls.put(url, e);
[7726]563 }
[15033]564 for (ImageryInfo m : e.getMirrors()) {
565 url = getUrlStripped(m);
[16650]566 Field origNameField = SourceInfo.class.getDeclaredField("origName");
[15033]567 ReflectionUtils.setObjectsAccessible(origNameField);
[15034]568 origNameField.set(m, m.getOriginalName().replaceAll(" mirror server( \\d+)?", ""));
[9658]569 if (josmUrls.containsKey(url)) {
[18382]570 myprintln("~~~ JOSM-Mirror-URL is not unique: "+url);
[9658]571 } else {
[15033]572 josmUrls.put(url, m);
573 josmMirrors.put(url, m);
[9658]574 }
575 }
[7726]576 }
[15033]577 myprintln("*** Loaded "+josmEntries.size()+" entries (JOSM). ***");
[7726]578 }
579
[17453]580 // catch reordered arguments, make them uppercase, and switches to WMS version 1.3.0
[17328]581 String unifyWMS(String url) {
[17453]582 String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x")
583 .replaceAll("(?i)SRS=", "CRS=")
584 .replaceAll("(?i)BBOX=", "BBOX=")
585 .replaceAll("(?i)FORMAT=", "FORMAT=")
586 .replaceAll("(?i)LAYERS=", "LAYERS=")
587 .replaceAll("(?i)MAP=", "MAP=")
588 .replaceAll("(?i)REQUEST=", "REQUEST=")
589 .replaceAll("(?i)SERVICE=", "SERVICE=")
590 .replaceAll("(?i)STYLES=", "STYLES=")
591 .replaceAll("(?i)TRANSPARENT=FALSE", "TRANSPARENT=FALSE")
592 .replaceAll("(?i)TRANSPARENT=TRUE", "TRANSPARENT=TRUE")
593 .replaceAll("(?i)WIDTH=", "WIDTH=")
594 .replaceAll("(?i)HEIGHT=", "HEIGHT=")
595 .split("\\?");
[17454]596 return x[0] +"?" + Arrays.stream(x[1].split("&"))
597 .filter(s -> !s.endsWith("=")) // filter empty params
598 .sorted()
599 .collect(Collectors.joining("&"));
[17328]600 }
601
[15692]602 void checkInOneButNotTheOther() {
[15033]603 List<String> le = new LinkedList<>(eliUrls.keySet());
604 List<String> lj = new LinkedList<>(josmUrls.keySet());
[13593]605
[17453]606 for (String url : new LinkedList<>(le)) {
[15033]607 if (lj.contains(url)) {
608 le.remove(url);
609 lj.remove(url);
[13593]610 }
611 }
612
[15033]613 if (!le.isEmpty() && !lj.isEmpty()) {
[17453]614 List<String> ke = new LinkedList<>(le);
[15033]615 for (String urle : ke) {
616 JsonObject e = eliUrls.get(urle);
617 String ide = getId(e);
[15034]618 String urlhttps = urle.replace("http:", "https:");
[15033]619 if (lj.contains(urlhttps)) {
620 myprintln("+ Missing https: "+getDescription(e));
621 eliUrls.put(urlhttps, eliUrls.get(urle));
622 eliUrls.remove(urle);
623 le.remove(urle);
624 lj.remove(urlhttps);
[19375]625 } else if (!Utils.isStripEmpty(ide)) {
[17453]626 checkUrlsEquality(ide, e, urle, le, lj);
[13517]627 }
[7726]628 }
629 }
[13714]630
[15033]631 myprintln("*** URLs found in ELI but not in JOSM ("+le.size()+"): ***");
632 Collections.sort(le);
[13593]633 if (!le.isEmpty()) {
[15033]634 for (String l : le) {
[19137]635 String e = "";
[19139]636 if (idUrls.get(l) != null && rapidUrls.get(l) != null)
[19137]637 e = " **iD+Rapid**";
[19139]638 else if (idUrls.get(l) != null)
[19137]639 e = " **iD**";
[19139]640 else if (rapidUrls.get(l) != null)
[19137]641 e = " **Rapid**";
642 myprintln("- " + getDescription(eliUrls.get(l)) + e);
[11412]643 }
[7726]644 }
[15033]645 myprintln("*** URLs found in JOSM but not in ELI ("+lj.size()+"): ***");
646 Collections.sort(lj);
[13593]647 if (!lj.isEmpty()) {
[15033]648 for (String l : lj) {
649 myprintln("+ " + getDescription(josmUrls.get(l)));
[11412]650 }
[7726]651 }
652 }
[9667]653
[17453]654 void checkUrlsEquality(String ide, JsonObject e, String urle, List<String> le, List<String> lj) {
655 for (String urlj : new LinkedList<>(lj)) {
656 ImageryInfo j = josmUrls.get(urlj);
657 String idj = getId(j);
658
659 if (checkUrlEquality(ide, "id", idj, e, j, urle, urlj, le, lj)) {
660 return;
661 }
662 Collection<String> old = j.getOldIds();
663 if (old != null) {
664 for (String oidj : old) {
665 if (checkUrlEquality(ide, "oldid", oidj, e, j, urle, urlj, le, lj)) {
666 return;
667 }
668 }
669 }
670 }
671 }
672
673 boolean checkUrlEquality(
674 String ide, String idtype, String idj, JsonObject e, ImageryInfo j, String urle, String urlj, List<String> le, List<String> lj) {
675 if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
676 if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
677 myprintln("# WMS-URL for "+idtype+" "+idj+" modified: "+getDescription(j));
678 } else {
679 myprintln("* URL for "+idtype+" "+idj+" differs ("+urle+"): "+getDescription(j));
680 }
681 le.remove(urle);
682 lj.remove(urlj);
683 // replace key for this entry with JOSM URL
684 eliUrls.remove(urle);
685 eliUrls.put(urlj, e);
686 return true;
687 }
688 return false;
689 }
690
[15692]691 void checkCommonEntries() {
[15034]692 doSameUrlButDifferentName();
693 doSameUrlButDifferentId();
694 doSameUrlButDifferentType();
695 doSameUrlButDifferentZoomBounds();
696 doSameUrlButDifferentCountryCode();
697 doSameUrlButDifferentQuality();
698 doSameUrlButDifferentDates();
699 doSameUrlButDifferentInformation();
700 doMismatchingShapes();
701 doMismatchingIcons();
[15692]702 doMismatchingCategories();
[15034]703 doMiscellaneousChecks();
704 }
705
[15692]706 void doSameUrlButDifferentName() {
[15033]707 myprintln("*** Same URL, but different name: ***");
708 for (String url : eliUrls.keySet()) {
709 JsonObject e = eliUrls.get(url);
710 if (!josmUrls.containsKey(url)) continue;
711 ImageryInfo j = josmUrls.get(url);
[15034]712 String ename = getName(e).replace("'", "\u2019");
713 String jname = getName(j).replace("'", "\u2019");
[11951]714 if (!ename.equals(jname)) {
[15033]715 myprintln("* Name differs ('"+getName(e)+"' != '"+getName(j)+"'): "+getUrl(j));
[7726]716 }
717 }
[15034]718 }
[9667]719
[15692]720 void doSameUrlButDifferentId() {
[15033]721 myprintln("*** Same URL, but different Id: ***");
722 for (String url : eliUrls.keySet()) {
723 JsonObject e = eliUrls.get(url);
724 if (!josmUrls.containsKey(url)) continue;
725 ImageryInfo j = josmUrls.get(url);
726 String ename = getId(e);
727 String jname = getId(j);
728 if (!Objects.equals(ename, jname)) {
729 myprintln("# Id differs ('"+getId(e)+"' != '"+getId(j)+"'): "+getUrl(j));
[12126]730 }
[12226]731 }
[15034]732 }
[12126]733
[15692]734 void doSameUrlButDifferentType() {
[15033]735 myprintln("*** Same URL, but different type: ***");
736 for (String url : eliUrls.keySet()) {
737 JsonObject e = eliUrls.get(url);
738 if (!josmUrls.containsKey(url)) continue;
739 ImageryInfo j = josmUrls.get(url);
740 if (!Objects.equals(getType(e), getType(j))) {
741 myprintln("* Type differs ("+getType(e)+" != "+getType(j)+"): "+getName(j)+" - "+getUrl(j));
[7726]742 }
743 }
[15034]744 }
[9667]745
[15692]746 void doSameUrlButDifferentZoomBounds() {
[15033]747 myprintln("*** Same URL, but different zoom bounds: ***");
748 for (String url : eliUrls.keySet()) {
749 JsonObject e = eliUrls.get(url);
750 if (!josmUrls.containsKey(url)) continue;
751 ImageryInfo j = josmUrls.get(url);
[7726]752
[15033]753 Integer eMinZoom = getMinZoom(e);
754 Integer jMinZoom = getMinZoom(j);
[13997]755 /* dont warn for entries copied from the base of the mirror */
[15033]756 if (eMinZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
[13997]757 jMinZoom = null;
[15033]758 if (!Objects.equals(eMinZoom, jMinZoom) && !(Objects.equals(eMinZoom, 0) && jMinZoom == null)) {
759 myprintln("* Minzoom differs ("+eMinZoom+" != "+jMinZoom+"): "+getDescription(j));
[7726]760 }
[15033]761 Integer eMaxZoom = getMaxZoom(e);
762 Integer jMaxZoom = getMaxZoom(j);
[13997]763 /* dont warn for entries copied from the base of the mirror */
[15033]764 if (eMaxZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
[13997]765 jMaxZoom = null;
[15033]766 if (!Objects.equals(eMaxZoom, jMaxZoom)) {
767 myprintln("* Maxzoom differs ("+eMaxZoom+" != "+jMaxZoom+"): "+getDescription(j));
[7726]768 }
769 }
[15034]770 }
[9667]771
[15692]772 void doSameUrlButDifferentCountryCode() {
[15033]773 myprintln("*** Same URL, but different country code: ***");
774 for (String url : eliUrls.keySet()) {
775 JsonObject e = eliUrls.get(url);
776 if (!josmUrls.containsKey(url)) continue;
777 ImageryInfo j = josmUrls.get(url);
778 String cce = getCountryCode(e);
[13931]779 if ("ZZ".equals(cce)) { /* special ELI country code */
[15033]780 cce = null;
[13931]781 }
[15033]782 if (cce != null && !cce.equals(getCountryCode(j))) {
783 myprintln("* Country code differs ("+getCountryCode(e)+" != "+getCountryCode(j)+"): "+getDescription(j));
[7726]784 }
785 }
[15034]786 }
787
[15692]788 void doSameUrlButDifferentQuality() {
[15033]789 myprintln("*** Same URL, but different quality: ***");
790 for (String url : eliUrls.keySet()) {
791 JsonObject e = eliUrls.get(url);
[9515]792 if (!josmUrls.containsKey(url)) {
[15033]793 String q = getQuality(e);
794 if ("eli-best".equals(q)) {
795 myprintln("- Quality best entry not in JOSM for "+getDescription(e));
[9515]796 }
[15033]797 continue;
[9515]798 }
[15033]799 ImageryInfo j = josmUrls.get(url);
800 if (!Objects.equals(getQuality(e), getQuality(j))) {
801 myprintln("* Quality differs ("+getQuality(e)+" != "+getQuality(j)+"): "+getDescription(j));
[9505]802 }
[11599]803 }
[15034]804 }
805
[15692]806 void doSameUrlButDifferentDates() {
[15033]807 myprintln("*** Same URL, but different dates: ***");
808 Pattern pattern = Pattern.compile("^(.*;)(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?$");
809 for (String url : eliUrls.keySet()) {
810 String ed = getDate(eliUrls.get(url));
811 if (!josmUrls.containsKey(url)) continue;
812 ImageryInfo j = josmUrls.get(url);
813 String jd = getDate(j);
[11612]814 // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
[15034]815 String ef = ed.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
[11639]816 // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
[15033]817 String ed2 = ed;
818 Matcher m = pattern.matcher(ed);
819 if (m.matches()) {
820 Calendar cal = Calendar.getInstance();
[19106]821 cal.set(Integer.parseInt(m.group(2)),
822 m.group(4) == null ? 0 : Integer.parseInt(m.group(4))-1,
823 m.group(6) == null ? 1 : Integer.parseInt(m.group(6)));
[15033]824 cal.add(Calendar.DAY_OF_MONTH, -1);
825 ed2 = m.group(1) + cal.get(Calendar.YEAR);
826 if (m.group(4) != null)
827 ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1);
828 if (m.group(6) != null)
829 ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH));
[11639]830 }
[15034]831 String ef2 = ed2.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
[11639]832 if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
[15033]833 String t = "'"+ed+"'";
[11612]834 if (!ed.equals(ef)) {
[15033]835 t += " or '"+ef+"'";
[11612]836 }
[11666]837 if (jd.isEmpty()) {
[15033]838 myprintln("- Missing JOSM date ("+t+"): "+getDescription(j));
[11668]839 } else if (!ed.isEmpty()) {
[15033]840 myprintln("* Date differs ('"+t+"' != '"+jd+"'): "+getDescription(j));
841 } else if (!optionNoEli) {
842 myprintln("+ Missing ELI date ('"+jd+"'): "+getDescription(j));
[11666]843 }
[11573]844 }
[11665]845 }
[15034]846 }
847
[15692]848 void doSameUrlButDifferentInformation() {
[15033]849 myprintln("*** Same URL, but different information: ***");
850 for (String url : eliUrls.keySet()) {
851 if (!josmUrls.containsKey(url)) continue;
852 JsonObject e = eliUrls.get(url);
853 ImageryInfo j = josmUrls.get(url);
[11981]854
[15082]855 compareDescriptions(e, j);
[16127]856 comparePrivacyPolicyUrls(e, j);
[15082]857 comparePermissionReferenceUrls(e, j);
858 compareAttributionUrls(e, j);
859 compareAttributionTexts(e, j);
860 compareProjections(e, j);
861 compareDefaults(e, j);
862 compareOverlays(e, j);
863 compareNoTileHeaders(e, j);
864 }
865 }
866
[15692]867 void compareDescriptions(JsonObject e, ImageryInfo j) {
[15082]868 String et = getDescriptions(e).getOrDefault("en", "");
869 String jt = getDescriptions(j).getOrDefault("en", "");
870 if (!et.equals(jt)) {
871 if (jt.isEmpty()) {
872 myprintln("- Missing JOSM description ("+et+"): "+getDescription(j));
873 } else if (!et.isEmpty()) {
874 myprintln("* Description differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
875 } else if (!optionNoEli) {
876 myprintln("+ Missing ELI description ('"+jt+"'): "+getDescription(j));
[11981]877 }
[15082]878 }
879 }
[11981]880
[16127]881 void comparePrivacyPolicyUrls(JsonObject e, ImageryInfo j) {
882 String et = getPrivacyPolicyUrl(e);
883 String jt = getPrivacyPolicyUrl(j);
884 if (!Objects.equals(et, jt)) {
[19375]885 if (Utils.isStripEmpty(jt)) {
[16127]886 myprintln("- Missing JOSM privacy policy URL ("+et+"): "+getDescription(j));
[19375]887 } else if (!Utils.isStripEmpty(et)) {
[17053]888 myprintln("* Privacy policy URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
[16127]889 } else if (!optionNoEli) {
890 myprintln("+ Missing ELI privacy policy URL ('"+jt+"'): "+getDescription(j));
891 }
892 }
893 }
894
[15692]895 void comparePermissionReferenceUrls(JsonObject e, ImageryInfo j) {
[15082]896 String et = getPermissionReferenceUrl(e);
897 String jt = getPermissionReferenceUrl(j);
898 String jt2 = getTermsOfUseUrl(j);
[19375]899 if (Utils.isStripEmpty(jt)) jt = jt2;
[15082]900 if (!Objects.equals(et, jt)) {
[19375]901 if (Utils.isStripEmpty(jt)) {
[15082]902 myprintln("- Missing JOSM license URL ("+et+"): "+getDescription(j));
[19375]903 } else if (!Utils.isStripEmpty(et)) {
[15082]904 String ethttps = et.replace("http:", "https:");
[19375]905 if (Utils.isStripEmpty(jt2) || !(jt2.equals(ethttps) || jt2.equals(et+"/") || jt2.equals(ethttps+"/"))) {
[15082]906 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
907 myprintln("+ License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
908 } else {
909 String ja = getAttributionUrl(j);
910 if (ja != null && (ja.equals(et) || ja.equals(ethttps) || ja.equals(et+"/") || ja.equals(ethttps+"/"))) {
911 myprintln("+ ELI License URL in JOSM Attribution: "+getDescription(j));
[13578]912 } else {
[15082]913 myprintln("* License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
[13578]914 }
[13551]915 }
[11981]916 }
[15082]917 } else if (!optionNoEli) {
918 myprintln("+ Missing ELI license URL ('"+jt+"'): "+getDescription(j));
[11981]919 }
[15082]920 }
921 }
[11981]922
[15692]923 void compareAttributionUrls(JsonObject e, ImageryInfo j) {
[15082]924 String et = getAttributionUrl(e);
925 String jt = getAttributionUrl(j);
926 if (!Objects.equals(et, jt)) {
[19375]927 if (Utils.isStripEmpty(jt)) {
[15082]928 myprintln("- Missing JOSM attribution URL ("+et+"): "+getDescription(j));
[19375]929 } else if (!Utils.isStripEmpty(et)) {
[15082]930 String ethttps = et.replace("http:", "https:");
931 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
932 myprintln("+ Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
933 } else {
934 myprintln("* Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
[11981]935 }
[15082]936 } else if (!optionNoEli) {
937 myprintln("+ Missing ELI attribution URL ('"+jt+"'): "+getDescription(j));
[11981]938 }
[15082]939 }
940 }
[11981]941
[15692]942 void compareAttributionTexts(JsonObject e, ImageryInfo j) {
[15082]943 String et = getAttributionText(e);
944 String jt = getAttributionText(j);
945 if (!Objects.equals(et, jt)) {
[19375]946 if (Utils.isStripEmpty(jt)) {
[15082]947 myprintln("- Missing JOSM attribution text ("+et+"): "+getDescription(j));
[19375]948 } else if (!Utils.isStripEmpty(et)) {
[15082]949 myprintln("* Attribution text differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
950 } else if (!optionNoEli) {
951 myprintln("+ Missing ELI attribution text ('"+jt+"'): "+getDescription(j));
[11981]952 }
[15082]953 }
954 }
[11981]955
[15692]956 void compareProjections(JsonObject e, ImageryInfo j) {
[15082]957 String et = getProjections(e).stream().sorted().collect(Collectors.joining(" "));
958 String jt = getProjections(j).stream().sorted().collect(Collectors.joining(" "));
959 if (!Objects.equals(et, jt)) {
[19375]960 if (Utils.isStripEmpty(jt)) {
[15082]961 String t = getType(e);
962 if ("wms_endpoint".equals(t) || "tms".equals(t)) {
963 myprintln("+ ELI projections for type "+t+": "+getDescription(j));
964 } else {
965 myprintln("- Missing JOSM projections ("+et+"): "+getDescription(j));
[11981]966 }
[19375]967 } else if (!Utils.isStripEmpty(et)) {
[15082]968 if ("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) {
969 myprintln("+ ELI has minimal projections ('"+et+"' != '"+jt+"'): "+getDescription(j));
970 } else {
971 myprintln("* Projections differ ('"+et+"' != '"+jt+"'): "+getDescription(j));
972 }
973 } else if (!optionNoEli && !"tms".equals(getType(e))) {
974 myprintln("+ Missing ELI projections ('"+jt+"'): "+getDescription(j));
[11981]975 }
[15082]976 }
977 }
[12226]978
[15692]979 void compareDefaults(JsonObject e, ImageryInfo j) {
[15082]980 boolean ed = getDefault(e);
981 boolean jd = getDefault(j);
982 if (ed != jd) {
983 if (!jd) {
984 myprintln("- Missing JOSM default: "+getDescription(j));
985 } else if (!optionNoEli) {
986 myprintln("+ Missing ELI default: "+getDescription(j));
[12226]987 }
[15082]988 }
989 }
990
[15692]991 void compareOverlays(JsonObject e, ImageryInfo j) {
[15082]992 boolean eo = getOverlay(e);
993 boolean jo = getOverlay(j);
994 if (eo != jo) {
995 if (!jo) {
996 myprintln("- Missing JOSM overlay flag: "+getDescription(j));
997 } else if (!optionNoEli) {
998 myprintln("+ Missing ELI overlay flag: "+getDescription(j));
[13536]999 }
[11981]1000 }
[15034]1001 }
1002
[15692]1003 void compareNoTileHeaders(JsonObject e, ImageryInfo j) {
[15082]1004 Map<String, Set<String>> eh = getNoTileHeader(e);
1005 Map<String, Set<String>> jh = getNoTileHeader(j);
1006 if (!Objects.equals(eh, jh)) {
[18208]1007 if (Utils.isEmpty(jh)) {
[15082]1008 myprintln("- Missing JOSM no tile headers ("+eh+"): "+getDescription(j));
[18211]1009 } else if (!Utils.isEmpty(eh)) {
[15082]1010 myprintln("* No tile headers differ ('"+eh+"' != '"+jh+"'): "+getDescription(j));
1011 } else if (!optionNoEli) {
1012 myprintln("+ Missing ELI no tile headers ('"+jh+"'): "+getDescription(j));
1013 }
1014 }
1015 }
1016
[15692]1017 void doMismatchingShapes() {
[15033]1018 myprintln("*** Mismatching shapes: ***");
1019 for (String url : josmUrls.keySet()) {
1020 ImageryInfo j = josmUrls.get(url);
1021 int num = 1;
1022 for (Shape shape : getShapes(j)) {
1023 List<Coordinate> p = shape.getPoints();
[15034]1024 if (!p.get(0).equals(p.get(p.size()-1))) {
[18382]1025 myprintln("~~~ JOSM shape "+num+" unclosed: "+getDescription(j));
[11410]1026 }
[15033]1027 for (int nump = 1; nump < p.size(); ++nump) {
1028 if (Objects.equals(p.get(nump-1), p.get(nump))) {
[19449]1029 myprintln("~~~ JOSM shape "+num+" double point at "+(nump-1)+" ("
1030 +p.get(nump).getLat()+", "+p.get(nump).getLon()+"): "+getDescription(j));
[11964]1031 }
1032 }
[15033]1033 ++num;
[11410]1034 }
1035 }
[15033]1036 for (String url : eliUrls.keySet()) {
1037 JsonObject e = eliUrls.get(url);
1038 int num = 1;
1039 List<Shape> s = null;
[13771]1040 try {
[15033]1041 s = getShapes(e);
1042 for (Shape shape : s) {
1043 List<Coordinate> p = shape.getPoints();
[15034]1044 if (!p.get(0).equals(p.get(p.size()-1)) && !optionNoEli) {
[15033]1045 myprintln("+++ ELI shape "+num+" unclosed: "+getDescription(e));
[11964]1046 }
[15033]1047 for (int nump = 1; nump < p.size(); ++nump) {
1048 if (Objects.equals(p.get(nump-1), p.get(nump))) {
1049 myprintln("+++ ELI shape "+num+" double point at "+(nump-1)+": "+getDescription(e));
[13771]1050 }
1051 }
[15033]1052 ++num;
[11964]1053 }
[15033]1054 } catch (IllegalArgumentException err) {
1055 String desc = getDescription(e);
[17301]1056 myprintln("+++ ELI shape contains invalid data for "+desc+": "+err.getMessage());
[11410]1057 }
[13780]1058 if (s == null || !josmUrls.containsKey(url)) {
[15033]1059 continue;
[11410]1060 }
[15033]1061 ImageryInfo j = josmUrls.get(url);
1062 List<Shape> js = getShapes(j);
1063 if (s.isEmpty() && !js.isEmpty()) {
1064 if (!optionNoEli) {
1065 myprintln("+ No ELI shape: "+getDescription(j));
[11414]1066 }
[15034]1067 } else if (js.isEmpty() && !s.isEmpty()) {
[11415]1068 // don't report boundary like 5 point shapes as difference
[15033]1069 if (s.size() != 1 || s.get(0).getPoints().size() != 5) {
1070 myprintln("- No JOSM shape: "+getDescription(j));
[11415]1071 }
[15034]1072 } else if (s.size() != js.size()) {
[15033]1073 myprintln("* Different number of shapes ("+s.size()+" != "+js.size()+"): "+getDescription(j));
[11413]1074 } else {
[15033]1075 boolean[] edone = new boolean[s.size()];
1076 boolean[] jdone = new boolean[js.size()];
1077 for (int enums = 0; enums < s.size(); ++enums) {
1078 List<Coordinate> ep = s.get(enums).getPoints();
1079 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1080 List<Coordinate> jp = js.get(jnums).getPoints();
1081 if (ep.size() == jp.size() && !jdone[jnums]) {
[14576]1082 boolean err = false;
[15034]1083 for (int nump = 0; nump < ep.size() && !err; ++nump) {
[15033]1084 Coordinate ept = ep.get(nump);
1085 Coordinate jpt = jp.get(nump);
[17737]1086 if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon()))
[15033]1087 err = true;
[11413]1088 }
[15034]1089 if (!err) {
[15033]1090 edone[enums] = true;
1091 jdone[jnums] = true;
1092 break;
[14576]1093 }
[11413]1094 }
1095 }
[11411]1096 }
[15033]1097 for (int enums = 0; enums < s.size(); ++enums) {
1098 List<Coordinate> ep = s.get(enums).getPoints();
1099 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1100 List<Coordinate> jp = js.get(jnums).getPoints();
1101 if (ep.size() == jp.size() && !jdone[jnums]) {
[14576]1102 boolean err = false;
[15033]1103 for (int nump = 0; nump < ep.size() && !err; ++nump) {
1104 Coordinate ept = ep.get(nump);
1105 Coordinate jpt = jp.get(nump);
[17737]1106 if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon())) {
[15033]1107 String numtxt = Integer.toString(enums+1);
1108 if (enums != jnums) {
1109 numtxt += '/' + Integer.toString(jnums+1);
1110 }
1111 myprintln("* Different coordinate for point "+(nump+1)+" of shape "+numtxt+": "+getDescription(j));
1112 break;
[14576]1113 }
1114 }
[15033]1115 edone[enums] = true;
1116 jdone[jnums] = true;
1117 break;
[14576]1118 }
1119 }
1120 }
[15033]1121 for (int enums = 0; enums < s.size(); ++enums) {
1122 List<Coordinate> ep = s.get(enums).getPoints();
1123 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1124 List<Coordinate> jp = js.get(jnums).getPoints();
1125 if (!jdone[jnums]) {
1126 String numtxt = Integer.toString(enums+1);
1127 if (enums != jnums) {
1128 numtxt += '/' + Integer.toString(jnums+1);
1129 }
[15699]1130 myprintln("* Different number of points for shape "+numtxt+" ("+ep.size()+" ! = "+jp.size()+"): "
[15034]1131 + getDescription(j));
[15033]1132 edone[enums] = true;
1133 jdone[jnums] = true;
1134 break;
[14576]1135 }
1136 }
1137 }
[11410]1138 }
1139 }
[15034]1140 }
1141
[17737]1142 private boolean differentCoordinate(double v1, double v2) {
1143 double epsilon = 0.00001;
1144 return Math.abs(v1 - v2) > epsilon;
1145 }
1146
[15692]1147 void doMismatchingIcons() {
[15033]1148 myprintln("*** Mismatching icons: ***");
[15692]1149 doMismatching(this::compareIcons);
1150 }
1151
1152 void doMismatchingCategories() {
1153 myprintln("*** Mismatching categories: ***");
1154 doMismatching(this::compareCategories);
1155 }
1156
1157 void doMismatching(BiConsumer<ImageryInfo, JsonObject> comparator) {
[15033]1158 for (String url : eliUrls.keySet()) {
[15692]1159 if (josmUrls.containsKey(url)) {
1160 comparator.accept(josmUrls.get(url), eliUrls.get(url));
[11420]1161 }
[15692]1162 }
1163 }
1164
1165 void compareIcons(ImageryInfo j, JsonObject e) {
1166 String ij = getIcon(j);
1167 String ie = getIcon(e);
[19375]1168 boolean ijok = !Utils.isStripEmpty(ij);
1169 boolean ieok = !Utils.isStripEmpty(ie);
[15692]1170 if (ijok && !ieok) {
1171 if (!optionNoEli) {
1172 myprintln("+ No ELI icon: "+getDescription(j));
[11420]1173 }
[15692]1174 } else if (!ijok && ieok) {
1175 myprintln("- No JOSM icon: "+getDescription(j));
1176 } else if (ijok && ieok && !Objects.equals(ij, ie) && !(
1177 (ie.startsWith("https://osmlab.github.io/editor-layer-index/")
1178 || ie.startsWith("https://raw.githubusercontent.com/osmlab/editor-layer-index/")) &&
1179 ij.startsWith("data:"))) {
1180 String iehttps = ie.replace("http:", "https:");
1181 if (ij.equals(iehttps)) {
1182 myprintln("+ Different icons: "+getDescription(j));
1183 } else {
1184 myprintln("* Different icons: "+getDescription(j));
1185 }
[11420]1186 }
[15034]1187 }
1188
[15692]1189 void compareCategories(ImageryInfo j, JsonObject e) {
1190 String cj = getCategory(j);
1191 String ce = getCategory(e);
[19375]1192 boolean cjok = !Utils.isStripEmpty(cj);
1193 boolean ceok = !Utils.isStripEmpty(ce);
[15692]1194 if (cjok && !ceok) {
1195 if (!optionNoEli) {
1196 myprintln("+ No ELI category: "+getDescription(j));
1197 }
1198 } else if (!cjok && ceok) {
1199 myprintln("- No JOSM category: "+getDescription(j));
1200 } else if (cjok && ceok && !Objects.equals(cj, ce)) {
[15699]1201 myprintln("* Different categories ('"+ce+"' != '"+cj+"'): "+getDescription(j));
[15692]1202 }
1203 }
1204
1205 void doMiscellaneousChecks() {
[15033]1206 myprintln("*** Miscellaneous checks: ***");
1207 Map<String, ImageryInfo> josmIds = new HashMap<>();
1208 Collection<String> all = Projections.getAllProjectionCodes();
[13551]1209 DomainValidator dv = DomainValidator.getInstance();
[15033]1210 for (String url : josmUrls.keySet()) {
1211 ImageryInfo j = josmUrls.get(url);
1212 String id = getId(j);
1213 if ("wms".equals(getType(j))) {
1214 String urlLc = url.toLowerCase(Locale.ENGLISH);
1215 if (getProjections(j).isEmpty()) {
[18382]1216 myprintln("~ WMS without projections: "+getDescription(j));
[13526]1217 } else {
[15033]1218 List<String> unsupported = new LinkedList<>();
1219 List<String> old = new LinkedList<>();
1220 for (String p : getProjectionsUnstripped(j)) {
1221 if ("CRS:84".equals(p)) {
1222 if (!urlLc.contains("version=1.3")) {
[18382]1223 myprintln("~ CRS:84 without WMS 1.3: "+getDescription(j));
[13526]1224 }
[15033]1225 } else if (oldproj.containsKey(p)) {
1226 old.add(p);
1227 } else if (!all.contains(p) && !ignoreproj.contains(p)) {
1228 unsupported.add(p);
[13526]1229 }
1230 }
[15033]1231 if (!unsupported.isEmpty()) {
[18382]1232 myprintln("~ Projections "+String.join(", ", unsupported)+" not supported by JOSM: "+getDescription(j));
[13526]1233 }
[15033]1234 for (String o : old) {
[18382]1235 myprintln("~ Projection "+o+" is an old unsupported code and has been replaced by "+oldproj.get(o)+": "
[15034]1236 + getDescription(j));
[13527]1237 }
[13526]1238 }
[15033]1239 if (urlLc.contains("version=1.3") && !urlLc.contains("crs={proj}")) {
[18382]1240 myprintln("~ WMS 1.3 with strange CRS specification: "+getDescription(j));
[15033]1241 } else if (urlLc.contains("version=1.1") && !urlLc.contains("srs={proj}")) {
[18382]1242 myprintln("~ WMS 1.1 with strange SRS specification: "+getDescription(j));
[13526]1243 }
[13511]1244 }
[15033]1245 List<String> urls = new LinkedList<>();
1246 if (!"scanex".equals(getType(j))) {
1247 urls.add(url);
[13532]1248 }
[15033]1249 String jt = getPermissionReferenceUrl(j);
[19375]1250 if (!Utils.isStripEmpty(jt) && !"Public Domain".equalsIgnoreCase(jt))
[15033]1251 urls.add(jt);
1252 jt = getTermsOfUseUrl(j);
[19375]1253 if (!Utils.isStripEmpty(jt))
[15033]1254 urls.add(jt);
1255 jt = getAttributionUrl(j);
[19375]1256 if (!Utils.isStripEmpty(jt))
[15033]1257 urls.add(jt);
1258 jt = getIcon(j);
[19375]1259 if (!Utils.isStripEmpty(jt)) {
[15440]1260 if (!jt.startsWith("data:image/"))
[15439]1261 urls.add(jt);
1262 else {
[15440]1263 try {
1264 new ImageProvider(jt).get();
1265 } catch (RuntimeException e) {
[18382]1266 myprintln("~ Strange Icon: "+getDescription(j));
[15439]1267 }
1268 }
1269 }
[15163]1270 Pattern patternU = Pattern.compile("^https?://([^/]+?)(:\\d+)?(/.*)?");
[15033]1271 for (String u : urls) {
[15163]1272 if (!patternU.matcher(u).matches() || u.matches(".*[ \t]+$")) {
[18382]1273 myprintln("~ Strange URL '"+u+"': "+getDescription(j));
[15033]1274 } else {
[15163]1275 try {
[19106]1276 URL jurl = new URL(u.replaceAll("\\{switch:[^}]*}", "x"));
[15163]1277 String domain = jurl.getHost();
1278 int port = jurl.getPort();
1279 if (!(domain.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$")) && !dv.isValid(domain))
[18382]1280 myprintln("~ Strange Domain '"+domain+"': "+getDescription(j));
[15163]1281 else if (80 == port || 443 == port) {
[18382]1282 myprintln("~ Useless port '"+port+"': "+getDescription(j));
[15163]1283 }
1284 } catch (MalformedURLException e) {
[18382]1285 myprintln("~ Malformed URL '"+u+"': "+getDescription(j)+" => "+e.getMessage());
[13554]1286 }
[13551]1287 }
1288 }
1289
[15033]1290 if (josmMirrors.containsKey(url)) {
1291 continue;
[11420]1292 }
[19375]1293 if (Utils.isStripEmpty(id)) {
[18382]1294 myprintln("~ No JOSM-ID: "+getDescription(j));
[15033]1295 } else if (josmIds.containsKey(id)) {
[18382]1296 myprintln("~ JOSM-ID "+id+" not unique: "+getDescription(j));
[11420]1297 } else {
[15033]1298 josmIds.put(id, j);
[11420]1299 }
[15033]1300 String d = getDate(j);
[19375]1301 if (!Utils.isStripEmpty(d)) {
[15033]1302 Pattern patternD = Pattern.compile("^(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?)(;(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?))?$");
1303 Matcher m = patternD.matcher(d);
1304 if (!m.matches()) {
[18382]1305 myprintln("~ JOSM-Date '"+d+"' is strange: "+getDescription(j));
[11572]1306 } else {
1307 try {
[15033]1308 Date first = verifyDate(m.group(2), m.group(4), m.group(6));
1309 Date second = verifyDate(m.group(9), m.group(11), m.group(13));
1310 if (second.compareTo(first) < 0) {
[18382]1311 myprintln("~ JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j));
[11572]1312 }
[15034]1313 } catch (Exception e) {
[18382]1314 myprintln("~ JOSM-Date '"+d+"' is strange ("+e.getMessage()+"): "+getDescription(j));
[11572]1315 }
1316 }
[11603]1317 }
[19375]1318 if (!Utils.isStripEmpty(getAttributionUrl(j)) && Utils.isStripEmpty(getAttributionText(j))) {
[18382]1319 myprintln("~ Attribution link without text: "+getDescription(j));
[12261]1320 }
[19375]1321 if (!Utils.isStripEmpty(getLogoUrl(j)) && Utils.isStripEmpty(getLogoImage(j))) {
[18382]1322 myprintln("~ Logo link without image: "+getDescription(j));
[12261]1323 }
[19375]1324 if (!Utils.isStripEmpty(getTermsOfUseText(j)) && Utils.isStripEmpty(getTermsOfUseUrl(j))) {
[18382]1325 myprintln("~ Terms of Use text without link: "+getDescription(j));
[12261]1326 }
[15033]1327 List<Shape> js = getShapes(j);
1328 if (!js.isEmpty()) {
1329 double minlat = 1000;
1330 double minlon = 1000;
1331 double maxlat = -1000;
1332 double maxlon = -1000;
1333 for (Shape s: js) {
1334 for (Coordinate p: s.getPoints()) {
1335 double lat = p.getLat();
1336 double lon = p.getLon();
[15034]1337 if (lat > maxlat) maxlat = lat;
1338 if (lon > maxlon) maxlon = lon;
1339 if (lat < minlat) minlat = lat;
1340 if (lon < minlon) minlon = lon;
[11422]1341 }
1342 }
[15033]1343 ImageryBounds b = j.getBounds();
[17737]1344 if (differentCoordinate(b.getMinLat(), minlat)
1345 || differentCoordinate(b.getMinLon(), minlon)
1346 || differentCoordinate(b.getMaxLat(), maxlat)
1347 || differentCoordinate(b.getMaxLon(), maxlon)) {
[18382]1348 myprintln("~ Bounds do not match shape (is "+b.getMinLat()+","+b.getMinLon()+","+b.getMaxLat()+","+b.getMaxLon()
[15034]1349 + ", calculated <bounds min-lat='"+minlat+"' min-lon='"+minlon+"' max-lat='"+maxlat+"' max-lon='"+maxlon+"'>): "
1350 + getDescription(j));
[11422]1351 }
1352 }
[15658]1353 List<String> knownCategories = Arrays.asList(
1354 "photo", "elevation", "map", "historicmap", "osmbasedmap", "historicphoto", "qa", "other");
[15033]1355 String cat = getCategory(j);
[19375]1356 if (Utils.isStripEmpty(cat)) {
[18382]1357 myprintln("~ No category: "+getDescription(j));
[15033]1358 } else if (!knownCategories.contains(cat)) {
[18382]1359 myprintln("~ Strange category "+cat+": "+getDescription(j));
[13792]1360 }
[11420]1361 }
[7726]1362 }
[9667]1363
[15033]1364 /*
[7726]1365 * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
1366 */
[15033]1367
[7726]1368 static String getUrl(Object e) {
[15033]1369 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getUrl();
[19137]1370 JsonObject p = ((Map<String, JsonObject>) e).get("properties");
1371 if (p != null)
1372 return p.getString("url");
1373 else
[19139]1374 return ((JsonObject) e).getString("template");
[7726]1375 }
[15033]1376
[12242]1377 static String getUrlStripped(Object e) {
[19275]1378 return getUrl(e); //.replaceAll("\\?(apikey|access_token)=[^&?]*", "");
[12242]1379 }
[15033]1380
[11572]1381 static String getDate(Object e) {
[15033]1382 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getDate() != null ? ((ImageryInfo) e).getDate() : "";
1383 JsonObject p = ((Map<String, JsonObject>) e).get("properties");
1384 String start = p.containsKey("start_date") ? p.getString("start_date") : "";
1385 String end = p.containsKey("end_date") ? p.getString("end_date") : "";
[15034]1386 if (!start.isEmpty() && !end.isEmpty())
[15033]1387 return start+";"+end;
[15034]1388 else if (!start.isEmpty())
[15033]1389 return start+";-";
[15034]1390 else if (!end.isEmpty())
[15033]1391 return "-;"+end;
1392 return "";
[11572]1393 }
[15033]1394
1395 static Date verifyDate(String year, String month, String day) throws ParseException {
1396 String date;
[15034]1397 if (year == null) {
[15033]1398 date = "3000-01-01";
[11854]1399 } else {
[15033]1400 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day);
[11854]1401 }
[15033]1402 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
1403 df.setLenient(false);
1404 return df.parse(date);
[11572]1405 }
[15033]1406
[11420]1407 static String getId(Object e) {
[15033]1408 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getId();
1409 return ((Map<String, JsonObject>) e).get("properties").getString("id");
[11420]1410 }
[15033]1411
[7726]1412 static String getName(Object e) {
[15033]1413 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getOriginalName();
1414 return ((Map<String, JsonObject>) e).get("properties").getString("name");
[7726]1415 }
[15033]1416
1417 static List<ImageryInfo> getMirrors(Object e) {
1418 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getMirrors();
1419 return Collections.emptyList();
[11967]1420 }
[15033]1421
1422 static List<String> getProjections(Object e) {
1423 List<String> r = new ArrayList<>();
1424 List<String> u = getProjectionsUnstripped(e);
[19106]1425 for (String p : u) {
1426 if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
1427 r.add(p);
[13530]1428 }
1429 }
[15033]1430 return r;
[13530]1431 }
[15033]1432
1433 static List<String> getProjectionsUnstripped(Object e) {
1434 List<String> r = null;
[11975]1435 if (e instanceof ImageryInfo) {
[15033]1436 r = ((ImageryInfo) e).getServerProjections();
[11975]1437 } else {
[15033]1438 JsonValue s = ((Map<String, JsonObject>) e).get("properties").get("available_projections");
1439 if (s != null) {
1440 r = new ArrayList<>();
1441 for (JsonValue p : s.asJsonArray()) {
1442 r.add(((JsonString) p).getString());
[13530]1443 }
[11981]1444 }
[11975]1445 }
[15033]1446 return r != null ? r : Collections.emptyList();
[11975]1447 }
[15033]1448
[16740]1449 static void addJsonShapes(List<Shape> l, JsonArray a) {
1450 if (a.get(0).asJsonArray().get(0) instanceof JsonArray) {
1451 for (JsonValue sub: a.asJsonArray()) {
1452 addJsonShapes(l, sub.asJsonArray());
1453 }
1454 } else {
1455 Shape s = new Shape();
1456 for (JsonValue point: a.asJsonArray()) {
1457 JsonArray ar = point.asJsonArray();
1458 String lon = ar.getJsonNumber(0).toString();
1459 String lat = ar.getJsonNumber(1).toString();
1460 s.addPoint(lat, lon);
1461 }
1462 l.add(s);
1463 }
1464 }
[16750]1465
[11410]1466 static List<Shape> getShapes(Object e) {
1467 if (e instanceof ImageryInfo) {
[15033]1468 ImageryBounds bounds = ((ImageryInfo) e).getBounds();
[15034]1469 if (bounds != null) {
[15033]1470 return bounds.getShapes();
[11411]1471 }
[15033]1472 return Collections.emptyList();
[11410]1473 }
[15033]1474 JsonValue ex = ((Map<String, JsonValue>) e).get("geometry");
1475 if (ex != null && !JsonValue.NULL.equals(ex) && !ex.asJsonObject().isNull("coordinates")) {
1476 JsonArray poly = ex.asJsonObject().getJsonArray("coordinates");
1477 List<Shape> l = new ArrayList<>();
1478 for (JsonValue shapes: poly) {
[16740]1479 addJsonShapes(l, shapes.asJsonArray());
[11410]1480 }
[15033]1481 return l;
[11410]1482 }
[15033]1483 return Collections.emptyList();
[11410]1484 }
[15033]1485
[7726]1486 static String getType(Object e) {
[15033]1487 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getImageryType().getTypeString();
1488 return ((Map<String, JsonObject>) e).get("properties").getString("type");
[7726]1489 }
[15033]1490
[7726]1491 static Integer getMinZoom(Object e) {
1492 if (e instanceof ImageryInfo) {
[15033]1493 int mz = ((ImageryInfo) e).getMinZoom();
1494 return mz == 0 ? null : mz;
[7726]1495 } else {
[15033]1496 JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("min_zoom");
1497 if (num == null) return null;
1498 return num.intValue();
[7726]1499 }
1500 }
[15033]1501
[7726]1502 static Integer getMaxZoom(Object e) {
1503 if (e instanceof ImageryInfo) {
[15033]1504 int mz = ((ImageryInfo) e).getMaxZoom();
1505 return mz == 0 ? null : mz;
[7726]1506 } else {
[15033]1507 JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("max_zoom");
1508 if (num == null) return null;
1509 return num.intValue();
[7726]1510 }
1511 }
[15033]1512
[7726]1513 static String getCountryCode(Object e) {
[15033]1514 if (e instanceof ImageryInfo) return "".equals(((ImageryInfo) e).getCountryCode()) ? null : ((ImageryInfo) e).getCountryCode();
1515 return ((Map<String, JsonObject>) e).get("properties").getString("country_code", null);
[7726]1516 }
[15033]1517
[9505]1518 static String getQuality(Object e) {
[15033]1519 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isBestMarked() ? "eli-best" : null;
1520 return (((Map<String, JsonObject>) e).get("properties").containsKey("best")
1521 && ((Map<String, JsonObject>) e).get("properties").getBoolean("best")) ? "eli-best" : null;
[9505]1522 }
[15033]1523
1524 static boolean getOverlay(Object e) {
1525 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isOverlay();
1526 return (((Map<String, JsonObject>) e).get("properties").containsKey("overlay")
1527 && ((Map<String, JsonObject>) e).get("properties").getBoolean("overlay"));
[13536]1528 }
[15033]1529
[11420]1530 static String getIcon(Object e) {
[15033]1531 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getIcon();
1532 return ((Map<String, JsonObject>) e).get("properties").getString("icon", null);
[11420]1533 }
[15033]1534
[11975]1535 static String getAttributionText(Object e) {
[15033]1536 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionText(0, null, null);
1537 try {
1538 return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("text", null);
1539 } catch (NullPointerException ex) {
1540 return null;
1541 }
[11975]1542 }
[15033]1543
[11975]1544 static String getAttributionUrl(Object e) {
[15033]1545 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionLinkURL();
1546 try {
1547 return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("url", null);
1548 } catch (NullPointerException ex) {
1549 return null;
1550 }
[11975]1551 }
[15033]1552
[11975]1553 static String getTermsOfUseText(Object e) {
[15033]1554 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseText();
1555 return null;
[11975]1556 }
[15033]1557
[11975]1558 static String getTermsOfUseUrl(Object e) {
[15033]1559 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseURL();
1560 return null;
[11975]1561 }
[15033]1562
[13792]1563 static String getCategory(Object e) {
1564 if (e instanceof ImageryInfo) {
[15033]1565 return ((ImageryInfo) e).getImageryCategoryOriginalString();
[13792]1566 }
[15692]1567 return ((Map<String, JsonObject>) e).get("properties").getString("category", null);
[13792]1568 }
[15033]1569
[12261]1570 static String getLogoImage(Object e) {
[15033]1571 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageRaw();
1572 return null;
[12261]1573 }
[15033]1574
[12261]1575 static String getLogoUrl(Object e) {
[15033]1576 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageURL();
1577 return null;
[12261]1578 }
[15033]1579
[11975]1580 static String getPermissionReferenceUrl(Object e) {
[15033]1581 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPermissionReferenceURL();
1582 return ((Map<String, JsonObject>) e).get("properties").getString("license_url", null);
[11975]1583 }
[15033]1584
[16127]1585 static String getPrivacyPolicyUrl(Object e) {
1586 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPrivacyPolicyURL();
1587 return ((Map<String, JsonObject>) e).get("properties").getString("privacy_policy_url", null);
1588 }
1589
[15082]1590 static Map<String, Set<String>> getNoTileHeader(Object e) {
1591 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getNoTileHeaders();
1592 JsonObject nth = ((Map<String, JsonObject>) e).get("properties").getJsonObject("no_tile_header");
1593 return nth == null ? null : nth.keySet().stream().collect(Collectors.toMap(
1594 Function.identity(),
1595 k -> nth.getJsonArray(k).stream().map(x -> ((JsonString) x).getString()).collect(Collectors.toSet())));
1596 }
1597
[15034]1598 static Map<String, String> getDescriptions(Object e) {
[15082]1599 Map<String, String> res = new HashMap<>();
[11975]1600 if (e instanceof ImageryInfo) {
[15033]1601 String a = ((ImageryInfo) e).getDescription();
1602 if (a != null) res.put("en", a);
[11975]1603 } else {
[15033]1604 String a = ((Map<String, JsonObject>) e).get("properties").getString("description", null);
[15034]1605 if (a != null) res.put("en", a.replaceAll("''", "'"));
[11975]1606 }
[15033]1607 return res;
[11975]1608 }
[15033]1609
1610 static boolean getValidGeoreference(Object e) {
1611 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isGeoreferenceValid();
1612 return false;
[11975]1613 }
[15033]1614
1615 static boolean getDefault(Object e) {
1616 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isDefaultEntry();
1617 return ((Map<String, JsonObject>) e).get("properties").getBoolean("default", false);
[12226]1618 }
[15033]1619
[7726]1620 String getDescription(Object o) {
[15033]1621 String url = getUrl(o);
1622 String cc = getCountryCode(o);
[7726]1623 if (cc == null) {
[15033]1624 ImageryInfo j = josmUrls.get(url);
1625 if (j != null) cc = getCountryCode(j);
[7726]1626 if (cc == null) {
[15033]1627 JsonObject e = eliUrls.get(url);
1628 if (e != null) cc = getCountryCode(e);
[7726]1629 }
1630 }
1631 if (cc == null) {
[15033]1632 cc = "";
[7726]1633 } else {
[15033]1634 cc = "["+cc+"] ";
[7726]1635 }
[15878]1636 String name = getName(o);
1637 String id = getId(o);
1638 String d = cc;
[18211]1639 if (!Utils.isEmpty(name)) {
[15878]1640 d += name;
[18211]1641 if (!Utils.isEmpty(id))
[15878]1642 d += " ["+id+"]";
[18211]1643 } else if (!Utils.isEmpty(url))
[15878]1644 d += url;
[15033]1645 if (optionShorten) {
1646 if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "...";
[7726]1647 }
[15033]1648 return d;
[7726]1649 }
1650}
Note: See TracBrowser for help on using the repository browser.