Changeset 16426 in josm for trunk/src/org
- Timestamp:
- 2020-05-16T20:59:34+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r16367 r16426 21 21 import java.util.HashMap; 22 22 import java.util.HashSet; 23 import java.util.Iterator;24 23 import java.util.List; 25 24 import java.util.Map; … … 43 42 import org.openstreetmap.josm.data.preferences.PreferencesWriter; 44 43 import org.openstreetmap.josm.gui.MainApplication; 45 import org.openstreetmap.josm.io.OfflineAccessException; 46 import org.openstreetmap.josm.io.OnlineResource; 44 import org.openstreetmap.josm.io.NetworkManager; 47 45 import org.openstreetmap.josm.spi.preferences.AbstractPreferences; 48 46 import org.openstreetmap.josm.spi.preferences.Config; … … 804 802 public Collection<String> getOnlinePluginSites() { 805 803 Collection<String> pluginSites = new ArrayList<>(getPluginSites()); 806 for (Iterator<String> it = pluginSites.iterator(); it.hasNext();) { 807 try { 808 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(it.next(), Config.getUrls().getJOSMWebsite()); 809 } catch (OfflineAccessException ex) { 810 Logging.log(Logging.LEVEL_WARN, ex); 811 it.remove(); 812 } 813 } 804 pluginSites.removeIf(NetworkManager::isOffline); 814 805 return pluginSites; 815 806 } -
trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java
r14746 r16426 15 15 import org.openstreetmap.josm.gui.util.GuiHelper; 16 16 import org.openstreetmap.josm.io.CacheCustomContent; 17 import org.openstreetmap.josm.io. OnlineResource;17 import org.openstreetmap.josm.io.NetworkManager; 18 18 import org.openstreetmap.josm.tools.HttpClient; 19 19 import org.openstreetmap.josm.tools.Logging; … … 63 63 64 64 @Override 65 protected void checkOfflineAccess() {65 protected boolean isOffline() { 66 66 try { 67 String attributionUrl = getAttributionUrl().toExternalForm(); 68 OnlineResource.ALL.checkOfflineAccess(attributionUrl, attributionUrl); 67 return NetworkManager.isOffline(getAttributionUrl().toExternalForm()); 69 68 } catch (MalformedURLException e) { 70 69 Logging.error(e); 70 return false; 71 71 } 72 72 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r14214 r16426 22 22 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 23 23 import org.openstreetmap.josm.io.CachedFile; 24 import org.openstreetmap.josm.io.OfflineAccessException; 25 import org.openstreetmap.josm.io.OnlineResource; 24 import org.openstreetmap.josm.io.NetworkManager; 26 25 import org.openstreetmap.josm.io.imagery.ImageryReader; 27 26 import org.openstreetmap.josm.spi.preferences.Config; … … 159 158 160 159 protected void loadSource(String source) { 161 boolean online = true; 162 try { 163 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(source, Config.getUrls().getJOSMWebsite()); 164 } catch (OfflineAccessException e) { 165 Logging.log(Logging.LEVEL_WARN, e); 166 online = false; 167 } 160 boolean online = !NetworkManager.isOffline(source); 168 161 if (clearCache && online) { 169 162 CachedFile.cleanup(source); -
trunk/src/org/openstreetmap/josm/gui/GettingStarted.java
r16006 r16426 30 30 import org.openstreetmap.josm.gui.widgets.JosmEditorPane; 31 31 import org.openstreetmap.josm.io.CacheCustomContent; 32 import org.openstreetmap.josm.io.NetworkManager; 32 33 import org.openstreetmap.josm.io.OnlineResource; 33 34 import org.openstreetmap.josm.spi.preferences.Config; … … 107 108 108 109 @Override 109 protected void checkOfflineAccess() {110 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(new WikiReader().getBaseUrlWiki(), Config.getUrls().getJOSMWebsite());110 protected boolean isOffline() { 111 return NetworkManager.isOffline(OnlineResource.JOSM_WEBSITE); 111 112 } 112 113 -
trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java
r13647 r16426 95 95 } 96 96 97 private boolean isOffline() { 98 try { 99 checkOfflineAccess(); 100 return false; 101 } catch (OfflineAccessException e) { 102 Logging.trace(e); 103 return true; 104 } 105 } 106 107 /** 108 * Ensures underlying resource is not accessed in offline mode. 109 * @throws OfflineAccessException if resource is accessed in offline mode 110 */ 111 protected abstract void checkOfflineAccess(); 97 /** 98 * Checks underlying resource is not accessed in offline mode. 99 * @return whether resource is accessed in offline mode 100 */ 101 protected abstract boolean isOffline(); 112 102 113 103 /** -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r15588 r16426 435 435 File localFile = null; 436 436 List<String> localPathEntry = new ArrayList<>(Config.getPref().getList(prefKey)); 437 boolean offline = false; 438 try { 439 checkOfflineAccess(urlStr); 440 } catch (OfflineAccessException e) { 441 Logging.trace(e); 442 offline = true; 443 } 437 boolean offline = NetworkManager.isOffline(urlStr); 444 438 if (localPathEntry.size() == 2) { 445 439 localFile = new File(localPathEntry.get(1)); … … 534 528 } 535 529 536 private static void checkOfflineAccess(String urlString) {537 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(urlString, Config.getUrls().getJOSMWebsite());538 OnlineResource.OSM_API.checkOfflineAccess(urlString, OsmApi.getOsmApi().getServerUrl());539 }540 541 530 private static String truncatePath(String directory, String fileName) { 542 531 if (directory.length() + fileName.length() > 255) { -
trunk/src/org/openstreetmap/josm/io/NetworkManager.java
r14273 r16426 74 74 75 75 /** 76 * Determines if the given online resource specified as URL is currently offline. 77 * @param url the online resource specified as URL 78 * @return {@code true} if {@code url} is offline and should not be accessed 79 * @since 16426 80 */ 81 public static boolean isOffline(String url) { 82 return OFFLINE_RESOURCES.stream().anyMatch(r -> r.matches(url)); 83 } 84 85 /** 76 86 * Determines if the given online resource is currently offline. 77 87 * @param r the online resource -
trunk/src/org/openstreetmap/josm/io/OnlineResource.java
r14999 r16426 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import org.openstreetmap.josm.spi.preferences.Config; 5 7 6 8 /** … … 37 39 38 40 /** 41 * Replies whether the given URL matches this online resource 42 * @return whether the given URL matches this online resource 43 */ 44 public final boolean matches(String url) { 45 final String baseUrl; 46 switch (this) { 47 case ALL: 48 return true; 49 case OSM_API: 50 baseUrl = OsmApi.getOsmApi().getServerUrl(); 51 break; 52 case JOSM_WEBSITE: 53 baseUrl = Config.getUrls().getJOSMWebsite(); 54 break; 55 default: 56 return false; 57 } 58 return url.startsWith(baseUrl.substring(baseUrl.indexOf("://")), url.indexOf("://")); 59 } 60 61 /** 39 62 * Ensures resource is not accessed in offline mode. 40 63 * @param downloadString The attempted download string 41 * @param resourceString The resource download string that should not be accessed64 * @param ignore ignored 42 65 * @throws OfflineAccessException if resource is accessed in offline mode, in any protocol 66 * @deprecated use {@link NetworkManager#isOffline(String)} 43 67 */ 44 public final void checkOfflineAccess(String downloadString, String resourceString) {45 if (NetworkManager.isOffline(this) && downloadString46 .startsWith(resourceString.substring(resourceString.indexOf("://")), downloadString.indexOf("://"))) {68 @Deprecated 69 public final void checkOfflineAccess(String downloadString, String ignore) { 70 if (NetworkManager.isOffline(downloadString)) { 47 71 throw new OfflineAccessException(tr("Unable to access ''{0}'': {1} not available (offline mode)", downloadString, getLocName())); 48 72 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r16422 r16426 209 209 210 210 @Override 211 protected void checkOfflineAccess() {212 OnlineResource.OSM_API.checkOfflineAccess(getBaseUrl(getServerUrlFromPref(), "0.6")+CAPABILITIES, getServerUrlFromPref());211 protected boolean isOffline() { 212 return NetworkManager.isOffline(OnlineResource.OSM_API); 213 213 } 214 214 -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r16422 r16426 20 20 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 21 21 import org.openstreetmap.josm.io.auth.CredentialsManager; 22 import org.openstreetmap.josm.spi.preferences.Config;23 22 import org.openstreetmap.josm.tools.HttpClient; 24 23 import org.openstreetmap.josm.tools.Logging; … … 158 157 boolean uncompressAccordingToContentDisposition, String httpMethod, byte[] requestBody) throws OsmTransferException { 159 158 try { 160 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(urlStr, Config.getUrls().getJOSMWebsite()); 161 OnlineResource.OSM_API.checkOfflineAccess(urlStr, OsmApi.getOsmApi().getServerUrl()); 159 if (NetworkManager.isOffline(urlStr)) { 160 throw new OsmApiException(new OfflineAccessException(tr("{0} not available (offline mode)", urlStr))); 161 } 162 162 163 163 URL url = null; -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r15801 r16426 67 67 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 68 68 import org.openstreetmap.josm.io.NetworkManager; 69 import org.openstreetmap.josm.io.OfflineAccessException;70 import org.openstreetmap.josm.io.OnlineResource;71 69 import org.openstreetmap.josm.spi.preferences.Config; 72 70 import org.openstreetmap.josm.tools.Destroyable; … … 436 434 */ 437 435 public static boolean checkAndConfirmPluginUpdate(Component parent) { 438 if ( !checkOfflineAccess()) {436 if (Preferences.main().getPluginSites().stream().anyMatch(NetworkManager::isOffline)) { 439 437 Logging.info(tr("{0} not available (offline mode)", tr("Plugin update"))); 440 438 return false; … … 541 539 } 542 540 return ret == 0; 543 }544 545 private static boolean checkOfflineAccess() {546 if (NetworkManager.isOffline(OnlineResource.ALL)) {547 return false;548 }549 if (NetworkManager.isOffline(OnlineResource.JOSM_WEBSITE)) {550 for (String updateSite : Preferences.main().getPluginSites()) {551 try {552 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(updateSite, Config.getUrls().getJOSMWebsite());553 } catch (OfflineAccessException e) {554 Logging.trace(e);555 return false;556 }557 }558 }559 return true;560 541 } 561 542
Note:
See TracChangeset
for help on using the changeset viewer.