Ignore:
Timestamp:
2020-05-16T20:59:34+02:00 (4 years ago)
Author:
simon04
Message:

see #18712 - Add NetworkManager.isOffline(String) to test offline status of given URL

Deprecates OnlineResource.checkOfflineAccess(String, String)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OnlineResource.java

    r14999 r16426  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import org.openstreetmap.josm.spi.preferences.Config;
    57
    68/**
     
    3739
    3840    /**
     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    /**
    3962     * Ensures resource is not accessed in offline mode.
    4063     * @param downloadString The attempted download string
    41      * @param resourceString The resource download string that should not be accessed
     64     * @param ignore ignored
    4265     * @throws OfflineAccessException if resource is accessed in offline mode, in any protocol
     66     * @deprecated use {@link NetworkManager#isOffline(String)}
    4367     */
    44     public final void checkOfflineAccess(String downloadString, String resourceString) {
    45         if (NetworkManager.isOffline(this) && downloadString
    46                 .startsWith(resourceString.substring(resourceString.indexOf("://")), downloadString.indexOf("://"))) {
     68    @Deprecated
     69    public final void checkOfflineAccess(String downloadString, String ignore) {
     70        if (NetworkManager.isOffline(downloadString)) {
    4771            throw new OfflineAccessException(tr("Unable to access ''{0}'': {1} not available (offline mode)", downloadString, getLocName()));
    4872        }
Note: See TracChangeset for help on using the changeset viewer.