/
Property.java
531 lines (448 loc) · 14.7 KB
/
Property.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/**
* Copyright (c) 2012, Ben Fortuna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of Ben Fortuna nor the names of any other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.fortuna.ical4j.model;
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.XProperty;
import net.fortuna.ical4j.util.Strings;
import net.fortuna.ical4j.validate.ValidationException;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
/**
* Defines an iCalendar property. Subclasses of this class provide additional validation and typed values for specific
* iCalendar properties.
* <p/>
* Note that subclasses must provide a reference to the factory used to create the
* property to support property cloning (copy). If no factory is specified an
* {@link UnsupportedOperationException} will be thrown by the {@link #copy()} method.
*
* @author Ben Fortuna
* <p/>
* $Id$ [Apr 5, 2004]
*/
public abstract class Property extends Content {
private static final long serialVersionUID = 7048785558435608687L;
// iCalendar properties..
/**
* Product identifier property name.
*/
public static final String PRODID = "PRODID";
/**
* iCalendar version property name.
*/
public static final String VERSION = "VERSION";
/**
* Calendar scale property name.
*/
public static final String CALSCALE = "CALSCALE";
/**
* iTIP method property name.
*/
public static final String METHOD = "METHOD";
// Component properties..
/**
* Busy type property name.
*/
public static final String BUSYTYPE = "BUSYTYPE";
/**
* Classifier property name.
*/
public static final String CLASS = "CLASS";
/**
* Creation date property name.
*/
public static final String CREATED = "CREATED";
/**
* Description property name.
*/
public static final String DESCRIPTION = "DESCRIPTION";
/**
* Start date property name.
*/
public static final String DTSTART = "DTSTART";
/**
* Geographic location property name.
*/
public static final String GEO = "GEO";
/**
* Last modified date property name.
*/
public static final String LAST_MODIFIED = "LAST-MODIFIED";
/**
* Location property name.
*/
public static final String LOCATION = "LOCATION";
/**
* Organiser property name.
*/
public static final String ORGANIZER = "ORGANIZER";
/**
* Percentage complete property name.
*/
public static final String PERCENT_COMPLETE = "PERCENT-COMPLETE";
/**
* Prority property name.
*/
public static final String PRIORITY = "PRIORITY";
/**
* Date-stamp property name.
*/
public static final String DTSTAMP = "DTSTAMP";
/**
* Sequence property name.
*/
public static final String SEQUENCE = "SEQUENCE";
/**
* Status property name.
*/
public static final String STATUS = "STATUS";
/**
* Summary property name.
*/
public static final String SUMMARY = "SUMMARY";
/**
* Transparency property name.
*/
public static final String TRANSP = "TRANSP";
/**
* Unique identifier property name.
*/
public static final String UID = "UID";
/**
* Uniform resource locator property name.
*/
public static final String URL = "URL";
/**
* Recurrence identifier property name.
*/
public static final String RECURRENCE_ID = "RECURRENCE-ID";
/**
* Completed date property name.
*/
public static final String COMPLETED = "COMPLETED";
/**
* Due date property name.
*/
public static final String DUE = "DUE";
/**
* Free/busy property name.
*/
public static final String FREEBUSY = "FREEBUSY";
/**
* Timezone identifier property name.
*/
public static final String TZID = "TZID";
/**
* Timezone name property name.
*/
public static final String TZNAME = "TZNAME";
/**
* Prior timezone offset property name.
*/
public static final String TZOFFSETFROM = "TZOFFSETFROM";
/**
* New timezone offset property name.
*/
public static final String TZOFFSETTO = "TZOFFSETTO";
/**
* URL for timezone definition property name.
*/
public static final String TZURL = "TZURL";
/**
* Alarm action property name.
*/
public static final String ACTION = "ACTION";
/**
* Repeat rule property name.
*/
public static final String REPEAT = "REPEAT";
/**
* Alarm trigger property name.
*/
public static final String TRIGGER = "TRIGGER";
/**
* Request status property name.
*/
public static final String REQUEST_STATUS = "REQUEST-STATUS";
/**
* End date property name.
*/
public static final String DTEND = "DTEND";
/**
* Duration property name.
*/
public static final String DURATION = "DURATION";
/**
* Attachment property name.
*/
public static final String ATTACH = "ATTACH";
/**
* Attendee property name.
*/
public static final String ATTENDEE = "ATTENDEE";
/**
* Categories property name.
*/
public static final String CATEGORIES = "CATEGORIES";
/**
* Comment property name.
*/
public static final String COMMENT = "COMMENT";
/**
* Contact property name.
*/
public static final String CONTACT = "CONTACT";
/**
* Exclusion date property name.
*/
public static final String EXDATE = "EXDATE";
/**
* Exclusion rule property name.
*/
public static final String EXRULE = "EXRULE";
/**
* Relationship property name.
*/
public static final String RELATED_TO = "RELATED-TO";
/**
* Resources property name.
*/
public static final String RESOURCES = "RESOURCES";
/**
* Recurrence date property name.
*/
public static final String RDATE = "RDATE";
/**
* Recurrence rule property name.
*/
public static final String RRULE = "RRULE";
/**
* Prefix for non-standard properties.
*/
public static final String EXPERIMENTAL_PREFIX = "X-";
/**
* VVENUE country property name.
*/
public static final String COUNTRY = "COUNTRY";
/**
* VVENUE extended address property name.
*/
public static final String EXTENDED_ADDRESS = "EXTENDED-ADDRESS";
/**
* VVENUE locality property name.
*/
public static final String LOCALITY = "LOCALITY";
/**
* VVENUE location type property name.
*/
public static final String LOCATION_TYPE = "LOCATION-TYPE";
/**
* VVENUE name property name.
*/
public static final String NAME = "NAME";
/**
* VVENUE postal code property name.
*/
public static final String POSTALCODE = "POSTAL-CODE";
/**
* VVENUE region property name.
*/
public static final String REGION = "REGION";
/**
* VVENUE street address property name.
*/
public static final String STREET_ADDRESS = "STREET-ADDRESS";
/**
* VVENUE telephone property name.
*/
public static final String TEL = "TEL";
/**
* Acknowledged Property taken from http://tools.ietf.org/html/draft-daboo-valarm-extensions-04
*/
public static final String ACKNOWLEDGED = "ACKNOWLEDGED";
private final String name;
private final ParameterList parameters;
private final PropertyFactory<?> factory;
/**
* Constructor.
*
* @param aName property name
* @param factory the factory used to create the property instance
*/
protected Property(final String aName, PropertyFactory<?> factory) {
this(aName, new ParameterList(), factory);
}
/**
* Constructor made protected to enforce the use of <code>PropertyFactory</code> for property instantiation.
* @param aName property name
* @param aList a list of parameters
*/
// protected Property(final String aName, final ParameterList aList) {
// this(aName, aList, new Factory());
// }
/**
* @param aName a property identifier
* @param aList a list of initial parameters
* @param factory the factory used to create the property instance
*/
protected Property(final String aName, final ParameterList aList, PropertyFactory<?> factory) {
this.name = aName;
this.parameters = aList;
this.factory = factory;
}
/**
* Creates a deep copy of the specified property. That is, the name, parameter list, and value are duplicated from
* the specified property. This constructor should only be called from sub-classes to ensure type integrity is
* maintained.
*
* @param property a property to copy
* @throws URISyntaxException where the specified property contains an invalid URI value
* @throws ParseException where the specified property has invalid data
* @throws IOException where an error occurs reading data from the specified property
* @deprecated Use {@link #copy()} instead
*/
protected Property(final Property property) throws IOException,
URISyntaxException, ParseException {
this(property.getName(), new ParameterList(property.getParameters(), false),
property.factory);
setValue(property.getValue());
}
/**
* {@inheritDoc}
*/
public final String toString() {
final StringBuilder buffer = new StringBuilder();
buffer.append(getName());
if (getParameters() != null) {
buffer.append(getParameters());
}
buffer.append(':');
boolean needsEscape = false;
if (this instanceof XProperty) {
Value valParam = getParameter(Parameter.VALUE);
if (valParam == null || valParam.equals(Value.TEXT)) {
needsEscape = true;
}
} else if (this instanceof Escapable) {
needsEscape = true;
}
if (needsEscape) {
buffer.append(Strings.escape(Strings.valueOf(getValue())));
} else {
buffer.append(Strings.valueOf(getValue()));
}
buffer.append(Strings.LINE_SEPARATOR);
return buffer.toString();
}
/**
* @return Returns the name.
*/
public final String getName() {
return name;
}
/**
* @return Returns the parameters.
*/
public final ParameterList getParameters() {
return parameters;
}
/**
* Convenience method for retrieving a list of named parameters.
*
* @param name name of parameters to retrieve
* @return a parameter list containing only parameters with the specified name
*/
public final ParameterList getParameters(final String name) {
return getParameters().getParameters(name);
}
/**
* Convenience method for retrieving a single parameter.
*
* @param name name of the parameter to retrieve
* @return the first parameter from the parameter list with the specified name
*/
public final <T extends Parameter> T getParameter(final String name) {
return getParameters().getParameter(name);
}
/**
* Sets the current value of the property.
*
* @param aValue a string representation of the property value
* @throws IOException possibly thrown by setting the value of certain properties
* @throws URISyntaxException possibly thrown by setting the value of certain properties
* @throws ParseException possibly thrown by setting the value of certain properties
*/
public abstract void setValue(String aValue) throws IOException,
URISyntaxException, ParseException;
/**
* Perform validation on a property.
*
* @throws ValidationException where the property is not in a valid state
*/
public abstract void validate() throws ValidationException;
/**
* {@inheritDoc}
*/
public final boolean equals(final Object arg0) {
if (arg0 instanceof Property) {
final Property p = (Property) arg0;
return getName().equals(p.getName())
&& new EqualsBuilder().append(getValue(), p.getValue()).append(getParameters(), p.getParameters()).isEquals();
}
return super.equals(arg0);
}
/**
* {@inheritDoc}
*/
public int hashCode() {
// as property name is case-insensitive generate hash for uppercase..
return new HashCodeBuilder().append(getName().toUpperCase()).append(
getValue()).append(getParameters()).toHashCode();
}
/**
* Create a (deep) copy of this property.
*
* @return the copy of the property
* @throws URISyntaxException where the property contains an invalid URI value
* @throws ParseException where the property contains an invalid date value
*/
public Property copy() throws URISyntaxException, ParseException {
if (factory == null) {
throw new UnsupportedOperationException("No factory specified");
}
// Deep copy parameter list..
final ParameterList params = new ParameterList(getParameters(), false);
return factory.createProperty(params, getValue());
}
}