Changeset 2097 in josm
- Timestamp:
- 2009-09-12T06:45:07+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r2013 r2097 17 17 import org.openstreetmap.josm.data.osm.DataSet; 18 18 import org.openstreetmap.josm.data.osm.DataSource; 19 import org.openstreetmap.josm.gui.ExceptionDialogUtil;20 19 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 21 20 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; … … 28 27 import org.openstreetmap.josm.io.OsmServerReader; 29 28 import org.openstreetmap.josm.io.OsmTransferException; 29 import org.openstreetmap.josm.tools.ExceptionUtil; 30 30 import org.xml.sax.SAXException; 31 31 … … 107 107 return; 108 108 if (lastException != null) { 109 Exception DialogUtil.explainException(lastException);109 getProgressMonitor().setErrorMessage(ExceptionUtil.explainException(lastException)); 110 110 DownloadOsmTask.this.setFailed(true); 111 111 return; … … 113 113 if (dataSet == null) 114 114 return; // user canceled download or error occurred 115 if (currentBounds == null) {115 if (currentBounds == null) 116 116 return; // no data retrieved 117 }118 117 if (dataSet.allPrimitives().isEmpty()) { 119 118 progressMonitor.setErrorMessage(tr("No data imported.")); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r2077 r2097 95 95 String errors = ""; 96 96 97 LinkedList<Integer> shown = new LinkedList<Integer>(); 97 98 for(DownloadTask dt : osmTasks) { 98 99 String err = dt.getErrorMessage(); 99 if(err.equals("")) { 100 // avoid display of identical messages 101 if (err.equals("") || shown.contains(err.hashCode())) { 100 102 continue; 101 103 } 104 shown.add(err.hashCode()); 102 105 errors += "<br>* " + err; 103 106 } -
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r2075 r2097 6 6 import java.io.IOException; 7 7 import java.net.HttpURLConnection; 8 import java.net.MalformedURLException;9 8 import java.net.SocketException; 10 import java.net.URL;11 9 import java.net.UnknownHostException; 12 10 … … 14 12 15 13 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.io.OsmApi;17 14 import org.openstreetmap.josm.io.OsmApiException; 18 15 import org.openstreetmap.josm.io.OsmApiInitializationException; 19 16 import org.openstreetmap.josm.io.OsmChangesetCloseException; 20 17 import org.openstreetmap.josm.io.OsmTransferException; 18 import org.openstreetmap.josm.tools.ExceptionUtil; 21 19 22 20 /** … … 29 27 * just static utility functions. no constructor 30 28 */ 31 private ExceptionDialogUtil() {} 29 private ExceptionDialogUtil() { 30 } 32 31 33 32 /** … … 37 36 */ 38 37 public static void explainOsmApiInitializationException(OsmApiInitializationException e) { 39 e.printStackTrace(); 40 JOptionPane.showMessageDialog( 41 Main.parent, 42 tr( "<html>Failed to initialize communication with the OSM server {0}.<br>" 43 + "Check the server URL in your preferences and your internet connection.</html>", 44 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api") 45 ), 46 tr("Error"), 47 JOptionPane.ERROR_MESSAGE 48 ); 38 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmApiInitializationException(e), tr("Error"), 39 JOptionPane.ERROR_MESSAGE); 49 40 } 50 41 … … 55 46 */ 56 47 public static void explainOsmChangesetCloseException(OsmChangesetCloseException e) { 57 e.printStackTrace(); 58 String changsetId = e.getChangeset() == null ? tr("unknown") : Long.toString(e.getChangeset().getId()); 59 JOptionPane.showMessageDialog( 60 Main.parent, 61 tr( "<html>Failed to close changeset ''{0}'' on the OSM server ''{1}''.<br>" 62 + "The changeset will automatically be closed by the server after a timeout.</html>", 63 changsetId, 64 Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api") 65 ), 66 tr("Error"), 67 JOptionPane.ERROR_MESSAGE 68 ); 69 } 70 48 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainOsmChangesetCloseException(e), tr("Error"), 49 JOptionPane.ERROR_MESSAGE); 50 } 71 51 72 52 /** … … 76 56 */ 77 57 public static void explainPreconditionFailed(OsmApiException e) { 78 e.printStackTrace(); 79 JOptionPane.showMessageDialog( 80 Main.parent, 81 tr("<html>Uploading to the server <strong>failed</strong> because your current<br>" 82 +"dataset violates a precondition.<br>" 83 +"The error message is:<br>" 84 + "{0}" 85 + "</html>", 86 e.getMessage().replace("&", "&").replace("<", "<").replace(">", ">") 87 ), 88 tr("Precondition violation"), 89 JOptionPane.ERROR_MESSAGE 90 ); 91 } 92 58 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainPreconditionFailed(e), 59 tr("Precondition violation"), JOptionPane.ERROR_MESSAGE); 60 } 93 61 94 62 /** … … 98 66 */ 99 67 public static void explainGeneric(Exception e) { 100 String msg = e.getMessage(); 101 if (msg == null || msg.trim().equals("")) { 102 msg = e.toString(); 103 } 104 e.printStackTrace(); 105 JOptionPane.showMessageDialog( 106 Main.parent, 107 msg, 108 tr("Error"), 109 JOptionPane.ERROR_MESSAGE 110 ); 68 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGeneric(e), tr("Error"), 69 JOptionPane.ERROR_MESSAGE); 111 70 } 112 71 … … 120 79 121 80 public static void explainSecurityException(OsmTransferException e) { 122 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 123 String host = tr("unknown"); 124 try { 125 host = new URL(apiUrl).getHost(); 126 } catch(MalformedURLException ex) { 127 // shouldn't happen 128 } 129 130 String message = tr("<html>Failed to open a connection to the remote server<br>" 131 + "''{0}''<br>" 132 + "for security reasons. This is most likely because you are running<br>" 133 + "in an applet and because you didn''t load your applet from ''{1}''.</html>", 134 apiUrl, host 135 ); 136 JOptionPane.showMessageDialog( 137 Main.parent, 138 message, 139 tr("Security exception"), 140 JOptionPane.ERROR_MESSAGE 141 ); 81 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainSecurityException(e), tr("Security exception"), 82 JOptionPane.ERROR_MESSAGE); 142 83 } 143 84 … … 151 92 152 93 public static void explainNestedSocketException(OsmTransferException e) { 153 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 154 String message = tr("<html>Failed to open a connection to the remote server<br>" 155 + "''{0}''.<br>" 156 + "Please check your internet connection.</html>", 157 apiUrl 158 ); 159 e.printStackTrace(); 160 JOptionPane.showMessageDialog( 161 Main.parent, 162 message, 163 tr("Network exception"), 164 JOptionPane.ERROR_MESSAGE 165 ); 94 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedSocketException(e), 95 tr("Network exception"), JOptionPane.ERROR_MESSAGE); 166 96 } 167 97 … … 175 105 176 106 public static void explainNestedIOException(OsmTransferException e) { 177 IOException ioe = getNestedException(e, IOException.class); 178 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 179 String message = tr("<html>Failed to upload data to or download data from<br>" 180 + "''{0}''<br>" 181 + "due to a problem with transferring data.<br>" 182 + "Details(untranslated): {1}</html>", 183 apiUrl, ioe.getMessage() 184 ); 185 e.printStackTrace(); 186 JOptionPane.showMessageDialog( 187 Main.parent, 188 message, 189 tr("IO Exception"), 190 JOptionPane.ERROR_MESSAGE 191 ); 107 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedIOException(e), tr("IO Exception"), 108 JOptionPane.ERROR_MESSAGE); 192 109 } 193 110 … … 200 117 201 118 public static void explainInternalServerError(OsmTransferException e) { 202 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 203 String message = tr("<html>The OSM server<br>" 204 + "''{0}''<br>" 205 + "reported an internal server error.<br>" 206 + "This is most likely a temporary problem. Please try again later.</html>", 207 apiUrl 208 ); 209 e.printStackTrace(); 210 JOptionPane.showMessageDialog( 211 Main.parent, 212 message, 213 tr("Internal Server Error"), 214 JOptionPane.ERROR_MESSAGE 215 ); 119 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainInternalServerError(e), 120 tr("Internal Server Error"), JOptionPane.ERROR_MESSAGE); 216 121 } 217 122 … … 223 128 */ 224 129 public static void explainBadRequest(OsmApiException e) { 225 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 226 String message = tr("The OSM server ''{0}'' reported a bad request.<br>", 227 apiUrl 228 ); 229 if (e.getErrorHeader() != null && e.getErrorHeader().startsWith("The maximum bbox")) { 230 message += "<br>" + tr("The area you tried to download is too big or your request was too large." 231 + "<br>Either request a smaller area or use an export file provided by the OSM community."); 232 } else if (e.getErrorHeader() != null){ 233 message += tr("<br>Error message(untranslated): {0}", e.getErrorHeader()); 234 } 235 message = "<html>" + message + "</html>"; 236 e.printStackTrace(); 237 JOptionPane.showMessageDialog( 238 Main.parent, 239 message, 240 tr("Bad Request"), 241 JOptionPane.ERROR_MESSAGE 242 ); 130 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainBadRequest(e), tr("Bad Request"), 131 JOptionPane.ERROR_MESSAGE); 243 132 } 244 133 … … 252 141 253 142 public static void explainNestedUnkonwnHostException(OsmTransferException e) { 254 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 255 String host = tr("unknown"); 256 try { 257 host = new URL(apiUrl).getHost(); 258 } catch(MalformedURLException ex) { 259 // shouldn't happen 260 } 261 262 String message = tr("<html>Failed to open a connection to the remote server<br>" 263 + "''{0}''.<br>" 264 + "Host name ''{1}'' couldn''t be resolved. <br>" 265 + "Please check the API URL in your preferences and your internet connection.</html>", 266 apiUrl, host 267 ); 268 e.printStackTrace(); 269 JOptionPane.showMessageDialog( 270 Main.parent, 271 message, 272 tr("Unknown host"), 273 JOptionPane.ERROR_MESSAGE 274 ); 143 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainNestedUnkonwnHostException(e), 144 tr("Unknown host"), JOptionPane.ERROR_MESSAGE); 275 145 } 276 146 … … 290 160 t = t.getCause(); 291 161 } 292 if (t== null) 162 if (t == null) 293 163 return null; 294 164 else if (nestedClass.isInstance(t)) … … 319 189 return; 320 190 } 321 if (e instanceof OsmApiInitializationException){ 322 explainOsmApiInitializationException((OsmApiInitializationException)e); 323 return; 324 } 325 if (e instanceof OsmChangesetCloseException){ 326 explainOsmChangesetCloseException((OsmChangesetCloseException)e); 191 if (e instanceof OsmApiInitializationException) { 192 explainOsmApiInitializationException((OsmApiInitializationException) e); 193 return; 194 } 195 if (e instanceof OsmChangesetCloseException) { 196 explainOsmChangesetCloseException((OsmChangesetCloseException) e); 327 197 return; 328 198 } 329 199 330 200 if (e instanceof OsmApiException) { 331 OsmApiException oae = (OsmApiException)e; 201 OsmApiException oae = (OsmApiException) e; 332 202 if (oae.getResponseCode() == HttpURLConnection.HTTP_PRECON_FAILED) { 333 203 explainPreconditionFailed(oae); … … 358 228 */ 359 229 public static void explainGoneForUnknownPrimitive(OsmApiException e) { 360 String msg = tr("<html>Uploading <strong>failed</strong> because a primitive you tried to<br>" 361 + "delete on the server is already deleted.<br>" 362 + "<br>" 363 + "The error message is:<br>" 364 + "{0}" 365 + "</html>", 366 e.getMessage().replace("&", "&").replace("<", "<").replace(">", ">") 367 ); 368 JOptionPane.showMessageDialog( 369 Main.parent, 370 msg, 371 tr("Primitive already deleted"), 372 JOptionPane.ERROR_MESSAGE 373 ); 230 JOptionPane.showMessageDialog(Main.parent, ExceptionUtil.explainGoneForUnknownPrimitive(e), 231 tr("Primitive already deleted"), JOptionPane.ERROR_MESSAGE); 374 232 375 233 } … … 382 240 public static void explainException(Exception e) { 383 241 if (e instanceof OsmTransferException) { 384 explainOsmTransferException((OsmTransferException)e); 242 explainOsmTransferException((OsmTransferException) e); 385 243 return; 386 244 }
Note:
See TracChangeset
for help on using the changeset viewer.