Changeset 5361 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-07-25T02:31:52+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 18 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r5317 r5361 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 25 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmBzip2Task; 25 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeCompressedTask; 26 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmCompressedTask; 26 27 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask; 27 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; … … 56 57 addDownloadTaskClass(DownloadOsmChangeTask.class); 57 58 addDownloadTaskClass(DownloadOsmUrlTask.class); 58 addDownloadTaskClass(DownloadOsmBzip2Task.class); 59 addDownloadTaskClass(DownloadOsmCompressedTask.class); 60 addDownloadTaskClass(DownloadOsmChangeCompressedTask.class); 59 61 } 60 62 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java
r5357 r5361 8 8 import org.openstreetmap.josm.data.osm.DataSet; 9 9 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 10 import org.openstreetmap.josm.io.OsmBzip2Importer;11 10 import org.openstreetmap.josm.io.OsmServerLocationReader; 12 11 import org.openstreetmap.josm.io.OsmTransferException; 13 12 14 public class DownloadOsmBzip2Task extends DownloadOsmTask { 15 16 OsmBzip2Importer importer; 13 public class DownloadOsmCompressedTask extends DownloadOsmTask { 17 14 18 15 /* (non-Javadoc) … … 21 18 @Override 22 19 public boolean acceptsUrl(String url) { 23 return url != null && url.matches("http://.*/.*\\.osm. bz2?"); // Remote.osm.bz / .osm.bz2 files20 return url != null && url.matches("http://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files 24 21 } 25 22 … … 38 35 * @param The URL as String 39 36 */ 40 public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {37 public Future<?> loadUrl(boolean new_layer, final String url, ProgressMonitor progressMonitor) { 41 38 downloadTask = new DownloadTask(new_layer, new OsmServerLocationReader(url), progressMonitor) { 42 39 @Override 43 40 protected DataSet parseDataSet() throws OsmTransferException { 44 return reader.parseOsmBzip2(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 41 ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 42 if (url.matches("http://.*/.*\\.osm.bz2?")) { 43 return reader.parseOsmBzip2(subTaskMonitor); 44 } else { 45 return reader.parseOsmGzip(subTaskMonitor); 46 } 45 47 } 46 48 }; 47 49 currentBounds = null; 48 // Extract .osm. bz/bz2 filename from URL to set the new layer name49 extractOsmFilename("http://.*/(.*\\.osm. bz2?)", url);50 // Extract .osm.gz/bz/bz2 filename from URL to set the new layer name 51 extractOsmFilename("http://.*/(.*\\.osm.(gz|bz2?))", url); 50 52 return Main.worker.submit(downloadTask); 51 53 } -
trunk/src/org/openstreetmap/josm/io/FileImporter.java
r3679 r5361 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedInputStream; 6 7 import java.io.File; 7 8 import java.io.IOException; 9 import java.io.InputStream; 8 10 import java.util.List; 11 import java.util.zip.GZIPInputStream; 9 12 10 13 import javax.swing.JOptionPane; 11 14 15 import org.apache.tools.bzip2.CBZip2InputStream; 12 16 import org.openstreetmap.josm.Main; 13 17 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 97 101 return (new Double(this.getPriority())).compareTo(other.getPriority()); 98 102 } 103 104 public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException { 105 if (in == null) { 106 return null; 107 } 108 BufferedInputStream bis = new BufferedInputStream(in); 109 int b = bis.read(); 110 if (b != 'B') 111 throw new IOException(tr("Invalid bz2 file.")); 112 b = bis.read(); 113 if (b != 'Z') 114 throw new IOException(tr("Invalid bz2 file.")); 115 return new CBZip2InputStream(bis); 116 } 99 117 118 public static GZIPInputStream getGZipInputStream(InputStream in) throws IOException { 119 if (in == null) { 120 return null; 121 } 122 return new GZIPInputStream(in); 123 } 100 124 } -
trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java
r4898 r5361 12 12 public class GeoJSONExporter extends FileExporter { 13 13 14 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 15 "json,geojson", "json", tr("GeoJSON Files") + " (*.json *.geojson)"); 16 14 17 public GeoJSONExporter() { 15 super( new ExtensionFileFilter("json,geojson", "json", tr("GeoJSON Files") + " (*.json *.geojson)"));18 super(FILE_FILTER); 16 19 } 17 20 -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r4483 r5361 27 27 28 28 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.actions.ExtensionFileFilter;30 29 import org.openstreetmap.josm.data.gpx.GpxData; 31 30 import org.openstreetmap.josm.data.osm.DataSet; … … 43 42 44 43 public GpxExporter() { 45 super( new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)"));44 super(GpxImporter.FILE_FILTER); 46 45 } 47 46 -
trunk/src/org/openstreetmap/josm/io/GpxImporter.java
r4874 r5361 22 22 public class GpxImporter extends FileImporter { 23 23 24 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 25 "gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)"); 26 24 27 protected static class GpxImporterData { 25 28 public GpxLayer gpxLayer; … … 29 32 30 33 public GpxImporter() { 31 super( new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)"));34 super(FILE_FILTER); 32 35 } 33 36 -
trunk/src/org/openstreetmap/josm/io/JpgImporter.java
r4310 r5361 19 19 public class JpgImporter extends FileImporter { 20 20 private GpxLayer gpx; 21 22 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 23 "jpg", "jpg", tr("Image Files") + " (*.jpg, "+ tr("folder")+")"); 21 24 22 25 public JpgImporter() { 23 super( new ExtensionFileFilter("jpg", "jpg", tr("Image Files") + " (*.jpg, "+ tr("folder")+")"));26 super(FILE_FILTER); 24 27 } 25 28 -
trunk/src/org/openstreetmap/josm/io/NMEAImporter.java
r4244 r5361 20 20 public class NMEAImporter extends FileImporter { 21 21 22 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 23 "nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files") + " (*.nmea *.nme *.nma *.log *.txt)"); 24 22 25 public NMEAImporter() { 23 super( 24 new ExtensionFileFilter("nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files") 25 + " (*.nmea *.nme *.nma *.log *.txt)")); 26 super(FILE_FILTER); 26 27 } 27 28 -
trunk/src/org/openstreetmap/josm/io/OsmBzip2Exporter.java
r3083 r5361 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.io.File; … … 11 9 12 10 import org.apache.tools.bzip2.CBZip2OutputStream; 13 import org.openstreetmap.josm.actions.ExtensionFileFilter;14 11 public class OsmBzip2Exporter extends OsmExporter { 15 12 16 13 public OsmBzip2Exporter() { 17 super(new ExtensionFileFilter("osm.bz2, osm.bz", "osm.bz2", tr("OSM Server Files bzip2 compressed") 18 + " (*.osm.bz2 *.osm.bz)")); 14 super(OsmBzip2Importer.FILE_FILTER); 19 15 } 20 16 -
trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java
r5317 r5361 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedInputStream;7 6 import java.io.File; 8 7 import java.io.FileInputStream; 9 8 import java.io.IOException; 10 import java.io.InputStream;11 9 12 import org.apache.tools.bzip2.CBZip2InputStream;13 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 16 13 public class OsmBzip2Importer extends OsmImporter { 17 14 15 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 16 "osm.bz2,osm.bz", "osm.bz2", tr("OSM Server Files bzip2 compressed") + " (*.osm.bz2 *.osm.bz)"); 17 18 18 public OsmBzip2Importer() { 19 super(new ExtensionFileFilter("osm.bz2,osm.bz", "osm.bz2", tr("OSM Server Files bzip2 compressed") 20 + " (*.osm.bz2 *.osm.bz)")); 19 super(FILE_FILTER); 21 20 } 22 21 … … 25 24 importData(getBZip2InputStream(new FileInputStream(file)), file); 26 25 } 27 28 public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException {29 if (in == null) {30 return null;31 }32 BufferedInputStream bis = new BufferedInputStream(in);33 int b = bis.read();34 if (b != 'B')35 throw new IOException(tr("Invalid bz2 file."));36 b = bis.read();37 if (b != 'Z')38 throw new IOException(tr("Invalid bz2 file."));39 return new CBZip2InputStream(bis);40 }41 26 } -
trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java
r4533 r5361 22 22 public class OsmChangeImporter extends FileImporter { 23 23 24 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 25 "osc,osc.bz2,osc.bz,osc.gz", "osc", tr("OsmChange File") + " (*.osc *.osc.bz2 *.osc.bz *.osc.gz)"); 26 24 27 public OsmChangeImporter() { 25 super( new ExtensionFileFilter("osc", "osc", tr("OsmChange File") + " (*.osc)"));28 super(FILE_FILTER); 26 29 } 27 30 … … 33 36 try { 34 37 FileInputStream in = new FileInputStream(file); 35 importData(in, file); 38 39 if (file.getName().endsWith(".osc")) { 40 importData(in, file); 41 } else if (file.getName().endsWith(".gz")) { 42 importData(getGZipInputStream(in), file); 43 } else { 44 importData(getBZip2InputStream(in), file); 45 } 46 36 47 } catch (FileNotFoundException e) { 37 48 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/io/OsmExporter.java
r5025 r5361 25 25 26 26 public OsmExporter() { 27 super( new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)"));27 super(OsmImporter.FILE_FILTER); 28 28 } 29 29 -
trunk/src/org/openstreetmap/josm/io/OsmGzipExporter.java
r3083 r5361 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.io.File; … … 10 8 import java.io.OutputStream; 11 9 import java.util.zip.GZIPOutputStream; 12 13 import org.openstreetmap.josm.actions.ExtensionFileFilter;14 10 public class OsmGzipExporter extends OsmExporter { 15 11 16 12 public OsmGzipExporter() { 17 super( new ExtensionFileFilter("osm.gz", "osm.gz", tr("OSM Server Files gzip compressed") + " (*.osm.gz)"));13 super(OsmGzipImporter.FILE_FILTER); 18 14 } 19 15 -
trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java
r3083 r5361 7 7 import java.io.FileInputStream; 8 8 import java.io.IOException; 9 import java.util.zip.GZIPInputStream;10 9 11 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 14 13 public class OsmGzipImporter extends OsmImporter { 15 14 15 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 16 "osm.gz", "osm.gz", tr("OSM Server Files gzip compressed") + " (*.osm.gz)"); 17 16 18 public OsmGzipImporter() { 17 super( new ExtensionFileFilter("osm.gz", "osm.gz", tr("OSM Server Files gzip compressed") + " (*.osm.gz)"));19 super(FILE_FILTER); 18 20 } 19 21 20 22 @Override 21 23 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 22 GZIPInputStream in = new GZIPInputStream(new FileInputStream(file)); 23 importData(in, file); 24 importData(getGZipInputStream(new FileInputStream(file)), file); 24 25 } 25 26 } -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r5205 r5361 22 22 public class OsmImporter extends FileImporter { 23 23 24 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 25 "osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)"); 26 24 27 public static class OsmImporterData { 25 28 … … 42 45 43 46 public OsmImporter() { 44 super( new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)"));47 super(FILE_FILTER); 45 48 } 46 49 -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r5317 r5361 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.zip.GZIPInputStream; 8 9 9 10 import org.apache.tools.bzip2.CBZip2InputStream; … … 76 77 if (in == null) 77 78 return null; 78 CBZip2InputStream bzin = OsmBzip2Importer.getBZip2InputStream(in);79 CBZip2InputStream bzin = FileImporter.getBZip2InputStream(in); 79 80 progressMonitor.subTask(tr("Downloading OSM data...")); 80 81 return OsmReader.parseDataSet(bzin, progressMonitor.createSubTaskMonitor(1, false)); 82 } 83 }, progressMonitor); 84 } 85 86 /** 87 * Method to download GZip-compressed OSM files from somewhere 88 */ 89 @Override 90 public DataSet parseOsmGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 91 return doParse(new Parser<DataSet>() { 92 @Override 93 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 94 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 95 if (in == null) 96 return null; 97 GZIPInputStream gzin = FileImporter.getGZipInputStream(in); 98 progressMonitor.subTask(tr("Downloading OSM data...")); 99 return OsmReader.parseDataSet(gzin, progressMonitor.createSubTaskMonitor(1, false)); 81 100 } 82 101 }, progressMonitor); … … 97 116 progressMonitor.subTask(tr("Downloading OSM data...")); 98 117 return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 118 } 119 }, progressMonitor); 120 } 121 122 /** 123 * Method to download BZip2-compressed OSM Change files from somewhere 124 */ 125 @Override 126 public DataSet parseOsmChangeBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 127 return doParse(new Parser<DataSet>() { 128 @Override 129 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 130 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 131 if (in == null) 132 return null; 133 CBZip2InputStream bzin = FileImporter.getBZip2InputStream(in); 134 progressMonitor.subTask(tr("Downloading OSM data...")); 135 return OsmChangeReader.parseDataSet(bzin, progressMonitor.createSubTaskMonitor(1, false)); 136 } 137 }, progressMonitor); 138 } 139 140 /** 141 * Method to download GZip-compressed OSM Change files from somewhere 142 */ 143 @Override 144 public DataSet parseOsmChangeGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 145 return doParse(new Parser<DataSet>() { 146 @Override 147 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 148 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 149 if (in == null) 150 return null; 151 GZIPInputStream gzin = FileImporter.getGZipInputStream(in); 152 progressMonitor.subTask(tr("Downloading OSM data...")); 153 return OsmChangeReader.parseDataSet(gzin, progressMonitor.createSubTaskMonitor(1, false)); 99 154 } 100 155 }, progressMonitor); -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r5324 r5361 151 151 return null; 152 152 } 153 153 154 public DataSet parseOsmChangeBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 155 return null; 156 } 157 158 public DataSet parseOsmChangeGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 159 return null; 160 } 161 154 162 public GpxData parseRawGps(final ProgressMonitor progressMonitor) throws OsmTransferException { 155 163 return null; … … 159 167 return null; 160 168 } 161 169 170 public DataSet parseOsmGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 171 return null; 172 } 173 162 174 /** 163 175 * Returns true if this reader is adding authentication credentials to the read -
trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java
r3720 r5361 2 2 package org.openstreetmap.josm.io; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import org.openstreetmap.josm.actions.ExtensionFileFilter; 7 8 public class WMSLayerExporter extends FileExporter{ 4 public class WMSLayerExporter extends FileExporter { 9 5 10 6 public WMSLayerExporter() { 11 super( new ExtensionFileFilter("wms", "wms", tr("WMS Files (*.wms)")));7 super(WMSLayerImporter.FILE_FILTER); 12 8 } 13 9 } -
trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java
r3720 r5361 6 6 import org.openstreetmap.josm.actions.ExtensionFileFilter; 7 7 8 public class WMSLayerImporter extends FileImporter {8 public class WMSLayerImporter extends FileImporter { 9 9 10 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 11 "wms", "wms", tr("WMS Files (*.wms)")); 12 10 13 public WMSLayerImporter() { 11 super( new ExtensionFileFilter("wms", "wms", tr("WMS Files (*.wms)")));14 super(FILE_FILTER); 12 15 } 13 14 16 }
Note:
See TracChangeset
for help on using the changeset viewer.