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

Last change on this file since 2474 was 2198, checked in by Gubaer, 15 years ago

fixed #3249: Resolve conflicts between invisible and deleted primitives automatically

File size: 2.1 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 *
14 */
15public class OsmApiPrimitiveGoneException extends OsmApiException{
16 /**
17 * The regexp pattern for the error header replied by the OSM API
18 */
19 static public 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 OsmPrimitiveType type;
22 /** the id of the primitive */
23 private long id;
24
25
26 public OsmApiPrimitiveGoneException(String errorHeader, String errorBody) {
27 super(HttpURLConnection.HTTP_GONE, errorHeader, errorBody);
28 if (errorHeader == null) return;
29 Pattern p = Pattern.compile(ERROR_HEADER_PATTERN);
30 Matcher m = p.matcher(errorHeader);
31 if (m.matches()) {
32 type = OsmPrimitiveType.from(m.group(1));
33 id = Long.parseLong(m.group(2));
34 }
35 }
36
37 /**
38 * Replies true if we know what primitive this exception was thrown for
39 *
40 * @return true if we know what primitive this exception was thrown for
41 */
42 public boolean isKnownPrimitive() {
43 return id > 0 && type != null;
44 }
45
46 /**
47 * Replies the type of the primitive this exception was thrown for. null,
48 * if the type is not known.
49 *
50 * @return the type of the primitive this exception was thrown for
51 */
52 public OsmPrimitiveType getPrimitiveType() {
53 return type;
54 }
55
56 /**
57 * Replies the id of the primitive this exception was thrown for. 0, if
58 * the id is not known.
59 *
60 * @return the id of the primitive this exception was thrown for
61 */
62 public long getPrimitiveId() {
63 return id;
64 }
65}
Note: See TracBrowser for help on using the repository browser.