Permalink
Browse files

Extracted validation classes to separate package

  • Loading branch information...
benfortuna committed Sep 12, 2015
1 parent 764878f commit d0b9d25b6bc27592c4656d0147b3f7727b1698e3
Showing with 2,550 additions and 2,190 deletions.
  1. +3 −3 src/main/java/net/fortuna/ical4j/data/CalendarOutputter.java
  2. +4 −3 src/main/java/net/fortuna/ical4j/model/Calendar.java
  3. +1 −0 src/main/java/net/fortuna/ical4j/model/Component.java
  4. +1 −13 src/main/java/net/fortuna/ical4j/model/Property.java
  5. +2 −1 src/main/java/net/fortuna/ical4j/model/component/Available.java
  6. +4 −12 src/main/java/net/fortuna/ical4j/model/component/CalendarComponent.java
  7. +2 −1 src/main/java/net/fortuna/ical4j/model/component/Observance.java
  8. +10 −122 src/main/java/net/fortuna/ical4j/model/component/VAlarm.java
  9. +3 −1 src/main/java/net/fortuna/ical4j/model/component/VAvailability.java
  10. +15 −771 src/main/java/net/fortuna/ical4j/model/component/VEvent.java
  11. +10 −171 src/main/java/net/fortuna/ical4j/model/component/VFreeBusy.java
  12. +9 −218 src/main/java/net/fortuna/ical4j/model/component/VJournal.java
  13. +5 −55 src/main/java/net/fortuna/ical4j/model/component/VTimeZone.java
  14. +12 −746 src/main/java/net/fortuna/ical4j/model/component/VToDo.java
  15. +3 −1 src/main/java/net/fortuna/ical4j/model/component/VVenue.java
  16. +2 −2 src/main/java/net/fortuna/ical4j/model/component/XComponent.java
  17. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Action.java
  18. +6 −1 src/main/java/net/fortuna/ical4j/model/property/Attach.java
  19. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Attendee.java
  20. +1 −0 src/main/java/net/fortuna/ical4j/model/property/BusyType.java
  21. +2 −1 src/main/java/net/fortuna/ical4j/model/property/CalScale.java
  22. +8 −0 src/main/java/net/fortuna/ical4j/model/property/CalendarProperty.java
  23. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Categories.java
  24. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Clazz.java
  25. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Comment.java
  26. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Contact.java
  27. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Country.java
  28. +2 −1 src/main/java/net/fortuna/ical4j/model/property/DateProperty.java
  29. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Description.java
  30. +1 −0 src/main/java/net/fortuna/ical4j/model/property/DtEnd.java
  31. +1 −0 src/main/java/net/fortuna/ical4j/model/property/DtStart.java
  32. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Due.java
  33. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Duration.java
  34. +2 −1 src/main/java/net/fortuna/ical4j/model/property/ExDate.java
  35. +1 −0 src/main/java/net/fortuna/ical4j/model/property/ExRule.java
  36. +1 −0 src/main/java/net/fortuna/ical4j/model/property/ExtendedAddress.java
  37. +2 −1 src/main/java/net/fortuna/ical4j/model/property/FreeBusy.java
  38. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Geo.java
  39. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Locality.java
  40. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Location.java
  41. +2 −1 src/main/java/net/fortuna/ical4j/model/property/LocationType.java
  42. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Method.java
  43. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Name.java
  44. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Organizer.java
  45. +1 −0 src/main/java/net/fortuna/ical4j/model/property/PercentComplete.java
  46. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Postalcode.java
  47. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Priority.java
  48. +2 −1 src/main/java/net/fortuna/ical4j/model/property/ProdId.java
  49. +2 −1 src/main/java/net/fortuna/ical4j/model/property/RDate.java
  50. +1 −0 src/main/java/net/fortuna/ical4j/model/property/RRule.java
  51. +2 −1 src/main/java/net/fortuna/ical4j/model/property/RecurrenceId.java
  52. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Region.java
  53. +2 −1 src/main/java/net/fortuna/ical4j/model/property/RelatedTo.java
  54. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Repeat.java
  55. +2 −1 src/main/java/net/fortuna/ical4j/model/property/RequestStatus.java
  56. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Resources.java
  57. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Sequence.java
  58. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Status.java
  59. +1 −0 src/main/java/net/fortuna/ical4j/model/property/StreetAddress.java
  60. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Summary.java
  61. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Tel.java
  62. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Transp.java
  63. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Trigger.java
  64. +1 −0 src/main/java/net/fortuna/ical4j/model/property/TzId.java
  65. +2 −1 src/main/java/net/fortuna/ical4j/model/property/TzName.java
  66. +1 −0 src/main/java/net/fortuna/ical4j/model/property/TzOffsetFrom.java
  67. +1 −0 src/main/java/net/fortuna/ical4j/model/property/TzOffsetTo.java
  68. +1 −0 src/main/java/net/fortuna/ical4j/model/property/TzUrl.java
  69. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Uid.java
  70. +1 −0 src/main/java/net/fortuna/ical4j/model/property/Url.java
  71. +5 −1 src/main/java/net/fortuna/ical4j/model/property/UtcProperty.java
  72. +2 −1 src/main/java/net/fortuna/ical4j/model/property/Version.java
  73. +1 −1 src/main/java/net/fortuna/ical4j/model/property/XProperty.java
  74. +1 −2 src/main/java/net/fortuna/ical4j/{util → validate}/ComponentValidator.java
  75. +14 −0 src/main/java/net/fortuna/ical4j/validate/EmptyValidator.java
  76. +1 −2 src/main/java/net/fortuna/ical4j/{util → validate}/ParameterValidator.java
  77. +1 −2 src/main/java/net/fortuna/ical4j/{util → validate}/PropertyValidator.java
  78. +2 −2 src/main/java/net/fortuna/ical4j/{model → validate}/ValidationException.java
  79. +3 −3 src/main/java/net/fortuna/ical4j/{model → validate}/Validator.java
  80. +25 −0 src/main/java/net/fortuna/ical4j/validate/component/VAlarmAudioValidator.java
  81. +25 −0 src/main/java/net/fortuna/ical4j/validate/component/VAlarmDisplayValidator.java
  82. +44 −0 src/main/java/net/fortuna/ical4j/validate/component/VAlarmEmailValidator.java
  83. +53 −0 src/main/java/net/fortuna/ical4j/validate/component/VAlarmITIPValidator.java
  84. +34 −0 src/main/java/net/fortuna/ical4j/validate/component/VAlarmProcedureValidator.java
  85. +102 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventAddValidator.java
  86. +102 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventCancelValidator.java
  87. +109 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventCounterValidator.java
  88. +105 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventDeclineCounterValidator.java
  89. +110 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventPublishValidator.java
  90. +107 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventRefreshValidator.java
  91. +101 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventReplyValidator.java
  92. +103 −0 src/main/java/net/fortuna/ical4j/validate/component/VEventRequestValidator.java
  93. +63 −0 src/main/java/net/fortuna/ical4j/validate/component/VFreeBusyPublishValidator.java
  94. +64 −0 src/main/java/net/fortuna/ical4j/validate/component/VFreeBusyReplyValidator.java
  95. +60 −0 src/main/java/net/fortuna/ical4j/validate/component/VFreeBusyRequestValidator.java
  96. +76 −0 src/main/java/net/fortuna/ical4j/validate/component/VJournalAddValidator.java
  97. +79 −0 src/main/java/net/fortuna/ical4j/validate/component/VJournalCancelValidator.java
  98. +80 −0 src/main/java/net/fortuna/ical4j/validate/component/VJournalPublishValidator.java
  99. +61 −0 src/main/java/net/fortuna/ical4j/validate/component/VTimeZoneITIPValidator.java
  100. +100 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoAddValidator.java
  101. +100 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoCancelValidator.java
  102. +102 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoCounterValidator.java
  103. +94 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoDeclineCounterValidator.java
  104. +109 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoPublishValidator.java
  105. +101 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoRefreshValidator.java
  106. +97 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoReplyValidator.java
  107. +106 −0 src/main/java/net/fortuna/ical4j/validate/component/VToDoRequestValidator.java
  108. +1 −1 src/test/java/net/fortuna/ical4j/data/CalendarBuilderTest.java
  109. +6 −7 src/test/java/net/fortuna/ical4j/data/CalendarEqualsTest.java
  110. +1 −1 src/test/java/net/fortuna/ical4j/data/CalendarOutputterTest.java
  111. +2 −2 src/test/java/net/fortuna/ical4j/filter/ComponentRuleTest.java
  112. +3 −3 src/test/java/net/fortuna/ical4j/filter/HasPropertyRuleTest.java
  113. +1 −0 src/test/java/net/fortuna/ical4j/model/AbstractPropertyTest.java
  114. +1 −0 src/test/java/net/fortuna/ical4j/model/CalendarTest.java
  115. +1 −0 src/test/java/net/fortuna/ical4j/model/ComponentTest.java
  116. +5 −4 src/test/java/net/fortuna/ical4j/model/PropertyTest.java
  117. +1 −1 src/test/java/net/fortuna/ical4j/model/component/CalendarComponentTest.java
  118. +1 −0 src/test/java/net/fortuna/ical4j/model/component/VEventTest.java
  119. +1 −0 src/test/java/net/fortuna/ical4j/model/property/AttachTest.java
  120. +6 −10 src/test/java/net/fortuna/ical4j/model/property/CategoriesTest.java
  121. +1 −1 src/test/java/net/fortuna/ical4j/model/property/TriggerTest.java
