001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006/** 007 * Online resources directly used by JOSM. 008 * This does not include websites where user can sometimes be redirected through its web browser, 009 * but only those to we establish a connection. 010 * 011 * @since 7434 012 */ 013public enum OnlineResource { 014 015 /** The OSM API, used for download, upload, history, etc. */ 016 OSM_API(tr("OSM API")), 017 /** The JOSM website, used for startup page, imagery/presets/styles/rules entries, help, etc. */ 018 JOSM_WEBSITE(tr("JOSM website")), 019 /** Value used to represent all online resources */ 020 ALL(tr("All")); 021 022 private final String locName; 023 024 OnlineResource(String locName) { 025 this.locName = locName; 026 } 027 028 /** 029 * Replies the localized name. 030 * @return the localized name 031 */ 032 public final String getLocName() { 033 return locName; 034 } 035 036 /** 037 * Ensures resource is not accessed in offline mode. 038 * @param downloadString The attempted download string 039 * @param resourceString The resource download string that should not be accessed 040 * @throws OfflineAccessException if resource is accessed in offline mode, in any protocol 041 */ 042 public final void checkOfflineAccess(String downloadString, String resourceString) { 043 if (NetworkManager.isOffline(this) && downloadString 044 .startsWith(resourceString.substring(resourceString.indexOf("://")), downloadString.indexOf("://"))) { 045 throw new OfflineAccessException(tr("Unable to access ''{0}'': {1} not available (offline mode)", downloadString, getLocName())); 046 } 047 } 048}