michael@0: /** michael@0: * Copyright (c) 2012, Ben Fortuna michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * o Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * o Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * o Neither the name of Ben Fortuna nor the names of any other contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: package net.fortuna.ical4j.model; michael@0: michael@0: import java.net.URISyntaxException; michael@0: michael@0: import net.fortuna.ical4j.util.Strings; michael@0: michael@4: import org.apache.commons.lang3.builder.EqualsBuilder; michael@4: import org.apache.commons.lang3.builder.HashCodeBuilder; michael@0: michael@0: /** michael@0: * Defines an iCalendar parameter. Subclasses of this class provide additional validation and typed values for specific michael@0: * iCalendar parameters. michael@0: * michael@0: * Note that subclasses must provide a reference to the factory used to create the michael@0: * parameter to support parameter cloning (copy). If no factory is specified an michael@0: * {@link UnsupportedOperationException} will be thrown by the {@link #copy()} method. michael@0: * michael@0: * @author Ben Fortuna michael@0: * michael@0: * $Id$ [Apr 5, 2004] michael@0: */ michael@0: public abstract class Parameter extends Content { michael@0: michael@0: private static final long serialVersionUID = -2058497904769713528L; michael@0: michael@0: /** michael@0: * Region abbreviation. michael@0: */ michael@0: public static final String ABBREV = "ABBREV"; michael@0: michael@0: /** michael@0: * Alternate text representation. michael@0: */ michael@0: public static final String ALTREP = "ALTREP"; michael@0: michael@0: /** michael@0: * Common name. michael@0: */ michael@0: public static final String CN = "CN"; michael@0: michael@0: /** michael@0: * Calendar user type. michael@0: */ michael@0: public static final String CUTYPE = "CUTYPE"; michael@0: michael@0: /** michael@0: * Delegator. michael@0: */ michael@0: public static final String DELEGATED_FROM = "DELEGATED-FROM"; michael@0: michael@0: /** michael@0: * Delegatee. michael@0: */ michael@0: public static final String DELEGATED_TO = "DELEGATED-TO"; michael@0: michael@0: /** michael@0: * Directory entry. michael@0: */ michael@0: public static final String DIR = "DIR"; michael@0: michael@0: /** michael@0: * Inline encoding. michael@0: */ michael@0: public static final String ENCODING = "ENCODING"; michael@0: michael@0: /** michael@0: * Format type. michael@0: */ michael@0: public static final String FMTTYPE = "FMTTYPE"; michael@0: michael@0: /** michael@0: * Free/busy time type. michael@0: */ michael@0: public static final String FBTYPE = "FBTYPE"; michael@0: michael@0: /** michael@0: * Language for text. michael@0: */ michael@0: public static final String LANGUAGE = "LANGUAGE"; michael@0: michael@0: /** michael@0: * Group or list membership. michael@0: */ michael@0: public static final String MEMBER = "MEMBER"; michael@0: michael@0: /** michael@0: * Participation status. michael@0: */ michael@0: public static final String PARTSTAT = "PARTSTAT"; michael@0: michael@0: /** michael@0: * Recurrence identifier range. michael@0: */ michael@0: public static final String RANGE = "RANGE"; michael@0: michael@0: /** michael@0: * Alarm trigger relationship. michael@0: */ michael@0: public static final String RELATED = "RELATED"; michael@0: michael@0: /** michael@0: * Relationship type. michael@0: */ michael@0: public static final String RELTYPE = "RELTYPE"; michael@0: michael@0: /** michael@0: * Participation role. michael@0: */ michael@0: public static final String ROLE = "ROLE"; michael@0: michael@0: /** michael@0: * RSVP expectation. michael@0: */ michael@0: public static final String RSVP = "RSVP"; michael@0: michael@0: /** michael@0: * Schedule agent. michael@0: */ michael@0: public static final String SCHEDULE_AGENT = "SCHEDULE-AGENT"; michael@0: michael@0: /** michael@0: * Schedule status. michael@0: */ michael@0: public static final String SCHEDULE_STATUS = "SCHEDULE-STATUS"; michael@0: michael@0: /** michael@0: * Sent by. michael@0: */ michael@0: public static final String SENT_BY = "SENT-BY"; michael@0: michael@0: /** michael@0: * Type. michael@0: */ michael@0: public static final String TYPE = "TYPE"; michael@0: michael@0: /** michael@0: * Reference to time zone object. michael@0: */ michael@0: public static final String TZID = "TZID"; michael@0: michael@0: /** michael@0: * Property value data type. michael@0: */ michael@0: public static final String VALUE = "VALUE"; michael@0: michael@0: /** michael@0: * Reference to vvenue component. michael@0: */ michael@0: public static final String VVENUE = "VVENUE"; michael@0: michael@0: /** michael@0: * Prefix to all experimental parameters. michael@0: */ michael@0: public static final String EXPERIMENTAL_PREFIX = "X-"; michael@0: michael@0: private String name; michael@0: michael@0: private final ParameterFactory factory; michael@0: michael@0: /** michael@0: * @param aName the parameter identifier michael@0: * @param factory the factory used to create the parameter michael@0: */ michael@0: public Parameter(final String aName, ParameterFactory factory) { michael@0: this.name = aName; michael@0: this.factory = factory; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final String toString() { michael@0: final StringBuffer b = new StringBuffer(); michael@0: b.append(getName()); michael@0: b.append('='); michael@0: if (isQuotable()) { michael@0: b.append(Strings.quote(Strings.valueOf(getValue()))); michael@0: } michael@0: else { michael@0: b.append(Strings.valueOf(getValue())); michael@0: } michael@0: return b.toString(); michael@0: } michael@0: michael@0: /** michael@0: * Indicates whether the current parameter value should be quoted. michael@0: * @return true if the value should be quoted, otherwise false michael@0: */ michael@0: protected boolean isQuotable() { michael@0: return Strings.PARAM_QUOTE_PATTERN.matcher(Strings.valueOf(getValue())) michael@0: .find(); michael@0: } michael@0: michael@0: /** michael@0: * @return Returns the name. michael@0: */ michael@0: public final String getName() { michael@0: return name; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final boolean equals(final Object arg0) { michael@0: if (arg0 instanceof Parameter) { michael@0: final Parameter p = (Parameter) arg0; michael@0: return new EqualsBuilder().append(getName(), p.getName()) michael@0: .append(getValue(), p.getValue()).isEquals(); michael@0: } michael@0: return super.equals(arg0); michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final int hashCode() { michael@0: // as parameter name is case-insensitive generate hash for uppercase.. michael@0: return new HashCodeBuilder().append(getName().toUpperCase()).append( michael@0: getValue()).toHashCode(); michael@0: } michael@0: michael@0: /** michael@0: * Deep copy of parameter. michael@0: * @return new parameter michael@0: * @throws URISyntaxException where an invalid URI is encountered michael@0: */ michael@0: public Parameter copy() throws URISyntaxException { michael@0: if (factory == null) { michael@0: throw new UnsupportedOperationException("No factory specified"); michael@0: } michael@0: return factory.createParameter(getName(), getValue()); michael@0: } michael@0: }