1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.text.DateFormat;
|
---|
7 | import java.text.ParseException;
|
---|
8 | import java.text.SimpleDateFormat;
|
---|
9 | import java.util.Date;
|
---|
10 | import java.util.Locale;
|
---|
11 | import java.util.regex.Matcher;
|
---|
12 | import java.util.regex.Pattern;
|
---|
13 |
|
---|
14 | public 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 | }
|
---|