Ticket #8809: download_task_self_documentation.diff​

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

Modified version. Drop the number in front of the task. Give each task a "friendly" name. I think the task name helps group the patterns which otherwise would be overwhelming.

Line 
1Index: src/org/openstreetmap/josm/actions/OpenLocationAction.java
2===================================================================
3--- src/org/openstreetmap/josm/actions/OpenLocationAction.java (revision 6015)
4+++ src/org/openstreetmap/josm/actions/OpenLocationAction.java (working copy)
5@@ -146,7 +146,32 @@
6 return result;
7 }
8
9+
10 /**
11+ * Summarizes acceptable urls for error message purposes.
12+ * @since 6015
13+ */
14+ public String findSummaryDocumentation() {
15+ String result = "";
16+ //for (Class<? extends DownloadTask> taskClass : downloadTasks) {
17+ for (int i = 0; i < downloadTasks.size(); i++) {
18+ Class<? extends DownloadTask> taskClass = downloadTasks.get(i);
19+ if (taskClass != null) {
20+ try {
21+ DownloadTask task = taskClass.getConstructor().newInstance();
22+ result += "<br/>" + task.acceptsDocumentationSummary();
23+ } catch (Exception e) {
24+ e.printStackTrace();
25+ }
26+ }
27+ }
28+ return result;
29+ }
30+
31+
32+
33+
34+ /**
35 * Open the given URL.
36 * @param new_layer true if the URL needs to be opened in a new layer, false otherwise
37 * @param url The URL to open
38@@ -163,11 +188,12 @@
39 if (future != null) {
40 Main.worker.submit(new PostDownloadHandler(task, future));
41 } else {
42+ final String details = findSummaryDocumentation(); // Explain what patterns are supported
43 SwingUtilities.invokeLater(new Runnable() {
44 public void run() {
45 JOptionPane.showMessageDialog(Main.parent, tr(
46- "<html>Cannot open URL ''{0}'' because no suitable download task is available.</html>",
47- url), tr("Download Location"), JOptionPane.ERROR_MESSAGE);
48+ "<html><p>Cannot open URL ''{0}''<br/>The following load tasks accept the URL patterns shown:<br/>{1}</p></html>",
49+ url, details), tr("Download Location"), JOptionPane.ERROR_MESSAGE);
50 }
51 });
52 }
53Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
54===================================================================
55--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java (revision 6015)
56+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java (working copy)
57@@ -46,7 +46,15 @@
58 || url.matches("https?://.*/.*\\.osc") // Remote .osc files
59 );
60 }
61-
62+ @Override
63+ public String acceptsDocumentationSummary() {
64+ String foo = "Download OSM Change:<br/";
65+ foo += "<ul>";
66+ foo += "<li>" + "http://.*/api/0.6/changeset/\\p{Digit}+/download"; // Keep in sync with above
67+ foo += "<li>" + "https?://.*/.*\\.osc"; // Keep in sync with above
68+ foo += "</ul>";
69+ return foo;
70+ }
71 /* (non-Javadoc)
72 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
73 */
74Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
75===================================================================
76--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java (revision 6015)
77+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java (working copy)
78@@ -81,7 +81,19 @@
79 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX)
80 || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE));
81 }
82+ @Override
83+ public String acceptsDocumentationSummary() {
84+ String foo = "Download GPS:<br/>";
85+ foo += "<ul>";
86+ foo += "<li>" + PATTERN_TRACE_ID;
87+ foo += "<li>" + PATTERN_TRACKPOINTS_BBOX;
88+ foo += "<li>" + PATTERN_EXTERNAL_GPX_SCRIPT;
89+ foo += "<li>" + PATTERN_EXTERNAL_GPX_FILE;
90+ foo += "</ul>";
91+ return foo;
92+ }
93
94+
95 public void cancel() {
96 if (downloadTask != null) {
97 downloadTask.cancel();
98Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java
99===================================================================
100--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java (revision 6015)
101+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java (working copy)
102@@ -18,7 +18,14 @@
103 public boolean acceptsUrl(String url) {
104 return url != null && url.matches("https?://.*/.*\\.osc.(gz|bz2?)"); // Remote .osc.gz / .osc.bz / .osc.bz2 files
105 }
106-
107+ @Override
108+ public String acceptsDocumentationSummary() {
109+ String foo = "Download Compressed OSM Change:<br/";
110+ foo += "<ul>";
111+ foo += "<li>" + "https?://.*/.*\\.osc.(gz|bz2?)"; // Keep in sync with above
112+ foo += "</ul>";
113+ return foo;
114+ }
115 /**
116 * Loads a given URL
117 * @param new_layer {@code true} if the data should be saved to a new layer
118Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
119===================================================================
120--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java (revision 6015)
121+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java (working copy)
122@@ -168,6 +168,17 @@
123 || url.matches(PATTERN_EXTERNAL_OSM_FILE) // Remote .osm files
124 );
125 }
126+ @Override
127+ public String acceptsDocumentationSummary() {
128+ String foo = "Download Osm:<br/";
129+ foo += "<ul>";
130+ foo += "<li>" + PATTERN_OSM_API_URL;
131+ foo += "<li>" + PATTERN_OVERPASS_API_URL;
132+ foo += "<li>" + PATTERN_OVERPASS_API_XAPI_URL;
133+ foo += "<li>" + PATTERN_EXTERNAL_OSM_FILE;
134+ foo += "</ul>";
135+ return foo;
136+ }
137
138 public void cancel() {
139 if (downloadTask != null) {
140Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java
141===================================================================
142--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java (revision 6015)
143+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java (working copy)
144@@ -79,6 +79,12 @@
145 boolean acceptsUrl(String url);
146
147 /**
148+ * Returns a short html documentation string, describing acceptable URLs.
149+ */
150+ String acceptsDocumentationSummary();
151+
152+
153+ /**
154 * Replies the error objects of the task. Empty list, if no error messages are available.
155 *
156 * Error objects are either {@link String}s with error messages or {@link Exception}s.
157Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java
158===================================================================
159--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java (revision 6015)
160+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java (working copy)
161@@ -19,4 +19,12 @@
162 url.matches("http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*")
163 );
164 }
165+ @Override
166+ public String acceptsDocumentationSummary() {
167+ String foo = "Download OSM URL:<br/";
168+ foo += "<ul>";
169+ foo += "<li>" + "http://www.openstreetmap.org/?lat=.*&lon=.*"; // Keep in sync with above
170+ foo += "</ul>";
171+ return foo;
172+ }
173 }
174Index: src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java
175===================================================================
176--- src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java (revision 6015)
177+++ src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java (working copy)
178@@ -11,15 +11,25 @@
179 import org.openstreetmap.josm.io.OsmTransferException;
180
181 public class DownloadOsmCompressedTask extends DownloadOsmTask {
182-
183+
184+ String PATTERN_GZ = "https?://.*/.*\\.osm.(gz|bz2?)";
185+
186 /* (non-Javadoc)
187 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)
188 */
189 @Override
190 public boolean acceptsUrl(String url) {
191- return url != null && url.matches("https?://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files
192+ return url != null && url.matches(PATTERN_GZ); // Remote .osm.gz / .osm.bz / .osm.bz2 files
193 }
194-
195+ @Override
196+ public String acceptsDocumentationSummary() {
197+ String foo = "Download Compressed OSM:<br/";
198+ foo += "<ul>";
199+ foo += "<li>" + PATTERN_GZ;
200+ foo += "</ul>";
201+ return foo;
202+ }
203+
204 /* (non-Javadoc)
205 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
206 */