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