Ticket #8809: download_task_self_documentation.diff
File download_task_self_documentation.diff, 9.0 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/actions/OpenLocationAction.java
146 146 return result; 147 147 } 148 148 149 149 150 /** 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 /** 150 175 * Open the given URL. 151 176 * @param new_layer true if the URL needs to be opened in a new layer, false otherwise 152 177 * @param url The URL to open … … 163 188 if (future != null) { 164 189 Main.worker.submit(new PostDownloadHandler(task, future)); 165 190 } else { 191 final String details = findSummaryDocumentation(); // Explain what patterns are supported 166 192 SwingUtilities.invokeLater(new Runnable() { 167 193 public void run() { 168 194 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); 171 197 } 172 198 }); 173 199 } -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
46 46 || url.matches("https?://.*/.*\\.osc") // Remote .osc files 47 47 ); 48 48 } 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 } 50 58 /* (non-Javadoc) 51 59 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor) 52 60 */ -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
81 81 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX) 82 82 || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE)); 83 83 } 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 } 84 95 96 85 97 public void cancel() { 86 98 if (downloadTask != null) { 87 99 downloadTask.cancel(); -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java
18 18 public boolean acceptsUrl(String url) { 19 19 return url != null && url.matches("https?://.*/.*\\.osc.(gz|bz2?)"); // Remote .osc.gz / .osc.bz / .osc.bz2 files 20 20 } 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 } 22 29 /** 23 30 * Loads a given URL 24 31 * @param new_layer {@code true} if the data should be saved to a new layer -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
168 168 || url.matches(PATTERN_EXTERNAL_OSM_FILE) // Remote .osm files 169 169 ); 170 170 } 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 } 171 182 172 183 public void cancel() { 173 184 if (downloadTask != null) { -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java
79 79 boolean acceptsUrl(String url); 80 80 81 81 /** 82 * Returns a short html documentation string, describing acceptable URLs. 83 */ 84 String acceptsDocumentationSummary(); 85 86 87 /** 82 88 * Replies the error objects of the task. Empty list, if no error messages are available. 83 89 * 84 90 * Error objects are either {@link String}s with error messages or {@link Exception}s. -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java
19 19 url.matches("http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*") 20 20 ); 21 21 } 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 } 22 30 } -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java
11 11 import org.openstreetmap.josm.io.OsmTransferException; 12 12 13 13 public class DownloadOsmCompressedTask extends DownloadOsmTask { 14 14 15 String PATTERN_GZ = "https?://.*/.*\\.osm.(gz|bz2?)"; 16 15 17 /* (non-Javadoc) 16 18 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String) 17 19 */ 18 20 @Override 19 21 public boolean acceptsUrl(String url) { 20 return url != null && url.matches( "https?://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files22 return url != null && url.matches(PATTERN_GZ); // Remote .osm.gz / .osm.bz / .osm.bz2 files 21 23 } 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 23 33 /* (non-Javadoc) 24 34 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor) 25 35 */