source: josm/trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionImporter.java@ 8419

Last change on this file since 8419 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.session;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.io.InputStream;
8
9import javax.xml.xpath.XPath;
10import javax.xml.xpath.XPathConstants;
11import javax.xml.xpath.XPathExpression;
12import javax.xml.xpath.XPathExpressionException;
13import javax.xml.xpath.XPathFactory;
14
15import org.openstreetmap.josm.gui.layer.Layer;
16import org.openstreetmap.josm.gui.progress.ProgressMonitor;
17import org.openstreetmap.josm.io.GpxImporter;
18import org.openstreetmap.josm.io.IllegalDataException;
19import org.openstreetmap.josm.io.NMEAImporter;
20import org.w3c.dom.Element;
21
22public class GpxTracksSessionImporter implements SessionLayerImporter {
23
24 @Override
25 public Layer load(Element elem, SessionReader.ImportSupport support, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
26 String version = elem.getAttribute("version");
27 if (!"0.1".equals(version)) {
28 throw new IllegalDataException(tr("Version ''{0}'' of meta data for gpx track layer is not supported. Expected: 0.1", version));
29 }
30 try {
31 XPathFactory xPathFactory = XPathFactory.newInstance();
32 XPath xpath = xPathFactory.newXPath();
33 XPathExpression fileExp = xpath.compile("file/text()");
34 String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
35 if (fileStr == null || fileStr.isEmpty()) {
36 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
37 }
38
39 try (InputStream in = support.getInputStream(fileStr)) {
40 GpxImporter.GpxImporterData importData = null;
41
42 if (NMEAImporter.FILE_FILTER.acceptName(fileStr)) {
43 importData = NMEAImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), null);
44 } else {
45 importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), null, progressMonitor);
46 }
47
48 support.addPostLayersTask(importData.getPostLayerTask());
49 return importData.getGpxLayer();
50 }
51
52 } catch (XPathExpressionException e) {
53 throw new IllegalDataException(e);
54 }
55 }
56}
Note: See TracBrowser for help on using the repository browser.