Changeset 2115 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-09-13T19:30:36+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2074 r2115 23 23 import java.util.Collections; 24 24 import java.util.HashMap; 25 import java.util.Properties;26 25 27 26 import javax.xml.parsers.SAXParserFactory; … … 32 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 32 import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor; 33 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 34 34 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 35 35 import org.xml.sax.Attributes; … … 205 205 206 206 /** 207 * Makes an XML string from an OSM primitive. Uses the OsmWriter class. 208 * @param o the OSM primitive 209 * @param addBody true to generate the full XML, false to only generate the encapsulating tag 210 * @return XML string 211 */ 212 private String toXml(Changeset s) { 213 swriter.getBuffer().setLength(0); 214 osmWriter.header(); 215 s.visit(osmWriter); 216 osmWriter.footer(); 217 osmWriter.out.flush(); 218 return swriter.toString(); 219 } 220 221 /** 207 222 * Returns the base URL for API requests, including the negotiated version number. 208 223 * @return base URL string … … 229 244 */ 230 245 public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 231 initialize(monitor);232 246 String ret = ""; 233 247 try { 248 ensureValidChangeset(); 249 initialize(monitor); 234 250 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor); 235 251 osm.setOsmId(Long.parseLong(ret.trim()), 1); … … 244 260 * version. 245 261 * 246 * @param osm the primitive 262 * @param osm the primitive. Must not be null 247 263 * @throws OsmTransferException if something goes wrong 248 264 */ 249 265 public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 250 initialize(monitor); 251 if (version.equals("0.5")) { 252 // legacy mode does not return the new object version. 253 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor); 254 } else { 255 String ret = null; 256 // normal mode (0.6 and up) returns new object version. 257 try { 266 String ret = null; 267 try { 268 ensureValidChangeset(); 269 initialize(monitor); 270 if (version.equals("0.5")) { 271 // legacy mode does not return the new object version. 272 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor); 273 } else { 274 // normal mode (0.6 and up) returns new object version. 258 275 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 259 276 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim())); 260 } catch(NumberFormatException e) {261 throw new OsmTransferException(tr("unexpected format of new version of modified primitive ''{0}'', got ''{1}''", osm.getId(), ret));262 277 } 278 } catch(NumberFormatException e) { 279 throw new OsmTransferException(tr("unexpected format of new version of modified primitive ''{0}'', got ''{1}''", osm.getId(), ret)); 263 280 } 264 281 } … … 270 287 */ 271 288 public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 289 ensureValidChangeset(); 272 290 initialize(monitor); 273 291 // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow … … 280 298 281 299 /** 282 * Creates a new changeset based on the keys in <code>changeset</code> 283 * 284 * @param changeset the changeset to be used for uploading 300 * Creates a new changeset based on the keys in <code>changeset</code>. If this 301 * method succeeds, changeset.getId() replies the id the server assigned to the new 302 * changeset 303 * 304 * The changeset must not be null, but its key/value-pairs may be empty. 305 * 306 * @param changeset the changeset toe be created. Must not be null. 285 307 * @param progressMonitor the progress monitor 286 308 * @throws OsmTransferException signifying a non-200 return code, or connection errors 287 */ 288 public void createChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException { 309 * @throws IllegalArgumentException thrown if changeset is null 310 */ 311 public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException { 312 if (changeset == null) 313 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "changeset")); 289 314 try { 290 315 progressMonitor.beginTask((tr("Creating changeset..."))); 291 createPrimitive(changeset, progressMonitor); 292 this.changeset = changeset; 293 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",this.changeset.getId()))); 316 initialize(progressMonitor); 317 String ret = ""; 318 try { 319 ret = sendRequest("PUT", "changeset/create", toXml(changeset),progressMonitor); 320 changeset.setId(Long.parseLong(ret.trim())); 321 changeset.setOpen(true); 322 } catch(NumberFormatException e){ 323 throw new OsmTransferException(tr("unexpected format of id replied by the server, got ''{0}''", ret)); 324 } 325 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId()))); 294 326 } finally { 295 327 progressMonitor.finishTask(); … … 298 330 299 331 /** 300 * Updates the current changeset with the keys in <code>changesetUpdate</code>. 301 * 302 * @param changesetUpdate the changeset to update 303 * @param progressMonitor the progress monitor 332 * Updates a changeset with the keys in <code>changesetUpdate</code>. The changeset must not 333 * be null and id > 0 must be true. 334 * 335 * @param changeset the changeset to update. Must not be null. 336 * @param monitor the progress monitor. If null, uses the {@see NullProgressMonitor#INSTANCE}. 304 337 * 305 338 * @throws OsmTransferException if something goes wrong. 306 */ 307 public void updateChangeset(Changeset changesetUpdate, ProgressMonitor progressMonitor) throws OsmTransferException { 339 * @throws IllegalArgumentException if changeset is null 340 * @throws IllegalArgumentException if changeset.getId() == 0 341 * 342 */ 343 public void updateChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException { 344 if (changeset == null) 345 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "changeset")); 346 if (monitor == null) { 347 monitor = NullProgressMonitor.INSTANCE; 348 } 349 if (changeset.getId() <= 0) 350 throw new IllegalArgumentException(tr("id of changeset > 0 required. Got {0}", changeset.getId())); 308 351 try { 309 progressMonitor.beginTask(tr("Updating changeset...")); 310 initialize(progressMonitor); 311 if (this.changeset != null && this.changeset.getId() > 0) { 312 if (this.changeset.hasEqualSemanticAttributes(changesetUpdate)) { 313 progressMonitor.setCustomText(tr("Changeset {0} is unchanged. Skipping update.", changesetUpdate.getId())); 314 return; 315 } 316 this.changeset.setKeys(changesetUpdate.getKeys()); 317 progressMonitor.setCustomText(tr("Updating changeset {0}...", this.changeset.getId())); 318 sendRequest( 319 "PUT", 320 OsmPrimitiveType.from(changesetUpdate).getAPIName() + "/" + this.changeset.getId(), 321 toXml(this.changeset, true), 322 progressMonitor 323 ); 324 } else 325 throw new OsmTransferException(tr("Failed to update changeset. Either there is no current changeset or the id of the current changeset is 0")); 352 monitor.beginTask(tr("Updating changeset...")); 353 initialize(monitor); 354 monitor.setCustomText(tr("Updating changeset {0}...", changeset.getId())); 355 sendRequest( 356 "PUT", 357 "changeset/" + this.changeset.getId(), 358 toXml(this.changeset), 359 monitor 360 ); 326 361 } finally { 327 progressMonitor.finishTask(); 328 } 329 } 330 331 /** 332 * Closes a changeset on the server. 333 * 334 * @param changesetProcessingType how changesets are currently handled 335 * @param progressMonitor the progress monitor 362 monitor.finishTask(); 363 } 364 } 365 366 367 /** 368 * Closes a changeset on the server. Sets changeset.setOpen(false) if this operation 369 * succeeds. 370 * 371 * @param changeset the changeset to be closed. Must not be null. changeset.getId() > 0 required. 372 * @param monitor the progress monitor. If null, uses {@see NullProgressMonitor#INSTANCE} 336 373 * 337 374 * @throws OsmTransferException if something goes wrong. 338 */ 339 public void stopChangeset(ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 340 if (changesetProcessingType == null) { 341 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE; 342 } 375 * @throws IllegalArgumentException thrown if changeset is null 376 * @throws IllegalArgumentException thrown if changeset.getId() <= 0 377 */ 378 public void closeChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException { 379 if (changeset == null) 380 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "changeset")); 381 if (monitor == null) { 382 monitor = NullProgressMonitor.INSTANCE; 383 } 384 if (changeset.getId() <= 0) 385 throw new IllegalArgumentException(tr("id of changeset > 0 required. Got {0}", changeset.getId())); 343 386 try { 344 progressMonitor.beginTask(tr("Closing changeset...")); 345 initialize(progressMonitor); 346 if (changesetProcessingType.isCloseAfterUpload()) { 347 progressMonitor.setCustomText(tr("Closing changeset {0}...", changeset.getId())); 348 if (this.changeset != null && this.changeset.getId() > 0) { 349 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor); 350 changeset = null; 351 } 352 } else { 353 progressMonitor.setCustomText(tr("Leaving changeset {0} open...", changeset.getId())); 354 } 387 monitor.beginTask(tr("Closing changeset...")); 388 initialize(monitor); 389 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, monitor); 390 changeset.setOpen(false); 355 391 } finally { 356 progressMonitor.finishTask();392 monitor.finishTask(); 357 393 } 358 394 } … … 365 401 * @throws OsmTransferException if something is wrong 366 402 */ 367 public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list, ProgressMonitor progressMonitor) throws OsmTransferException { 368 369 progressMonitor.beginTask("", list.size() * 2); 403 public Collection<OsmPrimitive> uploadDiff(Collection<OsmPrimitive> list, ProgressMonitor progressMonitor) throws OsmTransferException { 370 404 try { 405 progressMonitor.beginTask("", list.size() * 2); 371 406 if (changeset == null) 372 407 throw new OsmTransferException(tr("No changeset present for diff upload")); … … 385 420 386 421 String diff = duv.getDocument(); 387 try { 388 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff,progressMonitor); 389 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 390 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 391 } catch(OsmTransferException e) { 392 throw e; 393 } catch(Exception e) { 394 throw new OsmTransferException(e); 395 } 396 422 String diffresult = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diff,progressMonitor); 423 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 424 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 397 425 return processed; 426 } catch(OsmTransferException e) { 427 throw e; 428 } catch(Exception e) { 429 throw new OsmTransferException(e); 398 430 } finally { 399 431 progressMonitor.finishTask(); … … 536 568 } 537 569 throw new OsmTransferException(e); 570 } catch(OsmTransferException e) { 571 throw e; 538 572 } catch (Exception e) { 539 if (e instanceof OsmTransferException) throw (OsmTransferException) e;540 573 throw new OsmTransferException(e); 541 574 } … … 552 585 } 553 586 554 /** 555 * Replies the current changeset 556 * 557 * @return the current changeset 558 */ 559 public Changeset getCurrentChangeset() { 587 588 /** 589 * Ensures that the current changeset can be used for uploading data 590 * 591 * @throws OsmTransferException thrown if the current changeset can't be used for 592 * uploading data 593 */ 594 protected void ensureValidChangeset() throws OsmTransferException { 595 if (changeset == null) 596 throw new OsmTransferException(tr("current changeset is null. Can't upload data.")); 597 if (changeset.getId() <= 0) 598 throw new OsmTransferException(tr("id of current changeset > required. Current id is {0}", changeset.getId())); 599 } 600 /** 601 * Replies the changeset data uploads are currently directed to 602 * 603 * @return the changeset data uploads are currently directed to 604 */ 605 public Changeset getChangeset() { 560 606 return changeset; 561 607 } 608 609 /** 610 * Sets the changesets to which further data uploads are directed. The changeset 611 * can be null. If it isn't null it must have been created, i.e. id > 0 is required. Furthermore, 612 * it must be open. 613 * 614 * @param changeset the changeset 615 * @throws IllegalArgumentException thrown if changeset.getId() <= 0 616 * @throws IllegalArgumentException thrown if !changeset.isOpen() 617 */ 618 public void setChangeset(Changeset changeset) { 619 if (changeset == null) { 620 this.changeset = null; 621 return; 622 } 623 if (changeset.getId() <= 0) 624 throw new IllegalArgumentException(tr("Changeset id > 0 expected. Got {0}", changeset.getId())); 625 if (!changeset.isOpen()) 626 throw new IllegalArgumentException(tr("Open changeset expected. Got closed changeset with id {0}", changeset.getId())); 627 this.changeset = changeset; 628 } 629 562 630 } -
trunk/src/org/openstreetmap/josm/io/OsmDataParsingException.java
r2094 r2115 7 7 import org.xml.sax.SAXException; 8 8 9 /**10 * Represents a parsing error in an OSM data file.11 *12 * Use {@see #getColumnNumber()} and {@see #getLineNumber()} to locate13 * the position in the file where the parsing error occured.14 *15 */16 9 public class OsmDataParsingException extends SAXException { 17 10 private int columnNumber; -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r2094 r2115 36 36 37 37 /** 38 * Parser for the Osm Api. Read from an input stream and construct sa dataset out of it.38 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it. 39 39 * 40 40 */ … … 80 80 } 81 81 82 private static class OsmPrimitiveData { 83 public long id = 0; 84 public boolean modified = false; 85 public boolean deleted = false; 86 public Date timestamp = new Date(); 87 public User user = null; 88 public boolean visible = true; 89 public int version = 0; 90 public LatLon latlon = new LatLon(0,0); 91 private OsmPrimitive primitive; 92 93 public void copyTo(OsmPrimitive osm) { 94 osm.setModified(modified); 95 osm.setDeleted(deleted); 96 // id < 0 possible if read from a file 97 if (id <= 0) { 98 osm.clearOsmId(); 99 } else { 100 osm.setOsmId(id, version); 101 } 102 osm.setTimestamp(timestamp); 103 osm.user = user; 104 osm.setVisible(visible); 105 osm.mappaintStyle = null; 106 } 107 108 public Node createNode() { 109 Node node = new Node(); 110 node.setCoor(latlon); 111 copyTo(node); 112 primitive = node; 113 return node; 114 } 115 116 public Way createWay() { 117 Way way = new Way(); 118 copyTo(way); 119 primitive = way; 120 return way; 121 } 122 public Relation createRelation() { 123 Relation relation= new Relation(); 124 copyTo(relation); 125 primitive = relation; 126 return relation; 127 } 128 129 public void rememberTag(String key, String value) { 130 primitive.put(key, value); 131 } 132 } 82 133 83 134 /** … … 100 151 */ 101 152 private Map<Long, Collection<RelationMemberData>> relations = new HashMap<Long, Collection<RelationMemberData>>(); 102 103 153 104 154 private class Parser extends DefaultHandler { … … 241 291 current.rememberTag(key, value); 242 292 } else { 243 System.out.println(tr("Warning:Undefined element ''{0}'' found in input stream.Skipping.", qName));293 throwException(tr("Undefined element ''{0}'' found in input stream. Aborting.", qName)); 244 294 } 245 295 } … … 503 553 } 504 554 } 505 506 /**507 * Temporarily holds data for a parsed {@see OsmPrimitive} and provides508 * methods for creating an {@see OsmPrimitive} based on this data.509 */510 private static class OsmPrimitiveData {511 public long id = 0;512 public boolean modified = false;513 public boolean deleted = false;514 public Date timestamp = new Date();515 public User user = null;516 public boolean visible = true;517 public int version = 0;518 public LatLon latlon = new LatLon(0,0);519 private OsmPrimitive primitive;520 521 public void copyTo(OsmPrimitive osm) {522 // id < 0 possible if read from a file523 if (id <= 0) {524 osm.clearOsmId();525 } else {526 osm.setOsmId(id, version);527 }528 osm.setDeleted(deleted);529 osm.setModified(modified);530 osm.setTimestamp(timestamp);531 osm.user = user;532 osm.setVisible(visible);533 osm.mappaintStyle = null;534 }535 536 public Node createNode() {537 Node node = new Node();538 node.setCoor(latlon);539 copyTo(node);540 primitive = node;541 return node;542 }543 544 public Way createWay() {545 Way way = new Way();546 copyTo(way);547 primitive = way;548 return way;549 }550 public Relation createRelation() {551 Relation relation= new Relation();552 copyTo(relation);553 primitive = relation;554 return relation;555 }556 557 public void rememberTag(String key, String value) {558 primitive.put(key, value);559 }560 }561 555 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2081 r2115 65 65 * 66 66 * @param primitives the collection of primitives to upload 67 * @param changeset the changeset to be used if <code>changesetProcessingType</code> indicates that68 * a new changeset should be opened69 * @param changesetProcessingType how we handle changesets70 67 * @param progressMonitor the progress monitor 71 68 * @throws OsmTransferException thrown if an exception occurs 72 69 */ 73 protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType,ProgressMonitor progressMonitor) throws OsmTransferException {70 protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 74 71 try { 75 72 progressMonitor.beginTask(tr("Starting to upload with one request per primitive ...")); 76 73 progressMonitor.setTicksCount(primitives.size()); 77 if (changesetProcessingType.isUseNew()) {78 api.createChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false));79 } else {80 api.updateChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false));81 }82 74 uploadStartTime = System.currentTimeMillis(); 83 75 for (OsmPrimitive osm : primitives) { … … 86 78 String msg = ""; 87 79 switch(OsmPrimitiveType.from(osm)) { 88 case NODE: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading node ''{4}'' (id: {5})"); break; 89 case WAY: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading way ''{4}'' (id: {5})"); break; 90 case RELATION: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading relation ''{4}'' (id: {5})"); break; 80 case NODE: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading node ''{4}'' (id: {5})"); break; 81 case WAY: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading way ''{4}'' (id: {5})"); break; 82 case RELATION: msg = marktr("{0}% ({1}/{2}), {3} left. Uploading relation ''{4}'' (id: {5})"); break; 91 83 } 92 84 progressMonitor.subTask( … … 107 99 throw new OsmTransferException(e); 108 100 } finally { 109 try { 110 // starting the changeset may have failed, for instance because the user 111 // cancelled the upload task. Only close the changeset if we currently have 112 // an open changeset 113 114 if (api.getCurrentChangeset() != null && api.getCurrentChangeset().getId() > 0) { 115 api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false)); 116 } 117 } catch(Exception e) { 118 OsmChangesetCloseException closeException = new OsmChangesetCloseException(e); 119 closeException.setChangeset(api.getCurrentChangeset()); 120 throw closeException; 121 } finally { 122 progressMonitor.finishTask(); 123 } 101 progressMonitor.finishTask(); 124 102 } 125 103 } … … 132 110 * @throws OsmTransferException thrown if an exception occurs 133 111 */ 134 protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType,ProgressMonitor progressMonitor) throws OsmTransferException {112 protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 135 113 // upload everything in one changeset 136 114 // 137 115 try { 138 116 progressMonitor.beginTask(tr("Starting to upload in one request ...")); 139 if (changesetProcessingType.isUseNew()) {140 api.createChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false));141 } else {142 api.updateChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false));143 }144 117 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 145 118 } catch(OsmTransferException e) { … … 148 121 throw new OsmTransferException(e); 149 122 } finally { 150 try { 151 api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false)); 152 } catch (Exception ee) { 153 OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee); 154 closeException.setChangeset(api.getCurrentChangeset()); 155 throw closeException; 156 } finally { 157 progressMonitor.finishTask(); 158 } 159 123 progressMonitor.finishTask(); 160 124 } 161 125 } … … 167 131 * @param primitives list of objects to send 168 132 */ 169 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, Changeset ProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {133 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, boolean closeChangesetAfterUpload, ProgressMonitor progressMonitor) throws OsmTransferException { 170 134 processed = new LinkedList<OsmPrimitive>(); 171 135 progressMonitor.beginTask(tr("Uploading data ...")); … … 184 148 useDiffUpload = false; 185 149 } 186 150 if (changeset == null) { 151 changeset = new Changeset(); 152 } 153 if (changeset.getId() == 0) { 154 api.openChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false)); 155 } else { 156 api.updateChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false)); 157 } 158 api.setChangeset(changeset); 187 159 if (useDiffUpload) { 188 uploadChangesAsDiffUpload(primitives, changeset, changesetProcessingType,progressMonitor.createSubTaskMonitor(0,false));160 uploadChangesAsDiffUpload(primitives,progressMonitor.createSubTaskMonitor(0,false)); 189 161 } else { 190 uploadChangesIndividually(primitives,changeset,changesetProcessingType, progressMonitor.createSubTaskMonitor(0,false)); 191 } 162 uploadChangesIndividually(primitives,progressMonitor.createSubTaskMonitor(0,false)); 163 } 164 } catch(OsmTransferException e) { 165 throw e; 166 } catch(Exception e) { 167 throw new OsmTransferException(e); 192 168 } finally { 193 progressMonitor.finishTask(); 169 try { 170 if (closeChangesetAfterUpload && api.getChangeset() != null && api.getChangeset().getId() > 0) { 171 api.closeChangeset(changeset,progressMonitor.createSubTaskMonitor(0, false)); 172 api.setChangeset(null); 173 } 174 } catch (Exception ee) { 175 OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee); 176 closeException.setChangeset(api.getChangeset()); 177 throw closeException; 178 } finally { 179 progressMonitor.finishTask(); 180 } 194 181 } 195 182 } -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r2070 r2115 6 6 import java.util.Map.Entry; 7 7 8 import org.openstreetmap.josm.data.coor.CoordinateFormat; 8 9 import org.openstreetmap.josm.data.osm.Changeset; 9 10 import org.openstreetmap.josm.data.osm.DataSet; … … 14 15 import org.openstreetmap.josm.data.osm.Relation; 15 16 import org.openstreetmap.josm.data.osm.RelationMember; 16 import org.openstreetmap.josm.data.osm. User;17 import org.openstreetmap.josm.data.osm.Tagged; 17 18 import org.openstreetmap.josm.data.osm.Way; 18 19 import org.openstreetmap.josm.data.osm.visitor.Visitor; … … 143 144 144 145 public void visit(Changeset cs) { 145 addCommon(cs, "changeset"); 146 out.println(">\n"); 147 addTags(cs, "changeset", false); 148 } 149 150 public final void footer(PrintWriter out) { 151 out.println("</osm>"); 146 out.print(" <changeset "); 147 out.print(" id='"+cs.getId()+"'"); 148 if (cs.getUser() != null) { 149 out.print(" user='"+cs.getUser().getName() +"'"); 150 out.print(" uid='"+cs.getUser().getId() +"'"); 151 } 152 if (cs.getCreatedAt() != null) { 153 out.print(" created_at='"+DateUtils.fromDate(cs.getCreatedAt()) +"'"); 154 } 155 if (cs.getClosedAt() != null) { 156 out.print(" closed_at='"+DateUtils.fromDate(cs.getClosedAt()) +"'"); 157 } 158 out.print(" open='"+ (cs.isOpen() ? "true" : "false") +"'"); 159 if (cs.getMin() != null) { 160 out.print(" min_lon='"+ cs.getMin().lonToString(CoordinateFormat.DECIMAL_DEGREES) +"'"); 161 out.print(" min_lat='"+ cs.getMin().latToString(CoordinateFormat.DECIMAL_DEGREES) +"'"); 162 } 163 if (cs.getMax() != null) { 164 out.print(" max_lon='"+ cs.getMin().lonToString(CoordinateFormat.DECIMAL_DEGREES) +"'"); 165 out.print(" max_lat='"+ cs.getMin().latToString(CoordinateFormat.DECIMAL_DEGREES) +"'"); 166 } 167 out.println(">"); 168 addTags(cs, "changeset", false); // also writes closing </changeset> 152 169 } 153 170 … … 164 181 } 165 182 166 private void addTags( OsmPrimitiveosm, String tagname, boolean tagOpen) {183 private void addTags(Tagged osm, String tagname, boolean tagOpen) { 167 184 if (osm.hasKeys()) { 168 185 if (tagOpen) { 169 186 out.println(">"); 170 187 } 171 for (Entry<String, String> e : osm.entrySet()) { 188 for (Entry<String, String> e : osm.getKeys().entrySet()) { 172 189 if ((osm instanceof Changeset) || !("created_by".equals(e.getKey()))) { 173 190 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) +
Note:
See TracChangeset
for help on using the changeset viewer.