org.openstreetmap.josm.gui.preferences.server
Class ApiUrlTestTask

java.lang.Object
  extended by org.openstreetmap.josm.gui.PleaseWaitRunnable
      extended by org.openstreetmap.josm.gui.preferences.server.ApiUrlTestTask
All Implemented Interfaces:
java.lang.Runnable, ProgressMonitor.CancelListener

public class ApiUrlTestTask
extends PleaseWaitRunnable

This is an asynchronous task for testing whether an URL points to an OSM API server. It tries to retrieve a list of changesets from the given URL. If it succeeds, the method isSuccess() replies true, otherwise false. Note: it fetches a list of changesets instead of the much smaller capabilities because - strangely enough - an OSM server "http://x.y.y/api/0.6" not only responds to "http://x.y.y/api/0.6/capabilities" but also to "http://x.y.y/api/0/capabilities" or "http://x.y.y/a/capabilities" with valid capabilities. If we get valid capabilities with an URL we therefore can't be sure that the base URL is valid API URL.


Field Summary
private  boolean canceled
           
private  java.net.HttpURLConnection connection
           
private  java.awt.Component parent
           
private  boolean success
           
private  java.lang.String url
           
 
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
 
Constructor Summary
ApiUrlTestTask(java.awt.Component parent, java.lang.String url)
          Creates the task
 
Method Summary
protected  void alertConnectionFailed()
           
protected  void alertInvalidChangesetList()
           
protected  void alertInvalidChangesetUrl(java.lang.String url)
           
protected  void alertInvalidServerResult(int retCode)
           
protected  void alertInvalidUrl(java.lang.String url)
           
protected  void cancel()
          User pressed cancel button.
protected  void finish()
          Finish up the data work.
protected  java.lang.String getNormalizedApiUrl()
          Removes leading and trailing whitespace from the API URL and removes trailing '/'.
 boolean isCanceled()
           
 boolean isSuccess()
           
protected  void realRun()
          Called in the worker thread to do the actual work.
 
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, canRunInBackground, getProgressMonitor, operationCanceled, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

private java.lang.String url

canceled

private boolean canceled

success

private boolean success

parent

private java.awt.Component parent

connection

private java.net.HttpURLConnection connection
Constructor Detail

ApiUrlTestTask

public ApiUrlTestTask(java.awt.Component parent,
                      java.lang.String url)
               throws java.lang.IllegalArgumentException
Creates the task

Parameters:
parent - the parent component relative to which the PleaseWaitRunnable-Dialog is displayed
url - the url. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown if url is null.
Method Detail

alertInvalidUrl

protected void alertInvalidUrl(java.lang.String url)

alertInvalidChangesetUrl

protected void alertInvalidChangesetUrl(java.lang.String url)

alertConnectionFailed

protected void alertConnectionFailed()

alertInvalidServerResult

protected void alertInvalidServerResult(int retCode)

alertInvalidChangesetList

protected void alertInvalidChangesetList()

cancel

protected void cancel()
Description copied from class: PleaseWaitRunnable
User pressed cancel button.

Specified by:
cancel in class PleaseWaitRunnable

finish

protected void finish()
Description copied from class: PleaseWaitRunnable
Finish up the data work. Is guaranteed to be called if realRun is called. Finish is called in the gui thread just after the dialog disappeared.

Specified by:
finish in class PleaseWaitRunnable

getNormalizedApiUrl

protected java.lang.String getNormalizedApiUrl()
Removes leading and trailing whitespace from the API URL and removes trailing '/'.

Returns:
the normalized API URL

realRun

protected void realRun()
                throws org.xml.sax.SAXException,
                       java.io.IOException,
                       OsmTransferException
Description copied from class: PleaseWaitRunnable
Called in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.

Specified by:
realRun in class PleaseWaitRunnable
Throws:
org.xml.sax.SAXException
java.io.IOException
OsmTransferException

isCanceled

public boolean isCanceled()

isSuccess

public boolean isSuccess()


JOSM