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 package net.fortuna.ical4j.model.component;
35
36 import net.fortuna.ical4j.model.Component;
37 import net.fortuna.ical4j.model.Property;
38 import net.fortuna.ical4j.model.PropertyList;
39 import net.fortuna.ical4j.model.ValidationException;
40 import net.fortuna.ical4j.model.property.Action;
41 import net.fortuna.ical4j.util.PropertyValidator;
42
43 /***
44 * Defines an iCalendar VALARM component.
45 *
46 * @author benf
47 */
48 public class VAlarm extends Component {
49
50 /***
51 * Constructor.
52 *
53 * @param aList
54 * a list of properties
55 */
56 public VAlarm(final PropertyList aList) {
57
58 super(VALARM, aList);
59 }
60
61
62
63
64
65
66 public final void validate(boolean recurse) throws ValidationException {
67
68
69
70
71
72
73
74 Property action = getProperties().getProperty(Property.ACTION);
75
76 if (action == null) { throw new ValidationException("Property ["
77 + Property.ACTION + "] must be specified once"); }
78
79 if (getProperties().getProperty(Property.TRIGGER) == null) { throw new ValidationException(
80 "Property [" + Property.TRIGGER + "] must be specified once"); }
81
82
83
84
85
86
87
88 PropertyValidator.getInstance().validateOneOrLess(Property.DURATION,
89 getProperties());
90 PropertyValidator.getInstance().validateOneOrLess(Property.REPEAT,
91 getProperties());
92
93 if ((getProperties().getProperty(Property.DURATION) == null && getProperties()
94 .getProperty(Property.REPEAT) != null)
95 || (getProperties().getProperty(Property.REPEAT) == null && getProperties()
96 .getProperty(Property.DURATION) != null)) { throw new ValidationException(
97 "Properties [" + Property.DURATION + "," + Property.REPEAT
98 + "] must both be specified or not at all"); }
99
100
101
102
103
104
105
106 if (Action.AUDIO.equals(action.getValue())) {
107 validateAudio();
108 }
109 else if (Action.DISPLAY.equals(action.getValue())) {
110 validateDisplay();
111 }
112 else if (Action.EMAIL.equals(action.getValue())) {
113 validateEmail();
114 }
115 else if (Action.PROCEDURE.equals(action.getValue())) {
116 validateProcedure();
117 }
118
119 if (recurse) {
120 validateProperties();
121 }
122 }
123
124 private void validateAudio() throws ValidationException {
125
126
127
128
129
130 PropertyValidator.getInstance().validateOneOrLess(Property.ATTACH,
131 getProperties());
132 }
133
134 private void validateDisplay() throws ValidationException {
135
136
137
138
139
140 PropertyValidator.getInstance().validateOne(Property.DESCRIPTION,
141 getProperties());
142 }
143
144 private void validateEmail() throws ValidationException {
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 PropertyValidator.getInstance().validateOne(Property.DESCRIPTION,
161 getProperties());
162 PropertyValidator.getInstance().validateOne(Property.SUMMARY,
163 getProperties());
164
165 PropertyValidator.getInstance().validateOneOrMore(Property.ATTENDEE,
166 getProperties());
167 }
168
169 private void validateProcedure() throws ValidationException {
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 PropertyValidator.getInstance().validateOne(Property.ATTACH,
186 getProperties());
187
188 PropertyValidator.getInstance().validateOneOrLess(Property.DESCRIPTION,
189 getProperties());
190 }
191 }