source: josm/trunk/src/org/openstreetmap/josm/io/GpxImporter.java@ 1750

Last change on this file since 1750 was 1696, checked in by stoecker, 15 years ago

fixed mappaint area style handling for closed ways a little bit again

File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.FileNotFoundException;
9import java.io.IOException;
10import java.io.InputStream;
11import java.util.zip.GZIPInputStream;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.actions.ExtensionFileFilter;
15import org.openstreetmap.josm.gui.layer.GpxLayer;
16import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
17import org.xml.sax.SAXException;
18
19public class GpxImporter extends FileImporter {
20
21 public GpxImporter() {
22 super(new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)"));
23 }
24
25 @Override public void importData(File file) throws IOException {
26 String fn = file.getName();
27
28 try {
29 GpxReader r = null;
30 InputStream is;
31 if (file.getName().endsWith(".gpx.gz"))
32 is = new GZIPInputStream(new FileInputStream(file));
33 else
34 is = new FileInputStream(file);
35 // Workaround for SAX BOM bug
36 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206835
37 if (!((is.read() == 0xef) && (is.read() == 0xbb) && (is.read() == 0xbf))) {
38 is.close();
39 if (file.getName().endsWith(".gpx.gz"))
40 is = new GZIPInputStream(new FileInputStream(file));
41 else
42 is = new FileInputStream(file);
43 }
44 r = new GpxReader(is, file.getAbsoluteFile().getParentFile());
45 r.data.storageFile = file;
46 GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
47 Main.main.addLayer(gpxLayer);
48 if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
49 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer);
50 if (ml.data.size() > 0)
51 Main.main.addLayer(ml);
52 }
53 } catch (FileNotFoundException e) {
54 e.printStackTrace();
55 throw new IOException(tr("File \"{0}\" does not exist", file.getName()));
56 } catch (SAXException e) {
57 e.printStackTrace();
58 throw new IOException(tr("Parsing file \"{0}\" failed", file.getName()));
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.