Class AbstractDownloadTask<T>
- java.lang.Object
-
- org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask<T>
-
- Type Parameters:
T
- The downloaded data type
- All Implemented Interfaces:
DownloadTask
- Direct Known Subclasses:
AbstractChangesetDownloadTask
,DownloadGpsTask
,DownloadNotesTask
,DownloadOsmTask
,DownloadSessionTask
public abstract class AbstractDownloadTask<T> extends java.lang.Object implements DownloadTask
Common abstract implementation of other download tasks.- Since:
- 2322
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
canceled
protected T
downloadedData
private java.util.List<java.lang.Object>
errorMessages
private boolean
failed
protected boolean
zoomAfterDownload
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDownloadTask()
Constructs a newAbstractDownloadTask
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptsUrl(java.lang.String url)
Determines if the given URL is accepted bygetPatterns()
.boolean
acceptsUrl(java.lang.String url, boolean isRemotecontrol)
Returns true if the task is able to open the given URL, false otherwise.T
getDownloadedData()
Replies the downloaded data.ProjectionBounds
getDownloadProjectionBounds()
Returns the projection bounds of downloaded data.java.util.List<java.lang.Object>
getErrorObjects()
Replies the error objects of the task.java.lang.String[]
getPatterns()
Returns regular expressions that match the URLsjava.lang.String
getTitle()
Returns human-readable description of the taskboolean
isCanceled()
Determines if the download task has been canceled.boolean
isFailed()
Determines if the download task has failed.boolean
isSafeForRemotecontrolRequests()
Check / decide if the task is safe for remotecontrol.protected static <T extends java.lang.Enum<T> & UrlPattern>
java.lang.String[]patterns(java.lang.Class<T> urlPatternEnum)
protected void
rememberDownloadedData(T data)
protected void
rememberErrorMessage(java.lang.String message)
protected void
rememberException(java.lang.Exception exception)
void
setCanceled(boolean canceled)
Marks this download task as canceled.void
setFailed(boolean failed)
Marks this download task as failed.void
setZoomAfterDownload(boolean zoomAfterDownload)
Sets whether the map view will zoom to download area after downloadjava.lang.String
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, cancel, download, getConfirmationMessage, getErrorMessages, loadUrl
-
-
-
-
Field Detail
-
errorMessages
private final java.util.List<java.lang.Object> errorMessages
-
canceled
private boolean canceled
-
failed
private boolean failed
-
downloadedData
protected T downloadedData
-
zoomAfterDownload
protected boolean zoomAfterDownload
-
-
Constructor Detail
-
AbstractDownloadTask
protected AbstractDownloadTask()
Constructs a newAbstractDownloadTask
.
-
-
Method Detail
-
isCanceled
public boolean isCanceled()
Determines if the download task has been canceled.- Returns:
true
if the download task has been canceled
-
setCanceled
public void setCanceled(boolean canceled)
Marks this download task as canceled.- Parameters:
canceled
-true
to mark this download task as canceled
-
isFailed
public boolean isFailed()
Determines if the download task has failed.- Returns:
true
if the download task has failed
-
setFailed
public void setFailed(boolean failed)
Marks this download task as failed.- Parameters:
failed
-true
to mark this download task as failed
-
patterns
protected static <T extends java.lang.Enum<T> & UrlPattern> java.lang.String[] patterns(java.lang.Class<T> urlPatternEnum)
-
rememberErrorMessage
protected final void rememberErrorMessage(java.lang.String message)
-
rememberException
protected final void rememberException(java.lang.Exception exception)
-
rememberDownloadedData
protected final void rememberDownloadedData(T data)
-
getDownloadedData
public final T getDownloadedData()
Replies the downloaded data.- Returns:
- The downloaded data.
-
setZoomAfterDownload
public final void setZoomAfterDownload(boolean zoomAfterDownload)
Description copied from interface:DownloadTask
Sets whether the map view will zoom to download area after download- Specified by:
setZoomAfterDownload
in interfaceDownloadTask
- Parameters:
zoomAfterDownload
- if true, the map view will zoom to download area after download
-
getErrorObjects
public java.util.List<java.lang.Object> getErrorObjects()
Description copied from interface:DownloadTask
Replies the error objects of the task. Empty list, if no error messages are available.Error objects are either
String
s with error messages orException
s.- Specified by:
getErrorObjects
in interfaceDownloadTask
- Returns:
- the list of error objects
-
acceptsUrl
public boolean acceptsUrl(java.lang.String url)
Determines if the given URL is accepted bygetPatterns()
. Can be overridden for more complex checking logic.- Parameters:
url
- URL to download- Returns:
true
if this URL is accepted
-
isSafeForRemotecontrolRequests
public boolean isSafeForRemotecontrolRequests()
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.
- Returns:
- true if it is safe to download and open any file of the corresponding format, false otherwise
-
acceptsUrl
public boolean acceptsUrl(java.lang.String url, boolean isRemotecontrol)
Description copied from interface:DownloadTask
Returns true if the task is able to open the given URL, false otherwise.- Specified by:
acceptsUrl
in interfaceDownloadTask
- Parameters:
url
- the url to download fromisRemotecontrol
- True if download request comes from remotecontrol.- Returns:
- True if the task is able to open the given URL, false otherwise. Return false, if the request comes from remotecontrol, but the task is not safe for remotecontrol. A task is not safe for remotecontrol if it is possible to prepare a file for download which does something unintended, e.g. gain access to the local file system.
-
getTitle
public java.lang.String getTitle()
Description copied from interface:DownloadTask
Returns human-readable description of the task- Specified by:
getTitle
in interfaceDownloadTask
- Returns:
- The task description
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getPatterns
public java.lang.String[] getPatterns()
Description copied from interface:DownloadTask
Returns regular expressions that match the URLs- Specified by:
getPatterns
in interfaceDownloadTask
- Returns:
- The array of accepted URL patterns
-
getDownloadProjectionBounds
public ProjectionBounds getDownloadProjectionBounds()
Returns the projection bounds of downloaded data.- Returns:
- the projection bounds of downloaded data or
null
- Since:
- 11774
-
-