package biweekly; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import biweekly.ValidationWarnings.WarningsGroup; import biweekly.component.ICalComponent; import biweekly.property.ICalProperty; import biweekly.util.StringUtils; import biweekly.util.StringUtils.JoinCallback; /* Copyright (c) 2013-2023, Michael Angstadt All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 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. */ /** *
* Holds the validation warnings of an iCalendar object. *
** Examples: *
* *
* //validate an iCalendar object
* ValidationWarnings warnings = ical.validate();
*
* //print all warnings to a string:
* System.out.println(warnings.toString());
* //sample output:
* //[ICalendar]: ProductId is not set (it is a required property).
* //[ICalendar > VEvent > DateStart]: DateStart must come before DateEnd.
* //[ICalendar > VEvent > VAlarm]: The trigger must specify which date field its duration is relative to.
*
* //iterate over each warnings group
* //this gives you access to the property/component object and its parent components
* for (WarningsGroup group : warnings) {
* ICalProperty prop = group.getProperty();
* if (prop == null) {
* //then it was a component that caused the warnings
* ICalComponent comp = group.getComponent();
* }
*
* //get parent components
* List<ICalComponent> hierarchy = group.getComponentHierarchy();
*
* //get warning messages
* List<String> messages = group.getMessages();
* }
*
* //you can also get the warnings of specific properties/components
* List<WarningsGroup> dtstartWarnings = warnings.getByProperty(DateStart.class);
* List<WarningsGroup> veventWarnings = warnings.getByComponent(VEvent.class);
*
* @author Michael Angstadt
* @see ICalendar#validate(ICalVersion)
*/
public class ValidationWarnings implements Iterable* Outputs all validation warnings as a newline-delimited string. For * example: *
* ** [ICalendar]: ProductId is not set (it is a required property). * [ICalendar > VEvent > DateStart]: DateStart must come before DateEnd. * [ICalendar > VEvent > VAlarm]: The trigger must specify which date field its duration is relative to. **/ @Override public String toString() { return StringUtils.join(warnings, StringUtils.NEWLINE); } /** * Iterates over each warning group (same as calling * {@code getWarnings().iterator()}). * @return the iterator */ public Iterator
* Outputs each message in this warnings group as a newline-delimited * string. Each line includes the component hierarchy and the name of * the property/component. For example: *
* ** [ICalendar > VEvent > VAlarm]: Email alarms must have at least one attendee. * [ICalendar > VEvent > VAlarm]: The trigger must specify which date field its duration is relative to. **/ @Override public String toString() { final String prefix = "[" + buildPath() + "]: "; return StringUtils.join(warnings, StringUtils.NEWLINE, new JoinCallback