001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.io;
003
004import java.util.Locale;
005
006/**
007 * The proxy policy is how JOSM will use proxy information.
008 * @since 12805 (extracted from {@code ProxyPreferencesPanel})
009 */
010public enum ProxyPolicy {
011    /** No proxy: JOSM will access Internet resources directly */
012    NO_PROXY("no-proxy"),
013    /** Use system settings: JOSM will use system proxy settings */
014    USE_SYSTEM_SETTINGS("use-system-settings"),
015    /** Use HTTP proxy: JOSM will use the given HTTP proxy, configured manually */
016    USE_HTTP_PROXY("use-http-proxy"),
017    /** Use HTTP proxy: JOSM will use the given SOCKS proxy */
018    USE_SOCKS_PROXY("use-socks-proxy");
019
020    private final String policyName;
021
022    ProxyPolicy(String policyName) {
023        this.policyName = policyName;
024    }
025
026    /**
027     * Replies the policy name, to be stored in proxy preferences.
028     * @return the policy unique name
029     */
030    public String getName() {
031        return policyName;
032    }
033
034    /**
035     * Retrieves a proxy policy from its name found in preferences.
036     * @param policyName The policy name
037     * @return The proxy policy matching the given name, or {@code null}
038     */
039    public static ProxyPolicy fromName(String policyName) {
040        if (policyName == null) return null;
041        policyName = policyName.trim().toLowerCase(Locale.ENGLISH);
042        for (ProxyPolicy pp: values()) {
043            if (pp.getName().equals(policyName))
044                return pp;
045        }
046        return null;
047    }
048}