@Override
public Layer load(Element elem, ImportSupport support, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
String version = elem.getAttribute("version");
if (!"0.1".equals(version)) {
throw new IllegalDataException(tr("Version ''{0}'' of meta data for marker layer is not supported. Expected: 0.1", version));
}
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xpath = xPathFactory.newXPath();
XPathExpression fileExp = xpath.compile("file/text()");
String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);
if (fileStr == null || fileStr.isEmpty()) {
throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));
}
try (InputStream in = support.getInputStream(fileStr)) {
GpxImporter.GpxImporterData importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), null, progressMonitor);
support.addPostLayersTask(importData.getPostLayerTask());
GpxLayer gpxLayer = null;
List<SessionReader.LayerDependency> deps = support.getLayerDependencies();
if (!deps.isEmpty()) {
Layer layer = deps.iterator().next().getLayer();
if (layer instanceof GpxLayer) {
gpxLayer = (GpxLayer) layer;
}
}
MarkerLayer markerLayer = importData.getMarkerLayer();
if (markerLayer != null) {
markerLayer.fromLayer = gpxLayer;
}
return markerLayer;
}
} catch (XPathExpressionException e) {
throw new IllegalDataException(e);
}
}