source: josm/trunk/src/org/openstreetmap/josm/io/ChangesetClosedException.java@ 2480

Last change on this file since 2480 was 2480, checked in by Gubaer, 14 years ago

fixed #3937: Closed changeset (due to timeout) remains in the upload dialog

File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.text.DateFormat;
7import java.text.ParseException;
8import java.text.SimpleDateFormat;
9import java.util.Date;
10import java.util.Locale;
11import java.util.regex.Matcher;
12import java.util.regex.Pattern;
13
14public class ChangesetClosedException extends OsmTransferException {
15
16 /** the changeset id */
17 private long changesetId;
18 /** the date on which the changeset was closed */
19 private Date closedOn;
20
21 protected void parseErrorHeader(String errorHeader) {
22 String pattern = "The changeset (\\d+) was closed at (.*)";
23 Pattern p = Pattern.compile(pattern);
24 Matcher m = p.matcher(errorHeader);
25 if (m.matches()) {
26 changesetId = Long.parseLong(m.group(1));
27 // Example: Tue Oct 15 10:00:00 UTC 2009. Always parsed with english locale regardless
28 // of the current locale in JOSM
29 DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH);
30 try {
31 closedOn = formatter.parse(m.group(2));
32 } catch(ParseException ex) {
33 System.err.println(tr("Failed to parse date ''{0}'' replied by server.", m.group(2)));
34 ex.printStackTrace();
35 }
36 } else {
37 System.err.println(tr("Unexpected format of error header for conflict in changeset update. Got ''{0}''", errorHeader));
38 }
39 }
40
41 public ChangesetClosedException(String errorHeader) {
42 super(errorHeader);
43 parseErrorHeader(errorHeader);
44 }
45
46 public long getChangesetId() {
47 return changesetId;
48 }
49
50 public Date getClosedOn() {
51 return closedOn;
52 }
53}
Note: See TracBrowser for help on using the repository browser.