Class DownloadOsmTask
- java.lang.Object
-
- org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask<DataSet>
-
- org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask
-
- All Implemented Interfaces:
DownloadTask
- Direct Known Subclasses:
DownloadGeoJsonTask
,DownloadOsmChangeTask
,DownloadOsmIdTask
,DownloadOsmInViewAction.DownloadOsmInViewTask
,DownloadOsmUrlTask
public class DownloadOsmTask extends AbstractDownloadTask<DataSet>
Open the download dialog and download the data. Run in the worker thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DownloadOsmTask.AbstractInternalTask
Superclass of internal download task.protected class
DownloadOsmTask.DownloadTask
-
Field Summary
Fields Modifier and Type Field Description protected Bounds
currentBounds
protected DownloadOsmTask.DownloadTask
downloadTask
protected java.lang.String
newLayerName
private static java.lang.String
NO_DATA_FOUND
protected static java.lang.String
OVERPASS_INTERPRETER_DATA
protected boolean
warnAboutEmptyArea
This allows subclasses to ignore this warning-
Fields inherited from class org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask
downloadedData, zoomAfterDownload
-
-
Constructor Summary
Constructors Constructor Description DownloadOsmTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancels the asynchronous download task.protected java.util.concurrent.Future<?>
download(DownloadOsmTask.DownloadTask downloadTask, Bounds downloadArea)
java.util.concurrent.Future<?>
download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor)
Asynchronously launches the download task for a given bounding box.java.util.concurrent.Future<?>
download(OsmServerReader reader, DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor)
Asynchronously launches the download task for a given bounding box.protected void
extractOsmFilename(DownloadParams settings, java.lang.String pattern, java.lang.String url)
java.lang.String
getConfirmationMessage(java.net.URL url)
Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.ProjectionBounds
getDownloadProjectionBounds()
Returns the projection bounds of downloaded data.protected OsmServerReader
getOsmServerReader(java.lang.String url)
java.lang.String[]
getPatterns()
Returns regular expressions that match the URLsjava.lang.String
getTitle()
Returns human-readable description of the taskboolean
isSafeForRemotecontrolRequests()
Check / decide if the task is safe for remotecontrol.java.util.concurrent.Future<?>
loadUrl(DownloadParams settings, java.lang.String url, ProgressMonitor progressMonitor)
Loads a given URL from the OSM Serverprotected java.lang.String
modifyUrlBeforeLoad(java.lang.String url)
This allows subclasses to perform operations on the URL beforeloadUrl(org.openstreetmap.josm.actions.downloadtasks.DownloadParams, java.lang.String, org.openstreetmap.josm.gui.progress.ProgressMonitor)
is performed.protected void
rememberDownloadedBounds(Bounds bounds)
protected java.util.Collection<OsmPrimitive>
searchPotentiallyDeletedPrimitives(DataSet ds)
-
Methods inherited from class org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask
acceptsUrl, acceptsUrl, getDownloadedData, getErrorObjects, isCanceled, isFailed, patterns, rememberDownloadedData, rememberErrorMessage, rememberException, setCanceled, setFailed, setZoomAfterDownload, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.actions.downloadtasks.DownloadTask
acceptsDocumentationSummary, getErrorMessages
-
-
-
-
Field Detail
-
currentBounds
protected Bounds currentBounds
-
downloadTask
protected DownloadOsmTask.DownloadTask downloadTask
-
newLayerName
protected java.lang.String newLayerName
-
warnAboutEmptyArea
protected boolean warnAboutEmptyArea
This allows subclasses to ignore this warning
-
OVERPASS_INTERPRETER_DATA
protected static final java.lang.String OVERPASS_INTERPRETER_DATA
- See Also:
- Constant Field Values
-
NO_DATA_FOUND
private static final java.lang.String NO_DATA_FOUND
-
-
Constructor Detail
-
DownloadOsmTask
public DownloadOsmTask()
-
-
Method Detail
-
getPatterns
public java.lang.String[] getPatterns()
Description copied from interface:DownloadTask
Returns regular expressions that match the URLs- Specified by:
getPatterns
in interfaceDownloadTask
- Overrides:
getPatterns
in classAbstractDownloadTask<DataSet>
- Returns:
- The array of accepted URL patterns
-
getTitle
public java.lang.String getTitle()
Description copied from interface:DownloadTask
Returns human-readable description of the task- Specified by:
getTitle
in interfaceDownloadTask
- Overrides:
getTitle
in classAbstractDownloadTask<DataSet>
- Returns:
- The task description
-
download
public java.util.concurrent.Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor)
Description copied from interface:DownloadTask
Asynchronously launches the download task for a given bounding box.Set
progressMonitor
to null, if the task should create, open, and close a progress monitor. Set progressMonitor toNullProgressMonitor.INSTANCE
if progress information is to be discarded.You can wait for the asynchronous download task to finish by synchronizing on the returned
Future
, but make sure not to freeze up JOSM. Example:Future<?> future = task.download(...); // DON'T run this on the Swing EDT or JOSM will freeze future.get(); // waits for the dowload task to complete
The following example uses a pattern which is better suited if a task is launched from the Swing EDT:final Future<?> future = task.download(...); Runnable runAfterTask = new Runnable() { public void run() { // this is not strictly necessary because of the type of executor service // Main.worker is initialized with, but it doesn't harm either // future.get(); // wait for the download task to complete doSomethingAfterTheTaskCompleted(); } } MainApplication.worker.submit(runAfterTask);
- Parameters:
settings
- download settingsdownloadArea
- the area to downloadprogressMonitor
- the progressMonitor- Returns:
- the future representing the asynchronous task
-
download
public java.util.concurrent.Future<?> download(OsmServerReader reader, DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor)
Asynchronously launches the download task for a given bounding box. SetprogressMonitor
to null, if the task should create, open, and close a progress monitor. Set progressMonitor toNullProgressMonitor.INSTANCE
if progress information is to be discarded. You can wait for the asynchronous download task to finish by synchronizing on the returnedFuture
, but make sure not to freeze up JOSM. Example:Future<?> future = task.download(...); // DON'T run this on the Swing EDT or JOSM will freeze future.get(); // waits for the download task to complete
The following example uses a pattern which is better suited if a task is launched from the Swing EDT:final Future<?> future = task.download(...); Runnable runAfterTask = new Runnable() { public void run() { // this is not strictly necessary because of the type of executor service // Main.worker is initialized with, but it doesn't harm either // future.get(); // wait for the download task to complete doSomethingAfterTheTaskCompleted(); } } MainApplication.worker.submit(runAfterTask);
- Parameters:
reader
- the reader used to parse OSM data (seeOsmServerReader.parseOsm(org.openstreetmap.josm.gui.progress.ProgressMonitor)
)settings
- download settingsdownloadArea
- the area to downloadprogressMonitor
- the progressMonitor- Returns:
- the future representing the asynchronous task
- Since:
- 13927
-
download
protected java.util.concurrent.Future<?> download(DownloadOsmTask.DownloadTask downloadTask, Bounds downloadArea)
-
modifyUrlBeforeLoad
protected java.lang.String modifyUrlBeforeLoad(java.lang.String url)
This allows subclasses to perform operations on the URL beforeloadUrl(org.openstreetmap.josm.actions.downloadtasks.DownloadParams, java.lang.String, org.openstreetmap.josm.gui.progress.ProgressMonitor)
is performed.- Parameters:
url
- the original URL- Returns:
- the modified URL
-
loadUrl
public java.util.concurrent.Future<?> loadUrl(DownloadParams settings, java.lang.String url, ProgressMonitor progressMonitor)
Loads a given URL from the OSM Server- Parameters:
settings
- download settingsurl
- The URL as StringprogressMonitor
- the progressMonitor- Returns:
- the future representing the asynchronous task
- See Also:
DownloadTask.download(DownloadParams, Bounds, ProgressMonitor)
-
getOsmServerReader
protected OsmServerReader getOsmServerReader(java.lang.String url)
-
extractOsmFilename
protected final void extractOsmFilename(DownloadParams settings, java.lang.String pattern, java.lang.String url)
-
cancel
public void cancel()
Description copied from interface:DownloadTask
Cancels the asynchronous download task.
-
isSafeForRemotecontrolRequests
public boolean isSafeForRemotecontrolRequests()
Description copied from class:AbstractDownloadTask
Check / decide if the task is safe for remotecontrol.Keep in mind that a potential attacker has full control over the content of the file that will be downloaded. If it is possible to run arbitrary code or write to the local file system, then the task is (obviously) not save for remote execution.
The default value is false = unsafe. Override in a subclass to allow running the task via remotecontol.
- Overrides:
isSafeForRemotecontrolRequests
in classAbstractDownloadTask<DataSet>
- Returns:
- true if it is safe to download and open any file of the corresponding format, false otherwise
-
getDownloadProjectionBounds
public ProjectionBounds getDownloadProjectionBounds()
Description copied from class:AbstractDownloadTask
Returns the projection bounds of downloaded data.- Overrides:
getDownloadProjectionBounds
in classAbstractDownloadTask<DataSet>
- Returns:
- the projection bounds of downloaded data or
null
-
searchPotentiallyDeletedPrimitives
protected java.util.Collection<OsmPrimitive> searchPotentiallyDeletedPrimitives(DataSet ds)
-
rememberDownloadedBounds
protected final void rememberDownloadedBounds(Bounds bounds)
-
getConfirmationMessage
public java.lang.String getConfirmationMessage(java.net.URL url)
Description copied from interface:DownloadTask
Replies the HTML-formatted confirmation message to be shown to user when the given URL needs to be confirmed before loading.- Parameters:
url
- The URL to be confirmed- Returns:
- The HTML-formatted confirmation message to be shown to user
-
-