1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.concurrent.Future;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.Bounds;
|
---|
9 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
10 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
11 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
12 | import org.openstreetmap.josm.io.Compression;
|
---|
13 | import org.openstreetmap.josm.io.OsmServerLocationReader;
|
---|
14 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Task allowing to download compressed OSM files (gzip, xz and bzip2)
|
---|
18 | * @since 5317
|
---|
19 | */
|
---|
20 | public class DownloadOsmCompressedTask extends DownloadOsmTask {
|
---|
21 |
|
---|
22 | private static final String PATTERN_COMPRESS = "https?://.*/(.*\\.osm\\.(gz|xz|bz2?|zip))";
|
---|
23 |
|
---|
24 | @Override
|
---|
25 | public String[] getPatterns() {
|
---|
26 | return new String[]{PATTERN_COMPRESS};
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public String getTitle() {
|
---|
31 | return tr("Download Compressed OSM");
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
|
---|
36 | return null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Loads a given URL
|
---|
41 | * @param newLayer {@code true} if the data should be saved to a new layer
|
---|
42 | * @param url The URL as String
|
---|
43 | * @param progressMonitor progress monitor for user interaction
|
---|
44 | */
|
---|
45 | @Override
|
---|
46 | public Future<?> loadUrl(boolean newLayer, final String url, ProgressMonitor progressMonitor) {
|
---|
47 | downloadTask = new DownloadTask(newLayer, new OsmServerLocationReader(url), progressMonitor) {
|
---|
48 | @Override
|
---|
49 | protected DataSet parseDataSet() throws OsmTransferException {
|
---|
50 | ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
|
---|
51 | return reader.parseOsm(subTaskMonitor, Compression.byExtension(url));
|
---|
52 | }
|
---|
53 | };
|
---|
54 | currentBounds = null;
|
---|
55 | // Extract .osm.gz/bz/bz2/zip filename from URL to set the new layer name
|
---|
56 | extractOsmFilename(PATTERN_COMPRESS, url);
|
---|
57 | return MainApplication.worker.submit(downloadTask);
|
---|
58 | }
|
---|
59 | }
|
---|