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 booleancanceledprotected TdownloadedDataprivate java.util.List<java.lang.Object>errorMessagesprivate booleanfailedprotected booleanzoomAfterDownload
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDownloadTask()Constructs a newAbstractDownloadTask.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptsUrl(java.lang.String url)Determines if the given URL is accepted bygetPatterns().booleanacceptsUrl(java.lang.String url, boolean isRemotecontrol)Returns true if the task is able to open the given URL, false otherwise.TgetDownloadedData()Replies the downloaded data.ProjectionBoundsgetDownloadProjectionBounds()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.StringgetTitle()Returns human-readable description of the taskbooleanisCanceled()Determines if the download task has been canceled.booleanisFailed()Determines if the download task has failed.booleanisSafeForRemotecontrolRequests()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 voidrememberDownloadedData(T data)protected voidrememberErrorMessage(java.lang.String message)protected voidrememberException(java.lang.Exception exception)voidsetCanceled(boolean canceled)Marks this download task as canceled.voidsetFailed(boolean failed)Marks this download task as failed.voidsetZoomAfterDownload(boolean zoomAfterDownload)Sets whether the map view will zoom to download area after downloadjava.lang.StringtoString()-
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:
trueif the download task has been canceled
-
setCanceled
public void setCanceled(boolean canceled)
Marks this download task as canceled.- Parameters:
canceled-trueto mark this download task as canceled
-
isFailed
public boolean isFailed()
Determines if the download task has failed.- Returns:
trueif the download task has failed
-
setFailed
public void setFailed(boolean failed)
Marks this download task as failed.- Parameters:
failed-trueto 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:DownloadTaskSets whether the map view will zoom to download area after download- Specified by:
setZoomAfterDownloadin 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:DownloadTaskReplies the error objects of the task. Empty list, if no error messages are available.Error objects are either
Strings with error messages orExceptions.- Specified by:
getErrorObjectsin 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:
trueif 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:DownloadTaskReturns true if the task is able to open the given URL, false otherwise.- Specified by:
acceptsUrlin 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:DownloadTaskReturns human-readable description of the task- Specified by:
getTitlein interfaceDownloadTask- Returns:
- The task description
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getPatterns
public java.lang.String[] getPatterns()
Description copied from interface:DownloadTaskReturns regular expressions that match the URLs- Specified by:
getPatternsin 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
-
-