source: josm/trunk/src/org/openstreetmap/josm/tools/XmlParsingException.java@ 12748

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

sonar - fb-contrib - minor performance improvements:

  • Method passes constant String of length 1 to character overridden method
  • Method needlessly boxes a boolean constant
  • Method uses iterator().next() on a List to get the first item
  • Method converts String to boxed primitive using excessive boxing
  • Method converts String to primitive using excessive boxing
  • Method creates array using constants
  • Class defines List based fields but uses them like Sets
  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.xml.sax.Locator;
7import org.xml.sax.SAXException;
8
9/**
10 * An exception thrown during XML parsing, with known line and column.
11 * @since 6906
12 */
13public class XmlParsingException extends SAXException {
14 private int columnNumber;
15 private int lineNumber;
16
17 /**
18 * Constructs a new {@code XmlParsingException}.
19 * @param e The cause
20 */
21 public XmlParsingException(Exception e) {
22 super(e);
23 }
24
25 /**
26 * Constructs a new {@code XmlParsingException}.
27 * @param message The error message
28 * @param e The cause
29 */
30 public XmlParsingException(String message, Exception e) {
31 super(message, e);
32 }
33
34 /**
35 * Constructs a new {@code XmlParsingException}.
36 * @param message The error message
37 */
38 public XmlParsingException(String message) {
39 super(message);
40 }
41
42 /**
43 * Sets the location (line/column) where the exception occured.
44 * @param locator object giving the location (line/column) where the exception occured
45 * @return {@code this}
46 */
47 public XmlParsingException rememberLocation(Locator locator) {
48 if (locator != null) {
49 this.columnNumber = locator.getColumnNumber();
50 this.lineNumber = locator.getLineNumber();
51 }
52 return this;
53 }
54
55 @Override
56 public String getMessage() {
57 String msg = super.getMessage();
58 if (lineNumber == 0 && columnNumber == 0)
59 return msg;
60 if (msg == null) {
61 msg = getClass().getName();
62 }
63 return msg + ' ' + tr("(at line {0}, column {1})", lineNumber, columnNumber);
64 }
65
66 /**
67 * Returns the column number where the exception occured.
68 * @return the column number where the exception occured
69 */
70 public int getColumnNumber() {
71 return columnNumber;
72 }
73
74 /**
75 * Returns the line number where the exception occured.
76 * @return the line number where the exception occured
77 */
78 public int getLineNumber() {
79 return lineNumber;
80 }
81}
Note: See TracBrowser for help on using the repository browser.