Class AbstractIntervalValidator<T>
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.cms.contenttype.validation.AbstractContentValidator
org.ametys.cms.contenttype.validation.AbstractIntervalValidator<T>
- Type Parameters:
T
- The type tested by the validator.
- All Implemented Interfaces:
ContentValidator
,Configurable
,LogEnabled
- Direct Known Subclasses:
AbstractNumberIntervalValidator
,DateIntervalValidator
,DateTimeIntervalValidator
public abstract class AbstractIntervalValidator<T>
extends AbstractContentValidator
implements Configurable
Base
ContentValidator
validating the content by comparing one or more couples of values.
For each couple of values, the identified max value should be greater than or equal to the identified min value.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
_validateInterval
(Content content, Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, Object minValues, Object maxValues) Validate the interval values of a contentprotected abstract 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 abstract void
addIntervalError
(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, T min, T max) Add an error when the max value is less than the min valuevoid
configure
(Configuration configuration) protected abstract String
configureMaxPath
(Configuration configuration) Get the metadata max path from the configurationprotected abstract String
configureMinPath
(Configuration configuration) Get the metadata min path from the configurationprotected abstract boolean
isLessThan
(T n1, T n2) Test if the first number is less than the second one.protected abstract boolean
isSupportedType
(ElementType type) Test if the attribute type is one expected by the validatorvoid
Validates a content being editedvoid
Validates a content.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
-
AbstractIntervalValidator
public AbstractIntervalValidator()
-
-
Method Details
-
configure
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
validate
Description copied from interface:ContentValidator
Validates a content.- Specified by:
validate
in interfaceContentValidator
- Parameters:
content
- the content to validateerrors
- the structure to populate if the validation failed.
-
_validateInterval
protected void _validateInterval(Content content, Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, Object minValues, Object maxValues) Validate the interval values of a content- Parameters:
content
- The contenterrors
- The list of errors to fillminDefinition
- The definition for the min valuemaxDefinition
- The definition for the max valueminValues
- The list of min valuesmaxValues
- The list of max values
-
validate
Description copied from interface:ContentValidator
Validates a content being edited- Specified by:
validate
in interfaceContentValidator
- Parameters:
content
- the content to validatevalues
- the values being setview
- the viewerrors
- the structure to populate if the validation failed.
-
configureMinPath
protected abstract String configureMinPath(Configuration configuration) throws ConfigurationException Get the metadata min path from the configuration- Parameters:
configuration
- The configuration- Returns:
- The metadata min path
- Throws:
ConfigurationException
- If an error occurs
-
configureMaxPath
protected abstract String configureMaxPath(Configuration configuration) throws ConfigurationException Get the metadata max path from the configuration- Parameters:
configuration
- The configuration- Returns:
- The metadata max path
- Throws:
ConfigurationException
- If an error occurs
-
isLessThan
Test if the first number is less than the second one.- Parameters:
n1
- The first number to compare.n2
- The second number to compare.- Returns:
- true if the first number is less than the first, false otherwise.
-
isSupportedType
Test if the attribute type is one expected by the validator- Parameters:
type
- The attribute type- Returns:
- True if the type is supported
-
addIntervalError
protected abstract void addIntervalError(Errors errors, ElementDefinition minDefinition, ElementDefinition maxDefinition, T min, T max) Add an error when the max value is less than the min value- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionmin
- The min valuemax
- The max value
-
addErrorEmpty
protected abstract 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 mandatory- Parameters:
errors
- The list of errorsminDefinition
- The min definitionmaxDefinition
- The max definitionemptyLabel
- The label of the empty field
-