1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/net/fortuna/ical4j/model/Parameter.java Tue Feb 10 18:12:00 2015 +0100 1.3 @@ -0,0 +1,264 @@ 1.4 +/** 1.5 + * Copyright (c) 2012, Ben Fortuna 1.6 + * All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1.12 + * o Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * o Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 +package net.fortuna.ical4j.model; 1.36 + 1.37 +import java.net.URISyntaxException; 1.38 + 1.39 +import net.fortuna.ical4j.util.Strings; 1.40 + 1.41 +import org.apache.commons.lang.builder.EqualsBuilder; 1.42 +import org.apache.commons.lang.builder.HashCodeBuilder; 1.43 + 1.44 +/** 1.45 + * Defines an iCalendar parameter. Subclasses of this class provide additional validation and typed values for specific 1.46 + * iCalendar parameters. 1.47 + * 1.48 + * Note that subclasses must provide a reference to the factory used to create the 1.49 + * parameter to support parameter cloning (copy). If no factory is specified an 1.50 + * {@link UnsupportedOperationException} will be thrown by the {@link #copy()} method. 1.51 + * 1.52 + * @author Ben Fortuna 1.53 + * 1.54 + * $Id$ [Apr 5, 2004] 1.55 + */ 1.56 +public abstract class Parameter extends Content { 1.57 + 1.58 + private static final long serialVersionUID = -2058497904769713528L; 1.59 + 1.60 + /** 1.61 + * Region abbreviation. 1.62 + */ 1.63 + public static final String ABBREV = "ABBREV"; 1.64 + 1.65 + /** 1.66 + * Alternate text representation. 1.67 + */ 1.68 + public static final String ALTREP = "ALTREP"; 1.69 + 1.70 + /** 1.71 + * Common name. 1.72 + */ 1.73 + public static final String CN = "CN"; 1.74 + 1.75 + /** 1.76 + * Calendar user type. 1.77 + */ 1.78 + public static final String CUTYPE = "CUTYPE"; 1.79 + 1.80 + /** 1.81 + * Delegator. 1.82 + */ 1.83 + public static final String DELEGATED_FROM = "DELEGATED-FROM"; 1.84 + 1.85 + /** 1.86 + * Delegatee. 1.87 + */ 1.88 + public static final String DELEGATED_TO = "DELEGATED-TO"; 1.89 + 1.90 + /** 1.91 + * Directory entry. 1.92 + */ 1.93 + public static final String DIR = "DIR"; 1.94 + 1.95 + /** 1.96 + * Inline encoding. 1.97 + */ 1.98 + public static final String ENCODING = "ENCODING"; 1.99 + 1.100 + /** 1.101 + * Format type. 1.102 + */ 1.103 + public static final String FMTTYPE = "FMTTYPE"; 1.104 + 1.105 + /** 1.106 + * Free/busy time type. 1.107 + */ 1.108 + public static final String FBTYPE = "FBTYPE"; 1.109 + 1.110 + /** 1.111 + * Language for text. 1.112 + */ 1.113 + public static final String LANGUAGE = "LANGUAGE"; 1.114 + 1.115 + /** 1.116 + * Group or list membership. 1.117 + */ 1.118 + public static final String MEMBER = "MEMBER"; 1.119 + 1.120 + /** 1.121 + * Participation status. 1.122 + */ 1.123 + public static final String PARTSTAT = "PARTSTAT"; 1.124 + 1.125 + /** 1.126 + * Recurrence identifier range. 1.127 + */ 1.128 + public static final String RANGE = "RANGE"; 1.129 + 1.130 + /** 1.131 + * Alarm trigger relationship. 1.132 + */ 1.133 + public static final String RELATED = "RELATED"; 1.134 + 1.135 + /** 1.136 + * Relationship type. 1.137 + */ 1.138 + public static final String RELTYPE = "RELTYPE"; 1.139 + 1.140 + /** 1.141 + * Participation role. 1.142 + */ 1.143 + public static final String ROLE = "ROLE"; 1.144 + 1.145 + /** 1.146 + * RSVP expectation. 1.147 + */ 1.148 + public static final String RSVP = "RSVP"; 1.149 + 1.150 + /** 1.151 + * Schedule agent. 1.152 + */ 1.153 + public static final String SCHEDULE_AGENT = "SCHEDULE-AGENT"; 1.154 + 1.155 + /** 1.156 + * Schedule status. 1.157 + */ 1.158 + public static final String SCHEDULE_STATUS = "SCHEDULE-STATUS"; 1.159 + 1.160 + /** 1.161 + * Sent by. 1.162 + */ 1.163 + public static final String SENT_BY = "SENT-BY"; 1.164 + 1.165 + /** 1.166 + * Type. 1.167 + */ 1.168 + public static final String TYPE = "TYPE"; 1.169 + 1.170 + /** 1.171 + * Reference to time zone object. 1.172 + */ 1.173 + public static final String TZID = "TZID"; 1.174 + 1.175 + /** 1.176 + * Property value data type. 1.177 + */ 1.178 + public static final String VALUE = "VALUE"; 1.179 + 1.180 + /** 1.181 + * Reference to vvenue component. 1.182 + */ 1.183 + public static final String VVENUE = "VVENUE"; 1.184 + 1.185 + /** 1.186 + * Prefix to all experimental parameters. 1.187 + */ 1.188 + public static final String EXPERIMENTAL_PREFIX = "X-"; 1.189 + 1.190 + private String name; 1.191 + 1.192 + private final ParameterFactory factory; 1.193 + 1.194 + /** 1.195 + * @param aName the parameter identifier 1.196 + * @param factory the factory used to create the parameter 1.197 + */ 1.198 + public Parameter(final String aName, ParameterFactory factory) { 1.199 + this.name = aName; 1.200 + this.factory = factory; 1.201 + } 1.202 + 1.203 + /** 1.204 + * {@inheritDoc} 1.205 + */ 1.206 + public final String toString() { 1.207 + final StringBuffer b = new StringBuffer(); 1.208 + b.append(getName()); 1.209 + b.append('='); 1.210 + if (isQuotable()) { 1.211 + b.append(Strings.quote(Strings.valueOf(getValue()))); 1.212 + } 1.213 + else { 1.214 + b.append(Strings.valueOf(getValue())); 1.215 + } 1.216 + return b.toString(); 1.217 + } 1.218 + 1.219 + /** 1.220 + * Indicates whether the current parameter value should be quoted. 1.221 + * @return true if the value should be quoted, otherwise false 1.222 + */ 1.223 + protected boolean isQuotable() { 1.224 + return Strings.PARAM_QUOTE_PATTERN.matcher(Strings.valueOf(getValue())) 1.225 + .find(); 1.226 + } 1.227 + 1.228 + /** 1.229 + * @return Returns the name. 1.230 + */ 1.231 + public final String getName() { 1.232 + return name; 1.233 + } 1.234 + 1.235 + /** 1.236 + * {@inheritDoc} 1.237 + */ 1.238 + public final boolean equals(final Object arg0) { 1.239 + if (arg0 instanceof Parameter) { 1.240 + final Parameter p = (Parameter) arg0; 1.241 + return new EqualsBuilder().append(getName(), p.getName()) 1.242 + .append(getValue(), p.getValue()).isEquals(); 1.243 + } 1.244 + return super.equals(arg0); 1.245 + } 1.246 + 1.247 + /** 1.248 + * {@inheritDoc} 1.249 + */ 1.250 + public final int hashCode() { 1.251 + // as parameter name is case-insensitive generate hash for uppercase.. 1.252 + return new HashCodeBuilder().append(getName().toUpperCase()).append( 1.253 + getValue()).toHashCode(); 1.254 + } 1.255 + 1.256 + /** 1.257 + * Deep copy of parameter. 1.258 + * @return new parameter 1.259 + * @throws URISyntaxException where an invalid URI is encountered 1.260 + */ 1.261 + public Parameter copy() throws URISyntaxException { 1.262 + if (factory == null) { 1.263 + throw new UnsupportedOperationException("No factory specified"); 1.264 + } 1.265 + return factory.createParameter(getName(), getValue()); 1.266 + } 1.267 +}