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.component; michael@0: michael@0: import java.util.HashMap; michael@0: import java.util.Map; michael@0: michael@0: import net.fortuna.ical4j.model.Date; michael@0: import net.fortuna.ical4j.model.Property; michael@0: import net.fortuna.ical4j.model.PropertyList; michael@0: import net.fortuna.ical4j.model.ValidationException; michael@0: import net.fortuna.ical4j.model.Validator; michael@0: import net.fortuna.ical4j.model.property.Clazz; michael@0: import net.fortuna.ical4j.model.property.Created; michael@0: import net.fortuna.ical4j.model.property.Description; michael@0: import net.fortuna.ical4j.model.property.DtStamp; michael@0: import net.fortuna.ical4j.model.property.DtStart; michael@0: import net.fortuna.ical4j.model.property.LastModified; michael@0: import net.fortuna.ical4j.model.property.Method; michael@0: import net.fortuna.ical4j.model.property.Organizer; michael@0: import net.fortuna.ical4j.model.property.RecurrenceId; michael@0: import net.fortuna.ical4j.model.property.Sequence; michael@0: import net.fortuna.ical4j.model.property.Status; michael@0: import net.fortuna.ical4j.model.property.Summary; michael@0: import net.fortuna.ical4j.model.property.Uid; michael@0: import net.fortuna.ical4j.model.property.Url; michael@0: import net.fortuna.ical4j.util.CompatibilityHints; michael@0: import net.fortuna.ical4j.util.PropertyValidator; michael@0: michael@0: /** michael@0: * $Id$ [Apr 5, 2004] michael@0: * michael@0: * Defines an iCalendar VJOURNAL component. michael@0: * michael@0: *
michael@0: * 4.6.3 Journal Component michael@0: * michael@0: * Component Name: VJOURNAL michael@0: * michael@0: * Purpose: Provide a grouping of component properties that describe a michael@0: * journal entry. michael@0: * michael@0: * Formal Definition: A "VJOURNAL" calendar component is defined by the michael@0: * following notation: michael@0: * michael@0: * journalc = "BEGIN" ":" "VJOURNAL" CRLF michael@0: * jourprop michael@0: * "END" ":" "VJOURNAL" CRLF michael@0: * michael@0: * jourprop = *( michael@0: * michael@0: * ; the following are optional, michael@0: * ; but MUST NOT occur more than once michael@0: * michael@0: * class / created / description / dtstart / dtstamp / michael@0: * last-mod / organizer / recurid / seq / status / michael@0: * summary / uid / url / michael@0: * michael@0: * ; the following are optional, michael@0: * ; and MAY occur more than once michael@0: * michael@0: * attach / attendee / categories / comment / michael@0: * contact / exdate / exrule / related / rdate / michael@0: * rrule / rstatus / x-prop michael@0: * michael@0: * ) michael@0: *michael@0: * michael@0: * Example 1 - Creating a journal associated with an event: michael@0: * michael@0: *
michael@0: * DtStart meetingDate = (DtStart) meeting.getProperties().getProperty(
michael@0: * Property.DTSTART);
michael@0: *
michael@0: * VJournal minutes = new VJournal(meetingDate.getTime(),
michael@0: * "Progress Meeting - Minutes");
michael@0: *
michael@0: * // add timezone information..
michael@0: * TzId tzParam = meetingDate.getParameters().getParmaeter(Parameter.TZID);
michael@0: * minutes.getProperties().getProperty(Property.DTSTART).getParameters().add(
michael@0: * tzParam);
michael@0: *
michael@0: * // add description..
michael@0: * minutes.getProperties().add(new Description("1. Agenda.., 2. Action Items.."));
michael@0: *
michael@0: *
michael@0: * @author Ben Fortuna
michael@0: */
michael@0: public class VJournal extends CalendarComponent {
michael@0:
michael@0: private static final long serialVersionUID = -7635140949183238830L;
michael@0:
michael@0: private final Map methodValidators = new HashMap();
michael@0: {
michael@0: methodValidators.put(Method.ADD, new AddValidator());
michael@0: methodValidators.put(Method.CANCEL, new CancelValidator());
michael@0: methodValidators.put(Method.PUBLISH, new PublishValidator());
michael@0: }
michael@0:
michael@0: /**
michael@0: * Default constructor.
michael@0: */
michael@0: public VJournal() {
michael@0: super(VJOURNAL);
michael@0: getProperties().add(new DtStamp());
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructor.
michael@0: * @param properties a list of properties
michael@0: */
michael@0: public VJournal(final PropertyList properties) {
michael@0: super(VJOURNAL, properties);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Constructs a new VJOURNAL instance associated with the specified time with the specified summary.
michael@0: * @param start the date the journal entry is associated with
michael@0: * @param summary the journal summary
michael@0: */
michael@0: public VJournal(final Date start, final String summary) {
michael@0: this();
michael@0: getProperties().add(new DtStart(start));
michael@0: getProperties().add(new Summary(summary));
michael@0: }
michael@0:
michael@0: /**
michael@0: * {@inheritDoc}
michael@0: */
michael@0: public final void validate(final boolean recurse)
michael@0: throws ValidationException {
michael@0:
michael@0: if (!CompatibilityHints
michael@0: .isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) {
michael@0:
michael@0: // From "4.8.4.7 Unique Identifier":
michael@0: // Conformance: The property MUST be specified in the "VEVENT", "VTODO",
michael@0: // "VJOURNAL" or "VFREEBUSY" calendar components.
michael@0: PropertyValidator.getInstance().assertOne(Property.UID,
michael@0: getProperties());
michael@0:
michael@0: // From "4.8.7.2 Date/Time Stamp":
michael@0: // Conformance: This property MUST be included in the "VEVENT", "VTODO",
michael@0: // "VJOURNAL" or "VFREEBUSY" calendar components.
michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTAMP,
michael@0: getProperties());
michael@0: }
michael@0:
michael@0: /*
michael@0: * ; the following are optional, ; but MUST NOT occur more than once class / created / description / dtstart /
michael@0: * dtstamp / last-mod / organizer / recurid / seq / status / summary / uid / url /
michael@0: */
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CLASS,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CREATED,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.DTSTAMP,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.STATUS,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.UID,
michael@0: getProperties());
michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.URL,
michael@0: getProperties());
michael@0:
michael@0: final Status status = (Status) getProperty(Property.STATUS);
michael@0: if (status != null && !Status.VJOURNAL_DRAFT.getValue().equals(status.getValue())
michael@0: && !Status.VJOURNAL_FINAL.getValue().equals(status.getValue())
michael@0: && !Status.VJOURNAL_CANCELLED.getValue().equals(status.getValue())) {
michael@0: throw new ValidationException("Status property ["
michael@0: + status.toString() + "] may not occur in VJOURNAL");
michael@0: }
michael@0:
michael@0: /*
michael@0: * ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment /
michael@0: * contact / exdate / exrule / related / rdate / rrule / rstatus / x-prop
michael@0: */
michael@0:
michael@0: if (recurse) {
michael@0: validateProperties();
michael@0: }
michael@0: }
michael@0:
michael@0: /**
michael@0: * {@inheritDoc}
michael@0: */
michael@0: protected Validator getValidator(Method method) {
michael@0: return (Validator) methodValidators.get(method);
michael@0: }
michael@0:
michael@0: /**
michael@0: * michael@0: * Component/Property Presence michael@0: * ------------------- ---------------------------------------------- michael@0: * METHOD 1 MUST be "ADD" michael@0: * VJOURNAL 1 michael@0: * DESCRIPTION 1 Can be null. michael@0: * DTSTAMP 1 michael@0: * DTSTART 1 michael@0: * ORGANIZER 1 michael@0: * SEQUENCE 1 MUST be greater than 0 michael@0: * UID 1 MUST match that of the original journal michael@0: * michael@0: * ATTACH 0+ michael@0: * CATEGORIES 0 or 1 This property MAY contain a list of values michael@0: * CLASS 0 or 1 michael@0: * COMMENT 0 or 1 michael@0: * CONTACT 0+ michael@0: * CREATED 0 or 1 michael@0: * EXDATE 0+ michael@0: * EXRULE 0+ michael@0: * LAST-MODIFIED 0 or 1 michael@0: * RDATE 0+ michael@0: * RELATED-TO 0+ michael@0: * RRULE 0+ michael@0: * STATUS 0 or 1 MAY be one of DRAFT/FINAL/CANCELLED michael@0: * SUMMARY 0 or 1 Can be null michael@0: * URL 0 or 1 michael@0: * X-PROPERTY 0+ michael@0: * michael@0: * ATTENDEE 0 michael@0: * RECURRENCE-ID 0 michael@0: * michael@0: * VALARM 0+ michael@0: * VTIMEZONE 0 or 1 MUST be present if any date/time refers to michael@0: * a timezone michael@0: * X-COMPONENT 0+ michael@0: * michael@0: * VEVENT 0 michael@0: * VFREEBUSY 0 michael@0: * VTODO 0 michael@0: *michael@0: * michael@0: */ michael@0: private class AddValidator implements Validator { michael@0: michael@0: private static final long serialVersionUID = 1L; michael@0: michael@0: public void validate() throws ValidationException { michael@0: PropertyValidator.getInstance().assertOne(Property.DESCRIPTION, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTART, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.SEQUENCE, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.UID, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertNone(Property.ATTENDEE, getProperties()); michael@0: PropertyValidator.getInstance().assertNone(Property.RECURRENCE_ID, getProperties()); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: *
michael@0: * Component/Property Presence michael@0: * ------------------- --------------------------------------------- michael@0: * METHOD 1 MUST be "CANCEL" michael@0: * VJOURNAL 1+ All MUST have the same UID michael@0: * DTSTAMP 1 michael@0: * ORGANIZER 1 michael@0: * SEQUENCE 1 michael@0: * UID 1 MUST be the UID of the original REQUEST michael@0: * michael@0: * ATTACH 0+ michael@0: * ATTENDEE 0+ michael@0: * CATEGORIES 0 or 1 This property MAY contain a list of values michael@0: * CLASS 0 or 1 michael@0: * COMMENT 0 or 1 michael@0: * CONTACT 0+ michael@0: * CREATED 0 or 1 michael@0: * DESCRIPTION 0 or 1 michael@0: * DTSTART 0 or 1 michael@0: * EXDATE 0+ michael@0: * EXRULE 0+ michael@0: * LAST-MODIFIED 0 or 1 michael@0: * RDATE 0+ michael@0: * RECURRENCE-ID 0 or 1 only if referring to an instance of a michael@0: * recurring calendar component. Otherwise michael@0: * it MUST NOT be present. michael@0: * RELATED-TO 0+ michael@0: * RRULE 0+ michael@0: * STATUS 0 or 1 MAY be present, must be "CANCELLED" if michael@0: * present michael@0: * SUMMARY 0 or 1 michael@0: * URL 0 or 1 michael@0: * X-PROPERTY 0+ michael@0: * michael@0: * REQUEST-STATUS 0 michael@0: * michael@0: * VTIMEZONE 0+ MUST be present if any date/time refers to michael@0: * a timezone michael@0: * X-COMPONENT 0+ michael@0: * VALARM 0 michael@0: * VEVENT 0 michael@0: * VFREEBUSY 0 michael@0: * VTODO 0 michael@0: *michael@0: * michael@0: */ michael@0: private class CancelValidator implements Validator { michael@0: michael@0: private static final long serialVersionUID = 1L; michael@0: michael@0: public void validate() throws ValidationException { michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.SEQUENCE, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.UID, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties()); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: *
michael@0: * Component/Property Presence michael@0: * ------------------- ---------------------------------------------- michael@0: * METHOD 1 MUST be "PUBLISH" michael@0: * VJOURNAL 1+ michael@0: * DESCRIPTION 1 Can be null. michael@0: * DTSTAMP 1 michael@0: * DTSTART 1 michael@0: * ORGANIZER 1 michael@0: * UID 1 michael@0: * michael@0: * ATTACH 0+ michael@0: * CATEGORIES 0 or 1 This property MAY contain a list of values michael@0: * CLASS 0 or 1 michael@0: * COMMENT 0 or 1 michael@0: * CONTACT 0+ michael@0: * CREATED 0 or 1 michael@0: * EXDATE 0+ michael@0: * EXRULE 0+ michael@0: * LAST-MODIFIED 0 or 1 michael@0: * RDATE 0+ michael@0: * RECURRENCE-ID 0 or 1 MUST only if referring to an instance of a michael@0: * recurring calendar component. Otherwise michael@0: * it MUST NOT be present. michael@0: * RELATED-TO 0+ michael@0: * RRULE 0+ michael@0: * SEQUENCE 0 or 1 MUST echo the original SEQUENCE number. michael@0: * MUST be present if non-zero. MAY be michael@0: * present if zero. michael@0: * STATUS 0 or 1 MAY be one of DRAFT/FINAL/CANCELLED michael@0: * SUMMARY 0 or 1 Can be null michael@0: * URL 0 or 1 michael@0: * X-PROPERTY 0+ michael@0: * michael@0: * ATTENDEE 0 michael@0: * michael@0: * VALARM 0+ michael@0: * VTIMEZONE 0+ MUST be present if any date/time refers to michael@0: * a timezone michael@0: * X-COMPONENT 0+ michael@0: * michael@0: * VEVENT 0 michael@0: * VFREEBUSY 0 michael@0: * VTODO 0 michael@0: *michael@0: * michael@0: */ michael@0: private class PublishValidator implements Validator { michael@0: michael@0: private static final long serialVersionUID = 1L; michael@0: michael@0: public void validate() throws ValidationException { michael@0: PropertyValidator.getInstance().assertOne(Property.DESCRIPTION, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTART, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.UID, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties()); michael@0: michael@0: PropertyValidator.getInstance().assertNone(Property.ATTENDEE, getProperties()); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * @return the optional access classification property for a journal entry michael@0: */ michael@0: public final Clazz getClassification() { michael@0: return (Clazz) getProperty(Property.CLASS); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional creation-time property for a journal entry michael@0: */ michael@0: public final Created getCreated() { michael@0: return (Created) getProperty(Property.CREATED); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional description property for a journal entry michael@0: */ michael@0: public final Description getDescription() { michael@0: return (Description) getProperty(Property.DESCRIPTION); michael@0: } michael@0: michael@0: /** michael@0: * Convenience method to pull the DTSTART out of the property list. michael@0: * @return The DtStart object representation of the start Date michael@0: */ michael@0: public final DtStart getStartDate() { michael@0: return (DtStart) getProperty(Property.DTSTART); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional last-modified property for a journal entry michael@0: */ michael@0: public final LastModified getLastModified() { michael@0: return (LastModified) getProperty(Property.LAST_MODIFIED); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional organizer property for a journal entry michael@0: */ michael@0: public final Organizer getOrganizer() { michael@0: return (Organizer) getProperty(Property.ORGANIZER); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional date-stamp property michael@0: */ michael@0: public final DtStamp getDateStamp() { michael@0: return (DtStamp) getProperty(Property.DTSTAMP); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional sequence number property for a journal entry michael@0: */ michael@0: public final Sequence getSequence() { michael@0: return (Sequence) getProperty(Property.SEQUENCE); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional status property for a journal entry michael@0: */ michael@0: public final Status getStatus() { michael@0: return (Status) getProperty(Property.STATUS); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional summary property for a journal entry michael@0: */ michael@0: public final Summary getSummary() { michael@0: return (Summary) getProperty(Property.SUMMARY); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional URL property for a journal entry michael@0: */ michael@0: public final Url getUrl() { michael@0: return (Url) getProperty(Property.URL); michael@0: } michael@0: michael@0: /** michael@0: * @return the optional recurrence identifier property for a journal entry michael@0: */ michael@0: public final RecurrenceId getRecurrenceId() { michael@0: return (RecurrenceId) getProperty(Property.RECURRENCE_ID); michael@0: } michael@0: michael@0: /** michael@0: * Returns the UID property of this component if available. michael@0: * @return a Uid instance, or null if no UID property exists michael@0: */ michael@0: public final Uid getUid() { michael@0: return (Uid) getProperty(Property.UID); michael@0: } michael@0: }