@@ -31,14 +31,14 @@
*/
package net.fortuna.ical4j.data;
+import net.fortuna.ical4j.model.Calendar;
+import net.fortuna.ical4j.validate.ValidationException;
+
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
-import net.fortuna.ical4j.model.Calendar;
-import net.fortuna.ical4j.model.ValidationException;
-
/**
* <pre>
* $Id$ [Apr 5, 2004]
@@ -34,9 +34,10 @@
import net.fortuna.ical4j.model.component.CalendarComponent;
import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.CompatibilityHints;
-import net.fortuna.ical4j.util.ComponentValidator;
-import net.fortuna.ical4j.util.PropertyValidator;
import net.fortuna.ical4j.util.Strings;
+import net.fortuna.ical4j.validate.ComponentValidator;
+import net.fortuna.ical4j.validate.PropertyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -285,7 +286,7 @@ public void validate(final boolean recurse) throws ValidationException {
// validate properties..
for (final Property property : getProperties()) {
if (!(property instanceof XProperty)
- && !property.isCalendarProperty()) {
+ && !(property instanceof CalendarProperty)) {
throw new ValidationException("Invalid property: "
+ property.getName());
}
@@ -34,6 +34,7 @@
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.*;
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;
@@ -34,6 +34,7 @@
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;
@@ -434,19 +435,6 @@ public final String toString() {
return buffer.toString();
}
- /**
- * Indicates whether this property is a calendar property.
- *
- * @return boolean
- */
- public boolean isCalendarProperty() {
-
- return PRODID.equalsIgnoreCase(getName())
- || VERSION.equalsIgnoreCase(getName())
- || CALSCALE.equalsIgnoreCase(getName())
- || METHOD.equalsIgnoreCase(getName());
- }
-
/**
* @return Returns the name.
*/
@@ -35,7 +35,8 @@
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.DtEnd;
import net.fortuna.ical4j.model.property.DtStart;
-import net.fortuna.ical4j.util.PropertyValidator;
+import net.fortuna.ical4j.validate.PropertyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
/**
* $Id$ [05-Apr-2004]
@@ -33,9 +33,10 @@
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.PropertyList;
-import net.fortuna.ical4j.model.ValidationException;
-import net.fortuna.ical4j.model.Validator;
import net.fortuna.ical4j.model.property.Method;
+import net.fortuna.ical4j.validate.EmptyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
+import net.fortuna.ical4j.validate.Validator;
/**
* $Id$
@@ -80,7 +81,7 @@ public CalendarComponent(final String name, final PropertyList properties) {
public final void validate(Method method) throws ValidationException {
final Validator validator = getValidator(method);
if (validator != null) {
- validator.validate();
+ validator.validate(this);
}
else {
throw new ValidationException("Unsupported method: " + method);
@@ -164,14 +165,5 @@ public final void validateCounter() throws ValidationException {
public final void validateDeclineCounter() throws ValidationException {
validate(Method.DECLINE_COUNTER);
}
-
- private static class EmptyValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
- public void validate() throws ValidationException {
- // TODO Auto-generated method stub
-
- }
- }
}
@@ -35,8 +35,9 @@
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.Dates;
-import net.fortuna.ical4j.util.PropertyValidator;
import net.fortuna.ical4j.util.TimeZones;
+import net.fortuna.ical4j.validate.PropertyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +33,10 @@
import net.fortuna.ical4j.model.*;
import net.fortuna.ical4j.model.property.*;
-import net.fortuna.ical4j.util.PropertyValidator;
+import net.fortuna.ical4j.validate.PropertyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
+import net.fortuna.ical4j.validate.Validator;
+import net.fortuna.ical4j.validate.component.*;
import java.util.HashMap;
import java.util.Map;
@@ -193,13 +196,13 @@
private final Map<Action, Validator> actionValidators = new HashMap<Action, Validator>();
{
- actionValidators.put(Action.AUDIO, new AudioValidator());
- actionValidators.put(Action.DISPLAY, new DisplayValidator());
- actionValidators.put(Action.EMAIL, new EmailValidator());
- actionValidators.put(Action.PROCEDURE, new ProcedureValidator());
+ actionValidators.put(Action.AUDIO, new VAlarmAudioValidator());
+ actionValidators.put(Action.DISPLAY, new VAlarmDisplayValidator());
+ actionValidators.put(Action.EMAIL, new VAlarmEmailValidator());
+ actionValidators.put(Action.PROCEDURE, new VAlarmProcedureValidator());
}
- private final Validator itipValidator = new ITIPValidator();
+ private final Validator itipValidator = new VAlarmITIPValidator();
/**
* Default constructor.
@@ -268,7 +271,7 @@ public final void validate(final boolean recurse)
final Validator actionValidator = actionValidators.get(getAction());
if (actionValidator != null) {
- actionValidator.validate();
+ actionValidator.validate(this);
}
if (recurse) {
@@ -282,122 +285,7 @@ public final void validate(final boolean recurse)
protected Validator getValidator(Method method) {
return itipValidator;
}
-
- private class AudioValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * {@inheritDoc}
- */
- public void validate() throws ValidationException {
- /*
- * ; the following is optional, ; but MUST NOT occur more than once attach /
- */
- PropertyValidator.getInstance().assertOneOrLess(Property.ATTACH, getProperties());
- }
- }
-
- private class DisplayValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * {@inheritDoc}
- */
- public void validate() throws ValidationException {
- /*
- * ; the following are all REQUIRED, ; but MUST NOT occur more than once action / description / trigger /
- */
- PropertyValidator.getInstance().assertOne(Property.DESCRIPTION, getProperties());
- }
- }
-
- private class EmailValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * {@inheritDoc}
- */
- public void validate() throws ValidationException {
- /*
- * ; the following are all REQUIRED,
- * ; but MUST NOT occur more than once action / description / trigger / summary
- * ; the following is REQUIRED,
- * ; and MAY occur more than once attendee /
- * ; 'duration' and 'repeat' are both optional,
- * ; and MUST NOT occur more than once each,
- * ; but if one occurs, so MUST the other duration / repeat /
- * ; the following are optional,
- * ; and MAY occur more than once attach / x-prop
- */
- PropertyValidator.getInstance().assertOne(Property.DESCRIPTION, getProperties());
- PropertyValidator.getInstance().assertOne(Property.SUMMARY, getProperties());
-
- PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, getProperties());
- }
- }
-
- private class ProcedureValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * {@inheritDoc}
- */
- public void validate() throws ValidationException {
- /*
- * ; the following are all REQUIRED,
- * ; but MUST NOT occur more than once action / attach / trigger /
- * ; 'duration' and 'repeat' are both optional,
- * ; and MUST NOT occur more than once each,
- * ; but if one occurs, so MUST the other duration / repeat /
- * ; 'description' is optional,
- * ; and MUST NOT occur more than once description /
- * ; the following is optional, ; and MAY occur more than once x-prop
- */
- PropertyValidator.getInstance().assertOne(Property.ATTACH, getProperties());
-
- PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
- }
- }
- /**
- * Common validation for all iTIP methods.
- *
- * <pre>
- * Component/Property Presence
- * ------------------- ----------------------------------------------
- * VALARM 0+
- * ACTION 1
- * ATTACH 0+
- * DESCRIPTION 0 or 1
- * DURATION 0 or 1 if present REPEAT MUST be present
- * REPEAT 0 or 1 if present DURATION MUST be present
- * SUMMARY 0 or 1
- * TRIGGER 1
- * X-PROPERTY 0+
- * </pre>
- */
- private class ITIPValidator implements Validator {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * {@inheritDoc}
- */
- public void validate() throws ValidationException {
- PropertyValidator.getInstance().assertOne(Property.ACTION, getProperties());
- PropertyValidator.getInstance().assertOne(Property.TRIGGER, getProperties());
-
- PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
- PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
- PropertyValidator.getInstance().assertOneOrLess(Property.REPEAT, getProperties());
- PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties());
- }
- }
-
/**
* Returns the mandatory action property.
* @return the ACTION property or null if not specified
@@ -37,8 +37,10 @@
import net.fortuna.ical4j.model.property.DtStamp;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.Method;
-import net.fortuna.ical4j.util.PropertyValidator;
import net.fortuna.ical4j.util.Strings;
+import net.fortuna.ical4j.validate.PropertyValidator;
+import net.fortuna.ical4j.validate.ValidationException;
+import net.fortuna.ical4j.validate.Validator;
/**
* $Id$ [Apr 5, 2004]
Oops, something went wrong.

0 comments on commit d0b9d25

Please sign in to comment.