1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.hot.sds;
|
---|
3 |
|
---|
4 | import java.io.PrintWriter;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.Map.Entry;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
11 | import org.openstreetmap.josm.data.osm.Tagged;
|
---|
12 | import org.openstreetmap.josm.io.OsmWriter;
|
---|
13 | import org.openstreetmap.josm.io.XmlWriter;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * This is a special version of JOSM's OsmWriter that makes
|
---|
17 | * sure that special tags are never written to JOSM's standard
|
---|
18 | * output channels.
|
---|
19 | *
|
---|
20 | * In the context of HOT's separate data store, this is very
|
---|
21 | * important as otherwise private/confidential information could
|
---|
22 | * end up on public servers.
|
---|
23 | *
|
---|
24 | * @author Frederik Ramm
|
---|
25 | *
|
---|
26 | */
|
---|
27 | public class SdsOsmWriter extends OsmWriter {
|
---|
28 |
|
---|
29 | private SeparateDataStorePlugin plugin;
|
---|
30 |
|
---|
31 | public SdsOsmWriter(SeparateDataStorePlugin plugin, PrintWriter out, boolean osmConform, String version) {
|
---|
32 | super(out, osmConform, version);
|
---|
33 | this.plugin = plugin;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | protected void addTags(Tagged osm, String tagname, boolean tagOpen) {
|
---|
38 | if (osm.hasKeys()) {
|
---|
39 | if (tagOpen) {
|
---|
40 | out.println(">");
|
---|
41 | }
|
---|
42 | List<Entry<String, String>> entries = new ArrayList<>(osm.getKeys().entrySet());
|
---|
43 | Collections.sort(entries, byKeyComparator);
|
---|
44 | for (Entry<String, String> e : entries) {
|
---|
45 | String key = e.getKey();
|
---|
46 | if (!(osm instanceof Changeset) && ("created_by".equals(key))) continue;
|
---|
47 | if (key.startsWith(plugin.getIgnorePrefix())) continue;
|
---|
48 | out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) +
|
---|
49 | "' v='"+XmlWriter.encode(e.getValue())+ "' />");
|
---|
50 | }
|
---|
51 | out.println(" </" + tagname + ">");
|
---|
52 | } else if (tagOpen) {
|
---|
53 | out.println(" />");
|
---|
54 | } else {
|
---|
55 | out.println(" </" + tagname + ">");
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|