Changeset 1670 in josm for trunk/src/org/openstreetmap/josm/io/OsmWriter.java
- Timestamp:
- 2009-06-15T20:22:46+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r1640 r1670 11 11 import org.openstreetmap.josm.data.osm.Node; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 14 import org.openstreetmap.josm.data.osm.Relation; 14 15 import org.openstreetmap.josm.data.osm.RelationMember; … … 25 26 26 27 public final String DEFAULT_API_VERSION = "0.6"; 27 28 28 29 /** 29 30 * The counter for newly created objects. Starts at -1 and goes down. 30 31 */ 31 32 private long newIdCounter = -1; 32 33 33 34 /** 34 35 * All newly created ids and their primitive that uses it. This is a back reference … … 41 42 private String version; 42 43 private Changeset changeset; 43 44 44 45 public OsmWriter(PrintWriter out, boolean osmConform, String version) { 45 46 super(out); … … 47 48 this.version = (version == null ? DEFAULT_API_VERSION : version); 48 49 } 49 50 50 51 public void setWithBody(boolean wb) { 51 52 this.withBody = wb; … … 57 58 this.version = v; 58 59 } 59 60 60 61 public void header() { 61 62 out.println("<?xml version='1.0' encoding='UTF-8'?>"); … … 70 71 public void writeContent(DataSet ds) { 71 72 for (Node n : ds.nodes) 72 if (shouldWrite(n)) 73 if (shouldWrite(n)) { 73 74 visit(n); 75 } 74 76 for (Way w : ds.ways) 75 if (shouldWrite(w)) 77 if (shouldWrite(w)) { 76 78 visit(w); 79 } 77 80 for (Relation e : ds.relations) 78 if (shouldWrite(e)) 81 if (shouldWrite(e)) { 79 82 visit(e); 83 } 80 84 } 81 85 … … 100 104 out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'"); 101 105 if (!withBody) { 102 out.println("/>"); 106 out.println("/>"); 103 107 } else { 104 108 addTags(n, "node", true); … … 110 114 addCommon(w, "way"); 111 115 if (!withBody) { 112 out.println("/>"); 116 out.println("/>"); 113 117 } else { 114 118 out.println(">"); 115 for (Node n : w.nodes) 119 for (Node n : w.nodes) { 116 120 out.println(" <nd ref='"+getUsedId(n)+"' />"); 121 } 117 122 addTags(w, "way", false); 118 123 } … … 123 128 addCommon(e, "relation"); 124 129 if (!withBody) { 125 out.println("/>"); 130 out.println("/>"); 126 131 } else { 127 132 out.println(">"); 128 133 for (RelationMember em : e.members) { 129 134 out.print(" <member type='"); 130 out.print(Osm Api.which(em.member));135 out.print(OsmPrimitiveType.from(em.member).getAPIName()); 131 136 out.println("' ref='"+getUsedId(em.member)+"' role='" + 132 137 XmlWriter.encode(em.role == null ? "" : em.role) + "' />"); … … 160 165 private void addTags(OsmPrimitive osm, String tagname, boolean tagOpen) { 161 166 if (osm.keys != null) { 162 if (tagOpen) 167 if (tagOpen) { 163 168 out.println(">"); 164 for (Entry<String, String> e : osm.keys.entrySet()) 169 } 170 for (Entry<String, String> e : osm.keys.entrySet()) { 165 171 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 166 172 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 173 } 167 174 out.println(" </" + tagname + ">"); 168 } else if (tagOpen) 175 } else if (tagOpen) { 169 176 out.println(" />"); 170 else177 } else { 171 178 out.println(" </" + tagname + ">"); 179 } 172 180 } 173 181 … … 180 188 out.print(" <"+tagname); 181 189 if (id != 0) { 182 out.print(" id='"+getUsedId(osm)+"'");190 out.print(" id='"+getUsedId(osm)+"'"); 183 191 } 184 192 if (!osmConform) { 185 193 String action = null; 186 if (osm.deleted) 194 if (osm.deleted) { 187 195 action = "delete"; 188 else if (osm.modified) 196 } else if (osm.modified) { 189 197 action = "modify"; 190 if (action != null) 198 } 199 if (action != null) { 191 200 out.print(" action='"+action+"'"); 201 } 192 202 } 193 203 if (!osm.isTimestampEmpty()) { … … 199 209 } 200 210 out.print(" visible='"+osm.visible+"'"); 201 if (osm.version != -1) 211 if (osm.version != -1) { 202 212 out.print(" version='"+osm.version+"'"); 203 if (this.changeset != null && this.changeset.id != 0) 213 } 214 if (this.changeset != null && this.changeset.id != 0) { 204 215 out.print(" changeset='"+this.changeset.id+"'" ); 205 } 206 216 } 217 } 218 207 219 public void close() { 208 220 out.close(); 209 221 } 210 222 211 223 public void flush() { 212 224 out.flush();
Note:
See TracChangeset
for help on using the changeset viewer.
