[7937] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.io;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import org.openstreetmap.josm.Main;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Online resources directly used by JOSM.
|
---|
| 10 | * This does not include websites where user can sometimes be redirected through its web browser,
|
---|
| 11 | * but only those to we establish a connection.
|
---|
| 12 | *
|
---|
| 13 | * @since 7434
|
---|
| 14 | */
|
---|
| 15 | public enum OnlineResource {
|
---|
| 16 |
|
---|
| 17 | /** The OSM API, used for download, upload, history, etc. */
|
---|
| 18 | OSM_API(tr("OSM API")),
|
---|
| 19 | /** The JOSM website, used for startup page, imagery/presets/styles/rules entries, help, etc. */
|
---|
| 20 | JOSM_WEBSITE(tr("JOSM website")),
|
---|
| 21 | /** Value used to represent all online resources */
|
---|
| 22 | ALL(tr("All"));
|
---|
| 23 |
|
---|
| 24 | private final String locName;
|
---|
| 25 |
|
---|
[8674] | 26 | OnlineResource(String locName) {
|
---|
[7937] | 27 | this.locName = locName;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * Replies the localized name.
|
---|
| 32 | * @return the localized name
|
---|
| 33 | */
|
---|
| 34 | public final String getLocName() {
|
---|
| 35 | return locName;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Ensures resource is not accessed in offline mode.
|
---|
| 40 | * @param downloadString The attempted download string
|
---|
| 41 | * @param resourceString The resource download string that should not be accessed
|
---|
| 42 | * @throws OfflineAccessException if resource is accessed in offline mode, in any protocol
|
---|
| 43 | */
|
---|
| 44 | public final void checkOfflineAccess(String downloadString, String resourceString) {
|
---|
| 45 | if (Main.isOffline(this) && downloadString.substring(downloadString.indexOf("://"))
|
---|
| 46 | .startsWith(resourceString.substring(resourceString.indexOf("://")))) {
|
---|
| 47 | throw new OfflineAccessException(tr("Unable to access ''{0}'': {1} not available (offline mode)", downloadString, getLocName()));
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|