diff --git a/src/main/java/net/fortuna/ical4j/validate/PropertyRuleSet.java b/src/main/java/net/fortuna/ical4j/validate/PropertyRuleSet.java index 0160cfd5c..bea85d190 100644 --- a/src/main/java/net/fortuna/ical4j/validate/PropertyRuleSet.java +++ b/src/main/java/net/fortuna/ical4j/validate/PropertyRuleSet.java @@ -39,16 +39,20 @@ import java.util.Collections; import java.util.List; -public class PropertyRuleSet extends AbstractValidationRuleSet { +public class PropertyRuleSet extends AbstractValidationRuleSet { - public PropertyRuleSet(String context, ValidationRule... rules) { - super(context, rules); + public PropertyRuleSet(ValidationRule... rules) { + super(rules); } @Override - public List apply(Property target) { + public List apply(String context, Property target) { List results = new ArrayList<>(); for (ValidationRule rule: rules) { + // predicate rule hack.. + if (rule.getType() == null) { + continue; + } List matches = Collections.emptyList(); int total = rule.getInstances().stream().mapToInt(s -> target.getParameters(s).size()).sum(); switch (rule.getType()) { @@ -72,12 +76,15 @@ public List apply(Property target) { break; case AllOrNone: if (total > 0 && total != rule.getInstances().size()) { - results.add(new ValidationEntry(rule, context)); + results.add(new ValidationEntry(rule, target.getName())); } break; + case ValueMatch: + matches = matches(rule.getInstances(), s -> !target.getValue().matches(s)); + break; } if (!matches.isEmpty()) { - results.add(new ValidationEntry(rule, context, matches.toArray(new String[0]))); + results.add(new ValidationEntry(rule, target.getName(), matches.toArray(new String[0]))); } } return results; diff --git a/src/main/java/net/fortuna/ical4j/validate/ValidationRule.java b/src/main/java/net/fortuna/ical4j/validate/ValidationRule.java index e9ac05806..a06e73d4c 100644 --- a/src/main/java/net/fortuna/ical4j/validate/ValidationRule.java +++ b/src/main/java/net/fortuna/ical4j/validate/ValidationRule.java @@ -21,7 +21,8 @@ public enum ValidationType { OneOrLess("The following are OPTIONAL, but MUST NOT occur more than once."), OneOrMore("The following are OPTIONAL, and MAY occur more than once."), OneExclusive("If one is present, ALL others MUST NOT be present."), - AllOrNone("If one is present, ALL must be present."); + AllOrNone("If one is present, ALL must be present."), + ValueMatch("Value MUST match expression."); private final String description;