source: josm/trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionImporter.java@ 8540

Last change on this file since 8540 was 8540, checked in by Don-vip, 9 years ago

fix remaining checkstyle issues

  • Property svn:eol-style set to native
File size: 2.1 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.IllegalDataException;
18import org.openstreetmap.josm.io.OsmImporter;
19import org.openstreetmap.josm.io.session.SessionReader.ImportSupport;
20import org.w3c.dom.Element;
21
22public class OsmDataSessionImporter implements SessionLayerImporter {
23
24 @Override
25 public Layer load(Element elem, 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 osm data 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 OsmImporter importer = new OsmImporter();
40 try (InputStream in = support.getInputStream(fileStr)) {
41 OsmImporter.OsmImporterData importData = importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(),
42 progressMonitor);
43
44 support.addPostLayersTask(importData.getPostLayerTask());
45 return importData.getLayer();
46 }
47 } catch (XPathExpressionException e) {
48 throw new IllegalDataException(e);
49 }
50 }
51}
52
Note: See TracBrowser for help on using the repository browser.