source: josm/trunk/scripts/TagInfoExtract.java@ 17977

Last change on this file since 17977 was 17977, checked in by Don-vip, 5 years ago

fix #21079 - TagInfo: group required tags too

File size: 27.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2import java.awt.Graphics2D;
3import java.awt.image.BufferedImage;
4import java.io.BufferedReader;
5import java.io.IOException;
6import java.io.OutputStream;
7import java.io.StringWriter;
8import java.io.UncheckedIOException;
9import java.io.Writer;
10import java.nio.file.Files;
11import java.nio.file.Path;
12import java.nio.file.Paths;
13import java.time.Instant;
14import java.time.ZoneId;
15import java.time.format.DateTimeFormatter;
16import java.util.ArrayList;
17import java.util.Arrays;
18import java.util.Collection;
19import java.util.Collections;
20import java.util.EnumSet;
21import java.util.LinkedHashMap;
22import java.util.List;
23import java.util.Locale;
24import java.util.Map;
25import java.util.Optional;
26import java.util.Set;
27import java.util.regex.Matcher;
28import java.util.regex.Pattern;
29import java.util.stream.Collectors;
30import java.util.stream.Stream;
31
32import javax.imageio.ImageIO;
33import javax.json.Json;
34import javax.json.JsonArrayBuilder;
35import javax.json.JsonObjectBuilder;
36import javax.json.JsonWriter;
37import javax.json.stream.JsonGenerator;
38
39import org.openstreetmap.josm.actions.DeleteAction;
40import org.openstreetmap.josm.command.DeleteCommand;
41import org.openstreetmap.josm.data.Preferences;
42import org.openstreetmap.josm.data.Version;
43import org.openstreetmap.josm.data.coor.LatLon;
44import org.openstreetmap.josm.data.osm.Node;
45import org.openstreetmap.josm.data.osm.OsmPrimitive;
46import org.openstreetmap.josm.data.osm.Tag;
47import org.openstreetmap.josm.data.osm.Way;
48import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
49import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
50import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
51import org.openstreetmap.josm.data.preferences.JosmUrls;
52import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
53import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
54import org.openstreetmap.josm.data.projection.ProjectionRegistry;
55import org.openstreetmap.josm.data.projection.Projections;
56import org.openstreetmap.josm.gui.NavigatableComponent;
57import org.openstreetmap.josm.gui.mappaint.Cascade;
58import org.openstreetmap.josm.gui.mappaint.Environment;
59import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
60import org.openstreetmap.josm.gui.mappaint.MultiCascade;
61import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory;
62import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
63import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
64import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
65import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
66import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
67import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement;
68import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
69import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
70import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
71import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
72import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
73import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup;
74import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
75import org.openstreetmap.josm.io.CachedFile;
76import org.openstreetmap.josm.io.OsmTransferException;
77import org.openstreetmap.josm.spi.preferences.Config;
78import org.openstreetmap.josm.tools.Http1Client;
79import org.openstreetmap.josm.tools.HttpClient;
80import org.openstreetmap.josm.tools.Logging;
81import org.openstreetmap.josm.tools.OptionParser;
82import org.openstreetmap.josm.tools.Territories;
83import org.openstreetmap.josm.tools.Utils;
84import org.xml.sax.SAXException;
85
86/**
87 * Extracts tag information for the taginfo project.
88 * <p>
89 * Run from the base directory of a JOSM checkout:
90 * <p>
91 * java -cp dist/josm-custom.jar TagInfoExtract --type mappaint
92 * java -cp dist/josm-custom.jar TagInfoExtract --type presets
93 * java -cp dist/josm-custom.jar TagInfoExtract --type external_presets
94 */
95public class TagInfoExtract {
96
97 /**
98 * Main method.
99 * @param args Main program arguments
100 * @throws Exception if any error occurs
101 */
102 public static void main(String[] args) throws Exception {
103 HttpClient.setFactory(Http1Client::new);
104 TagInfoExtract script = new TagInfoExtract();
105 script.parseCommandLineArguments(args);
106 script.init();
107 switch (script.options.mode) {
108 case MAPPAINT:
109 script.new StyleSheet().run();
110 break;
111 case PRESETS:
112 script.new Presets().run();
113 break;
114 case EXTERNAL_PRESETS:
115 script.new ExternalPresets().run();
116 break;
117 default:
118 throw new IllegalStateException("Invalid type " + script.options.mode);
119 }
120 if (!script.options.noexit) {
121 System.exit(0);
122 }
123 }
124
125 enum Mode {
126 MAPPAINT, PRESETS, EXTERNAL_PRESETS
127 }
128
129 private final Options options = new Options();
130
131 /**
132 * Parse command line arguments.
133 * @param args command line arguments
134 */
135 private void parseCommandLineArguments(String[] args) {
136 if (args.length == 1 && "--help".equals(args[0])) {
137 this.usage();
138 }
139 final OptionParser parser = new OptionParser(getClass().getName());
140 parser.addArgumentParameter("type", OptionParser.OptionCount.REQUIRED, options::setMode);
141 parser.addArgumentParameter("input", OptionParser.OptionCount.OPTIONAL, options::setInputFile);
142 parser.addArgumentParameter("output", OptionParser.OptionCount.OPTIONAL, options::setOutputFile);
143 parser.addArgumentParameter("imgdir", OptionParser.OptionCount.OPTIONAL, options::setImageDir);
144 parser.addArgumentParameter("imgurlprefix", OptionParser.OptionCount.OPTIONAL, options::setImageUrlPrefix);
145 parser.addFlagParameter("noexit", options::setNoExit);
146 parser.addFlagParameter("help", this::usage);
147 parser.parseOptionsOrExit(Arrays.asList(args));
148 }
149
150 private void usage() {
151 System.out.println("java " + getClass().getName());
152 System.out.println(" --type TYPE\tthe project type to be generated: " + Arrays.toString(Mode.values()));
153 System.out.println(" --input FILE\tthe input file to use (overrides defaults for types mappaint, presets)");
154 System.out.println(" --output FILE\tthe output file to use (defaults to STDOUT)");
155 System.out.println(" --imgdir DIRECTORY\tthe directory to put the generated images in (default: " + options.imageDir + ")");
156 System.out.println(" --imgurlprefix STRING\timage URLs prefix for generated image files (public path on webserver)");
157 System.out.println(" --noexit\tdo not call System.exit(), for use from Ant script");
158 System.out.println(" --help\tshow this help");
159 System.exit(0);
160 }
161
162 private static class Options {
163 Mode mode;
164 int josmSvnRevision = Version.getInstance().getVersion();
165 Path baseDir = Paths.get("");
166 Path imageDir = Paths.get("taginfo-img");
167 String imageUrlPrefix;
168 CachedFile inputFile;
169 Path outputFile;
170 boolean noexit;
171
172 void setMode(String value) {
173 mode = Mode.valueOf(value.toUpperCase(Locale.ENGLISH));
174 switch (mode) {
175 case MAPPAINT:
176 inputFile = new CachedFile("resource://styles/standard/elemstyles.mapcss");
177 break;
178 case PRESETS:
179 inputFile = new CachedFile("resource://data/defaultpresets.xml");
180 break;
181 default:
182 inputFile = null;
183 }
184 }
185
186 void setInputFile(String value) {
187 inputFile = new CachedFile(value);
188 }
189
190 void setOutputFile(String value) {
191 outputFile = Paths.get(value);
192 }
193
194 void setImageDir(String value) {
195 imageDir = Paths.get(value);
196 }
197
198 void setImageUrlPrefix(String value) {
199 imageUrlPrefix = value;
200 }
201
202 void setNoExit() {
203 noexit = true;
204 }
205
206 /**
207 * Determine full image url (can refer to JOSM or OSM repository).
208 * @param path the image path
209 * @return full image url
210 */
211 private String findImageUrl(String path) {
212 final Path f = baseDir.resolve("resources").resolve("images").resolve(path);
213 if (Files.exists(f)) {
214 return "https://josm.openstreetmap.de/export/" + josmSvnRevision + "/josm/trunk/resources/images/" + path;
215 }
216 throw new IllegalStateException("Cannot find image url for " + path);
217 }
218 }
219
220 private abstract class Extractor {
221 abstract void run() throws Exception;
222
223 void writeJson(String name, String description, Iterable<TagInfoTag> tags) throws IOException {
224 try (Writer writer = options.outputFile != null ? Files.newBufferedWriter(options.outputFile) : new StringWriter();
225 JsonWriter json = Json
226 .createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true))
227 .createWriter(writer)) {
228 JsonObjectBuilder project = Json.createObjectBuilder()
229 .add("name", name)
230 .add("description", description)
231 .add("project_url", JosmUrls.getInstance().getJOSMWebsite())
232 .add("icon_url", options.findImageUrl("logo_16x16x8.png"))
233 .add("contact_name", "JOSM developer team")
234 .add("contact_email", "josm-dev@openstreetmap.org");
235 final JsonArrayBuilder jsonTags = Json.createArrayBuilder();
236 for (TagInfoTag t : tags) {
237 jsonTags.add(t.toJson());
238 }
239 json.writeObject(Json.createObjectBuilder()
240 .add("data_format", 1)
241 .add("data_updated", DateTimeFormatter.ofPattern("yyyyMMdd'T'hhmmss'Z'").withZone(ZoneId.of("Z")).format(Instant.now()))
242 .add("project", project)
243 .add("tags", jsonTags)
244 .build());
245 if (options.outputFile == null) {
246 System.out.println(writer.toString());
247 }
248 }
249 }
250 }
251
252 private class Presets extends Extractor {
253
254 @Override
255 void run() throws IOException, OsmTransferException, SAXException {
256 try (BufferedReader reader = options.inputFile.getContentReader()) {
257 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(reader, true);
258 List<TagInfoTag> tags = convertPresets(presets, "", true);
259 Logging.info("Converting {0} internal presets", tags.size());
260 writeJson("JOSM main presets", "Tags supported by the default presets in the OSM editor JOSM", tags);
261 }
262 }
263
264 List<TagInfoTag> convertPresets(Iterable<TaggingPreset> presets, String descriptionPrefix, boolean addImages) {
265 final List<TagInfoTag> tags = new ArrayList<>();
266 final Map<Tag, TagInfoTag> requiredTags = new LinkedHashMap<>();
267 final Map<Tag, TagInfoTag> optionalTags = new LinkedHashMap<>();
268 for (TaggingPreset preset : presets) {
269 preset.data.stream()
270 .flatMap(item -> item instanceof KeyedItem
271 ? Stream.of(((KeyedItem) item))
272 : item instanceof CheckGroup
273 ? ((CheckGroup) item).checks.stream()
274 : Stream.empty())
275 .forEach(item -> {
276 for (String value : values(item)) {
277 Set<TagInfoTag.Type> types = TagInfoTag.Type.forPresetTypes(preset.types);
278 if (item.isKeyRequired()) {
279 fillTagsMap(requiredTags, item, value, preset.getName(), types,
280 descriptionPrefix + TagInfoTag.REQUIRED_FOR_COUNT + ": ",
281 addImages && preset.iconName != null ? options.findImageUrl(preset.iconName) : null);
282 } else if (Presets.class.equals(getClass())) { // not for ExternalPresets
283 fillTagsMap(optionalTags, item, value, preset.getName(), types,
284 descriptionPrefix + TagInfoTag.OPTIONAL_FOR_COUNT + ": ", null);
285 }
286 }
287 });
288 }
289 tags.addAll(requiredTags.values());
290 tags.addAll(optionalTags.values());
291 return tags;
292 }
293
294 private void fillTagsMap(Map<Tag, TagInfoTag> optionalTags, KeyedItem item, String value, String presetName, Set<TagInfoTag.Type> types, String descriptionPrefix, String iconUrl) {
295 optionalTags.compute(new Tag(item.key, value), (osmTag, tagInfoTag) -> {
296 if (tagInfoTag == null) {
297 return new TagInfoTag(descriptionPrefix + presetName, item.key, value, types, iconUrl);
298 } else {
299 tagInfoTag.descriptions.add(presetName);
300 tagInfoTag.objectTypes.addAll(types);
301 return tagInfoTag;
302 }
303 });
304 }
305
306 private Collection<String> values(KeyedItem item) {
307 final Collection<String> values = item.getValues();
308 return values.isEmpty() || values.size() > 50 ? Collections.singleton(null) : values;
309 }
310 }
311
312 private class ExternalPresets extends Presets {
313
314 @Override
315 void run() throws IOException, OsmTransferException, SAXException {
316 TaggingPresetReader.setLoadIcons(false);
317 final Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor().loadAndGetAvailableSources();
318 final List<TagInfoTag> tags = new ArrayList<>();
319 for (SourceEntry source : sources) {
320 if (source.url.startsWith("resource")) {
321 // default presets
322 continue;
323 }
324 try {
325 Logging.info("Loading {0}", source.url);
326 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, false);
327 final List<TagInfoTag> t = convertPresets(presets, source.title + " ", false);
328 Logging.info("Converting {0} presets of {1}", t.size(), source.title);
329 tags.addAll(t);
330 } catch (Exception ex) {
331 Logging.warn("Skipping {0} due to error", source.url);
332 Logging.warn(ex);
333 }
334 }
335 writeJson("JOSM user presets", "Tags supported by the user contributed presets in the OSM editor JOSM", tags);
336 }
337 }
338
339 private class StyleSheet extends Extractor {
340 private MapCSSStyleSource styleSource;
341
342 @Override
343 void run() throws IOException, ParseException {
344 init();
345 parseStyleSheet();
346 final List<TagInfoTag> tags = convertStyleSheet();
347 writeJson("JOSM main mappaint style", "Tags supported by the main mappaint style in the OSM editor JOSM", tags);
348 }
349
350 /**
351 * Read the style sheet file and parse the MapCSS code.
352 * @throws IOException if any I/O error occurs
353 * @throws ParseException in case of parsing error
354 */
355 private void parseStyleSheet() throws IOException, ParseException {
356 try (BufferedReader reader = options.inputFile.getContentReader()) {
357 MapCSSParser parser = new MapCSSParser(reader, MapCSSParser.LexicalState.DEFAULT);
358 styleSource = new MapCSSStyleSource("");
359 styleSource.url = "";
360 parser.sheet(styleSource);
361 }
362 }
363
364 /**
365 * Collect all the tag from the style sheet.
366 * @return list of taginfo tags
367 */
368 private List<TagInfoTag> convertStyleSheet() {
369 return styleSource.rules.stream()
370 .flatMap(rule -> rule.selectors.stream())
371 .flatMap(selector -> selector.getConditions().stream())
372 .filter(ConditionFactory.SimpleKeyValueCondition.class::isInstance)
373 .map(ConditionFactory.SimpleKeyValueCondition.class::cast)
374 .map(condition -> condition.asTag(null))
375 .distinct()
376 .map(tag -> {
377 String iconUrl = null;
378 final EnumSet<TagInfoTag.Type> types = EnumSet.noneOf(TagInfoTag.Type.class);
379 Optional<String> nodeUrl = new NodeChecker(tag).findUrl(true);
380 if (nodeUrl.isPresent()) {
381 iconUrl = nodeUrl.get();
382 types.add(TagInfoTag.Type.NODE);
383 }
384 Optional<String> wayUrl = new WayChecker(tag).findUrl(iconUrl == null);
385 if (wayUrl.isPresent()) {
386 if (iconUrl == null) {
387 iconUrl = wayUrl.get();
388 }
389 types.add(TagInfoTag.Type.WAY);
390 }
391 Optional<String> areaUrl = new AreaChecker(tag).findUrl(iconUrl == null);
392 if (areaUrl.isPresent()) {
393 if (iconUrl == null) {
394 iconUrl = areaUrl.get();
395 }
396 types.add(TagInfoTag.Type.AREA);
397 }
398 return new TagInfoTag(null, tag.getKey(), tag.getValue(), types, iconUrl);
399 })
400 .collect(Collectors.toList());
401 }
402
403 /**
404 * Check if a certain tag is supported by the style as node / way / area.
405 */
406 private abstract class Checker {
407 private final Pattern reservedChars = Pattern.compile("[<>:\"|\\?\\*]");
408
409 Checker(Tag tag) {
410 this.tag = tag;
411 }
412
413 Environment applyStylesheet(OsmPrimitive osm) {
414 osm.put(tag);
415 MultiCascade mc = new MultiCascade();
416
417 Environment env = new Environment(osm, mc, null, styleSource);
418 for (MapCSSRule r : styleSource.rules) {
419 env.clearSelectorMatchingInformation();
420 if (r.matches(env)) {
421 // ignore selector range
422 if (env.layer == null) {
423 env.layer = "default";
424 }
425 r.execute(env);
426 }
427 }
428 env.layer = "default";
429 return env;
430 }
431
432 /**
433 * Create image file from StyleElement.
434 * @param element style element
435 * @param type object type
436 * @param nc navigable component
437 *
438 * @return the URL
439 */
440 String createImage(StyleElement element, final String type, NavigatableComponent nc) {
441 BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
442 Graphics2D g = img.createGraphics();
443 g.setClip(0, 0, 16, 16);
444 StyledMapRenderer renderer = new StyledMapRenderer(g, nc, false);
445 renderer.getSettings(false);
446 element.paintPrimitive(osm, MapPaintSettings.INSTANCE, renderer, false, false, false);
447 final String imageName = type + "_" + normalize(tag.toString()) + ".png";
448 try (OutputStream out = Files.newOutputStream(options.imageDir.resolve(imageName))) {
449 ImageIO.write(img, "png", out);
450 } catch (IOException e) {
451 throw new UncheckedIOException(e);
452 }
453 final String baseUrl = options.imageUrlPrefix != null ? options.imageUrlPrefix : options.imageDir.toString();
454 return baseUrl + "/" + imageName;
455 }
456
457 /**
458 * Normalizes tag so that it can used as a filename on all platforms, including Windows.
459 * @param tag OSM tag, that can contain illegal path characters
460 * @return OSM tag with all illegal path characters replaced by underscore ('_')
461 */
462 String normalize(String tag) {
463 Matcher m = reservedChars.matcher(tag);
464 return m.find() ? m.replaceAll("_") : tag;
465 }
466
467 /**
468 * Checks, if tag is supported and find URL for image icon in this case.
469 *
470 * @param generateImage if true, create or find a suitable image icon and return URL,
471 * if false, just check if tag is supported and return true or false
472 * @return URL for image icon if tag is supported
473 */
474 abstract Optional<String> findUrl(boolean generateImage);
475
476 protected Tag tag;
477 protected OsmPrimitive osm;
478 }
479
480 private class NodeChecker extends Checker {
481 NodeChecker(Tag tag) {
482 super(tag);
483 }
484
485 @Override
486 Optional<String> findUrl(boolean generateImage) {
487 this.osm = new Node(LatLon.ZERO);
488 Environment env = applyStylesheet(osm);
489 Cascade c = env.getCascade("default");
490 Object image = c.get("icon-image");
491 if (image instanceof MapPaintStyles.IconReference && !((MapPaintStyles.IconReference) image).isDeprecatedIcon()) {
492 return Optional.of(options.findImageUrl(((MapPaintStyles.IconReference) image).iconName));
493 }
494 return Optional.empty();
495 }
496 }
497
498 private class WayChecker extends Checker {
499 WayChecker(Tag tag) {
500 super(tag);
501 }
502
503 @Override
504 Optional<String> findUrl(boolean generateImage) {
505 this.osm = new Way();
506 NavigatableComponent nc = new NavigatableComponent();
507 Node n1 = new Node(nc.getLatLon(2, 8));
508 Node n2 = new Node(nc.getLatLon(14, 8));
509 ((Way) osm).addNode(n1);
510 ((Way) osm).addNode(n2);
511 Environment env = applyStylesheet(osm);
512 LineElement les = LineElement.createLine(env);
513 if (les != null) {
514 return Optional.of(generateImage ? createImage(les, "way", nc) : "");
515 }
516 return Optional.empty();
517 }
518 }
519
520 private class AreaChecker extends Checker {
521 AreaChecker(Tag tag) {
522 super(tag);
523 }
524
525 @Override
526 Optional<String> findUrl(boolean generateImage) {
527 this.osm = new Way();
528 NavigatableComponent nc = new NavigatableComponent();
529 Node n1 = new Node(nc.getLatLon(2, 2));
530 Node n2 = new Node(nc.getLatLon(14, 2));
531 Node n3 = new Node(nc.getLatLon(14, 14));
532 Node n4 = new Node(nc.getLatLon(2, 14));
533 ((Way) osm).addNode(n1);
534 ((Way) osm).addNode(n2);
535 ((Way) osm).addNode(n3);
536 ((Way) osm).addNode(n4);
537 ((Way) osm).addNode(n1);
538 Environment env = applyStylesheet(osm);
539 AreaElement aes = AreaElement.create(env);
540 if (aes != null) {
541 if (!generateImage) return Optional.of("");
542 return Optional.of(createImage(aes, "area", nc));
543 }
544 return Optional.empty();
545 }
546 }
547 }
548
549 /**
550 * POJO representing a <a href="https://wiki.openstreetmap.org/wiki/Taginfo/Projects">Taginfo tag</a>.
551 */
552 private static class TagInfoTag {
553 static final String REQUIRED_FOR_COUNT = "Required for {count}";
554 static final String OPTIONAL_FOR_COUNT = "Optional for {count}";
555 final Collection<String> descriptions = new ArrayList<>();
556 final String key;
557 final String value;
558 final Set<Type> objectTypes;
559 final String iconURL;
560
561 TagInfoTag(String description, String key, String value, Set<Type> objectTypes, String iconURL) {
562 if (description != null) {
563 this.descriptions.add(description);
564 }
565 this.key = key;
566 this.value = value;
567 this.objectTypes = objectTypes;
568 this.iconURL = iconURL;
569 }
570
571 JsonObjectBuilder toJson() {
572 final JsonObjectBuilder object = Json.createObjectBuilder();
573 if (!descriptions.isEmpty()) {
574 final int size = descriptions.size();
575 object.add("description", String.join(", ", Utils.limit(descriptions, 8, "..."))
576 .replace(REQUIRED_FOR_COUNT, size > 3 ? "Required for " + size : "Required for")
577 .replace(OPTIONAL_FOR_COUNT, size > 3 ? "Optional for " + size : "Optional for"));
578 }
579 object.add("key", key);
580 if (value != null) {
581 object.add("value", value);
582 }
583 if ((!objectTypes.isEmpty())) {
584 final JsonArrayBuilder types = Json.createArrayBuilder();
585 objectTypes.stream().map(Enum::name).map(String::toLowerCase).forEach(types::add);
586 object.add("object_types", types);
587 }
588 if (iconURL != null) {
589 object.add("icon_url", iconURL);
590 }
591 return object;
592 }
593
594 enum Type {
595 NODE, WAY, AREA, RELATION;
596
597 static TagInfoTag.Type forPresetType(TaggingPresetType type) {
598 switch (type) {
599 case CLOSEDWAY:
600 return AREA;
601 case MULTIPOLYGON:
602 return RELATION;
603 default:
604 return valueOf(type.toString());
605 }
606 }
607
608 static Set<TagInfoTag.Type> forPresetTypes(Set<TaggingPresetType> types) {
609 return types == null ? Collections.emptySet() : types.stream()
610 .map(Type::forPresetType)
611 .collect(Collectors.toCollection(() -> EnumSet.noneOf(Type.class)));
612 }
613 }
614 }
615
616 /**
617 * Initialize the script.
618 * @throws IOException if any I/O error occurs
619 */
620 private void init() throws IOException {
621 Logging.setLogLevel(Logging.LEVEL_INFO);
622 Preferences.main().enableSaveOnPut(false);
623 Config.setPreferencesInstance(Preferences.main());
624 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
625 Config.setUrlsProvider(JosmUrls.getInstance());
626 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857"));
627 Path tmpdir = Files.createTempDirectory(options.baseDir, "pref");
628 tmpdir.toFile().deleteOnExit();
629 System.setProperty("josm.home", tmpdir.toString());
630 DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback);
631 Territories.initializeInternalData();
632 Files.createDirectories(options.imageDir);
633 }
634}
Note: See TracBrowser for help on using the repository browser.