1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.util.Locale;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * The proxy policy is how JOSM will use proxy information.
|
---|
8 | * @since 12805 (extracted from {@code ProxyPreferencesPanel})
|
---|
9 | */
|
---|
10 | public enum ProxyPolicy {
|
---|
11 | /** No proxy: JOSM will access Internet resources directly */
|
---|
12 | NO_PROXY("no-proxy"),
|
---|
13 | /** Use system settings: JOSM will use system proxy settings */
|
---|
14 | USE_SYSTEM_SETTINGS("use-system-settings"),
|
---|
15 | /** Use HTTP proxy: JOSM will use the given HTTP proxy, configured manually */
|
---|
16 | USE_HTTP_PROXY("use-http-proxy"),
|
---|
17 | /** Use HTTP proxy: JOSM will use the given SOCKS proxy */
|
---|
18 | USE_SOCKS_PROXY("use-socks-proxy");
|
---|
19 |
|
---|
20 | private final String policyName;
|
---|
21 |
|
---|
22 | ProxyPolicy(String policyName) {
|
---|
23 | this.policyName = policyName;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Replies the policy name, to be stored in proxy preferences.
|
---|
28 | * @return the policy unique name
|
---|
29 | */
|
---|
30 | public String getName() {
|
---|
31 | return policyName;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Retrieves a proxy policy from its name found in preferences.
|
---|
36 | * @param policyName The policy name
|
---|
37 | * @return The proxy policy matching the given name, or {@code null}
|
---|
38 | */
|
---|
39 | public static ProxyPolicy fromName(String policyName) {
|
---|
40 | if (policyName == null) return null;
|
---|
41 | policyName = policyName.trim().toLowerCase(Locale.ENGLISH);
|
---|
42 | for (ProxyPolicy pp: values()) {
|
---|
43 | if (pp.getName().equals(policyName))
|
---|
44 | return pp;
|
---|
45 | }
|
---|
46 | return null;
|
---|
47 | }
|
---|
48 | }
|
---|