Changeset 18954 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2024-01-23T15:17:43+01:00 (10 months ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/session
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionImporter.java
r18466 r18954 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 9 import javax.xml.xpath.XPath;10 import javax.xml.xpath.XPathConstants;11 import javax.xml.xpath.XPathExpression;12 import javax.xml.xpath.XPathExpressionException;13 import javax.xml.xpath.XPathFactory;14 8 15 9 import org.openstreetmap.josm.gui.io.importexport.GpxImporter; … … 21 15 import org.openstreetmap.josm.io.IllegalDataException; 22 16 import org.openstreetmap.josm.tools.Logging; 23 import org.openstreetmap.josm.tools.Utils;24 17 import org.w3c.dom.Element; 25 18 import org.w3c.dom.Node; … … 39 32 throw new IllegalDataException(tr("Version ''{0}'' of meta data for gpx track layer is not supported. Expected: 0.1", version)); 40 33 } 41 try { 42 XPathFactory xPathFactory = XPathFactory.newInstance(); 43 XPath xpath = xPathFactory.newXPath(); 44 XPathExpression fileExp = xpath.compile("file/text()"); 45 String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING); 46 if (Utils.isEmpty(fileStr)) { 47 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex())); 34 String fileStr = OsmDataSessionImporter.extractFileName(elem, support); 35 36 try (InputStream in = support.getInputStream(fileStr)) { 37 GpxImporter.GpxImporterData importData; 38 39 if (NMEAImporter.FILE_FILTER.acceptName(fileStr)) { 40 importData = NMEAImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName()); 41 } else if (RtkLibImporter.FILE_FILTER.acceptName(fileStr)) { 42 importData = RtkLibImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName()); 43 } else { 44 importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), progressMonitor); 45 } 46 if (importData.getGpxLayer() != null && importData.getGpxLayer().data != null) { 47 importData.getGpxLayer().data.fromSession = true; 48 } 49 NodeList markerNodes = elem.getElementsByTagName("markerLayer"); 50 if (markerNodes.getLength() > 0 && markerNodes.item(0).getNodeType() == Node.ELEMENT_NODE) { 51 Element markerEl = (Element) markerNodes.item(0); 52 try { 53 int index = Integer.parseInt(markerEl.getAttribute("index")); 54 support.addSubLayer(index, importData.getMarkerLayer(), markerEl); 55 } catch (NumberFormatException ex) { 56 Logging.warn(ex); 57 } 48 58 } 49 59 50 try (InputStream in = support.getInputStream(fileStr)) { 51 GpxImporter.GpxImporterData importData; 52 53 if (NMEAImporter.FILE_FILTER.acceptName(fileStr)) { 54 importData = NMEAImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName()); 55 } else if (RtkLibImporter.FILE_FILTER.acceptName(fileStr)) { 56 importData = RtkLibImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName()); 57 } else { 58 importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), progressMonitor); 59 } 60 if (importData.getGpxLayer() != null && importData.getGpxLayer().data != null) { 61 importData.getGpxLayer().data.fromSession = true; 62 } 63 NodeList markerNodes = elem.getElementsByTagName("markerLayer"); 64 if (markerNodes.getLength() > 0 && markerNodes.item(0).getNodeType() == Node.ELEMENT_NODE) { 65 Element markerEl = (Element) markerNodes.item(0); 66 try { 67 int index = Integer.parseInt(markerEl.getAttribute("index")); 68 support.addSubLayer(index, importData.getMarkerLayer(), markerEl); 69 } catch (NumberFormatException ex) { 70 Logging.warn(ex); 71 } 72 } 73 74 support.addPostLayersTask(importData.getPostLayerTask()); 75 return getLayer(importData); 76 } 77 78 } catch (XPathExpressionException e) { 79 throw new IllegalDataException(e); 60 support.addPostLayersTask(importData.getPostLayerTask()); 61 return getLayer(importData); 80 62 } 81 63 } -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionImporter.java
r18466 r18954 7 7 import java.io.InputStream; 8 8 9 import javax.xml.xpath.XPath;10 import javax.xml.xpath.XPathConstants;11 import javax.xml.xpath.XPathExpression;12 import javax.xml.xpath.XPathExpressionException;13 import javax.xml.xpath.XPathFactory;14 15 9 import org.openstreetmap.josm.gui.io.importexport.GpxImporter; 16 10 import org.openstreetmap.josm.gui.layer.Layer; … … 19 13 import org.openstreetmap.josm.io.IllegalDataException; 20 14 import org.openstreetmap.josm.io.session.SessionReader.ImportSupport; 21 import org.openstreetmap.josm.tools.Utils;22 15 import org.w3c.dom.Element; 23 16 … … 34 27 throw new IllegalDataException(tr("Version ''{0}'' of meta data for marker layer is not supported. Expected: 0.1", version)); 35 28 } 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 } 29 String fileStr = OsmDataSessionImporter.extractFileName(elem, support); 44 30 45 46 47 31 try (InputStream in = support.getInputStream(fileStr)) { 32 GpxImporter.GpxImporterData importData = GpxImporter.loadLayers(in, support.getFile(fileStr), support.getLayerName(), 33 progressMonitor); 48 34 49 35 support.addPostLayersTask(importData.getPostLayerTask()); 50 36 51 importData.getGpxLayer().destroy(); 52 return importData.getMarkerLayer(); 53 } 54 } catch (XPathExpressionException e) { 55 throw new IllegalDataException(e); 37 importData.getGpxLayer().destroy(); 38 return importData.getMarkerLayer(); 56 39 } 57 40 } -
trunk/src/org/openstreetmap/josm/io/session/NoteSessionImporter.java
r18208 r18954 7 7 import java.io.InputStream; 8 8 9 import javax.xml.xpath.XPath;10 import javax.xml.xpath.XPathConstants;11 import javax.xml.xpath.XPathExpression;12 import javax.xml.xpath.XPathExpressionException;13 import javax.xml.xpath.XPathFactory;14 15 9 import org.openstreetmap.josm.gui.io.importexport.NoteImporter; 16 10 import org.openstreetmap.josm.gui.layer.Layer; … … 19 13 import org.openstreetmap.josm.io.IllegalDataException; 20 14 import org.openstreetmap.josm.io.session.SessionReader.ImportSupport; 21 import org.openstreetmap.josm.tools.Utils;22 15 import org.w3c.dom.Element; 23 16 import org.xml.sax.SAXException; … … 35 28 throw new IllegalDataException(tr("Version ''{0}'' of meta data for note layer is not supported. Expected: 0.1", version)); 36 29 } 37 try {38 XPathFactory xPathFactory = XPathFactory.newInstance();39 XPath xpath = xPathFactory.newXPath();40 XPathExpression fileExp = xpath.compile("file/text()");41 String fileStr = (String) fileExp.evaluate(elem, XPathConstants.STRING);42 if (Utils.isEmpty(fileStr)) {43 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex()));44 }45 30 46 NoteImporter importer = new NoteImporter(); 47 try (InputStream in = support.getInputStream(fileStr)) { 48 return importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), progressMonitor); 49 } 50 } catch (XPathExpressionException | SAXException e) { 31 String fileStr = OsmDataSessionImporter.extractFileName(elem, support); 32 33 NoteImporter importer = new NoteImporter(); 34 try (InputStream in = support.getInputStream(fileStr)) { 35 return importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), progressMonitor); 36 } catch (SAXException e) { 51 37 throw new IllegalDataException(e); 52 38 } -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionImporter.java
r18807 r18954 23 23 import org.openstreetmap.josm.io.session.SessionReader.ImportSupport; 24 24 import org.openstreetmap.josm.tools.Utils; 25 import org.w3c.dom.Attr; 25 26 import org.w3c.dom.Element; 27 import org.w3c.dom.Node; 28 import org.w3c.dom.NodeList; 26 29 27 30 /** … … 30 33 */ 31 34 public class OsmDataSessionImporter implements SessionLayerImporter { 35 36 private static Attr x2; 32 37 33 38 @Override … … 68 73 public static String extractFileName(Element elem, ImportSupport support) throws IllegalDataException { 69 74 try { 75 // see #23427: try first to avoid possibly very slow XPath call 76 NodeList x = elem.getElementsByTagName("file"); 77 if (x.getLength() > 0 && x.item(0).getNodeType() == Node.ELEMENT_NODE) { 78 String fileStr = x.item(0).getTextContent(); 79 if (!Utils.isEmpty(fileStr)) 80 return fileStr; 81 } 70 82 XPathFactory xPathFactory = XPathFactory.newInstance(); 71 83 XPath xpath = xPathFactory.newXPath();
Note:
See TracChangeset
for help on using the changeset viewer.