Changeset 7476 in josm
- Timestamp:
- 2014-08-31T13:30:38+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7442 r7476 548 548 List<Callable<Void>> tasks = new ArrayList<>(); 549 549 550 if (isOffline(OnlineResource.OSM_API)) { 551 Main.warn(tr("{0} not available (offline mode)", tr("OSM API"))); 552 } else { 553 tasks.add(new InitializationTask(tr("Initializing OSM API")) { 554 555 @Override 556 public void initialize() throws Exception { 557 // We try to establish an API connection early, so that any API 558 // capabilities are already known to the editor instance. However 559 // if it goes wrong that's not critical at this stage. 560 try { 561 OsmApi.getOsmApi().initialize(null, true); 562 } catch (Exception e) { 563 Main.warn(getErrorMessage(Utils.getRootCause(e))); 564 } 550 tasks.add(new InitializationTask(tr("Initializing OSM API")) { 551 552 @Override 553 public void initialize() throws Exception { 554 // We try to establish an API connection early, so that any API 555 // capabilities are already known to the editor instance. However 556 // if it goes wrong that's not critical at this stage. 557 try { 558 OsmApi.getOsmApi().initialize(null, true); 559 } catch (Exception e) { 560 Main.warn(getErrorMessage(Utils.getRootCause(e))); 565 561 } 566 } );567 } 562 } 563 }); 568 564 569 565 tasks.add(new InitializationTask(tr("Initializing validator")) { -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r7203 r7476 24 24 import org.openstreetmap.josm.data.Bounds; 25 25 import org.openstreetmap.josm.data.Preferences.pref; 26 import org.openstreetmap.josm.io.Capabilities; 26 27 import org.openstreetmap.josm.io.OsmApi; 27 28 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 148 149 } 149 150 } 150 151 151 152 /** name of the imagery entry (gets translated by josm usually) */ 152 153 private String name; … … 393 394 return true; 394 395 } 395 396 396 397 /** 397 398 * Check if this object equals another ImageryInfo with respect to the properties 398 399 * that get written to the preference file. 399 * 400 * 400 401 * The field {@link #pixelPerDegree} is ignored. 401 * 402 * 402 403 * @param other the ImageryInfo object to compare to 403 404 * @return true if they are equal … … 464 465 } 465 466 466 467 467 468 @Override 468 469 public int hashCode() { … … 679 680 /** 680 681 * Gets the entry id. 681 * 682 * 682 683 * Id can be null. This gets the configured id as is. Due to a user error, 683 684 * this may not be unique. Use {@link ImageryLayerInfo#getUniqueId} to ensure … … 696 697 this.id = id; 697 698 } 698 699 699 700 public void clearId() { 700 701 if (this.id != null) { … … 934 935 */ 935 936 public boolean isBlacklisted() { 936 return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url); 937 Capabilities capabilities = OsmApi.getOsmApi().getCapabilities(); 938 return capabilities != null && capabilities.isOnImageryBlacklist(this.url); 937 939 } 938 940 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r7473 r7476 203 203 if (initialized) 204 204 return; 205 if (Main.isOffline(OnlineResource.OSM_API)) {206 // At this point this is an error because all automatic or UI actions requiring OSM API should have been disabled earlier207 throw new OfflineAccessException(tr("{0} not available (offline mode)", OnlineResource.OSM_API.getLocName()));208 }209 205 cancel = false; 210 206 try { … … 217 213 initializeCapabilities(cache.updateForceString()); 218 214 } 219 if (capabilities.supportsVersion("0.6")) { 220 version = "0.6"; 221 } else { 215 if (capabilities == null) { 216 if (Main.isOffline(OnlineResource.OSM_API)) { 217 Main.warn(tr("{0} not available (offline mode)", tr("OSM API"))); 218 } else { 219 Main.error(tr("Unable to initialize OSM API.")); 220 } 221 return; 222 } else if (!capabilities.supportsVersion("0.6")) { 222 223 Main.error(tr("This version of JOSM is incompatible with the configured server.")); 223 224 Main.error(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.", 224 225 capabilities.get("version", "minimum"), capabilities.get("version", "maximum"))); 225 initialized = false; // FIXME gets overridden by next assignment 226 return; 227 } else { 228 version = "0.6"; 229 initialized = true; 226 230 } 227 initialized = true;228 231 229 232 /* This is an interim solution for openstreetmap.org not currently … … 233 236 * http://trac.openstreetmap.org/ticket/5024 234 237 * This list should not be maintained by each OSM editor (see #9210) */ 235 if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty()) 236 { 238 if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty()) { 237 239 capabilities.put("blacklist", "regex", ".*\\.google\\.com/.*"); 238 240 capabilities.put("blacklist", "regex", ".*209\\.85\\.2\\d\\d.*"); … … 245 247 * situation - probably only occurs if the user changes the API URL 246 248 * in the preferences menu. Otherwise they would not have been able 247 * to load the layers in the first place bec uase they would have249 * to load the layers in the first place because they would have 248 250 * been disabled! */ 249 251 if (Main.isDisplayingMapView()) { … … 268 270 } 269 271 270 private void initializeCapabilities(String xml) throws SAXException, IOException, ParserConfigurationException { 271 capabilities = CapabilitiesParser.parse(new InputSource(new StringReader(xml))); 272 private synchronized void initializeCapabilities(String xml) throws SAXException, IOException, ParserConfigurationException { 273 if (xml != null) { 274 capabilities = CapabilitiesParser.parse(new InputSource(new StringReader(xml))); 275 } 272 276 } 273 277 … … 731 735 * @return the API capabilities, or null, if the API is not initialized yet 732 736 */ 733 public Capabilities getCapabilities() {737 public synchronized Capabilities getCapabilities() { 734 738 return capabilities; 735 739 }
Note:
See TracChangeset
for help on using the changeset viewer.