1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
3 |
|
---|
4 | import java.util.concurrent.Future;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.data.Bounds;
|
---|
8 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
9 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
10 | import org.openstreetmap.josm.io.OsmServerLocationReader;
|
---|
11 | import org.openstreetmap.josm.io.OsmTransferException;
|
---|
12 |
|
---|
13 | public class DownloadOsmCompressedTask extends DownloadOsmTask {
|
---|
14 |
|
---|
15 | /* (non-Javadoc)
|
---|
16 | * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)
|
---|
17 | */
|
---|
18 | @Override
|
---|
19 | public boolean acceptsUrl(String url) {
|
---|
20 | return url != null && url.matches("https?://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files
|
---|
21 | }
|
---|
22 |
|
---|
23 | /* (non-Javadoc)
|
---|
24 | * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
|
---|
25 | */
|
---|
26 | @Override
|
---|
27 | public Future<?> download(boolean newLayer, Bounds downloadArea,
|
---|
28 | ProgressMonitor progressMonitor) {
|
---|
29 | return null;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Loads a given URL
|
---|
34 | * @param new_layer {@code true} if the data should be saved to a new layer
|
---|
35 | * @param url The URL as String
|
---|
36 | * @param progressMonitor progress monitor for user interaction
|
---|
37 | */
|
---|
38 | public Future<?> loadUrl(boolean new_layer, final String url, ProgressMonitor progressMonitor) {
|
---|
39 | downloadTask = new DownloadTask(new_layer, new OsmServerLocationReader(url), progressMonitor) {
|
---|
40 | @Override
|
---|
41 | protected DataSet parseDataSet() throws OsmTransferException {
|
---|
42 | ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
|
---|
43 | if (url.matches("https?://.*/.*\\.osm.bz2?")) {
|
---|
44 | return reader.parseOsmBzip2(subTaskMonitor);
|
---|
45 | } else {
|
---|
46 | return reader.parseOsmGzip(subTaskMonitor);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | };
|
---|
50 | currentBounds = null;
|
---|
51 | // Extract .osm.gz/bz/bz2 filename from URL to set the new layer name
|
---|
52 | extractOsmFilename("https?://.*/(.*\\.osm.(gz|bz2?))", url);
|
---|
53 | return Main.worker.submit(downloadTask);
|
---|
54 | }
|
---|
55 | }
|
---|