Changeset 14024 in josm
- Timestamp:
- 2018-07-08T22:49:51+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r14019 r14024 154 154 </attributes> 155 155 </classpathentry> 156 <classpathentry kind="lib" path="tools/groovy/groovy-json-2.5.0.jar">157 <attributes>158 <attribute name="test" value="true"/>159 </attributes>160 </classpathentry>161 156 <classpathentry kind="lib" path="tools/groovy/groovy-xml-2.5.0.jar"> 162 157 <attributes> -
trunk/scripts/TagInfoExtract.groovy
r14021 r14024 18 18 19 19 import javax.imageio.ImageIO 20 import javax.json.Json 21 import javax.json.stream.JsonGenerator 20 22 21 23 import org.openstreetmap.josm.Main … … 56 58 57 59 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings 58 import groovy.json.JsonBuilder59 60 60 61 class TagInfoExtract { … … 360 361 } 361 362 362 void write_json(name, description, tags) { 363 def json = new JsonBuilder() 364 def project = [ 365 name: name, 366 description: description, 367 project_url: "https://josm.openstreetmap.de/", 368 icon_url: "https://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png", 369 contact_name: "JOSM developer team", 370 contact_email: "josm-dev@openstreetmap.org", 371 ] 372 json data_format: 1, data_updated: DateTimeFormatter.ofPattern("yyyyMMdd'T'hhmmss'Z'").withZone(ZoneId.of("Z")).format(Instant.now()), project: project, tags: tags 363 void write_json(String name, String description, List<Map<String, ?>> tags) { 364 def config = [:] 365 config[JsonGenerator.PRETTY_PRINTING] = output_file == null 366 def writer = output_file != null ? output_file : new StringWriter() 367 Json.createWriterFactory(config).createWriter(writer).withCloseable {json -> 368 def project = Json.createObjectBuilder() 369 .add("name", name) 370 .add("description", description) 371 .add("project_url", "https://josm.openstreetmap.de/") 372 .add("icon_url", "https://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png") 373 .add("contact_name", "JOSM developer team") 374 .add("contact_email", "josm-dev@openstreetmap.org") 375 def jsonTags = Json.createArrayBuilder() 376 for (def t : tags) { 377 def o = Json.createObjectBuilder() 378 for (def e : t.entrySet()) { 379 def val = e.getValue() 380 if (e.getValue() instanceof List) { 381 def arr = Json.createArrayBuilder() 382 for (def v : e.getValue()) { 383 arr.add(v) 384 } 385 val = arr.build() 386 } 387 o.add(e.getKey(), val) 388 } 389 jsonTags.add(o.build()) 390 } 391 json.writeObject(Json.createObjectBuilder() 392 .add("data_format", 1) 393 .add("data_updated", DateTimeFormatter.ofPattern("yyyyMMdd'T'hhmmss'Z'").withZone(ZoneId.of("Z")).format(Instant.now())) 394 .add("project", project.build()) 395 .add("tags", jsonTags.build()) 396 .build()) 397 } 373 398 374 399 if (output_file != null) { 375 json.writeTo(output_file)376 400 output_file.close() 377 401 } else { 378 print json.toPrettyString()402 print writer.toString() 379 403 } 380 404 }
Note: See TracChangeset
for help on using the changeset viewer.