View Javadoc

1   /*
2    * $Id: Property.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;
35  
36  /***
37   * Defines an iCalendar property. Subclasses of this class provide additional
38   * validation and typed values for specific iCalendar properties.
39   *
40   * @author benf
41   */
42  public abstract class Property {
43  
44      // iCalendar properties..
45  
46      /***
47       * 'prodid' and 'version' are both REQUIRED, but MUST NOT occur more than
48       * once
49       */
50      public static final String PRODID = "PRODID";
51  
52      public static final String VERSION = "VERSION";
53  
54      /***
55       * 'calscale' and 'method' are optional, but MUST NOT occur more than once
56       */
57      public static final String CALSCALE = "CALSCALE";
58  
59      public static final String METHOD = "METHOD";
60  
61      // Component properties..
62  
63      /***
64       * the following are optional, but MUST NOT occur more than once
65       */
66      public static final String CLASS = "CLASS";
67  
68      public static final String CREATED = "CREATED";
69  
70      public static final String DESCRIPTION = "DESCRIPTION";
71  
72      public static final String DTSTART = "DTSTART";
73  
74      public static final String GEO = "GEO";
75  
76      public static final String LAST_MODIFIED = "LAST-MODIFIED";
77  
78      public static final String LOCATION = "LOCATION";
79  
80      public static final String ORGANIZER = "ORGANIZER";
81  
82      public static final String PERCENT_COMPLETE = "PERCENT-COMPLETE";
83  
84      public static final String PRIORITY = "PRIORITY";
85  
86      public static final String DTSTAMP = "DTSTAMP";
87  
88      public static final String SEQUENCE = "SEQUENCE";
89  
90      public static final String STATUS = "STATUS";
91  
92      public static final String SUMMARY = "SUMMARY";
93  
94      public static final String TRANSP = "TRANSP";
95  
96      public static final String UID = "UID";
97  
98      public static final String URL = "URL";
99  
100     public static final String RECURRENCE_ID = "RECURRENCE-ID";
101 
102     public static final String COMPLETED = "COMPLETED";
103 
104     public static final String DUE = "DUE";
105 
106     public static final String FREEBUSY = "FREEBUSY";
107 
108     public static final String TZID = "TZID";
109 
110     public static final String TZNAME = "TZNAME";
111 
112     public static final String TZOFFSETFROM = "TZOFFSETFROM";
113 
114     public static final String TZOFFSETTO = "TZOFFSETTO";
115 
116     public static final String TZURL = "TZURL";
117 
118     public static final String ACTION = "ACTION";
119 
120     public static final String REPEAT = "REPEAT";
121 
122     public static final String TRIGGER = "TRIGGER";
123 
124     public static final String REQUEST_STATUS = "REQUEST-STATUS";
125 
126     /***
127      * either 'dtend' or 'duration' may appear in a 'eventprop', but 'dtend' and
128      * 'duration' MUST NOT occur in the same 'eventprop'
129      */
130     public static final String DTEND = "DTEND";
131 
132     public static final String DURATION = "DURATION";
133 
134     /***
135      * the following are optional, and MAY occur more than once
136      */
137     public static final String ATTACH = "ATTACH";
138 
139     public static final String ATTENDEE = "ATTENDEE";
140 
141     public static final String CATEGORIES = "CATEGORIES";
142 
143     public static final String COMMENT = "COMMENT";
144 
145     public static final String CONTACT = "CONTACT";
146 
147     public static final String EXDATE = "EXDATE";
148 
149     public static final String EXRULE = "EXRULE";
150 
151     public static final String RSTATUS = "RSTATUS";
152 
153     public static final String RELATED_TO = "RELATED-TO";
154 
155     public static final String RESOURCES = "RESOURCES";
156 
157     public static final String RDATE = "RDATE";
158 
159     public static final String RRULE = "RRULE";
160 
161     private String name;
162 
163     private ParameterList parameters;
164 
165     /***
166      * Constructor.
167      * @param aName
168      *            property name
169      * @param aValue
170      *            property value
171      */
172     public Property(final String aName) {
173 
174         this(aName, null);
175     }
176 
177     /***
178      * Constructor made protected to enforce the use of
179      * <code>PropertyFactory</code> for property instantiation.
180      * @param aName
181      *            property name
182      * @param aList
183      *            a list of parameters
184      * @param aValue
185      *            property value
186      */
187     protected Property(final String aName, final ParameterList aList) {
188         this.name = aName;
189         this.parameters = aList;
190     }
191 
192     /***
193      * @see java.lang.Object#toString()
194      */
195     public final String toString() {
196 
197         if (getParameters() != null) {
198             return getName() + getParameters() + ":" + getValue() + "\r\n";
199         }
200 
201         return getName() + ":" + getValue() + "\r\n";
202     }
203 
204     /***
205      * Indicates whether this property is a
206      * calendar property
207      * @return boolean
208      */
209     public final boolean isCalendarProperty() {
210 
211         return PRODID.equals(getName()) || VERSION.equals(getName())
212                 || CALSCALE.equals(getName()) || METHOD.equals(getName());
213     }
214 
215     /***
216      * Indicates whether this property is a
217      * component property
218      * @return boolean
219      */
220     public final boolean isComponentProperty() {
221 
222         return false;
223     }
224 
225     /***
226      * @return Returns the name.
227      */
228     public final String getName() {
229         return name;
230     }
231 
232     /***
233      * @return Returns the parameters.
234      */
235     public final ParameterList getParameters() {
236         return parameters;
237     }
238 
239     /***
240      * @return Returns the value.
241      */
242     public abstract String getValue();
243 
244     /***
245      * Perform validation on a property.
246      *
247      * @throws ValidationException
248      *             where the property is not in a valid state
249      */
250     public void validate() throws ValidationException {
251         // empty implementation..
252     }
253 }