Class DateIntervalValidator
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.contenttype.validation.AbstractContentValidator
-
- org.ametys.cms.contenttype.validation.AbstractIntervalValidator<Date>
-
- org.ametys.cms.contenttype.validation.DateIntervalValidator
-
- All Implemented Interfaces:
ContentValidator
,Configurable
,LogEnabled
,Serviceable
public class DateIntervalValidator extends AbstractIntervalValidator<Date>
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/metadata/start"/> <endDate path="path/to/metadata/end"/> If the path of metadata 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, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, I18nizableText emptyLabel)
Add an error when the max or the min value is empty but the interval is mandatoryprotected void
addIntervalError(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, Date startDate, Date 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 SimpleField<Date>
getEmptyValue()
Get a value holder containing an empty value array.protected SimpleField<Date>
getValues(Form parentForm, String fieldName)
Get the values of the field to validate from the form.protected boolean
isLessThan(Date endDate, Date startDate)
Test if the first number is less than the second one.protected boolean
isSupportedType(MetadataType type)
Test if the metadata type is one expected by the validator-
Methods inherited from class org.ametys.cms.contenttype.validation.AbstractIntervalValidator
_validateInterval, configure, service, 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<Date>
- 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<Date>
- Parameters:
configuration
- The configuration- Returns:
- The metadata max path
- Throws:
ConfigurationException
- If an error occurs
-
getValues
protected SimpleField<Date> getValues(Form parentForm, String fieldName)
Description copied from class:AbstractIntervalValidator
Get the values of the field to validate from the form.- Specified by:
getValues
in classAbstractIntervalValidator<Date>
- Parameters:
parentForm
- The form containing the user values.fieldName
- The field name.- Returns:
- The values.
-
getEmptyValue
protected SimpleField<Date> getEmptyValue()
Description copied from class:AbstractIntervalValidator
Get a value holder containing an empty value array.- Specified by:
getEmptyValue
in classAbstractIntervalValidator<Date>
- Returns:
- a value holder containing an empty value array.
-
isLessThan
protected boolean isLessThan(Date endDate, Date startDate)
Description copied from class:AbstractIntervalValidator
Test if the first number is less than the second one.- Specified by:
isLessThan
in classAbstractIntervalValidator<Date>
- Parameters:
endDate
- The first number to compare.startDate
- The second number to compare.- Returns:
- true if the first number is less than the first, false otherwise.
-
isSupportedType
protected boolean isSupportedType(MetadataType type)
Description copied from class:AbstractIntervalValidator
Test if the metadata type is one expected by the validator- Specified by:
isSupportedType
in classAbstractIntervalValidator<Date>
- Parameters:
type
- The metadata type- Returns:
- True if the type is supported
-
addIntervalError
protected void addIntervalError(Errors errors, MetadataDefinition minDefinition, MetadataDefinition maxDefinition, Date startDate, Date endDate)
Description copied from class:AbstractIntervalValidator
Add an error when the max value is less than the min value- Specified by:
addIntervalError
in classAbstractIntervalValidator<Date>
- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionstartDate
- The min valueendDate
- The max value
-
addErrorEmpty
protected void addErrorEmpty(Errors errors, MetadataDefinition minDefinition, MetadataDefinition 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<Date>
- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field
-
-