Changeset 18807 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2023-08-15T15:16:08+02:00 (11 months ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/importexport/GeoJSONImporter.java
r18747 r18807 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File;7 6 import java.io.IOException; 8 7 import java.io.InputStream; 9 8 import java.util.Arrays; 10 import java.util.Locale;11 9 12 import javax.swing.JOptionPane;13 14 import jakarta.json.JsonException;15 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; 16 11 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.gui.MainApplication;18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;19 12 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 20 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 import org.openstreetmap.josm.gui.util.GuiHelper;22 14 import org.openstreetmap.josm.io.CachedFile; 23 15 import org.openstreetmap.josm.io.Compression; 24 16 import org.openstreetmap.josm.io.GeoJSONReader; 25 17 import org.openstreetmap.josm.io.IllegalDataException; 26 import org.openstreetmap.josm.tools.Logging;27 import org.openstreetmap.josm.tools.Utils;28 18 29 19 /** 30 20 * GeoJSON file importer. 31 21 * @author Ian Dees <ian.dees@gmail.com> 32 * @author matthieun <https://github.com/matthieun>33 * @since 15424 22 * @author <a href="https://github.com/matthieun">matthieun</a> 23 * @since 15424, extends {@link OsmImporter} since 18807 34 24 */ 35 public class GeoJSONImporter extends FileImporter {25 public class GeoJSONImporter extends OsmImporter { 36 26 37 27 private static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions( … … 46 36 } 47 37 48 @Override49 public void importData(final File file, final ProgressMonitor progressMonitor) {50 progressMonitor.beginTask(tr("Loading json file…"));51 progressMonitor.setTicksCount(2);52 Logging.info("Parsing GeoJSON: {0}", file.getAbsolutePath());53 try (InputStream fileInputStream = Compression.getUncompressedFileInputStream(file)) {54 DataSet data = GeoJSONReader.parseDataSet(fileInputStream, progressMonitor);55 progressMonitor.worked(1);56 MainApplication.getLayerManager().addLayer(new OsmDataLayer(data, file.getName(), file));57 } catch (IOException | IllegalArgumentException | IllegalDataException | JsonException e) {58 Logging.error("Error while reading json file!");59 Logging.error(e);60 String message = tr("Error loading geojson file {0}", file.getAbsolutePath())61 + tr(" ({0})", Utils.getSizeString(file.length(), Locale.getDefault()));62 GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(null, message, tr("Error"), JOptionPane.WARNING_MESSAGE));63 } finally {64 progressMonitor.finishTask();65 }66 }67 68 38 /** 69 39 * Parse GeoJSON dataset. … … 72 42 * @throws IOException in case of I/O error 73 43 * @throws IllegalDataException if an error was found while parsing the data from the source 44 * @deprecated since 18807, use {@link #parseDataSet(InputStream, ProgressMonitor)} instead 74 45 */ 46 @Deprecated 75 47 public DataSet parseDataSet(final String source) throws IOException, IllegalDataException { 76 48 try (CachedFile cf = new CachedFile(source)) { 77 49 InputStream fileInputStream = Compression.getUncompressedFileInputStream(cf.getFile()); // NOPMD 78 return GeoJSONReader.parseDataSet(fileInputStream, NullProgressMonitor.INSTANCE);50 return this.parseDataSet(fileInputStream, NullProgressMonitor.INSTANCE); 79 51 } 80 52 } 53 54 @Override 55 protected DataSet parseDataSet(InputStream in, ProgressMonitor progressMonitor) throws IllegalDataException { 56 return GeoJSONReader.parseDataSet(in, progressMonitor); 57 } 81 58 } -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionImporter.java
r18208 r18807 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File; 6 7 import java.io.IOException; 7 8 import java.io.InputStream; … … 13 14 import javax.xml.xpath.XPathFactory; 14 15 16 import org.openstreetmap.josm.actions.ExtensionFileFilter; 17 import org.openstreetmap.josm.gui.io.importexport.FileImporter; 15 18 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; 16 19 import org.openstreetmap.josm.gui.layer.Layer; … … 31 34 public Layer load(Element elem, ImportSupport support, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 32 35 checkMetaVersion(elem); 33 String fileStr = extractFileName(elem, support); 36 final String fileStr = extractFileName(elem, support); 37 final File file = new File(fileStr); 38 for (FileImporter importer : ExtensionFileFilter.getImporters()) { 39 if (importer instanceof OsmImporter && importer.acceptFile(file)) { 40 return importData((OsmImporter) importer, support, fileStr, progressMonitor); 41 } 42 } 43 // Fall back to the default OsmImporter, just in case. It will probably fail. 34 44 return importData(new OsmImporter(), support, fileStr, progressMonitor); 35 45 }
Note:
See TracChangeset
for help on using the changeset viewer.