source: josm/trunk/src/org/openstreetmap/josm/io/XmlStreamParsingException.java@ 13336

Last change on this file since 13336 was 11649, checked in by Don-vip, 7 years ago

sonar - pmd:UseStringBufferForStringAppends

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Optional;
7
8import javax.xml.stream.Location;
9import javax.xml.stream.XMLStreamException;
10
11/**
12 * Exception for unexpected processing errors during XML stream parsing.
13 * It uses proper JOSM i18n system to translate error message, including file location.
14 * @since 10235
15 */
16public class XmlStreamParsingException extends XMLStreamException {
17
18 /**
19 * Constructs a new {@code XmlStreamParsingException}.
20 * @param msg error message
21 * @param location file location
22 */
23 public XmlStreamParsingException(String msg, Location location) {
24 super(msg); /* cannot use super(msg, location) because it messes with the message preventing localization */
25 this.location = location;
26 }
27
28 /**
29 * Constructs a new {@code XmlStreamParsingException}.
30 * @param msg error message
31 * @param location file location
32 * @param th Throwable cause
33 */
34 public XmlStreamParsingException(String msg, Location location, Throwable th) {
35 super(msg, th);
36 this.location = location;
37 }
38
39 @Override
40 public String getMessage() {
41 String msg = Optional.ofNullable(super.getMessage()).orElseGet(() -> getClass().getName());
42 if (getLocation() == null)
43 return msg;
44 StringBuilder sb = new StringBuilder(msg).append(' ')
45 .append(tr("(at line {0}, column {1})", getLocation().getLineNumber(), getLocation().getColumnNumber()));
46 int offset = getLocation().getCharacterOffset();
47 if (offset > -1) {
48 sb.append(". ").append(tr("{0} bytes have been read", offset));
49 }
50 return sb.toString();
51 }
52}
Note: See TracBrowser for help on using the repository browser.