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

Last change on this file since 18327 was 18211, checked in by Don-vip, 3 years ago

global use of !Utils.isEmpty/isBlank

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