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