001    package ezvcard.parameter;
002    
003    import java.util.Collection;
004    
005    import ezvcard.property.Logo;
006    import ezvcard.property.Photo;
007    
008    /**
009     * Copyright 2011 George El-Haddad. All rights reserved.
010     * 
011     * Redistribution and use in source and binary forms, with or without modification, are
012     * permitted provided that the following conditions are met:
013     * 
014     *    1. Redistributions of source code must retain the above copyright notice, this list of
015     *       conditions and the following disclaimer.
016     * 
017     *    2. Redistributions in binary form must reproduce the above copyright notice, this list
018     *       of conditions and the following disclaimer in the documentation and/or other materials
019     *       provided with the distribution.
020     * 
021     * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED
022     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
023     * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR
024     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
026     * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
027     * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
028     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     * 
031     * The views and conclusions contained in the software and documentation are those of the
032     * authors and should not be interpreted as representing official policies, either expressed
033     * or implied, of George El-Haddad.
034     */
035    
036    /*
037     Copyright (c) 2013, Michael Angstadt
038     All rights reserved.
039    
040     Redistribution and use in source and binary forms, with or without
041     modification, are permitted provided that the following conditions are met: 
042    
043     1. Redistributions of source code must retain the above copyright notice, this
044     list of conditions and the following disclaimer. 
045     2. Redistributions in binary form must reproduce the above copyright notice,
046     this list of conditions and the following disclaimer in the documentation
047     and/or other materials provided with the distribution. 
048    
049     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
050     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
051     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
052     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
053     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
054     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
055     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
056     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
057     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
058     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
059    
060     The views and conclusions contained in the software and documentation are those
061     of the authors and should not be interpreted as representing official policies, 
062     either expressed or implied, of the FreeBSD Project.
063     */
064    
065    /**
066     * Represents an image media type used in the TYPE parameter, MEDIATYPE
067     * parameter, and data URIs of the {@link Photo} and {@link Logo}
068     * properties.
069     * <p>
070     * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
071     * </p>
072     * @author George El-Haddadt Mar 10, 2010
073     * @author Michael Angstadt
074     */
075    public class ImageType extends MediaTypeParameter {
076            private static final MediaTypeCaseClasses<ImageType> enums = new MediaTypeCaseClasses<ImageType>(ImageType.class);
077    
078            public static final ImageType GIF = new ImageType("GIF", "image/gif", "gif");
079            public static final ImageType JPEG = new ImageType("JPEG", "image/jpeg", "jpg");
080            public static final ImageType PNG = new ImageType("PNG", "image/png", "png");
081    
082            private ImageType(String value, String mediaType, String extension) {
083                    super(value, mediaType, extension);
084            }
085    
086            /**
087             * Searches for a parameter value that is defined as a static constant in
088             * this class.
089             * @param type the TYPE parameter value to search for (e.g. "JPEG") or null
090             * to not search by this value
091             * @param mediaType the media type to search for (e.g. "image/png") or null
092             * to not search by this value
093             * @param extension the file extension to search for (excluding the ".",
094             * e.g. "jpg") or null to not search by this value
095             * @return the object or null if not found
096             */
097            public static ImageType find(String type, String mediaType, String extension) {
098                    return enums.find(new String[] { type, mediaType, extension });
099            }
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    }