001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.io; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import org.xml.sax.Locator; 007 import org.xml.sax.SAXException; 008 009 public class OsmDataParsingException extends SAXException { 010 private int columnNumber; 011 private int lineNumber; 012 013 public OsmDataParsingException() { 014 super(); 015 } 016 017 public OsmDataParsingException(Exception e) { 018 super(e); 019 } 020 021 public OsmDataParsingException(String message, Exception e) { 022 super(message, e); 023 } 024 025 public OsmDataParsingException(String message) { 026 super(message); 027 } 028 029 public OsmDataParsingException rememberLocation(Locator locator) { 030 if (locator == null) return this; 031 this.columnNumber = locator.getColumnNumber(); 032 this.lineNumber = locator.getLineNumber(); 033 return this; 034 } 035 036 @Override 037 public String getMessage() { 038 String msg = super.getMessage(); 039 if (lineNumber == 0 && columnNumber == 0) 040 return msg; 041 if (msg == null) { 042 msg = getClass().getName(); 043 } 044 msg = msg + " " + tr("(at line {0}, column {1})", lineNumber, columnNumber); 045 return msg; 046 } 047 048 public int getColumnNumber() { 049 return columnNumber; 050 } 051 052 public int getLineNumber() { 053 return lineNumber; 054 } 055 }