Tue, 10 Feb 2015 18:12:00 +0100
Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.
michael@0 | 1 | /** |
michael@0 | 2 | * Copyright (c) 2012, Ben Fortuna |
michael@0 | 3 | * All rights reserved. |
michael@0 | 4 | * |
michael@0 | 5 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 6 | * modification, are permitted provided that the following conditions |
michael@0 | 7 | * are met: |
michael@0 | 8 | * |
michael@0 | 9 | * o Redistributions of source code must retain the above copyright |
michael@0 | 10 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 11 | * |
michael@0 | 12 | * o Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | * documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * o Neither the name of Ben Fortuna nor the names of any other contributors |
michael@0 | 17 | * may be used to endorse or promote products derived from this software |
michael@0 | 18 | * without specific prior written permission. |
michael@0 | 19 | * |
michael@0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
michael@0 | 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
michael@0 | 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
michael@0 | 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
michael@0 | 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
michael@0 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
michael@0 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | package net.fortuna.ical4j.model; |
michael@0 | 33 | |
michael@0 | 34 | import java.net.URISyntaxException; |
michael@0 | 35 | |
michael@0 | 36 | import net.fortuna.ical4j.util.Strings; |
michael@0 | 37 | |
michael@0 | 38 | import org.apache.commons.lang.builder.EqualsBuilder; |
michael@0 | 39 | import org.apache.commons.lang.builder.HashCodeBuilder; |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * Defines an iCalendar parameter. Subclasses of this class provide additional validation and typed values for specific |
michael@0 | 43 | * iCalendar parameters. |
michael@0 | 44 | * |
michael@0 | 45 | * Note that subclasses must provide a reference to the factory used to create the |
michael@0 | 46 | * parameter to support parameter cloning (copy). If no factory is specified an |
michael@0 | 47 | * {@link UnsupportedOperationException} will be thrown by the {@link #copy()} method. |
michael@0 | 48 | * |
michael@0 | 49 | * @author Ben Fortuna |
michael@0 | 50 | * |
michael@0 | 51 | * $Id$ [Apr 5, 2004] |
michael@0 | 52 | */ |
michael@0 | 53 | public abstract class Parameter extends Content { |
michael@0 | 54 | |
michael@0 | 55 | private static final long serialVersionUID = -2058497904769713528L; |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Region abbreviation. |
michael@0 | 59 | */ |
michael@0 | 60 | public static final String ABBREV = "ABBREV"; |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Alternate text representation. |
michael@0 | 64 | */ |
michael@0 | 65 | public static final String ALTREP = "ALTREP"; |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Common name. |
michael@0 | 69 | */ |
michael@0 | 70 | public static final String CN = "CN"; |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Calendar user type. |
michael@0 | 74 | */ |
michael@0 | 75 | public static final String CUTYPE = "CUTYPE"; |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Delegator. |
michael@0 | 79 | */ |
michael@0 | 80 | public static final String DELEGATED_FROM = "DELEGATED-FROM"; |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Delegatee. |
michael@0 | 84 | */ |
michael@0 | 85 | public static final String DELEGATED_TO = "DELEGATED-TO"; |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Directory entry. |
michael@0 | 89 | */ |
michael@0 | 90 | public static final String DIR = "DIR"; |
michael@0 | 91 | |
michael@0 | 92 | /** |
michael@0 | 93 | * Inline encoding. |
michael@0 | 94 | */ |
michael@0 | 95 | public static final String ENCODING = "ENCODING"; |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Format type. |
michael@0 | 99 | */ |
michael@0 | 100 | public static final String FMTTYPE = "FMTTYPE"; |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Free/busy time type. |
michael@0 | 104 | */ |
michael@0 | 105 | public static final String FBTYPE = "FBTYPE"; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Language for text. |
michael@0 | 109 | */ |
michael@0 | 110 | public static final String LANGUAGE = "LANGUAGE"; |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Group or list membership. |
michael@0 | 114 | */ |
michael@0 | 115 | public static final String MEMBER = "MEMBER"; |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Participation status. |
michael@0 | 119 | */ |
michael@0 | 120 | public static final String PARTSTAT = "PARTSTAT"; |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Recurrence identifier range. |
michael@0 | 124 | */ |
michael@0 | 125 | public static final String RANGE = "RANGE"; |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Alarm trigger relationship. |
michael@0 | 129 | */ |
michael@0 | 130 | public static final String RELATED = "RELATED"; |
michael@0 | 131 | |
michael@0 | 132 | /** |
michael@0 | 133 | * Relationship type. |
michael@0 | 134 | */ |
michael@0 | 135 | public static final String RELTYPE = "RELTYPE"; |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * Participation role. |
michael@0 | 139 | */ |
michael@0 | 140 | public static final String ROLE = "ROLE"; |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * RSVP expectation. |
michael@0 | 144 | */ |
michael@0 | 145 | public static final String RSVP = "RSVP"; |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * Schedule agent. |
michael@0 | 149 | */ |
michael@0 | 150 | public static final String SCHEDULE_AGENT = "SCHEDULE-AGENT"; |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Schedule status. |
michael@0 | 154 | */ |
michael@0 | 155 | public static final String SCHEDULE_STATUS = "SCHEDULE-STATUS"; |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Sent by. |
michael@0 | 159 | */ |
michael@0 | 160 | public static final String SENT_BY = "SENT-BY"; |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * Type. |
michael@0 | 164 | */ |
michael@0 | 165 | public static final String TYPE = "TYPE"; |
michael@0 | 166 | |
michael@0 | 167 | /** |
michael@0 | 168 | * Reference to time zone object. |
michael@0 | 169 | */ |
michael@0 | 170 | public static final String TZID = "TZID"; |
michael@0 | 171 | |
michael@0 | 172 | /** |
michael@0 | 173 | * Property value data type. |
michael@0 | 174 | */ |
michael@0 | 175 | public static final String VALUE = "VALUE"; |
michael@0 | 176 | |
michael@0 | 177 | /** |
michael@0 | 178 | * Reference to vvenue component. |
michael@0 | 179 | */ |
michael@0 | 180 | public static final String VVENUE = "VVENUE"; |
michael@0 | 181 | |
michael@0 | 182 | /** |
michael@0 | 183 | * Prefix to all experimental parameters. |
michael@0 | 184 | */ |
michael@0 | 185 | public static final String EXPERIMENTAL_PREFIX = "X-"; |
michael@0 | 186 | |
michael@0 | 187 | private String name; |
michael@0 | 188 | |
michael@0 | 189 | private final ParameterFactory factory; |
michael@0 | 190 | |
michael@0 | 191 | /** |
michael@0 | 192 | * @param aName the parameter identifier |
michael@0 | 193 | * @param factory the factory used to create the parameter |
michael@0 | 194 | */ |
michael@0 | 195 | public Parameter(final String aName, ParameterFactory factory) { |
michael@0 | 196 | this.name = aName; |
michael@0 | 197 | this.factory = factory; |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * {@inheritDoc} |
michael@0 | 202 | */ |
michael@0 | 203 | public final String toString() { |
michael@0 | 204 | final StringBuffer b = new StringBuffer(); |
michael@0 | 205 | b.append(getName()); |
michael@0 | 206 | b.append('='); |
michael@0 | 207 | if (isQuotable()) { |
michael@0 | 208 | b.append(Strings.quote(Strings.valueOf(getValue()))); |
michael@0 | 209 | } |
michael@0 | 210 | else { |
michael@0 | 211 | b.append(Strings.valueOf(getValue())); |
michael@0 | 212 | } |
michael@0 | 213 | return b.toString(); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Indicates whether the current parameter value should be quoted. |
michael@0 | 218 | * @return true if the value should be quoted, otherwise false |
michael@0 | 219 | */ |
michael@0 | 220 | protected boolean isQuotable() { |
michael@0 | 221 | return Strings.PARAM_QUOTE_PATTERN.matcher(Strings.valueOf(getValue())) |
michael@0 | 222 | .find(); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * @return Returns the name. |
michael@0 | 227 | */ |
michael@0 | 228 | public final String getName() { |
michael@0 | 229 | return name; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | /** |
michael@0 | 233 | * {@inheritDoc} |
michael@0 | 234 | */ |
michael@0 | 235 | public final boolean equals(final Object arg0) { |
michael@0 | 236 | if (arg0 instanceof Parameter) { |
michael@0 | 237 | final Parameter p = (Parameter) arg0; |
michael@0 | 238 | return new EqualsBuilder().append(getName(), p.getName()) |
michael@0 | 239 | .append(getValue(), p.getValue()).isEquals(); |
michael@0 | 240 | } |
michael@0 | 241 | return super.equals(arg0); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | /** |
michael@0 | 245 | * {@inheritDoc} |
michael@0 | 246 | */ |
michael@0 | 247 | public final int hashCode() { |
michael@0 | 248 | // as parameter name is case-insensitive generate hash for uppercase.. |
michael@0 | 249 | return new HashCodeBuilder().append(getName().toUpperCase()).append( |
michael@0 | 250 | getValue()).toHashCode(); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | /** |
michael@0 | 254 | * Deep copy of parameter. |
michael@0 | 255 | * @return new parameter |
michael@0 | 256 | * @throws URISyntaxException where an invalid URI is encountered |
michael@0 | 257 | */ |
michael@0 | 258 | public Parameter copy() throws URISyntaxException { |
michael@0 | 259 | if (factory == null) { |
michael@0 | 260 | throw new UnsupportedOperationException("No factory specified"); |
michael@0 | 261 | } |
michael@0 | 262 | return factory.createParameter(getName(), getValue()); |
michael@0 | 263 | } |
michael@0 | 264 | } |