source: josm/trunk/src/org/openstreetmap/josm/io/session/MarkerSessionImporter.java@ 18466

Last change on this file since 18466 was 18466, checked in by taylor.smock, 23 months ago

Fix #21813: Improve marker handling in sessions and #21923: Improve session workflow/Add "save session" (patch by Bjoeni)

  • Allow saving a previously saved session
  • Add "File" -> "Save Session"
  • Add shortcuts for saving sessions
  • Add warning if a layer in a session is being removed when saving over the session
  • Improve GPX marker handling
  • 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.io.importexport.GpxImporter;
16import org.openstreetmap.josm.gui.layer.Layer;
17import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
18import org.openstreetmap.josm.gui.progress.ProgressMonitor;
19import org.openstreetmap.josm.io.IllegalDataException;
20import org.openstreetmap.josm.io.session.SessionReader.ImportSupport;
21import org.openstreetmap.josm.tools.Utils;
22import org.w3c.dom.Element;
23
24/**
25 * Session importer for {@link MarkerLayer}.
26 * @since 5684
27 */
28public class MarkerSessionImporter implements SessionLayerImporter {
29
30 @Override
31 public Layer load(Element elem, ImportSupport support, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
32 String version = elem.getAttribute("version");
33 if (!"0.1".equals(version)) {
34 throw new IllegalDataException(tr("Version ''{0}'' of meta data for marker layer is not supported. Expected: 0.1", version));
35 }
36 try {
37 XPathFactory xPathFactory = XPathFactory.newInstance();
38 XPath xpath = xPathFactory.newXPath();
39 XPathExpression fileExp = xpath.compile("file/text()");
40 String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
41 if (Utils.isEmpty(fileStr)) {
42 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
43 }
44
45 try (InputStream in = support.getInputStream(fileStr)) {
46 GpxImporter.GpxImporterData importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(),
47 progressMonitor);
48
49 support.addPostLayersTask(importData.getPostLayerTask());
50
51 importData.getGpxLayer().destroy();
52 return importData.getMarkerLayer();
53 }
54 } catch (XPathExpressionException e) {
55 throw new IllegalDataException(e);
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.