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

Last change on this file since 19420 was 19375, checked in by stoecker, 9 months ago

drop commons3 usage in sync script

  • Property svn:eol-style set to native
File size: 71.9 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))) {
[18382]1029 myprintln("~~~ JOSM shape "+num+" double point at "+(nump-1)+": "+getDescription(j));
[11964]1030 }
1031 }
[15033]1032 ++num;
[11410]1033 }
1034 }
[15033]1035 for (String url : eliUrls.keySet()) {
1036 JsonObject e = eliUrls.get(url);
1037 int num = 1;
1038 List<Shape> s = null;
[13771]1039 try {
[15033]1040 s = getShapes(e);
1041 for (Shape shape : s) {
1042 List<Coordinate> p = shape.getPoints();
[15034]1043 if (!p.get(0).equals(p.get(p.size()-1)) && !optionNoEli) {
[15033]1044 myprintln("+++ ELI shape "+num+" unclosed: "+getDescription(e));
[11964]1045 }
[15033]1046 for (int nump = 1; nump < p.size(); ++nump) {
1047 if (Objects.equals(p.get(nump-1), p.get(nump))) {
1048 myprintln("+++ ELI shape "+num+" double point at "+(nump-1)+": "+getDescription(e));
[13771]1049 }
1050 }
[15033]1051 ++num;
[11964]1052 }
[15033]1053 } catch (IllegalArgumentException err) {
1054 String desc = getDescription(e);
[17301]1055 myprintln("+++ ELI shape contains invalid data for "+desc+": "+err.getMessage());
[11410]1056 }
[13780]1057 if (s == null || !josmUrls.containsKey(url)) {
[15033]1058 continue;
[11410]1059 }
[15033]1060 ImageryInfo j = josmUrls.get(url);
1061 List<Shape> js = getShapes(j);
1062 if (s.isEmpty() && !js.isEmpty()) {
1063 if (!optionNoEli) {
1064 myprintln("+ No ELI shape: "+getDescription(j));
[11414]1065 }
[15034]1066 } else if (js.isEmpty() && !s.isEmpty()) {
[11415]1067 // don't report boundary like 5 point shapes as difference
[15033]1068 if (s.size() != 1 || s.get(0).getPoints().size() != 5) {
1069 myprintln("- No JOSM shape: "+getDescription(j));
[11415]1070 }
[15034]1071 } else if (s.size() != js.size()) {
[15033]1072 myprintln("* Different number of shapes ("+s.size()+" != "+js.size()+"): "+getDescription(j));
[11413]1073 } else {
[15033]1074 boolean[] edone = new boolean[s.size()];
1075 boolean[] jdone = new boolean[js.size()];
1076 for (int enums = 0; enums < s.size(); ++enums) {
1077 List<Coordinate> ep = s.get(enums).getPoints();
1078 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1079 List<Coordinate> jp = js.get(jnums).getPoints();
1080 if (ep.size() == jp.size() && !jdone[jnums]) {
[14576]1081 boolean err = false;
[15034]1082 for (int nump = 0; nump < ep.size() && !err; ++nump) {
[15033]1083 Coordinate ept = ep.get(nump);
1084 Coordinate jpt = jp.get(nump);
[17737]1085 if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon()))
[15033]1086 err = true;
[11413]1087 }
[15034]1088 if (!err) {
[15033]1089 edone[enums] = true;
1090 jdone[jnums] = true;
1091 break;
[14576]1092 }
[11413]1093 }
1094 }
[11411]1095 }
[15033]1096 for (int enums = 0; enums < s.size(); ++enums) {
1097 List<Coordinate> ep = s.get(enums).getPoints();
1098 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1099 List<Coordinate> jp = js.get(jnums).getPoints();
1100 if (ep.size() == jp.size() && !jdone[jnums]) {
[14576]1101 boolean err = false;
[15033]1102 for (int nump = 0; nump < ep.size() && !err; ++nump) {
1103 Coordinate ept = ep.get(nump);
1104 Coordinate jpt = jp.get(nump);
[17737]1105 if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon())) {
[15033]1106 String numtxt = Integer.toString(enums+1);
1107 if (enums != jnums) {
1108 numtxt += '/' + Integer.toString(jnums+1);
1109 }
1110 myprintln("* Different coordinate for point "+(nump+1)+" of shape "+numtxt+": "+getDescription(j));
1111 break;
[14576]1112 }
1113 }
[15033]1114 edone[enums] = true;
1115 jdone[jnums] = true;
1116 break;
[14576]1117 }
1118 }
1119 }
[15033]1120 for (int enums = 0; enums < s.size(); ++enums) {
1121 List<Coordinate> ep = s.get(enums).getPoints();
1122 for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
1123 List<Coordinate> jp = js.get(jnums).getPoints();
1124 if (!jdone[jnums]) {
1125 String numtxt = Integer.toString(enums+1);
1126 if (enums != jnums) {
1127 numtxt += '/' + Integer.toString(jnums+1);
1128 }
[15699]1129 myprintln("* Different number of points for shape "+numtxt+" ("+ep.size()+" ! = "+jp.size()+"): "
[15034]1130 + getDescription(j));
[15033]1131 edone[enums] = true;
1132 jdone[jnums] = true;
1133 break;
[14576]1134 }
1135 }
1136 }
[11410]1137 }
1138 }
[15034]1139 }
1140
[17737]1141 private boolean differentCoordinate(double v1, double v2) {
1142 double epsilon = 0.00001;
1143 return Math.abs(v1 - v2) > epsilon;
1144 }
1145
[15692]1146 void doMismatchingIcons() {
[15033]1147 myprintln("*** Mismatching icons: ***");
[15692]1148 doMismatching(this::compareIcons);
1149 }
1150
1151 void doMismatchingCategories() {
1152 myprintln("*** Mismatching categories: ***");
1153 doMismatching(this::compareCategories);
1154 }
1155
1156 void doMismatching(BiConsumer<ImageryInfo, JsonObject> comparator) {
[15033]1157 for (String url : eliUrls.keySet()) {
[15692]1158 if (josmUrls.containsKey(url)) {
1159 comparator.accept(josmUrls.get(url), eliUrls.get(url));
[11420]1160 }
[15692]1161 }
1162 }
1163
1164 void compareIcons(ImageryInfo j, JsonObject e) {
1165 String ij = getIcon(j);
1166 String ie = getIcon(e);
[19375]1167 boolean ijok = !Utils.isStripEmpty(ij);
1168 boolean ieok = !Utils.isStripEmpty(ie);
[15692]1169 if (ijok && !ieok) {
1170 if (!optionNoEli) {
1171 myprintln("+ No ELI icon: "+getDescription(j));
[11420]1172 }
[15692]1173 } else if (!ijok && ieok) {
1174 myprintln("- No JOSM icon: "+getDescription(j));
1175 } else if (ijok && ieok && !Objects.equals(ij, ie) && !(
1176 (ie.startsWith("https://osmlab.github.io/editor-layer-index/")
1177 || ie.startsWith("https://raw.githubusercontent.com/osmlab/editor-layer-index/")) &&
1178 ij.startsWith("data:"))) {
1179 String iehttps = ie.replace("http:", "https:");
1180 if (ij.equals(iehttps)) {
1181 myprintln("+ Different icons: "+getDescription(j));
1182 } else {
1183 myprintln("* Different icons: "+getDescription(j));
1184 }
[11420]1185 }
[15034]1186 }
1187
[15692]1188 void compareCategories(ImageryInfo j, JsonObject e) {
1189 String cj = getCategory(j);
1190 String ce = getCategory(e);
[19375]1191 boolean cjok = !Utils.isStripEmpty(cj);
1192 boolean ceok = !Utils.isStripEmpty(ce);
[15692]1193 if (cjok && !ceok) {
1194 if (!optionNoEli) {
1195 myprintln("+ No ELI category: "+getDescription(j));
1196 }
1197 } else if (!cjok && ceok) {
1198 myprintln("- No JOSM category: "+getDescription(j));
1199 } else if (cjok && ceok && !Objects.equals(cj, ce)) {
[15699]1200 myprintln("* Different categories ('"+ce+"' != '"+cj+"'): "+getDescription(j));
[15692]1201 }
1202 }
1203
1204 void doMiscellaneousChecks() {
[15033]1205 myprintln("*** Miscellaneous checks: ***");
1206 Map<String, ImageryInfo> josmIds = new HashMap<>();
1207 Collection<String> all = Projections.getAllProjectionCodes();
[13551]1208 DomainValidator dv = DomainValidator.getInstance();
[15033]1209 for (String url : josmUrls.keySet()) {
1210 ImageryInfo j = josmUrls.get(url);
1211 String id = getId(j);
1212 if ("wms".equals(getType(j))) {
1213 String urlLc = url.toLowerCase(Locale.ENGLISH);
1214 if (getProjections(j).isEmpty()) {
[18382]1215 myprintln("~ WMS without projections: "+getDescription(j));
[13526]1216 } else {
[15033]1217 List<String> unsupported = new LinkedList<>();
1218 List<String> old = new LinkedList<>();
1219 for (String p : getProjectionsUnstripped(j)) {
1220 if ("CRS:84".equals(p)) {
1221 if (!urlLc.contains("version=1.3")) {
[18382]1222 myprintln("~ CRS:84 without WMS 1.3: "+getDescription(j));
[13526]1223 }
[15033]1224 } else if (oldproj.containsKey(p)) {
1225 old.add(p);
1226 } else if (!all.contains(p) && !ignoreproj.contains(p)) {
1227 unsupported.add(p);
[13526]1228 }
1229 }
[15033]1230 if (!unsupported.isEmpty()) {
[18382]1231 myprintln("~ Projections "+String.join(", ", unsupported)+" not supported by JOSM: "+getDescription(j));
[13526]1232 }
[15033]1233 for (String o : old) {
[18382]1234 myprintln("~ Projection "+o+" is an old unsupported code and has been replaced by "+oldproj.get(o)+": "
[15034]1235 + getDescription(j));
[13527]1236 }
[13526]1237 }
[15033]1238 if (urlLc.contains("version=1.3") && !urlLc.contains("crs={proj}")) {
[18382]1239 myprintln("~ WMS 1.3 with strange CRS specification: "+getDescription(j));
[15033]1240 } else if (urlLc.contains("version=1.1") && !urlLc.contains("srs={proj}")) {
[18382]1241 myprintln("~ WMS 1.1 with strange SRS specification: "+getDescription(j));
[13526]1242 }
[13511]1243 }
[15033]1244 List<String> urls = new LinkedList<>();
1245 if (!"scanex".equals(getType(j))) {
1246 urls.add(url);
[13532]1247 }
[15033]1248 String jt = getPermissionReferenceUrl(j);
[19375]1249 if (!Utils.isStripEmpty(jt) && !"Public Domain".equalsIgnoreCase(jt))
[15033]1250 urls.add(jt);
1251 jt = getTermsOfUseUrl(j);
[19375]1252 if (!Utils.isStripEmpty(jt))
[15033]1253 urls.add(jt);
1254 jt = getAttributionUrl(j);
[19375]1255 if (!Utils.isStripEmpty(jt))
[15033]1256 urls.add(jt);
1257 jt = getIcon(j);
[19375]1258 if (!Utils.isStripEmpty(jt)) {
[15440]1259 if (!jt.startsWith("data:image/"))
[15439]1260 urls.add(jt);
1261 else {
[15440]1262 try {
1263 new ImageProvider(jt).get();
1264 } catch (RuntimeException e) {
[18382]1265 myprintln("~ Strange Icon: "+getDescription(j));
[15439]1266 }
1267 }
1268 }
[15163]1269 Pattern patternU = Pattern.compile("^https?://([^/]+?)(:\\d+)?(/.*)?");
[15033]1270 for (String u : urls) {
[15163]1271 if (!patternU.matcher(u).matches() || u.matches(".*[ \t]+$")) {
[18382]1272 myprintln("~ Strange URL '"+u+"': "+getDescription(j));
[15033]1273 } else {
[15163]1274 try {
[19106]1275 URL jurl = new URL(u.replaceAll("\\{switch:[^}]*}", "x"));
[15163]1276 String domain = jurl.getHost();
1277 int port = jurl.getPort();
1278 if (!(domain.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$")) && !dv.isValid(domain))
[18382]1279 myprintln("~ Strange Domain '"+domain+"': "+getDescription(j));
[15163]1280 else if (80 == port || 443 == port) {
[18382]1281 myprintln("~ Useless port '"+port+"': "+getDescription(j));
[15163]1282 }
1283 } catch (MalformedURLException e) {
[18382]1284 myprintln("~ Malformed URL '"+u+"': "+getDescription(j)+" => "+e.getMessage());
[13554]1285 }
[13551]1286 }
1287 }
1288
[15033]1289 if (josmMirrors.containsKey(url)) {
1290 continue;
[11420]1291 }
[19375]1292 if (Utils.isStripEmpty(id)) {
[18382]1293 myprintln("~ No JOSM-ID: "+getDescription(j));
[15033]1294 } else if (josmIds.containsKey(id)) {
[18382]1295 myprintln("~ JOSM-ID "+id+" not unique: "+getDescription(j));
[11420]1296 } else {
[15033]1297 josmIds.put(id, j);
[11420]1298 }
[15033]1299 String d = getDate(j);
[19375]1300 if (!Utils.isStripEmpty(d)) {
[15033]1301 Pattern patternD = Pattern.compile("^(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?)(;(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?))?$");
1302 Matcher m = patternD.matcher(d);
1303 if (!m.matches()) {
[18382]1304 myprintln("~ JOSM-Date '"+d+"' is strange: "+getDescription(j));
[11572]1305 } else {
1306 try {
[15033]1307 Date first = verifyDate(m.group(2), m.group(4), m.group(6));
1308 Date second = verifyDate(m.group(9), m.group(11), m.group(13));
1309 if (second.compareTo(first) < 0) {
[18382]1310 myprintln("~ JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j));
[11572]1311 }
[15034]1312 } catch (Exception e) {
[18382]1313 myprintln("~ JOSM-Date '"+d+"' is strange ("+e.getMessage()+"): "+getDescription(j));
[11572]1314 }
1315 }
[11603]1316 }
[19375]1317 if (!Utils.isStripEmpty(getAttributionUrl(j)) && Utils.isStripEmpty(getAttributionText(j))) {
[18382]1318 myprintln("~ Attribution link without text: "+getDescription(j));
[12261]1319 }
[19375]1320 if (!Utils.isStripEmpty(getLogoUrl(j)) && Utils.isStripEmpty(getLogoImage(j))) {
[18382]1321 myprintln("~ Logo link without image: "+getDescription(j));
[12261]1322 }
[19375]1323 if (!Utils.isStripEmpty(getTermsOfUseText(j)) && Utils.isStripEmpty(getTermsOfUseUrl(j))) {
[18382]1324 myprintln("~ Terms of Use text without link: "+getDescription(j));
[12261]1325 }
[15033]1326 List<Shape> js = getShapes(j);
1327 if (!js.isEmpty()) {
1328 double minlat = 1000;
1329 double minlon = 1000;
1330 double maxlat = -1000;
1331 double maxlon = -1000;
1332 for (Shape s: js) {
1333 for (Coordinate p: s.getPoints()) {
1334 double lat = p.getLat();
1335 double lon = p.getLon();
[15034]1336 if (lat > maxlat) maxlat = lat;
1337 if (lon > maxlon) maxlon = lon;
1338 if (lat < minlat) minlat = lat;
1339 if (lon < minlon) minlon = lon;
[11422]1340 }
1341 }
[15033]1342 ImageryBounds b = j.getBounds();
[17737]1343 if (differentCoordinate(b.getMinLat(), minlat)
1344 || differentCoordinate(b.getMinLon(), minlon)
1345 || differentCoordinate(b.getMaxLat(), maxlat)
1346 || differentCoordinate(b.getMaxLon(), maxlon)) {
[18382]1347 myprintln("~ Bounds do not match shape (is "+b.getMinLat()+","+b.getMinLon()+","+b.getMaxLat()+","+b.getMaxLon()
[15034]1348 + ", calculated <bounds min-lat='"+minlat+"' min-lon='"+minlon+"' max-lat='"+maxlat+"' max-lon='"+maxlon+"'>): "
1349 + getDescription(j));
[11422]1350 }
1351 }
[15658]1352 List<String> knownCategories = Arrays.asList(
1353 "photo", "elevation", "map", "historicmap", "osmbasedmap", "historicphoto", "qa", "other");
[15033]1354 String cat = getCategory(j);
[19375]1355 if (Utils.isStripEmpty(cat)) {
[18382]1356 myprintln("~ No category: "+getDescription(j));
[15033]1357 } else if (!knownCategories.contains(cat)) {
[18382]1358 myprintln("~ Strange category "+cat+": "+getDescription(j));
[13792]1359 }
[11420]1360 }
[7726]1361 }
[9667]1362
[15033]1363 /*
[7726]1364 * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
1365 */
[15033]1366
[7726]1367 static String getUrl(Object e) {
[15033]1368 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getUrl();
[19137]1369 JsonObject p = ((Map<String, JsonObject>) e).get("properties");
1370 if (p != null)
1371 return p.getString("url");
1372 else
[19139]1373 return ((JsonObject) e).getString("template");
[7726]1374 }
[15033]1375
[12242]1376 static String getUrlStripped(Object e) {
[19275]1377 return getUrl(e); //.replaceAll("\\?(apikey|access_token)=[^&?]*", "");
[12242]1378 }
[15033]1379
[11572]1380 static String getDate(Object e) {
[15033]1381 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getDate() != null ? ((ImageryInfo) e).getDate() : "";
1382 JsonObject p = ((Map<String, JsonObject>) e).get("properties");
1383 String start = p.containsKey("start_date") ? p.getString("start_date") : "";
1384 String end = p.containsKey("end_date") ? p.getString("end_date") : "";
[15034]1385 if (!start.isEmpty() && !end.isEmpty())
[15033]1386 return start+";"+end;
[15034]1387 else if (!start.isEmpty())
[15033]1388 return start+";-";
[15034]1389 else if (!end.isEmpty())
[15033]1390 return "-;"+end;
1391 return "";
[11572]1392 }
[15033]1393
1394 static Date verifyDate(String year, String month, String day) throws ParseException {
1395 String date;
[15034]1396 if (year == null) {
[15033]1397 date = "3000-01-01";
[11854]1398 } else {
[15033]1399 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day);
[11854]1400 }
[15033]1401 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
1402 df.setLenient(false);
1403 return df.parse(date);
[11572]1404 }
[15033]1405
[11420]1406 static String getId(Object e) {
[15033]1407 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getId();
1408 return ((Map<String, JsonObject>) e).get("properties").getString("id");
[11420]1409 }
[15033]1410
[7726]1411 static String getName(Object e) {
[15033]1412 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getOriginalName();
1413 return ((Map<String, JsonObject>) e).get("properties").getString("name");
[7726]1414 }
[15033]1415
1416 static List<ImageryInfo> getMirrors(Object e) {
1417 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getMirrors();
1418 return Collections.emptyList();
[11967]1419 }
[15033]1420
1421 static List<String> getProjections(Object e) {
1422 List<String> r = new ArrayList<>();
1423 List<String> u = getProjectionsUnstripped(e);
[19106]1424 for (String p : u) {
1425 if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
1426 r.add(p);
[13530]1427 }
1428 }
[15033]1429 return r;
[13530]1430 }
[15033]1431
1432 static List<String> getProjectionsUnstripped(Object e) {
1433 List<String> r = null;
[11975]1434 if (e instanceof ImageryInfo) {
[15033]1435 r = ((ImageryInfo) e).getServerProjections();
[11975]1436 } else {
[15033]1437 JsonValue s = ((Map<String, JsonObject>) e).get("properties").get("available_projections");
1438 if (s != null) {
1439 r = new ArrayList<>();
1440 for (JsonValue p : s.asJsonArray()) {
1441 r.add(((JsonString) p).getString());
[13530]1442 }
[11981]1443 }
[11975]1444 }
[15033]1445 return r != null ? r : Collections.emptyList();
[11975]1446 }
[15033]1447
[16740]1448 static void addJsonShapes(List<Shape> l, JsonArray a) {
1449 if (a.get(0).asJsonArray().get(0) instanceof JsonArray) {
1450 for (JsonValue sub: a.asJsonArray()) {
1451 addJsonShapes(l, sub.asJsonArray());
1452 }
1453 } else {
1454 Shape s = new Shape();
1455 for (JsonValue point: a.asJsonArray()) {
1456 JsonArray ar = point.asJsonArray();
1457 String lon = ar.getJsonNumber(0).toString();
1458 String lat = ar.getJsonNumber(1).toString();
1459 s.addPoint(lat, lon);
1460 }
1461 l.add(s);
1462 }
1463 }
[16750]1464
[11410]1465 static List<Shape> getShapes(Object e) {
1466 if (e instanceof ImageryInfo) {
[15033]1467 ImageryBounds bounds = ((ImageryInfo) e).getBounds();
[15034]1468 if (bounds != null) {
[15033]1469 return bounds.getShapes();
[11411]1470 }
[15033]1471 return Collections.emptyList();
[11410]1472 }
[15033]1473 JsonValue ex = ((Map<String, JsonValue>) e).get("geometry");
1474 if (ex != null && !JsonValue.NULL.equals(ex) && !ex.asJsonObject().isNull("coordinates")) {
1475 JsonArray poly = ex.asJsonObject().getJsonArray("coordinates");
1476 List<Shape> l = new ArrayList<>();
1477 for (JsonValue shapes: poly) {
[16740]1478 addJsonShapes(l, shapes.asJsonArray());
[11410]1479 }
[15033]1480 return l;
[11410]1481 }
[15033]1482 return Collections.emptyList();
[11410]1483 }
[15033]1484
[7726]1485 static String getType(Object e) {
[15033]1486 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getImageryType().getTypeString();
1487 return ((Map<String, JsonObject>) e).get("properties").getString("type");
[7726]1488 }
[15033]1489
[7726]1490 static Integer getMinZoom(Object e) {
1491 if (e instanceof ImageryInfo) {
[15033]1492 int mz = ((ImageryInfo) e).getMinZoom();
1493 return mz == 0 ? null : mz;
[7726]1494 } else {
[15033]1495 JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("min_zoom");
1496 if (num == null) return null;
1497 return num.intValue();
[7726]1498 }
1499 }
[15033]1500
[7726]1501 static Integer getMaxZoom(Object e) {
1502 if (e instanceof ImageryInfo) {
[15033]1503 int mz = ((ImageryInfo) e).getMaxZoom();
1504 return mz == 0 ? null : mz;
[7726]1505 } else {
[15033]1506 JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("max_zoom");
1507 if (num == null) return null;
1508 return num.intValue();
[7726]1509 }
1510 }
[15033]1511
[7726]1512 static String getCountryCode(Object e) {
[15033]1513 if (e instanceof ImageryInfo) return "".equals(((ImageryInfo) e).getCountryCode()) ? null : ((ImageryInfo) e).getCountryCode();
1514 return ((Map<String, JsonObject>) e).get("properties").getString("country_code", null);
[7726]1515 }
[15033]1516
[9505]1517 static String getQuality(Object e) {
[15033]1518 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isBestMarked() ? "eli-best" : null;
1519 return (((Map<String, JsonObject>) e).get("properties").containsKey("best")
1520 && ((Map<String, JsonObject>) e).get("properties").getBoolean("best")) ? "eli-best" : null;
[9505]1521 }
[15033]1522
1523 static boolean getOverlay(Object e) {
1524 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isOverlay();
1525 return (((Map<String, JsonObject>) e).get("properties").containsKey("overlay")
1526 && ((Map<String, JsonObject>) e).get("properties").getBoolean("overlay"));
[13536]1527 }
[15033]1528
[11420]1529 static String getIcon(Object e) {
[15033]1530 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getIcon();
1531 return ((Map<String, JsonObject>) e).get("properties").getString("icon", null);
[11420]1532 }
[15033]1533
[11975]1534 static String getAttributionText(Object e) {
[15033]1535 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionText(0, null, null);
1536 try {
1537 return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("text", null);
1538 } catch (NullPointerException ex) {
1539 return null;
1540 }
[11975]1541 }
[15033]1542
[11975]1543 static String getAttributionUrl(Object e) {
[15033]1544 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionLinkURL();
1545 try {
1546 return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("url", null);
1547 } catch (NullPointerException ex) {
1548 return null;
1549 }
[11975]1550 }
[15033]1551
[11975]1552 static String getTermsOfUseText(Object e) {
[15033]1553 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseText();
1554 return null;
[11975]1555 }
[15033]1556
[11975]1557 static String getTermsOfUseUrl(Object e) {
[15033]1558 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseURL();
1559 return null;
[11975]1560 }
[15033]1561
[13792]1562 static String getCategory(Object e) {
1563 if (e instanceof ImageryInfo) {
[15033]1564 return ((ImageryInfo) e).getImageryCategoryOriginalString();
[13792]1565 }
[15692]1566 return ((Map<String, JsonObject>) e).get("properties").getString("category", null);
[13792]1567 }
[15033]1568
[12261]1569 static String getLogoImage(Object e) {
[15033]1570 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageRaw();
1571 return null;
[12261]1572 }
[15033]1573
[12261]1574 static String getLogoUrl(Object e) {
[15033]1575 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageURL();
1576 return null;
[12261]1577 }
[15033]1578
[11975]1579 static String getPermissionReferenceUrl(Object e) {
[15033]1580 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPermissionReferenceURL();
1581 return ((Map<String, JsonObject>) e).get("properties").getString("license_url", null);
[11975]1582 }
[15033]1583
[16127]1584 static String getPrivacyPolicyUrl(Object e) {
1585 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPrivacyPolicyURL();
1586 return ((Map<String, JsonObject>) e).get("properties").getString("privacy_policy_url", null);
1587 }
1588
[15082]1589 static Map<String, Set<String>> getNoTileHeader(Object e) {
1590 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getNoTileHeaders();
1591 JsonObject nth = ((Map<String, JsonObject>) e).get("properties").getJsonObject("no_tile_header");
1592 return nth == null ? null : nth.keySet().stream().collect(Collectors.toMap(
1593 Function.identity(),
1594 k -> nth.getJsonArray(k).stream().map(x -> ((JsonString) x).getString()).collect(Collectors.toSet())));
1595 }
1596
[15034]1597 static Map<String, String> getDescriptions(Object e) {
[15082]1598 Map<String, String> res = new HashMap<>();
[11975]1599 if (e instanceof ImageryInfo) {
[15033]1600 String a = ((ImageryInfo) e).getDescription();
1601 if (a != null) res.put("en", a);
[11975]1602 } else {
[15033]1603 String a = ((Map<String, JsonObject>) e).get("properties").getString("description", null);
[15034]1604 if (a != null) res.put("en", a.replaceAll("''", "'"));
[11975]1605 }
[15033]1606 return res;
[11975]1607 }
[15033]1608
1609 static boolean getValidGeoreference(Object e) {
1610 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isGeoreferenceValid();
1611 return false;
[11975]1612 }
[15033]1613
1614 static boolean getDefault(Object e) {
1615 if (e instanceof ImageryInfo) return ((ImageryInfo) e).isDefaultEntry();
1616 return ((Map<String, JsonObject>) e).get("properties").getBoolean("default", false);
[12226]1617 }
[15033]1618
[7726]1619 String getDescription(Object o) {
[15033]1620 String url = getUrl(o);
1621 String cc = getCountryCode(o);
[7726]1622 if (cc == null) {
[15033]1623 ImageryInfo j = josmUrls.get(url);
1624 if (j != null) cc = getCountryCode(j);
[7726]1625 if (cc == null) {
[15033]1626 JsonObject e = eliUrls.get(url);
1627 if (e != null) cc = getCountryCode(e);
[7726]1628 }
1629 }
1630 if (cc == null) {
[15033]1631 cc = "";
[7726]1632 } else {
[15033]1633 cc = "["+cc+"] ";
[7726]1634 }
[15878]1635 String name = getName(o);
1636 String id = getId(o);
1637 String d = cc;
[18211]1638 if (!Utils.isEmpty(name)) {
[15878]1639 d += name;
[18211]1640 if (!Utils.isEmpty(id))
[15878]1641 d += " ["+id+"]";
[18211]1642 } else if (!Utils.isEmpty(url))
[15878]1643 d += url;
[15033]1644 if (optionShorten) {
1645 if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "...";
[7726]1646 }
[15033]1647 return d;
[7726]1648 }
1649}
Note: See TracBrowser for help on using the repository browser.