- Timestamp:
- 2014-01-04T03:38:53+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/FileImporter.java
r6248 r6621 18 18 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 19 19 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 20 import org.openstreetmap.josm.gui.Notification; 20 21 import org.openstreetmap.josm.gui.layer.Layer; 21 22 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 import org.openstreetmap.josm.gui.util.GuiHelper; 22 24 23 25 public abstract class FileImporter implements Comparable<FileImporter>, LayerChangeListener { … … 66 68 importData(f, progressMonitor); 67 69 return true; 70 } catch (IllegalDataException e) { 71 Throwable cause = e.getCause(); 72 if (cause instanceof ImportCancelException) { 73 displayCancel(cause); 74 } else { 75 displayError(f, e); 76 } 77 return false; 68 78 } catch (Exception e) { 69 e.printStackTrace(); 70 HelpAwareOptionPane.showMessageDialogInEDT( 71 Main.parent, 72 tr("<html>Could not read file ''{0}''.<br>Error is:<br>{1}</html>", f.getName(), e.getMessage()), 73 tr("Error"), 74 JOptionPane.ERROR_MESSAGE, null 75 ); 79 displayError(f, e); 76 80 return false; 77 81 } 78 82 } 83 84 private static void displayError(File f, Exception e) { 85 e.printStackTrace(); 86 HelpAwareOptionPane.showMessageDialogInEDT( 87 Main.parent, 88 tr("<html>Could not read file ''{0}''.<br>Error is:<br>{1}</html>", f.getName(), e.getMessage()), 89 tr("Error"), 90 JOptionPane.ERROR_MESSAGE, null 91 ); 92 } 93 94 private static void displayCancel(final Throwable t) { 95 GuiHelper.runInEDTAndWait(new Runnable() { 96 @Override 97 public void run() { 98 Notification note = new Notification(t.getMessage()); 99 note.setIcon(JOptionPane.INFORMATION_MESSAGE); 100 note.setDuration(Notification.TIME_SHORT); 101 note.show(); 102 } 103 }); 104 } 105 79 106 public boolean importDataHandleExceptions(List<File> files, ProgressMonitor progressMonitor) { 80 107 try { -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r6316 r6621 84 84 } 85 85 86 protected void throwException(String msg, Throwable th) throws XMLStreamException { 87 throw new OsmParsingException(msg, parser.getLocation(), th); 88 } 89 86 90 protected void throwException(String msg) throws XMLStreamException { 87 91 throw new OsmParsingException(msg, parser.getLocation()); … … 135 139 if (cancel) { 136 140 cancel = false; 137 throw Exception(tr("Reading was canceled"));141 throw new OsmParsingCanceledException(tr("Reading was canceled"), parser.getLocation()); 138 142 } 139 143 … … 300 304 id = Long.parseLong(value); 301 305 } catch(NumberFormatException e) { 302 throwException(tr("Illegal value for attribute ''ref'' on member in relation {0}. Got {1}", Long.toString(r.getUniqueId()),value) );306 throwException(tr("Illegal value for attribute ''ref'' on member in relation {0}. Got {1}", Long.toString(r.getUniqueId()),value), e); 303 307 } 304 308 value = parser.getAttributeValue(null, "type"); … … 309 313 type = OsmPrimitiveType.fromApiTypeName(value); 310 314 } catch(IllegalArgumentException e) { 311 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(r.getUniqueId()), value) );315 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(r.getUniqueId()), value), e); 312 316 } 313 317 value = parser.getAttributeValue(null, "role"); … … 404 408 return User.createOsmUser(id, name); 405 409 } catch(NumberFormatException e) { 406 throwException(MessageFormat.format("Illegal value for attribute ''uid''. Got ''{0}''.", uid) );410 throwException(MessageFormat.format("Illegal value for attribute ''uid''. Got ''{0}''.", uid), e); 407 411 } 408 412 return null; … … 441 445 version = Integer.parseInt(versionString); 442 446 } catch(NumberFormatException e) { 443 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString) );447 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString), e); 444 448 } 445 449 if (ds.getVersion().equals("0.6")){ … … 502 506 } else { 503 507 // for an existing primitive this is a problem 504 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v) );508 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v), e); 505 509 } 506 510 } … … 526 530 return Long.parseLong(value); 527 531 } catch(NumberFormatException e) { 528 throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value) );532 throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value), e); 529 533 } 530 534 return 0; // should not happen … … 532 536 533 537 private static class OsmParsingException extends XMLStreamException { 534 public OsmParsingException() {535 super();536 }537 538 public OsmParsingException(String msg) {539 super(msg);540 }541 538 542 539 public OsmParsingException(String msg, Location location) { … … 548 545 super(msg, th); 549 546 this.location = location; 550 }551 552 public OsmParsingException(String msg, Throwable th) {553 super(msg, th);554 }555 556 public OsmParsingException(Throwable th) {557 super(th);558 547 } 559 548 … … 568 557 msg = msg + " " + tr("(at line {0}, column {1})", getLocation().getLineNumber(), getLocation().getColumnNumber()); 569 558 return msg; 559 } 560 } 561 562 /** 563 * Exception thrown after user cancelation. 564 */ 565 private static final class OsmParsingCanceledException extends OsmParsingException implements ImportCancelException { 566 /** 567 * Constructs a new {@code OsmParsingCanceledException}. 568 * @param msg The error message 569 * @param location The parser location 570 */ 571 public OsmParsingCanceledException(String msg, Location location) { 572 super(msg, location); 570 573 } 571 574 }
Note:
See TracChangeset
for help on using the changeset viewer.