View Javadoc

1   /*
2    * $Id: VEvent.java [Apr 5, 2004]
3    *
4    * Copyright (c) 2004, Ben Fortuna
5    * All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or without
8    * modification, are permitted provided that the following conditions
9    * are met:
10   *
11   * 	o Redistributions of source code must retain the above copyright
12   * notice, this list of conditions and the following disclaimer.
13   *
14   * 	o Redistributions in binary form must reproduce the above copyright
15   * notice, this list of conditions and the following disclaimer in the
16   * documentation and/or other materials provided with the distribution.
17   *
18   * 	o Neither the name of Ben Fortuna nor the names of any other contributors
19   * may be used to endorse or promote products derived from this software
20   * without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   */
34  package net.fortuna.ical4j.model.component;
35  
36  import net.fortuna.ical4j.model.Component;
37  import net.fortuna.ical4j.model.ComponentList;
38  import net.fortuna.ical4j.model.Property;
39  import net.fortuna.ical4j.model.PropertyList;
40  import net.fortuna.ical4j.model.ValidationException;
41  import net.fortuna.ical4j.util.PropertyValidator;
42  
43  /***
44   * Defines an iCalendar VEVENT component.
45   *
46   * @author benf
47   */
48  public class VEvent extends Component {
49  
50      private ComponentList alarms;
51  
52      /***
53       * Constructor.
54       *
55       * @param aList
56       *            a list of properties
57       */
58      public VEvent(final PropertyList aList) {
59  
60          super(VEVENT, aList);
61      }
62  
63      /***
64       * Constructor.
65       *
66       * @param aList
67       *            a list of properties
68       * @param cList
69       *            a list of alarms
70       */
71      public VEvent(final PropertyList aList, final ComponentList cList) {
72  
73          super(VEVENT, aList);
74  
75          this.alarms = cList;
76      }
77  
78      /***
79       * @see java.lang.Object#toString()
80       */
81      public final String toString() {
82  
83          if (alarms != null) {
84  
85          return BEGIN + ":" + getName() + "\r\n" + getProperties() + alarms
86                  + END + ":" + getName() + "\r\n"; }
87  
88          return super.toString();
89      }
90  
91      /***
92       * @see net.fortuna.ical4j.model.Component#validate(boolean)
93       */
94      public final void validate(boolean recurse) throws ValidationException {
95  
96          /*
97           * ; the following are optional, ; but MUST NOT occur more than once
98           *
99           * class / created / description / dtstart / geo / last-mod / location /
100          * organizer / priority / dtstamp / seq / status / summary / transp /
101          * uid / url / recurid /
102          */
103         PropertyValidator.getInstance().validateOneOrLess(Property.CLASS,
104                 getProperties());
105         PropertyValidator.getInstance().validateOneOrLess(Property.CREATED,
106                 getProperties());
107         PropertyValidator.getInstance().validateOneOrLess(Property.DESCRIPTION,
108                 getProperties());
109         PropertyValidator.getInstance().validateOneOrLess(Property.DTSTART,
110                 getProperties());
111         PropertyValidator.getInstance().validateOneOrLess(Property.GEO,
112                 getProperties());
113         PropertyValidator.getInstance().validateOneOrLess(
114                 Property.LAST_MODIFIED, getProperties());
115         PropertyValidator.getInstance().validateOneOrLess(Property.LOCATION,
116                 getProperties());
117         PropertyValidator.getInstance().validateOneOrLess(Property.ORGANIZER,
118                 getProperties());
119         PropertyValidator.getInstance().validateOneOrLess(Property.PRIORITY,
120                 getProperties());
121         PropertyValidator.getInstance().validateOneOrLess(Property.DTSTAMP,
122                 getProperties());
123         PropertyValidator.getInstance().validateOneOrLess(Property.SEQUENCE,
124                 getProperties());
125         PropertyValidator.getInstance().validateOneOrLess(Property.STATUS,
126                 getProperties());
127         PropertyValidator.getInstance().validateOneOrLess(Property.SUMMARY,
128                 getProperties());
129         PropertyValidator.getInstance().validateOneOrLess(Property.TRANSP,
130                 getProperties());
131         PropertyValidator.getInstance().validateOneOrLess(Property.UID,
132                 getProperties());
133         PropertyValidator.getInstance().validateOneOrLess(Property.URL,
134                 getProperties());
135         PropertyValidator.getInstance().validateOneOrLess(
136                 Property.RECURRENCE_ID, getProperties());
137 
138         /*
139          * ; either 'dtend' or 'duration' may appear in ; a 'eventprop', but
140          * 'dtend' and 'duration' ; MUST NOT occur in the same 'eventprop'
141          *
142          * dtend / duration /
143          */
144         if (getProperties().getProperty(Property.DTEND) != null
145                 && getProperties().getProperty(Property.DURATION) != null) { throw new ValidationException(
146                 "Properties [" + Property.DTEND + "," + Property.DURATION
147                         + "] may not occur in the same VEVENT"); }
148 
149         /*
150          * ; the following are optional, ; and MAY occur more than once
151          *
152          * attach / attendee / categories / comment / contact / exdate / exrule /
153          * rstatus / related / resources / rdate / rrule / x-prop
154          */
155         
156         if (recurse) {
157             validateProperties();
158         }
159     }
160 }