001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004/**
005 * Upload policy.
006 *
007 * Determines if upload to the OSM server is intended, discouraged, or disabled / blocked.
008 * @see DownloadPolicy
009 * @since 13559 (extracted from {@link DataSet})
010 */
011public enum UploadPolicy {
012    /**
013     * Normal dataset, upload intended.
014     */
015    NORMAL("true"),
016    /**
017     * Upload discouraged, for example when using or distributing a private dataset.
018     */
019    DISCOURAGED("false"),
020    /**
021     * Upload blocked.
022     * Upload options completely disabled. Intended for special cases
023     * where a warning dialog is not enough, see #12731.
024     *
025     * For the user, it shouldn't be too easy to disable this flag.
026     */
027    BLOCKED("never");
028
029    final String xmlFlag;
030
031    UploadPolicy(String xmlFlag) {
032        this.xmlFlag = xmlFlag;
033    }
034
035    /**
036     * Get the corresponding value of the <code>upload='...'</code> XML-attribute in the .osm file.
037     * @return value of the <code>upload</code> attribute
038     */
039    public String getXmlFlag() {
040        return xmlFlag;
041    }
042
043    /**
044     * Returns the {@code UploadPolicy} for the given <code>upload='...'</code> XML-attribute
045     * @param xmlFlag <code>upload='...'</code> XML-attribute to convert
046     * @return {@code UploadPolicy} value
047     * @throws IllegalArgumentException for invalid values
048     * @since 13434
049     */
050    public static UploadPolicy of(String xmlFlag) {
051        for (UploadPolicy policy : values()) {
052            if (policy.getXmlFlag().equalsIgnoreCase(xmlFlag)) {
053                return policy;
054            }
055        }
056        throw new IllegalArgumentException(xmlFlag);
057    }
058}