| 1 | package ezvcard.parameter; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | |
| 5 | import ezvcard.property.Logo; |
| 6 | import ezvcard.property.Photo; |
| 7 | |
| 8 | /* |
| 9 | * Copyright 2011 George El-Haddad. All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without modification, are |
| 12 | * permitted provided that the following conditions are met: |
| 13 | * |
| 14 | * 1. Redistributions of source code must retain the above copyright notice, this list of |
| 15 | * conditions and the following disclaimer. |
| 16 | * |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 18 | * of conditions and the following disclaimer in the documentation and/or other materials |
| 19 | * provided with the distribution. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED |
| 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR |
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
| 31 | * The views and conclusions contained in the software and documentation are those of the |
| 32 | * authors and should not be interpreted as representing official policies, either expressed |
| 33 | * or implied, of George El-Haddad. |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | Copyright (c) 2012-2023, Michael Angstadt |
| 38 | All rights reserved. |
| 39 | |
| 40 | Redistribution and use in source and binary forms, with or without |
| 41 | modification, are permitted provided that the following conditions are met: |
| 42 | |
| 43 | 1. Redistributions of source code must retain the above copyright notice, this |
| 44 | list of conditions and the following disclaimer. |
| 45 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 46 | this list of conditions and the following disclaimer in the documentation |
| 47 | and/or other materials provided with the distribution. |
| 48 | |
| 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 50 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 51 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 52 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 53 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 54 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 55 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 56 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 57 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 58 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 59 | |
| 60 | The views and conclusions contained in the software and documentation are those |
| 61 | of the authors and should not be interpreted as representing official policies, |
| 62 | either expressed or implied, of the FreeBSD Project. |
| 63 | */ |
| 64 | |
| 65 | /** |
| 66 | * Represents an image media type used in the TYPE parameter, MEDIATYPE |
| 67 | * parameter, and data URIs of the {@link Photo} and {@link Logo} |
| 68 | * properties. |
| 69 | * <p> |
| 70 | * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0} |
| 71 | * </p> |
| 72 | * @author George El-Haddadt Mar 10, 2010 |
| 73 | * @author Michael Angstadt |
| 74 | */ |
| 75 | public class ImageType extends MediaTypeParameter { |
| 76 | private static final MediaTypeCaseClasses<ImageType> enums = new MediaTypeCaseClasses<>(ImageType.class); |
| 77 | |
| 78 | public static final ImageType GIF = new ImageType("GIF", "image/gif", "gif"); |
| 79 | public static final ImageType JPEG = new ImageType("JPEG", "image/jpeg", "jpg"); |
| 80 | public static final ImageType PNG = new ImageType("PNG", "image/png", "png"); |
| 81 | |
| 82 | private ImageType(String value, String mediaType, String extension) { |
| 83 | super(value, mediaType, extension); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Searches for a parameter value that is defined as a static constant in |
| 88 | * this class. |
| 89 | * @param type the TYPE parameter value to search for (e.g. "JPEG") or null |
| 90 | * to not search by this value |
| 91 | * @param mediaType the media type to search for (e.g. "image/png") or null |
| 92 | * to not search by this value |
| 93 | * @param extension the file extension to search for (excluding the ".", |
| 94 | * e.g. "jpg") or null to not search by this value |
| 95 | * @return the object or null if not found |
| 96 | */ |
| 97 | public static ImageType find(String type, String mediaType, String extension) { |
| 98 | return enums.find(new String[] { type, mediaType, extension }); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Searches for a parameter value and creates one if it cannot be found. All |
| 103 | * objects are guaranteed to be unique, so they can be compared with |
| 104 | * {@code ==} equality. |
| 105 | * @param type the TYPE parameter value to search for (e.g. "JPEG") or null |
| 106 | * to not search by this value |
| 107 | * @param mediaType the media type to search for (e.g. "image/png") or null |
| 108 | * to not search by this value |
| 109 | * @param extension the file extension to search for (excluding the ".", |
| 110 | * e.g. "jpg") or null to not search by this value |
| 111 | * @return the object |
| 112 | */ |
| 113 | public static ImageType get(String type, String mediaType, String extension) { |
| 114 | return enums.get(new String[] { type, mediaType, extension }); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Gets all of the parameter values that are defined as static constants in |
| 119 | * this class. |
| 120 | * @return the parameter values |
| 121 | */ |
| 122 | public static Collection<ImageType> all() { |
| 123 | return enums.all(); |
| 124 | } |
| 125 | } |