001package ezvcard.parameter; 002 003import static ezvcard.VCardVersion.V2_1; 004import static ezvcard.VCardVersion.V3_0; 005 006import java.util.Collection; 007 008import ezvcard.SupportedVersions; 009 010/* 011 Copyright (c) 2012-2023, Michael Angstadt 012 All rights reserved. 013 014 Redistribution and use in source and binary forms, with or without 015 modification, are permitted provided that the following conditions are met: 016 017 1. Redistributions of source code must retain the above copyright notice, this 018 list of conditions and the following disclaimer. 019 2. Redistributions in binary form must reproduce the above copyright notice, 020 this list of conditions and the following disclaimer in the documentation 021 and/or other materials provided with the distribution. 022 023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 027 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 033 034 The views and conclusions contained in the software and documentation are those 035 of the authors and should not be interpreted as representing official policies, 036 either expressed or implied, of the FreeBSD Project. 037 */ 038 039/** 040 * Represents the "ENCODING" parameter. 041 * <p> 042 * <b>Supported versions:</b> {@code 2.1, 3.0} 043 * </p> 044 * @author Michael Angstadt 045 */ 046public class Encoding extends VCardParameter { 047 private static final VCardParameterCaseClasses<Encoding> enums = new VCardParameterCaseClasses<>(Encoding.class); 048 049 /** 050 * Note: This specific parameter value is in upper-case in order to resolve 051 * a compatibility issue with the Windows 10 Contacts app. The 2.1 spec does 052 * not seem to explicitly state that the various ENCODING parameter values 053 * are case-insensitive, so this is probably the better approach anyway. 054 * @see <a href="https://github.com/mangstadt/ez-vcard/issues/56">Issue 055 * 56</a> 056 */ 057 @SupportedVersions({ V2_1 }) 058 public static final Encoding QUOTED_PRINTABLE = new Encoding("QUOTED-PRINTABLE", true); 059 060 @SupportedVersions({ V2_1 }) 061 public static final Encoding BASE64 = new Encoding("BASE64", true); 062 063 @SupportedVersions({ V2_1 }) 064 public static final Encoding _8BIT = new Encoding("8BIT", true); 065 066 @SupportedVersions({ V2_1 }) 067 public static final Encoding _7BIT = new Encoding("7BIT", true); 068 069 @SupportedVersions({ V3_0 }) 070 public static final Encoding B = new Encoding("b"); 071 072 private Encoding(String value) { 073 super(value); 074 } 075 076 private Encoding(String value, boolean preserveCase) { 077 super(value, preserveCase); 078 } 079 080 /** 081 * Searches for a parameter value that is defined as a static constant in 082 * this class. 083 * @param value the parameter value 084 * @return the object or null if not found 085 */ 086 public static Encoding find(String value) { 087 return enums.find(value); 088 } 089 090 /** 091 * Searches for a parameter value and creates one if it cannot be found. All 092 * objects are guaranteed to be unique, so they can be compared with 093 * {@code ==} equality. 094 * @param value the parameter value 095 * @return the object 096 */ 097 public static Encoding get(String value) { 098 return enums.get(value); 099 } 100 101 /** 102 * Gets all of the parameter values that are defined as static constants in 103 * this class. 104 * @return the parameter values 105 */ 106 public static Collection<Encoding> all() { 107 return enums.all(); 108 } 109}