- Timestamp:
- 2019-09-26T20:05:02+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/build.xml
r15243 r15377 806 806 <ignore classname="org.fusesource.*"/> 807 807 <ignore classname="org.gdal.*"/> 808 <ignore classname="org.geotools.data.h2.*"/> 809 <ignore classname="org.geotools.gce.imagemosaic.*"/> 808 810 <ignore classname="org.hibernate.*"/> 809 811 <ignore classname="org.hsqldb.*"/> -
trunk/src/org/openstreetmap/josm/data/osm/Tags.java
r15376 r15377 42 42 return values; 43 43 } 44 45 @Override 46 public int hashCode() { 47 return Objects.hash(key, values); 48 } 49 50 @Override 51 public boolean equals(Object obj) { 52 if (this == obj) 53 return true; 54 if (obj == null || getClass() != obj.getClass()) 55 return false; 56 Tags other = (Tags) obj; 57 return Objects.equals(key, other.key) && Objects.equals(values, other.values); 58 } 59 60 @Override 61 public String toString() { 62 return "Tags [key=" + key + ", values=" + values + ']'; 63 } 44 64 } -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
r12800 r15377 8 8 import java.nio.charset.StandardCharsets; 9 9 10 import org.openstreetmap.josm.data.osm.DataSet; 10 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 12 import org.openstreetmap.josm.io.OsmWriter; … … 28 29 @Override 29 30 protected void addDataFile(OutputStream out) { 31 export(layer.data, out); 32 } 33 34 /** 35 * Exports OSM data to the given output stream. 36 * @param data data set 37 * @param out output stream 38 * @since 15377 39 */ 40 public static void export(DataSet data, OutputStream out) { 30 41 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 31 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion());32 layer.data.getReadLock().lock();42 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion()); 43 data.getReadLock().lock(); 33 44 try { 34 w.write( layer.data);45 w.write(data); 35 46 w.flush(); 36 47 } finally { 37 layer.data.getReadLock().unlock();48 data.getReadLock().unlock(); 38 49 } 39 50 } -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionImporter.java
r12671 r15377 29 29 @Override 30 30 public Layer load(Element elem, ImportSupport support, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 31 checkMetaVersion(elem); 32 String fileStr = extractFileName(elem, support); 33 return importData(new OsmImporter(), support, fileStr, progressMonitor); 34 } 35 36 /** 37 * Checks that element defines the expected version number. 38 * @param elem element to check 39 * @throws IllegalDataException if version is not the expected one 40 * @since 15377 41 */ 42 public static void checkMetaVersion(Element elem) throws IllegalDataException { 31 43 String version = elem.getAttribute("version"); 32 44 if (!"0.1".equals(version)) { 33 45 throw new IllegalDataException(tr("Version ''{0}'' of meta data for osm data layer is not supported. Expected: 0.1", version)); 34 46 } 47 } 48 49 /** 50 * Extract file name from element. 51 * @param elem element to parse 52 * @param support import/export support 53 * @return file name, if present 54 * @throws IllegalDataException if file name missing or empty 55 * @since 15377 56 */ 57 public static String extractFileName(Element elem, ImportSupport support) throws IllegalDataException { 35 58 try { 36 59 XPathFactory xPathFactory = XPathFactory.newInstance(); … … 41 64 throw new IllegalDataException(tr("File name expected for layer no. {0}", support.getLayerIndex())); 42 65 } 43 44 OsmImporter importer = new OsmImporter(); 45 try (InputStream in = support.getInputStream(fileStr)) { 46 OsmImporter.OsmImporterData importData = importer.loadLayer(in, support.getFile(fileStr), support.getLayerName(), 47 progressMonitor); 48 49 support.addPostLayersTask(importData.getPostLayerTask()); 50 return importData.getLayer(); 51 } 66 return fileStr; 52 67 } catch (XPathExpressionException e) { 53 68 throw new IllegalDataException(e); 54 69 } 55 70 } 71 72 /** 73 * Import data as a new layer. 74 * @param osmImporter OSM importer 75 * @param support import/export support 76 * @param fileStr file name to import 77 * @param progressMonitor progress monitor 78 * @return new layer 79 * @throws IOException in case of I/O error 80 * @throws IllegalDataException in case of illegal data 81 * @since 15377 82 */ 83 public static Layer importData(OsmImporter osmImporter, ImportSupport support, String fileStr, ProgressMonitor progressMonitor) 84 throws IOException, IllegalDataException { 85 try (InputStream in = support.getInputStream(fileStr)) { 86 OsmImporter.OsmImporterData importData = osmImporter.loadLayer( 87 in, support.getFile(fileStr), support.getLayerName(), progressMonitor); 88 89 support.addPostLayersTask(importData.getPostLayerTask()); 90 return importData.getLayer(); 91 } 92 } 56 93 }
Note:
See TracChangeset
for help on using the changeset viewer.