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.Main;
|
---|
9 | import org.openstreetmap.josm.data.Bounds;
|
---|
10 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
11 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
12 | import org.openstreetmap.josm.io.OsmServerLocationReader;
|
---|
13 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Task allowing to download compressed OSM files (gzip and bzip2)
|
---|
17 | * @since 5317
|
---|
18 | */
|
---|
19 | public class DownloadOsmCompressedTask extends DownloadOsmTask {
|
---|
20 |
|
---|
21 | private static final String PATTERN_COMPRESS = "https?://.*/.*\\.osm.(gz|bz2?|zip)";
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public String[] getPatterns() {
|
---|
25 | return new String[]{PATTERN_COMPRESS};
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public String getTitle() {
|
---|
30 | return tr("Download Compressed OSM");
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Future<?> download(boolean newLayer, Bounds downloadArea,
|
---|
35 | 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 | if (url.matches("https?://.*/.*\\.osm.bz2?")) {
|
---|
52 | return reader.parseOsmBzip2(subTaskMonitor);
|
---|
53 | } else if (url.matches("https?://.*/.*\\.osm.gz")) {
|
---|
54 | return reader.parseOsmGzip(subTaskMonitor);
|
---|
55 | } else {
|
---|
56 | return reader.parseOsmZip(subTaskMonitor);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | };
|
---|
60 | currentBounds = null;
|
---|
61 | // Extract .osm.gz/bz/bz2/zip filename from URL to set the new layer name
|
---|
62 | extractOsmFilename("https?://.*/(.*\\.osm.(gz|bz2?|zip))", url);
|
---|
63 | return Main.worker.submit(downloadTask);
|
---|
64 | }
|
---|
65 | }
|
---|