Ticket #17238: 17238-v3.patch
File 17238-v3.patch, 7.6 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/actions/GpxExportAction.java
9 9 import java.awt.event.KeyEvent; 10 10 import java.io.File; 11 11 import java.io.IOException; 12 import java.nio.file.InvalidPathException; 12 13 import java.text.MessageFormat; 13 14 14 15 import javax.swing.JOptionPane; … … 20 21 import org.openstreetmap.josm.gui.layer.Layer; 21 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 23 import org.openstreetmap.josm.tools.CheckParameterUtil; 23 import org.openstreetmap.josm.tools.Logging;24 24 import org.openstreetmap.josm.tools.Shortcut; 25 25 26 26 /** … … 107 107 if (exporter.acceptFile(file, layer)) { 108 108 try { 109 109 exporter.exportData(file, layer); 110 } catch (IOException e) {111 Logging.error(e);110 } catch (IOException | InvalidPathException e) { 111 SaveActionBase.showAndLogException(e); 112 112 } 113 113 } 114 114 } -
src/org/openstreetmap/josm/actions/SaveActionBase.java
6 6 import java.awt.event.ActionEvent; 7 7 import java.io.File; 8 8 import java.io.IOException; 9 import java.nio.file.InvalidPathException; 9 10 import java.util.Collection; 10 11 import java.util.LinkedList; 11 12 import java.util.List; … … 25 26 import org.openstreetmap.josm.spi.preferences.Config; 26 27 import org.openstreetmap.josm.tools.Logging; 27 28 import org.openstreetmap.josm.tools.Shortcut; 29 import org.openstreetmap.josm.tools.Utils; 28 30 29 31 /** 30 32 * Abstract superclass of save actions. … … 120 122 ((OsmDataLayer) layer).onPostSaveToFile(); 121 123 } 122 124 MainApplication.getMainFrame().repaint(); 123 } catch (IOException e) {124 Logging.error(e);125 } catch (IOException | InvalidPathException e) { 126 showAndLogException(e); 125 127 return false; 126 128 } 127 129 addToFileOpenHistory(file); … … 239 241 history.add(0, filepath); 240 242 PreferencesUtils.putListBounded(Config.getPref(), "file-open.history", maxsize, history); 241 243 } 244 245 static void showAndLogException(Exception e) { 246 GuiHelper.runInEDT(() -> 247 JOptionPane.showMessageDialog( 248 MainApplication.getMainFrame(), 249 tr("<html>An error occurred while saving.<br>Error is:<br>{0}</html>", 250 Utils.escapeReservedCharactersHTML(e.getClass().getSimpleName() + " - " + e.getMessage())), 251 tr("Error"), 252 JOptionPane.ERROR_MESSAGE 253 )); 254 255 Logging.error(e); 256 } 242 257 } -
src/org/openstreetmap/josm/gui/io/importexport/FileExporter.java
16 16 */ 17 17 public abstract class FileExporter implements ActiveLayerChangeListener { 18 18 19 /** the ExtensionFileFilter filter used by this exporter */ 19 20 public final ExtensionFileFilter filter; 20 21 21 22 private boolean enabled; -
src/org/openstreetmap/josm/gui/io/importexport/GpxExporter.java
10 10 import java.io.File; 11 11 import java.io.IOException; 12 12 import java.io.OutputStream; 13 import java.nio.file.InvalidPathException;14 13 import java.text.MessageFormat; 15 14 import java.time.Year; 16 15 import java.util.Optional; … … 38 37 import org.openstreetmap.josm.spi.preferences.Config; 39 38 import org.openstreetmap.josm.tools.CheckParameterUtil; 40 39 import org.openstreetmap.josm.tools.GBC; 41 import org.openstreetmap.josm.tools.Logging;42 40 43 41 /** 44 42 * Exports data to a .gpx file. Data may be native GPX or OSM data which will be converted. … … 205 203 gpxData.put(META_KEYWORDS, keywords.getText()); 206 204 } 207 205 208 try (OutputStream fo = Compression.getCompressedFileOutputStream(file)) { 209 new GpxWriter(fo).write(gpxData); 210 fo.flush(); 211 } catch (IOException | InvalidPathException ex) { 212 Logging.error(ex); 213 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while exporting {0}:\n{1}", fn, ex.getMessage()), 214 tr("Error"), JOptionPane.ERROR_MESSAGE); 206 try (OutputStream fo = Compression.getCompressedFileOutputStream(file); GpxWriter writer = new GpxWriter(fo)) { 207 writer.write(gpxData); 215 208 } 216 209 } 217 210 -
src/org/openstreetmap/josm/gui/io/importexport/OsmExporter.java
66 66 * @param layer Data layer. Must be an instance of {@link OsmDataLayer}. 67 67 * @param noBackup if {@code true}, the potential backup file created if the output file already exists will be deleted 68 68 * after a successful export 69 * @throws IOException in case of IO errors 70 * @throws InvalidPathException when file name cannot be converted into a Path 69 71 * @throws IllegalArgumentException if {@code layer} is not an instance of {@code OsmDataLayer} 70 72 */ 71 public void exportData(File file, Layer layer, boolean noBackup) {73 public void exportData(File file, Layer layer, boolean noBackup) throws IOException { 72 74 if (!(layer instanceof OsmDataLayer)) { 73 75 throw new IllegalArgumentException( 74 76 MessageFormat.format("Expected instance of OsmDataLayer. Got ''{0}''.", layer.getClass().getName())); … … 80 82 return Compression.getCompressedFileOutputStream(file); 81 83 } 82 84 83 private void save(File file, OsmDataLayer layer, boolean noBackup) {85 private void save(File file, OsmDataLayer layer, boolean noBackup) throws IOException { 84 86 File tmpFile = null; 85 87 try { 88 86 89 // use a tmp file because if something errors out in the process of writing the file, 87 90 // we might just end up with a truncated file. That can destroy lots of work. 88 91 if (file.exists()) { … … 97 100 layer.onPostSaveToFile(); 98 101 } catch (IOException | InvalidPathException e) { 99 102 Logging.error(e); 100 JOptionPane.showMessageDialog(101 MainApplication.getMainFrame(),102 tr("<html>An error occurred while saving.<br>Error is:<br>{0}</html>",103 Utils.escapeReservedCharactersHTML(e.getClass().getSimpleName() + " - " + e.getMessage())),104 tr("Error"),105 JOptionPane.ERROR_MESSAGE106 );107 103 108 104 try { 109 105 // if the file save failed, then the tempfile will not be deleted. So, restore the backup if we made one. … … 120 116 JOptionPane.ERROR_MESSAGE 121 117 ); 122 118 } 119 // re-throw original error 120 throw e; 123 121 } 124 122 } 125 123