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

Last change on this file since 18821 was 18801, checked in by taylor.smock, 2 years ago

Fix #22832: Code cleanup and some simplification, documentation fixes (patch by gaben)

There should not be any functional changes in this patch; it is intended to do
the following:

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