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 javax.xml.stream.Location;
|
---|
7 | import javax.xml.stream.XMLStreamException;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Exception for unexpected processing errors during XML stream parsing.
|
---|
11 | * It uses proper JOSM i18n system to translate error message, including file location.
|
---|
12 | * @since 10235
|
---|
13 | */
|
---|
14 | public class XmlStreamParsingException extends XMLStreamException {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Constructs a new {@code XmlStreamParsingException}.
|
---|
18 | * @param msg error message
|
---|
19 | * @param location file location
|
---|
20 | */
|
---|
21 | public XmlStreamParsingException(String msg, Location location) {
|
---|
22 | super(msg); /* cannot use super(msg, location) because it messes with the message preventing localization */
|
---|
23 | this.location = location;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructs a new {@code XmlStreamParsingException}.
|
---|
28 | * @param msg error message
|
---|
29 | * @param location file location
|
---|
30 | * @param th Throwable cause
|
---|
31 | */
|
---|
32 | public XmlStreamParsingException(String msg, Location location, Throwable th) {
|
---|
33 | super(msg, th);
|
---|
34 | this.location = location;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public String getMessage() {
|
---|
39 | String msg = super.getMessage();
|
---|
40 | if (msg == null) {
|
---|
41 | msg = getClass().getName();
|
---|
42 | }
|
---|
43 | if (getLocation() == null)
|
---|
44 | return msg;
|
---|
45 | msg += ' ' + tr("(at line {0}, column {1})", getLocation().getLineNumber(), getLocation().getColumnNumber());
|
---|
46 | int offset = getLocation().getCharacterOffset();
|
---|
47 | if (offset > -1) {
|
---|
48 | msg += ". "+ tr("{0} bytes have been read", offset);
|
---|
49 | }
|
---|
50 | return msg;
|
---|
51 | }
|
---|
52 | }
|
---|