1 | // License: GPL. Copyright 2007 by Martijn van Oosterhout and others
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 | import org.openstreetmap.josm.io.XmlWriter;
|
---|
6 | import org.openstreetmap.josm.io.XmlWriter.OsmWriterInterface;
|
---|
7 | import java.io.PrintWriter;
|
---|
8 | import java.util.Map;
|
---|
9 | import java.util.Map.Entry;
|
---|
10 | import java.util.HashMap;
|
---|
11 | import java.util.Collections;
|
---|
12 | import java.util.Collection;
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Represents a single changeset in JOSM. For now its only used during
|
---|
18 | * upload but in the future we may do more.
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public final class Changeset /*extends OsmPrimitive*/ implements OsmWriterInterface {
|
---|
22 | /**
|
---|
23 | * The key/value list for this primitive.
|
---|
24 | */
|
---|
25 | public Map<String, String> keys;
|
---|
26 |
|
---|
27 | public long id = 0;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * User that created thos changeset, as specified by the server.
|
---|
31 | * Never changed by JOSM.
|
---|
32 | */
|
---|
33 | public User user = null;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Time of last modification to this object. This is not set by JOSM but
|
---|
37 | * read from the server and delivered back to the server unmodified.
|
---|
38 | */
|
---|
39 | public String end_timestamp = null;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Time of first modification to this object. This is not set by JOSM but
|
---|
43 | * read from the server and delivered back to the server unmodified.
|
---|
44 | */
|
---|
45 | public String start_timestamp = null;
|
---|
46 |
|
---|
47 | private void addTags(PrintWriter out) {
|
---|
48 | if (this.keys != null) {
|
---|
49 | for (Entry<String, String> e : this.keys.entrySet())
|
---|
50 | out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) +
|
---|
51 | "' v='"+XmlWriter.encode(e.getValue())+ "' />");
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public final void header(PrintWriter out) {
|
---|
56 | out.print("<osm version='");
|
---|
57 | out.print(Main.pref.get("osm-server.version", "0.6"));
|
---|
58 | out.println("' generator='JOSM'>");
|
---|
59 | }
|
---|
60 | public final void write(PrintWriter out) {
|
---|
61 | out.print(" <changeset");
|
---|
62 | if (id != 0)
|
---|
63 | out.print(" id="+id);
|
---|
64 | if (this.user != null) {
|
---|
65 | out.print(" user='"+XmlWriter.encode(this.user.name)+"'");
|
---|
66 | }
|
---|
67 | out.println(">\n");
|
---|
68 | addTags( out );
|
---|
69 | out.println(" </changeset>");
|
---|
70 | }
|
---|
71 | public final void footer(PrintWriter out) {
|
---|
72 | out.println("</osm>");
|
---|
73 | }
|
---|
74 |
|
---|
75 | /******************************************************
|
---|
76 | * This tag stuff is copied from OsmPrimitive. Perhaps a changeset
|
---|
77 | * really is a primitive, but it's not right now. Perhaps it should
|
---|
78 | * be...
|
---|
79 | ******************************************************/
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Set the given value to the given key
|
---|
83 | * @param key The key, for which the value is to be set.
|
---|
84 | * @param value The value for the key.
|
---|
85 | */
|
---|
86 | public final void put(String key, String value) {
|
---|
87 | if (value == null)
|
---|
88 | remove(key);
|
---|
89 | else {
|
---|
90 | if (keys == null)
|
---|
91 | keys = new HashMap<String, String>();
|
---|
92 | keys.put(key, value);
|
---|
93 | }
|
---|
94 | }
|
---|
95 | /**
|
---|
96 | * Remove the given key from the list.
|
---|
97 | */
|
---|
98 | public final void remove(String key) {
|
---|
99 | if (keys != null) {
|
---|
100 | keys.remove(key);
|
---|
101 | if (keys.isEmpty())
|
---|
102 | keys = null;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | public final String get(String key) {
|
---|
107 | return keys == null ? null : keys.get(key);
|
---|
108 | }
|
---|
109 |
|
---|
110 | public final Collection<Entry<String, String>> entrySet() {
|
---|
111 | if (keys == null)
|
---|
112 | return Collections.emptyList();
|
---|
113 | return keys.entrySet();
|
---|
114 | }
|
---|
115 |
|
---|
116 | public final Collection<String> keySet() {
|
---|
117 | if (keys == null)
|
---|
118 | return Collections.emptyList();
|
---|
119 | return keys.keySet();
|
---|
120 | }
|
---|
121 | }
|
---|