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

Last change on this file since 9411 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

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