001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import org.openstreetmap.josm.spi.preferences.Config; 007 008/** 009 * Online resources directly used by JOSM. 010 * This does not include websites where user can sometimes be redirected through its web browser, 011 * but only those to we establish a connection. 012 * 013 * @since 7434 014 */ 015public enum OnlineResource { 016 017 /** The OSM API, used for download, upload, history, etc. */ 018 OSM_API(tr("OSM API")), 019 /** The JOSM website, used for startup page, imagery/presets/styles/rules entries, help, etc. */ 020 JOSM_WEBSITE(tr("JOSM website")), 021 /** Updates of {@link CachedFile} */ 022 CACHE_UPDATES(tr("Cache updates")), 023 /** Various government certificates downloaded on Windows to make https imagery work in some countries */ 024 CERTIFICATES(tr("Certificates")), 025 /** Value used to represent all online resources */ 026 ALL(tr("All")); 027 028 private final String locName; 029 030 OnlineResource(String locName) { 031 this.locName = locName; 032 } 033 034 /** 035 * Replies the localized name. 036 * @return the localized name 037 */ 038 public final String getLocName() { 039 return locName; 040 } 041 042 /** 043 * Replies the offline icon. 044 * @return the offline icon 045 * @since 17041 046 */ 047 public final String getOfflineIcon() { 048 switch (this) { 049 case OSM_API: 050 return /* ICON() */ "offline_osm_api"; 051 case JOSM_WEBSITE: 052 return /* ICON() */ "offline_josm_website"; 053 case CACHE_UPDATES: 054 return /* ICON() */ "offline_cache_updates"; 055 case CERTIFICATES: 056 return /* ICON() */ "offline_certificates"; 057 case ALL: 058 return /* ICON() */ "offline_all"; 059 default: 060 return null; 061 } 062 } 063 064 /** 065 * Replies whether the given URL matches this online resource 066 * @param url the URL to check 067 * @return whether the given URL matches this online resource 068 */ 069 public final boolean matches(String url) { 070 final String baseUrl; 071 switch (this) { 072 case ALL: 073 return true; 074 case OSM_API: 075 baseUrl = OsmApi.getOsmApi().getServerUrl(); 076 break; 077 case JOSM_WEBSITE: 078 baseUrl = Config.getUrls().getJOSMWebsite(); 079 break; 080 default: 081 return false; 082 } 083 return url.startsWith(baseUrl.substring(baseUrl.indexOf("://")), url.indexOf("://")); 084 } 085}