001package biweekly; 002 003import java.util.Collection; 004 005import biweekly.util.CaseClasses; 006 007/* 008 Copyright (c) 2013-2015, Michael Angstadt 009 All rights reserved. 010 011 Redistribution and use in source and binary forms, with or without 012 modification, are permitted provided that the following conditions are met: 013 014 1. Redistributions of source code must retain the above copyright notice, this 015 list of conditions and the following disclaimer. 016 2. Redistributions in binary form must reproduce the above copyright notice, 017 this list of conditions and the following disclaimer in the documentation 018 and/or other materials provided with the distribution. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032/** 033 * Defines the data type of a property's value. 034 * @author Michael Angstadt 035 * @see <a href="http://tools.ietf.org/html/rfc5545#page-29">RFC 5545 036 * p.29-50</a> 037 */ 038public class ICalDataType { 039 private static final CaseClasses<ICalDataType, String> enums = new CaseClasses<ICalDataType, String>(ICalDataType.class) { 040 @Override 041 protected ICalDataType create(String value) { 042 return new ICalDataType(value); 043 } 044 045 @Override 046 protected boolean matches(ICalDataType dataType, String value) { 047 return dataType.name.equalsIgnoreCase(value); 048 } 049 }; 050 051 /** 052 * Binary data (such as an image or word-processing document). 053 * @see <a href="http://tools.ietf.org/html/rfc5545#page-30">RFC 5545 054 * p.30-1</a> 055 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.18</a> 056 */ 057 public static final ICalDataType BINARY = new ICalDataType("BINARY"); 058 059 /** 060 * Boolean value (i.e. "true" or "false"). 061 * @see <a href="http://tools.ietf.org/html/rfc5545#page-31">RFC 5545 062 * p.31</a> 063 */ 064 public static final ICalDataType BOOLEAN = new ICalDataType("BOOLEAN"); 065 066 /** 067 * A URI containing a calendar user address (i.e. a "mailto" URI). 068 * @see <a href="http://tools.ietf.org/html/rfc5545#page-30">RFC 5545 069 * p.30-1</a> 070 */ 071 public static final ICalDataType CAL_ADDRESS = new ICalDataType("CAL-ADDRESS"); 072 073 /** 074 * The property value is located in a separate MIME entity (vCal 1.0 only). 075 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.17</a> 076 */ 077 public static final ICalDataType CONTENT_ID = new ICalDataType("CONTENT-ID"); //1.0 only 078 079 /** 080 * A date (e.g. "2014-03-12") 081 * @see <a href="http://tools.ietf.org/html/rfc5545#page-32">RFC 5545 082 * p.32</a> 083 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.16-7</a> 084 */ 085 public static final ICalDataType DATE = new ICalDataType("DATE"); 086 087 /** 088 * A date/time value (e.g. "2014-03-12 13:30:00") 089 * @see <a href="http://tools.ietf.org/html/rfc5545#page-32">RFC 5545 090 * p.32-4</a> 091 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.16-7</a> 092 */ 093 public static final ICalDataType DATE_TIME = new ICalDataType("DATE-TIME"); 094 095 /** 096 * A duration of time (e.g. "2 hours, 30 minutes"). 097 * @see <a href="http://tools.ietf.org/html/rfc5545#page-35">RFC 5545 098 * p.35-6</a> 099 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.17</a> 100 */ 101 public static final ICalDataType DURATION = new ICalDataType("DURATION"); 102 103 /** 104 * A floating point value (e.g. "3.14") 105 * @see <a href="http://tools.ietf.org/html/rfc5545#page-36">RFC 5545 106 * p.36</a> 107 */ 108 public static final ICalDataType FLOAT = new ICalDataType("FLOAT"); 109 110 /** 111 * An integer value (e.g. "42") 112 * @see <a href="http://tools.ietf.org/html/rfc5545#page-37">RFC 5545 113 * p.37</a> 114 */ 115 public static final ICalDataType INTEGER = new ICalDataType("INTEGER"); 116 117 /** 118 * A period of time (e.g. "October 3 through October 5"). 119 * @see <a href="http://tools.ietf.org/html/rfc5545#page-37-8">RFC 5545 120 * p.37-8</a> 121 */ 122 public static final ICalDataType PERIOD = new ICalDataType("PERIOD"); 123 124 /** 125 * A recurrence rule (e.g. "every Monday at 2pm"). 126 * @see <a href="http://tools.ietf.org/html/rfc5545#page-38">RFC 5545 127 * p.38-45</a> 128 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.18-23</a> 129 */ 130 public static final ICalDataType RECUR = new ICalDataType("RECUR"); 131 132 /** 133 * A plain text value. 134 * @see <a href="http://tools.ietf.org/html/rfc5545#page-45">RFC 5545 135 * p.45-6</a> 136 */ 137 public static final ICalDataType TEXT = new ICalDataType("TEXT"); 138 139 /** 140 * A time value (e.g. "2pm"). 141 * @see <a href="http://tools.ietf.org/html/rfc5545#page-47">RFC 5545 142 * p.47-8</a> 143 */ 144 public static final ICalDataType TIME = new ICalDataType("TIME"); 145 146 /** 147 * A URI value. 148 * @see <a href="http://tools.ietf.org/html/rfc5545#page-49">RFC 5545 149 * p.49</a> 150 */ 151 public static final ICalDataType URI = new ICalDataType("URI"); 152 153 /** 154 * A URL (e.g. "http://example.com/picture.jpg") (vCal 1.0 only). 155 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.17-8</a> 156 */ 157 public static final ICalDataType URL = new ICalDataType("URL"); 158 159 /** 160 * A UTC-offset (e.g. "+0500"). 161 * @see <a href="http://tools.ietf.org/html/rfc5545#page-49">RFC 5545 162 * p.49-50</a> 163 */ 164 public static final ICalDataType UTC_OFFSET = new ICalDataType("UTC-OFFSET"); 165 166 private final String name; 167 168 private ICalDataType(String name) { 169 this.name = name; 170 } 171 172 /** 173 * Gets the name of the data type. 174 * @return the name of the data type (e.g. "TEXT") 175 */ 176 public String getName() { 177 return name; 178 } 179 180 @Override 181 public String toString() { 182 return name; 183 } 184 185 /** 186 * Searches for a parameter value that is defined as a static constant in 187 * this class. 188 * @param value the parameter value 189 * @return the object or null if not found 190 */ 191 public static ICalDataType find(String value) { 192 if ("CID".equalsIgnoreCase(value)) { 193 //"CID" is an alias for "CONTENT-ID" (vCal 1.0, p.17) 194 return CONTENT_ID; 195 } 196 return enums.find(value); 197 } 198 199 /** 200 * Searches for a parameter value and creates one if it cannot be found. All 201 * objects are guaranteed to be unique, so they can be compared with 202 * {@code ==} equality. 203 * @param value the parameter value 204 * @return the object 205 */ 206 public static ICalDataType get(String value) { 207 if ("CID".equalsIgnoreCase(value)) { 208 //"CID" is an alias for "CONTENT-ID" (vCal 1.0, p.17) 209 return CONTENT_ID; 210 } 211 return enums.get(value); 212 } 213 214 /** 215 * Gets all of the parameter values that are defined as static constants in 216 * this class. 217 * @return the parameter values 218 */ 219 public static Collection<ICalDataType> all() { 220 return enums.all(); 221 } 222}