source: josm/trunk/src/org/openstreetmap/josm/io/OsmApiPrimitiveGoneException.java@ 11795

Last change on this file since 11795 was 10216, checked in by Don-vip, 8 years ago

findbugs - SF_SWITCH_NO_DEFAULT + various sonar fixes

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import java.net.HttpURLConnection;
5import java.util.regex.Matcher;
6import java.util.regex.Pattern;
7
8import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
9
10/**
11 * Represents an exception thrown by the OSM API if JOSM tries to update or delete a primitive
12 * which is already deleted on the server.
13 * @since 2198
14 */
15public class OsmApiPrimitiveGoneException extends OsmApiException {
16 /**
17 * The regexp pattern for the error header replied by the OSM API
18 */
19 public static final String ERROR_HEADER_PATTERN = "The (\\S+) with the id (\\d+) has already been deleted";
20 /** the type of the primitive which is gone on the server */
21 private final OsmPrimitiveType type;
22 /** the id of the primitive */
23 private final long id;
24
25 /**
26 * Constructs a new {@code OsmApiPrimitiveGoneException}.
27 * @param errorHeader error header
28 * @param errorBody error body
29 */
30 public OsmApiPrimitiveGoneException(String errorHeader, String errorBody) {
31 super(HttpURLConnection.HTTP_GONE, errorHeader, errorBody);
32 if (errorHeader != null) {
33 Matcher m = Pattern.compile(ERROR_HEADER_PATTERN).matcher(errorHeader);
34 if (m.matches()) {
35 type = OsmPrimitiveType.from(m.group(1));
36 id = Long.parseLong(m.group(2));
37 } else {
38 type = null;
39 id = 0;
40 }
41 } else {
42 type = null;
43 id = 0;
44 }
45 }
46
47 /**
48 * Replies true if we know what primitive this exception was thrown for
49 *
50 * @return true if we know what primitive this exception was thrown for
51 */
52 public boolean isKnownPrimitive() {
53 return id > 0 && type != null;
54 }
55
56 /**
57 * Replies the type of the primitive this exception was thrown for. null,
58 * if the type is not known.
59 *
60 * @return the type of the primitive this exception was thrown for
61 */
62 public OsmPrimitiveType getPrimitiveType() {
63 return type;
64 }
65
66 /**
67 * Replies the id of the primitive this exception was thrown for. 0, if
68 * the id is not known.
69 *
70 * @return the id of the primitive this exception was thrown for
71 */
72 public long getPrimitiveId() {
73 return id;
74 }
75}
Note: See TracBrowser for help on using the repository browser.