001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.io.importexport; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.io.File; 007import java.io.IOException; 008import java.io.InputStream; 009 010import org.openstreetmap.josm.actions.ExtensionFileFilter; 011import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData; 012import org.openstreetmap.josm.io.ozi.OziWptReader; 013 014/** 015 * File importer allowing to import OziExplorer Waypoint files (*.wpt files). 016 * @since 18179 017 */ 018public class OziWptImporter extends GpxLikeImporter<OziWptReader> { 019 020 /** 021 * The OziExplorer Waypoint file filter (*.wpt files). 022 */ 023 public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions( 024 "wpt", "wpt", tr("OziExplorer Waypoint Files"), false); 025 026 /** 027 * Constructs a new {@code OziWptImporter}. 028 */ 029 public OziWptImporter() { 030 super(FILE_FILTER, OziWptReader.class); 031 } 032 033 /** 034 * Replies the new GPX and marker layers corresponding to the specified wpt file. 035 * @param is input stream to data 036 * @param associatedFile wpt file 037 * @param gpxLayerName The GPX layer name 038 * @return the new GPX and marker layers corresponding to the specified wpt file 039 * @throws IOException if an I/O error occurs 040 */ 041 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 042 final String gpxLayerName) throws IOException { 043 final OziWptReader r = buildAndParse(is, OziWptReader.class); 044 final boolean parsedProperly = r.getNumberOfCoordinates() > 0; 045 r.getGpxData().storageFile = associatedFile; 046 return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName); 047 } 048}