| 1 | package ezvcard.parameter; |
| 2 | |
| 3 | import static ezvcard.VCardVersion.V2_1; |
| 4 | import static ezvcard.VCardVersion.V3_0; |
| 5 | |
| 6 | import java.util.Collection; |
| 7 | |
| 8 | import ezvcard.SupportedVersions; |
| 9 | |
| 10 | /* |
| 11 | Copyright (c) 2012-2023, Michael Angstadt |
| 12 | All rights reserved. |
| 13 | |
| 14 | Redistribution and use in source and binary forms, with or without |
| 15 | modification, are permitted provided that the following conditions are met: |
| 16 | |
| 17 | 1. Redistributions of source code must retain the above copyright notice, this |
| 18 | list of conditions and the following disclaimer. |
| 19 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 20 | this list of conditions and the following disclaimer in the documentation |
| 21 | and/or other materials provided with the distribution. |
| 22 | |
| 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | |
| 34 | The views and conclusions contained in the software and documentation are those |
| 35 | of the authors and should not be interpreted as representing official policies, |
| 36 | either expressed or implied, of the FreeBSD Project. |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * Represents the "ENCODING" parameter. |
| 41 | * <p> |
| 42 | * <b>Supported versions:</b> {@code 2.1, 3.0} |
| 43 | * </p> |
| 44 | * @author Michael Angstadt |
| 45 | */ |
| 46 | public class Encoding extends VCardParameter { |
| 47 | private static final VCardParameterCaseClasses<Encoding> enums = new VCardParameterCaseClasses<>(Encoding.class); |
| 48 | |
| 49 | /** |
| 50 | * Note: This specific parameter value is in upper-case in order to resolve |
| 51 | * a compatibility issue with the Windows 10 Contacts app. The 2.1 spec does |
| 52 | * not seem to explicitly state that the various ENCODING parameter values |
| 53 | * are case-insensitive, so this is probably the better approach anyway. |
| 54 | * @see <a href="https://github.com/mangstadt/ez-vcard/issues/56">Issue |
| 55 | * 56</a> |
| 56 | */ |
| 57 | @SupportedVersions({ V2_1 }) |
| 58 | public static final Encoding QUOTED_PRINTABLE = new Encoding("QUOTED-PRINTABLE", true); |
| 59 | |
| 60 | @SupportedVersions({ V2_1 }) |
| 61 | public static final Encoding BASE64 = new Encoding("BASE64", true); |
| 62 | |
| 63 | @SupportedVersions({ V2_1 }) |
| 64 | public static final Encoding _8BIT = new Encoding("8BIT", true); |
| 65 | |
| 66 | @SupportedVersions({ V2_1 }) |
| 67 | public static final Encoding _7BIT = new Encoding("7BIT", true); |
| 68 | |
| 69 | @SupportedVersions({ V3_0 }) |
| 70 | public static final Encoding B = new Encoding("b"); |
| 71 | |
| 72 | private Encoding(String value) { |
| 73 | super(value); |
| 74 | } |
| 75 | |
| 76 | private Encoding(String value, boolean preserveCase) { |
| 77 | super(value, preserveCase); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Searches for a parameter value that is defined as a static constant in |
| 82 | * this class. |
| 83 | * @param value the parameter value |
| 84 | * @return the object or null if not found |
| 85 | */ |
| 86 | public static Encoding find(String value) { |
| 87 | return enums.find(value); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Searches for a parameter value and creates one if it cannot be found. All |
| 92 | * objects are guaranteed to be unique, so they can be compared with |
| 93 | * {@code ==} equality. |
| 94 | * @param value the parameter value |
| 95 | * @return the object |
| 96 | */ |
| 97 | public static Encoding get(String value) { |
| 98 | return enums.get(value); |
| 99 | } |
| 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 | } |