Class DateIntervalValidator
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.contenttype.validation.AbstractContentValidator
-
- org.ametys.cms.contenttype.validation.AbstractIntervalValidator<LocalDate>
-
- org.ametys.cms.contenttype.validation.DateIntervalValidator
-
- All Implemented Interfaces:
ContentValidator
,Configurable
,LogEnabled
public class DateIntervalValidator extends AbstractIntervalValidator<LocalDate>
This implementation ofContentValidator
validates the content by comparing one or more couple of date values. For each couple of values, the identified end date should be greater than or equal to the identified start date. The start and end dates to compare are identified in validator's configuration by the metadata path as follows: <startDate path="path/to/attribute/start"/> <endDate path="path/to/attribute/end"/> The path of attribute can contain one or more repeaters.
-
-
Constructor Summary
Constructors Constructor Description DateIntervalValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addErrorEmpty(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, I18nizableText emptyLabel)
Add an error when the max or the min value is empty but the interval is mandatoryprotected void
addIntervalError(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, LocalDate startDate, LocalDate endDate)
Add an error when the max value is less than the min valueprotected String
configureMaxPath(Configuration configuration)
Get the metadata max path from the configurationprotected String
configureMinPath(Configuration configuration)
Get the metadata min path from the configurationprotected boolean
isLessThan(LocalDate date1, LocalDate date2)
Test if the first number is less than the second one.protected boolean
isSupportedType(ElementType type)
Test if the attribute type is one expected by the validator-
Methods inherited from class org.ametys.cms.contenttype.validation.AbstractIntervalValidator
_validateInterval, configure, validate, validate
-
Methods inherited from class org.ametys.cms.contenttype.validation.AbstractContentValidator
getContentType, setContentType
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Constructor Detail
-
DateIntervalValidator
public DateIntervalValidator()
-
-
Method Detail
-
configureMinPath
protected String configureMinPath(Configuration configuration) throws ConfigurationException
Description copied from class:AbstractIntervalValidator
Get the metadata min path from the configuration- Specified by:
configureMinPath
in classAbstractIntervalValidator<LocalDate>
- Parameters:
configuration
- The configuration- Returns:
- The metadata min path
- Throws:
ConfigurationException
- If an error occurs
-
configureMaxPath
protected String configureMaxPath(Configuration configuration) throws ConfigurationException
Description copied from class:AbstractIntervalValidator
Get the metadata max path from the configuration- Specified by:
configureMaxPath
in classAbstractIntervalValidator<LocalDate>
- Parameters:
configuration
- The configuration- Returns:
- The metadata max path
- Throws:
ConfigurationException
- If an error occurs
-
isLessThan
protected boolean isLessThan(LocalDate date1, LocalDate date2)
Description copied from class:AbstractIntervalValidator
Test if the first number is less than the second one.- Specified by:
isLessThan
in classAbstractIntervalValidator<LocalDate>
- Parameters:
date1
- The first number to compare.date2
- The second number to compare.- Returns:
- true if the first number is less than the first, false otherwise.
-
isSupportedType
protected boolean isSupportedType(ElementType type)
Description copied from class:AbstractIntervalValidator
Test if the attribute type is one expected by the validator- Specified by:
isSupportedType
in classAbstractIntervalValidator<LocalDate>
- Parameters:
type
- The attribute type- Returns:
- True if the type is supported
-
addIntervalError
protected void addIntervalError(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, LocalDate startDate, LocalDate endDate)
Description copied from class:AbstractIntervalValidator
Add an error when the max value is less than the min value- Specified by:
addIntervalError
in classAbstractIntervalValidator<LocalDate>
- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionstartDate
- The min valueendDate
- The max value
-
addErrorEmpty
protected void addErrorEmpty(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, I18nizableText emptyLabel)
Description copied from class:AbstractIntervalValidator
Add an error when the max or the min value is empty but the interval is mandatory- Specified by:
addErrorEmpty
in classAbstractIntervalValidator<LocalDate>
- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field
-
-