Ignore:
Timestamp:
2013-03-22T22:18:26+01:00 (12 years ago)
Author:
zverik
Message:

ImageryID refactoring and javadocs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/SimpleOffsetQueryTask.java

    r29380 r29384  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    11 import org.openstreetmap.josm.io.OsmTransferException;
    12 import org.xml.sax.SAXException;
    1311import static org.openstreetmap.josm.tools.I18n.tr;
    1412
    1513/**
     14 * A task to query the imagery offset server and process the response.
    1615 *
    17  * @author zverik
     16 * @author Zverik
     17 * @license WTFPL
    1818 */
    1919class SimpleOffsetQueryTask extends PleaseWaitRunnable {
     
    2424    private QuerySuccessListener listener;
    2525
     26    /**
     27     * Initialize the task.
     28     * @param query A query string, usually starting with an action word and a question mark.
     29     * @param title A title for the progress monitor.
     30     */
    2631    public SimpleOffsetQueryTask( String query, String title ) {
    2732        super(tr("Uploading"));
     
    3136    }
    3237
     38    /**
     39     * In case a query was not specified when the object was constructed,
     40     * it can be set with this method.
     41     * @see #SimpleOffsetQueryTask(java.lang.String, java.lang.String)
     42     */
    3343    public void setQuery( String query ) {
    3444        this.query = query;
    3545    }
    3646
     47    /**
     48     * Install a listener for successful responses. There can be only one.
     49     */
    3750    public void setListener( QuerySuccessListener listener ) {
    3851        this.listener = listener;
    3952    }
    4053
     54    /**
     55     * Remove a listener for successful responses.
     56     */
    4157    public void removeListener() {
    4258        this.listener = null;
    4359    }
    4460
     61    /**
     62     * The main method: calls {@link #doQuery(java.lang.String)} and processes exceptions.
     63     */
    4564    @Override
    46     protected void realRun() throws SAXException, IOException, OsmTransferException {
     65    protected void realRun() {
    4766        getProgressMonitor().indeterminateSubTask(title);
    4867        try {
     
    5675    }
    5776
     77    /**
     78     * Sends a request to the imagery offset server. Processes exceptions and
     79     * return codes, calls {@link #processResponse(java.io.InputStream)} on success.
     80     * @param query
     81     * @throws iodb.SimpleOffsetQueryTask.UploadException
     82     * @throws IOException
     83     */
    5884    private void doQuery( String query ) throws UploadException, IOException {
    5985        try {
    60             URL url = new URL(ImageryOffsetTools.getServerURL() + query);
    61             System.out.println("url=" + url); // todo: remove in release
     86            String serverURL = Main.pref.get("iodb.server.url", "http://offsets.textual.ru/");
     87            URL url = new URL(serverURL + query);
     88            Main.info("IODB URL = " + url); // todo: remove in release
    6289            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    6390            connection.connect();
     
    79106    }
    80107
     108    /**
     109     * Doesn't actually cancel, just raises a flag.
     110     */
    81111    @Override
    82112    protected void cancel() {
     
    84114    }
    85115
     116    /**
     117     * Is called after {@link #realRun()}. Either displays an error message
     118     * or notifies a listener of success.
     119     */
    86120    @Override
    87121    protected void finish() {
     
    93127    }
    94128
     129    /**
     130     * Parse the response input stream and determine whether an operation
     131     * was successful or not.
     132     * @throws iodb.SimpleOffsetQueryTask.UploadException Thrown if an error message was found.
     133     */
    95134    protected void processResponse( InputStream inp ) throws UploadException {
    96135        String response = "";
     
    110149    }
    111150
     151    /**
     152     * A placeholder exception for error messages.
     153     */
    112154    public static class UploadException extends Exception {
    113155        public UploadException( String message ) {
Note: See TracChangeset for help on using the changeset viewer.