001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.preferences; 003 004import org.openstreetmap.josm.io.OsmApi; 005import org.openstreetmap.josm.spi.preferences.Config; 006import org.openstreetmap.josm.spi.preferences.IUrls; 007 008/** 009 * Class that provides URLs values for JOSM. 010 * @since 14119 011 */ 012public final class JosmUrls implements IUrls { 013 014 /** 015 * The JOSM website URL. 016 */ 017 private static final String JOSM_WEBSITE = "https://josm.openstreetmap.de"; 018 019 /** 020 * The OSM website URL. 021 */ 022 private static final String OSM_WEBSITE = "https://www.openstreetmap.org"; 023 024 /** 025 * The OSM wiki URL. 026 */ 027 private static final String OSM_WIKI = "https://wiki.openstreetmap.org"; 028 029 /** 030 * public URL of the standard OSM API. 031 */ 032 private static final String DEFAULT_API_URL = "https://api.openstreetmap.org/api"; 033 034 private JosmUrls() { 035 // hide constructor 036 } 037 038 private static class InstanceHolder { 039 static final JosmUrls INSTANCE = new JosmUrls(); 040 } 041 042 /** 043 * Returns the unique instance. 044 * @return the unique instance 045 */ 046 public static JosmUrls getInstance() { 047 return InstanceHolder.INSTANCE; 048 } 049 050 @Override 051 public String getOSMWebsiteDependingOnSelectedApi() { 052 final String api = OsmApi.getOsmApi().getServerUrl(); 053 if (DEFAULT_API_URL.equals(api)) { 054 return getOSMWebsite(); 055 } else { 056 return api.replaceAll("/api$", ""); 057 } 058 } 059 060 @Override 061 public String getBaseBrowseUrl() { 062 if (Config.getPref() != null) 063 return Config.getPref().get("osm-browse.url", getOSMWebsiteDependingOnSelectedApi()); 064 return getOSMWebsiteDependingOnSelectedApi(); 065 } 066 067 @Override 068 public String getBaseUserUrl() { 069 if (Config.getPref() != null) 070 return Config.getPref().get("osm-user.url", getOSMWebsiteDependingOnSelectedApi() + "/user"); 071 return getOSMWebsiteDependingOnSelectedApi() + "/user"; 072 } 073 074 @Override 075 public String getJOSMWebsite() { 076 if (Config.getPref() != null) 077 return Config.getPref().get("josm.url", JOSM_WEBSITE); 078 return JOSM_WEBSITE; 079 } 080 081 @Override 082 public String getXMLBase() { 083 // Always return HTTP (issues reported with HTTPS) 084 return "http://josm.openstreetmap.de"; 085 } 086 087 @Override 088 public String getOSMWebsite() { 089 if (Config.getPref() != null) 090 return Config.getPref().get("osm.url", OSM_WEBSITE); 091 return OSM_WEBSITE; 092 } 093 094 @Override 095 public String getOSMWiki() { 096 if (Config.getPref() != null) 097 return Config.getPref().get("url.openstreetmap-wiki", OSM_WIKI); 098 return OSM_WIKI; 099 } 100 101 @Override 102 public String getDefaultOsmApiUrl() { 103 return DEFAULT_API_URL; 104 } 105}