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

Last change on this file since 17004 was 16750, checked in by Klumbumbus, 5 years ago

checkstyle fix

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