src/net/fortuna/ical4j/model/property/DateListProperty.java

Tue, 10 Feb 2015 19:58:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 19:58:00 +0100
changeset 4
45d57ecba757
permissions
-rw-r--r--

Upgrade the upgraded ical4j component to use org.apache.commons.lang3.

     1 /**
     2  * Copyright (c) 2012, Ben Fortuna
     3  * All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions
     7  * are met:
     8  *
     9  *  o Redistributions of source code must retain the above copyright
    10  * notice, this list of conditions and the following disclaimer.
    11  *
    12  *  o Redistributions in binary form must reproduce the above copyright
    13  * notice, this list of conditions and the following disclaimer in the
    14  * documentation and/or other materials provided with the distribution.
    15  *
    16  *  o Neither the name of Ben Fortuna nor the names of any other contributors
    17  * may be used to endorse or promote products derived from this software
    18  * without specific prior written permission.
    19  *
    20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  */
    32 package net.fortuna.ical4j.model.property;
    34 import java.io.IOException;
    35 import java.net.URISyntaxException;
    36 import java.text.ParseException;
    38 import net.fortuna.ical4j.model.DateList;
    39 import net.fortuna.ical4j.model.Parameter;
    40 import net.fortuna.ical4j.model.ParameterList;
    41 import net.fortuna.ical4j.model.Property;
    42 import net.fortuna.ical4j.model.PropertyFactory;
    43 import net.fortuna.ical4j.model.TimeZone;
    44 import net.fortuna.ical4j.model.parameter.TzId;
    45 import net.fortuna.ical4j.model.parameter.Value;
    46 import net.fortuna.ical4j.util.Strings;
    48 /**
    49  * $Id$
    50  *
    51  * Created on 11/08/2005
    52  *
    53  * Base class for properties with a list of dates as a value.
    54  * @author Ben Fortuna
    55  */
    56 public abstract class DateListProperty extends Property {
    58     /**
    59      * 
    60      */
    61     private static final long serialVersionUID = 5233773091972759919L;
    63     private DateList dates;
    65     private TimeZone timeZone;
    67     /**
    68      * @param name the property name
    69      */
    70     public DateListProperty(final String name, PropertyFactory factory) {
    71         this(name, new DateList(Value.DATE_TIME), factory);
    72     }
    74     /**
    75      * @param name the property name
    76      * @param parameters property parameters
    77      */
    78     public DateListProperty(final String name, final ParameterList parameters, PropertyFactory factory) {
    79         super(name, parameters, factory);
    80     }
    82     /**
    83      * @param name the property name
    84      * @param dates a list of initial dates for the property
    85      */
    86     public DateListProperty(final String name, final DateList dates, PropertyFactory factory) {
    87         this(name, new ParameterList(), dates, factory);
    88     }
    90     /**
    91      * @param name the property name
    92      * @param parameters property parameters
    93      * @param dates a list of initial dates for the property
    94      */
    95     public DateListProperty(final String name, final ParameterList parameters, final DateList dates,
    96             PropertyFactory factory) {
    97         super(name, parameters, factory);
    98         this.dates = dates;
    99         if (dates != null && !Value.DATE_TIME.equals(dates.getType())) {
   100             getParameters().replace(dates.getType());
   101         }
   102     }
   104     /**
   105      * @return Returns the dates.
   106      */
   107     public final DateList getDates() {
   108         return dates;
   109     }
   111     /**
   112      * {@inheritDoc}
   113      */
   114     public void setValue(final String aValue) throws ParseException {
   115         dates = new DateList(aValue, (Value) getParameter(Parameter.VALUE),
   116                 timeZone);
   117     }
   119     /**
   120      * {@inheritDoc}
   121      */
   122     public String getValue() {
   123         return Strings.valueOf(dates);
   124     }
   126     /**
   127      * Sets the timezone associated with this property.
   128      * @param timezone a timezone to associate with this property
   129      */
   130     public void setTimeZone(final TimeZone timezone) {
   131         if (dates == null) {
   132             throw new UnsupportedOperationException(
   133                     "TimeZone is not applicable to current value");
   134         }
   135         this.timeZone = timezone;
   136         if (timezone != null) {
   137             if (!Value.DATE_TIME.equals(getDates().getType())) {
   138                 throw new UnsupportedOperationException(
   139                         "TimeZone is not applicable to current value");
   140             }
   141             dates.setTimeZone(timezone);
   142             getParameters().remove(getParameter(Parameter.TZID));
   143             final TzId tzId = new TzId(timezone.getID());
   144             getParameters().replace(tzId);
   145         }
   146         else {
   147             // use setUtc() to reset timezone..
   148             setUtc(false);
   149         }
   150     }
   152     /**
   153      * @return the timezone
   154      */
   155     public final TimeZone getTimeZone() {
   156         return timeZone;
   157     }
   159     /**
   160      * Resets the timezone associated with the property. If utc is true, any TZID parameters are removed and the Java
   161      * timezone is updated to UTC time. If utc is false, TZID parameters are removed and the Java timezone is set to the
   162      * default timezone (i.e. represents a "floating" local time)
   163      * @param utc the UTC value
   164      */
   165     public final void setUtc(final boolean utc) {
   166         if (dates == null || !Value.DATE_TIME.equals(dates.getType())) {
   167             throw new UnsupportedOperationException(
   168                     "TimeZone is not applicable to current value");
   169         }
   170         dates.setUtc(utc);
   171         getParameters().remove(getParameter(Parameter.TZID));
   172     }
   174     /**
   175      * {@inheritDoc}
   176      */
   177     public final Property copy() throws IOException, URISyntaxException, ParseException {
   178         final Property copy = super.copy();
   180        ((DateListProperty) copy).timeZone = timeZone;
   181        ((DateListProperty) copy).setValue(getValue());
   183         return copy;
   184     }
   185 }

mercurial