Ticket #8809: download_task_self_documentation.diff

File download_task_self_documentation.diff, 9.0 KB (added by brycenesbitt, 11 years ago)

Patch to document acceptable patterns

  • src/org/openstreetmap/josm/actions/OpenLocationAction.java

     
    146146        return result;
    147147    }
    148148
     149
    149150    /**
     151     * Summarizes acceptable urls for error message purposes.
     152     * @since 6015
     153     */
     154    public String findSummaryDocumentation() {
     155        String result = "";
     156        //for (Class<? extends DownloadTask> taskClass : downloadTasks) {
     157        for (int i = 0; i < downloadTasks.size(); i++) {
     158            Class<? extends DownloadTask> taskClass = downloadTasks.get(i);
     159            if (taskClass != null) {
     160                try {
     161                    DownloadTask task = taskClass.getConstructor().newInstance();
     162                    result += "<br/>" + i + " - " + task.acceptsDocumentationSummary();
     163                } catch (Exception e) {
     164                    e.printStackTrace();
     165                }
     166            }
     167        }
     168        return result;
     169    }
     170
     171
     172
     173
     174    /**
    150175     * Open the given URL.
    151176     * @param new_layer true if the URL needs to be opened in a new layer, false otherwise
    152177     * @param url The URL to open
     
    163188        if (future != null) {
    164189            Main.worker.submit(new PostDownloadHandler(task, future));
    165190        } else {
     191            final String details = findSummaryDocumentation();    // Explain what patterns are supported
    166192            SwingUtilities.invokeLater(new Runnable() {
    167193                public void run() {
    168194                    JOptionPane.showMessageDialog(Main.parent, tr(
    169                             "<html>Cannot open URL ''{0}'' because no suitable download task is available.</html>",
    170                             url), tr("Download Location"), JOptionPane.ERROR_MESSAGE);
     195                            "<html><p>Cannot open URL ''{0}'' because no suitable matching task was found:<br/>{1}</p></html>",
     196                            url, details), tr("Download Location"), JOptionPane.ERROR_MESSAGE);
    171197                }
    172198            });
    173199        }
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

     
    4646             || url.matches("https?://.*/.*\\.osc")                             // Remote .osc files
    4747                );
    4848    }
    49 
     49    @Override
     50    public String acceptsDocumentationSummary() {
     51        String foo = "DownloadOsmChangeTask:<br/";
     52        foo += "<ul>";
     53        foo += "<li>" + "http://.*/api/0.6/changeset/\\p{Digit}+/download"; // Keep in sync with above
     54        foo += "<li>" + "https?://.*/.*\\.osc"; // Keep in sync with above
     55        foo += "</ul>";
     56        return foo;
     57    }
    5058    /* (non-Javadoc)
    5159     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
    5260     */
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

     
    8181        return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX)
    8282                || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE));
    8383    }
     84    @Override
     85    public String acceptsDocumentationSummary() {
     86        String foo = "DownloadGPSTask:<br/>";
     87        foo += "<ul>";
     88        foo += "<li>" + PATTERN_TRACE_ID;
     89        foo += "<li>" + PATTERN_TRACKPOINTS_BBOX;
     90        foo += "<li>" + PATTERN_EXTERNAL_GPX_SCRIPT;
     91        foo += "<li>" + PATTERN_EXTERNAL_GPX_FILE;
     92        foo += "</ul>";
     93        return foo;
     94    }
    8495
     96
    8597    public void cancel() {
    8698        if (downloadTask != null) {
    8799            downloadTask.cancel();
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java

     
    1818    public boolean acceptsUrl(String url) {
    1919        return url != null && url.matches("https?://.*/.*\\.osc.(gz|bz2?)"); // Remote .osc.gz / .osc.bz / .osc.bz2 files
    2020    }
    21        
     21    @Override
     22    public String acceptsDocumentationSummary() {
     23        String foo = "DownloadOsmChangeCompressedTask:<br/";
     24        foo += "<ul>";
     25        foo += "<li>" + "https?://.*/.*\\.osc.(gz|bz2?)";       // Keep in sync with above
     26        foo += "</ul>";
     27        return foo;
     28    }
    2229    /**
    2330     * Loads a given URL
    2431     * @param new_layer {@code true} if the data should be saved to a new layer
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

     
    168168             || url.matches(PATTERN_EXTERNAL_OSM_FILE)     // Remote .osm files
    169169                );
    170170    }
     171    @Override
     172    public String acceptsDocumentationSummary() {
     173        String foo = "DownloadOsmTask:<br/";
     174        foo += "<ul>";
     175        foo += "<li>" + PATTERN_OSM_API_URL;
     176        foo += "<li>" + PATTERN_OVERPASS_API_URL;
     177        foo += "<li>" + PATTERN_OVERPASS_API_XAPI_URL;
     178        foo += "<li>" + PATTERN_EXTERNAL_OSM_FILE;
     179        foo += "</ul>";
     180        return foo;
     181    }
    171182
    172183    public void cancel() {
    173184        if (downloadTask != null) {
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

     
    7979    boolean acceptsUrl(String url);
    8080
    8181    /**
     82     * Returns a short html documentation string, describing acceptable URLs.
     83     */
     84    String acceptsDocumentationSummary();
     85
     86
     87    /**
    8288     * Replies the error objects of the task. Empty list, if no error messages are available.
    8389     *
    8490     * Error objects are either {@link String}s with error messages or {@link Exception}s.
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java

     
    1919                url.matches("http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*")
    2020                );
    2121    }
     22    @Override
     23    public String acceptsDocumentationSummary() {
     24        String foo = "DownloadOsmUrlTask:<br/";
     25        foo += "<ul>";
     26        foo += "<li>" + "http://www.openstreetmap.org/?lat=.*&lon=.*"; // Keep in sync with above
     27        foo += "</ul>";
     28        return foo;
     29    }
    2230}
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java

     
    1111import org.openstreetmap.josm.io.OsmTransferException;
    1212
    1313public class DownloadOsmCompressedTask extends DownloadOsmTask {
    14    
     14
     15    String PATTERN_GZ =  "https?://.*/.*\\.osm.(gz|bz2?)";
     16
    1517    /* (non-Javadoc)
    1618     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)
    1719     */
    1820    @Override
    1921    public boolean acceptsUrl(String url) {
    20         return url != null && url.matches("https?://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files
     22        return url != null && url.matches(PATTERN_GZ); // Remote .osm.gz / .osm.bz / .osm.bz2 files
    2123    }
    22    
     24    @Override
     25    public String acceptsDocumentationSummary() {
     26        String foo = "DownloadOsmCompressedTask:<br/";
     27        foo += "<ul>";
     28        foo += "<li>" + PATTERN_GZ;
     29        foo += "</ul>";
     30        return foo;
     31    }
     32
    2333    /* (non-Javadoc)
    2434     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
    2535     */