Class DateTimeIntervalValidator
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.cms.contenttype.validation.AbstractContentValidator
org.ametys.cms.contenttype.validation.AbstractIntervalValidator<ZonedDateTime>
org.ametys.cms.contenttype.validation.DateTimeIntervalValidator
- All Implemented Interfaces:
ContentValidator
,Configurable
,LogEnabled
This implementation of
ContentValidator
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 attribute path as follows:
<startDate path="path/to/attribute/start"/>
<endDate path="path/to/attribute/end"/>
If the path of metadata can contain one or more repeaters.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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, ZonedDateTime startDate, ZonedDateTime 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
(ZonedDateTime date1, ZonedDateTime 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 validatorMethods 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 Details
-
DateTimeIntervalValidator
public DateTimeIntervalValidator()
-
-
Method Details
-
configureMinPath
Description copied from class:AbstractIntervalValidator
Get the metadata min path from the configuration- Specified by:
configureMinPath
in classAbstractIntervalValidator<ZonedDateTime>
- Parameters:
configuration
- The configuration- Returns:
- The metadata min path
- Throws:
ConfigurationException
- If an error occurs
-
configureMaxPath
Description copied from class:AbstractIntervalValidator
Get the metadata max path from the configuration- Specified by:
configureMaxPath
in classAbstractIntervalValidator<ZonedDateTime>
- Parameters:
configuration
- The configuration- Returns:
- The metadata max path
- Throws:
ConfigurationException
- If an error occurs
-
isLessThan
Description copied from class:AbstractIntervalValidator
Test if the first number is less than the second one.- Specified by:
isLessThan
in classAbstractIntervalValidator<ZonedDateTime>
- 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
Description copied from class:AbstractIntervalValidator
Test if the attribute type is one expected by the validator- Specified by:
isSupportedType
in classAbstractIntervalValidator<ZonedDateTime>
- Parameters:
type
- The attribute type- Returns:
- True if the type is supported
-
addIntervalError
protected void addIntervalError(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, ZonedDateTime startDate, ZonedDateTime endDate) Description copied from class:AbstractIntervalValidator
Add an error when the max value is less than the min value- Specified by:
addIntervalError
in classAbstractIntervalValidator<ZonedDateTime>
- 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<ZonedDateTime>
- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field
-