Class DefaultAnnotationValidator
- All Implemented Interfaces:
AnnotationValidatior
Implementation of AnnotationValidatior used by AnnotationValidationInterceptor2.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThread local execution state of algorithm about a field.static classThread local execution state of algorithm. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> Stringadjust()Invokes adjuster and returns result.protected voidcategoriseFields(Collection<Field> formFields) Sets how form fields should be converted (InterceptorContext setting property set 4).protected <T> voidcheckConversionMessage(ConversionResult<T> conversionResult) Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> voidcheckListConversionMessage(ConversionResult<T> conversionResult) Checks if list conversion results means a message must be written and writes appropriate type if needed.protected <T> voidcheckListPostConversionMessage(ValidationResult validationResult) Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> voidcheckNonConversionMessage(ValidationResult validationResult) Checks if non-conversion validation results means a message must be written and writes appropriate type if needed.protected <T> voidcheckPostConversionMessage(ValidationResult validationResult) Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> ConversionResult<T> convert()Invokes converter and returns result, or returns skipped result if the adjusted formatted value is empty string and the converter does not convert them.protected <T> voidCalled when processing of a form field is complete.protected voidCalled when this interceptor completes (and is not disabled).protected voidDoes not nothing and is a placeholder called aftercategoriseFields.filterFormFieldsPreCategorise(List<Field> formFields) Returns form fields except those that should be skipped before any policy annotations are analysed.protected HttpParametersfilterRequestParameters(HttpParameters requestParameters) Removes rejected request parameters from the allowed request parameters (property set 3), which are those that exceed max parameter length or fail filter if Action implements ParameterNameAware.protected StringgetDefaultMessage(String recipientFieldName, Class<?> recipientClass) Returns error message if a default converter fails.Returns default target for writing or logging conversion and validation failures.getFormFields(List<Field> allFields) Returns form member fields that can plausibly receive form data.booleanReturns whether form fields with no recognised annotations are ignored..protected StringgetMessage(TextProvider textProvider, String messageKey, String message) Returns message to use, extracted from text provider if required.protected Required.MessageTypeReturns target type for conversion and validation failures if annotation uses default type.intReturns maximum number entries of an array or collection field.intReturns maximum length of parameters that can be accepted.Returns policy lookup by annotation helper used in validation.getProperties(Class<?> type) Returns all form fields of defined by form class.protected FieldWhilst processing a field, returns field to receive a converted value.Whilst processing a field, returns whether the field to receive a converted value is single value, array, or collection.protected <T> Class<T> Whilst processing a field, for the field to receive a converted value, returns the field value for single value, array type for arrays, and entry type for collections.protected HttpParametersSets interceptor context's request parameters as a mutable copy.protected org.apache.logging.log4j.LoggergetValidationLogger(ActionInvocation invocation, Object action) Returns Log4j2 logger to use for conversion and validation failures.protected voidignoreMessage(org.apache.logging.log4j.Logger logger, String message) Called when an error message is to be ignored.protected <T> ConversionResult<T> Invokes list converter and returns result, or returns skipped result if the adjusted formatted value is empty string and the list converter does not handle those.protected <T> List<T> Invokes list post-conversion adjuster and returns result; or returns input list if it's empty list and adjuster skips them.protected <T> ValidationResultInvokes list post-conversion validator and returns result, or returns success result if the converted value is empty and validator skips them.protected voidlogDebugMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at DEBUG level.protected voidlogErrorMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at ERROR level.protected voidlogInfoMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at INFO level.protected voidlogTraceMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at TRACE level.protected voidlogWarnMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at WARN level.protected <T> Collection<T> makeCollectionForRecipient(Class<?> recipientFieldClass) Returns an empty collection to set the recipient field and will accept converted values.protected <T> DefaultAnnotationValidator.FieldContext<T> Returns an initial execution state about a field.Returns an initial execution state.protected <T> ValidationResultInvokes non-conversion validator and returns result, or success results if the adjusted formatted value is empty string and validator skips them.protected ParsedParameterparseRequestParameter(String parameterName, String parameterValue) Parses allowed HTTP parameter name into field name and index, if any.protected voidparseRequestParameters(HttpParameters allowedRequestParameters) Parses allowed HTTP parameters into field name and index, if any, and sets fieldParsedParameterListTable.protected ParsedParameterparseUploadedFileRequestParameter(String parameterName, UploadedFile uploadedFile) Parses allowed HTTP parameter name into field name and index, if any, for file uploads.protected <T> TInvokes post-conversion adjuster and returns result; or returns input value if it's null and adjuster skips them.protected <T> ValidationResultInvokes post-conversion validator and returns result, or returns success result if the converted value is null and validator skips them.protected voidSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected voidSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected voidSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected voidSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected <T> voidSets, adjusts, converts and validates a single value form field from a request parameter according to its conversion mode.protected <T> voidCalled after all processing for a field is complete.protected <T> voidCalled after processing for a field fails with an exception.protected <T> voidCalled to initialise processing for a field.protected voidCalls form to process request parameters not handled by other form fields and writes parameters that failed as conversion errors.protected <T> voidPresents form field values if any non-conversion validation or conversion failures happened.protected voidSets string field, string array or string collection form field for set only conversion mode.voidsetDefaultMessageType(Required.MessageType defaultMessageType) protected <T> voidSets the field to receive the unconverted value, if one applies.voidsetIgnoreNonAnnotatedFields(boolean ignoreNonAnnotatedFields) voidsetParamMaxListSize(int paramMaxListSize) voidsetParamNameMaxLength(int paramNameMaxLength) voidsetPolicyLookup(PolicyLookup policyLookup) protected <T> voidSets the field to receive the converted value, or converted values for collection converters, if one applies.protected <T> voidstartFieldContext(DefaultAnnotationValidator.FieldContext.ConversionMode conversionMode, FieldParsedParameterList fieldParsedParameterList, InterceptorCommonLibrary.FieldUsage<T> fieldUsage, InterceptorCommonLibrary.PairFieldUsage<T> pairFieldUsage) Called when algorithm is about to start for a field in earnest and sets FieldContext property set 2.protected voidstartInterceptorContext(ActionInvocation invocation) Called when algorithm is about to start in earnest and sets InterceptorContext property set 2.voidvalidate()Entry point called byAnnotationValidationInterceptor2.protected voidInitialisation that needs to be done before main logic of validate is run.protected voidwriteFieldError(ValidationAware validationAware, String fieldName, String message) Writes message to Action's field errors for field.protected voidwriteGeneralError(ValidationAware validationAware, String message) Writes message to Action's action errors.protected voidwriteInfoMessage(ValidationAware validationAware, String message) Writes message to Action's action messages.protected voidwriteWarningMessage(ValidationAware validationAware, String message) Writes message to Action's action warnings.
-
Constructor Details
-
DefaultAnnotationValidator
public DefaultAnnotationValidator()
-
-
Method Details
-
adjust
Invokes adjuster and returns result.
Can access all InterceptorContext properties and FieldContext property set 3 and lower.
-
categoriseFields
Sets how form fields should be converted (InterceptorContext setting property set 4).
Can access InterceptorContext property set 3 and lower.
-
checkConversionMessage
Checks if conversion results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkListConversionMessage
Checks if list conversion results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkListPostConversionMessage
Checks if conversion results means a message must be written and writes appropriate type if needed.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkNonConversionMessage
Checks if non-conversion validation results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkPostConversionMessage
Checks if conversion results means a message must be written and writes appropriate type if needed.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
convert
Invokes converter and returns result, or returns skipped result if the adjusted formatted value is empty string and the converter does not convert them.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
endFieldContext
protected <T> void endFieldContext()Called when processing of a form field is complete. Exists for subclasses. -
endInterceptorContext
protected void endInterceptorContext()Called when this interceptor completes (and is not disabled). Does nothing and really exists for extending subclasses. -
filterFormFieldsPostCategorise
protected void filterFormFieldsPostCategorise()Does not nothing and is a placeholder called after
categoriseFields.Can access InterceptorContext property set 4 and lower.
-
filterFormFieldsPreCategorise
Returns form fields except those that should be skipped before any policy annotations are analysed. Skips none and exists for extending subclasses.
Can access InterceptorContext property set 3 and lower.
-
filterRequestParameters
Removes rejected request parameters from the allowed request parameters (property set 3), which are those that exceed max parameter length or fail filter if Action implements ParameterNameAware.
Can access InterceptorContext property set 3 and lower.
-
getDefaultMessage
Returns error message if a default converter fails.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getFormFields
Returns form member fields that can plausibly receive form data. This excludes static and final fields.
Can access InterceptorContext property set 3 and lower.
-
getMessage
Returns message to use, extracted from text provider if required. textProvider can be null if Action does not implement it.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getMessageTypeForDefault
Returns target type for conversion and validation failures if annotation uses default type.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getProperties
Returns all form fields of defined by form class.
Can access InterceptorContext property set 3 and lower.
-
getRecipientFieldForConversionMode
Whilst processing a field, returns field to receive a converted value.
-
getRecipientFieldMultiplicityForConversionMode
protected InterceptorCommonLibrary.FieldMultiplicity getRecipientFieldMultiplicityForConversionMode()Whilst processing a field, returns whether the field to receive a converted value is single value, array, or collection.
-
getRecipientFieldTypeForConversionMode
Whilst processing a field, for the field to receive a converted value, returns the field value for single value, array type for arrays, and entry type for collections.
-
getRequestParameters
Sets interceptor context's request parameters as a mutable copy.
Can access InterceptorContext property set 2 and lower.
-
getValidationLogger
protected org.apache.logging.log4j.Logger getValidationLogger(ActionInvocation invocation, Object action) Returns Log4j2 logger to use for conversion and validation failures. Uses Action's
AbstractActionSupport.getLogger()if it exists, otherwise this classes logger. Cannot return null.Can access InterceptorContext property set 1.
-
ignoreMessage
Called when an error message is to be ignored. -
listConvert
Invokes list converter and returns result, or returns skipped result if the adjusted formatted value is empty string and the list converter does not handle those.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
listPostConversionAdjust
Invokes list post-conversion adjuster and returns result; or returns input list if it's empty list and adjuster skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
listPostConversionValidate
Invokes list post-conversion validator and returns result, or returns success result if the converted value is empty and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
logDebugMessage
Logs message to Action's logger at DEBUG level. -
logErrorMessage
Logs message to Action's logger at ERROR level. -
logInfoMessage
Logs message to Action's logger at INFO level. -
logTraceMessage
Logs message to Action's logger at TRACE level. -
logWarnMessage
Logs message to Action's logger at WARN level. -
makeCollectionForRecipient
Returns an empty collection to set the recipient field and will accept converted values.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
makeFieldContext
Returns an initial execution state about a field. -
makeInterceptorContext
Returns an initial execution state. -
nonConversionValidate
Invokes non-conversion validator and returns result, or success results if the adjusted formatted value is empty string and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 3 and lower.
-
parseRequestParameter
Parses allowed HTTP parameter name into field name and index, if any.
Can access InterceptorContext property set 3 and lower.
-
parseRequestParameters
Parses allowed HTTP parameters into field name and index, if any, and sets fieldParsedParameterListTable.
Can access InterceptorContext property set 3 and lower.
-
parseUploadedFileRequestParameter
protected ParsedParameter parseUploadedFileRequestParameter(String parameterName, UploadedFile uploadedFile) Parses allowed HTTP parameter name into field name and index, if any, for file uploads.
Can access InterceptorContext property set 3 and lower.
-
postConversionAdjust
protected <T> T postConversionAdjust()Invokes post-conversion adjuster and returns result; or returns input value if it's null and adjuster skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
postConversionValidate
Invokes post-conversion validator and returns result, or returns success result if the converted value is null and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processFileFormField
Sets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFileFormFieldArray
Sets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFileFormFieldCollection
protected void processFileFormFieldCollection() throws IllegalArgumentException, IllegalAccessExceptionSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFileFormFieldSingleValue
protected void processFileFormFieldSingleValue() throws IllegalArgumentException, IllegalAccessExceptionSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFormField
Sets, adjusts, converts and validates a single value form field from a request parameter according to its conversion mode. Not called for set only conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFormFieldEnd
protected <T> void processFormFieldEnd()Called after all processing for a field is complete. Not called for fields marked as manual parameter conversion.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processFormFieldFailed
Called after processing for a field fails with an exception. Not called for fields marked as manual parameter conversion.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processFormFieldStart
protected <T> void processFormFieldStart()Called to initialise processing for a field. Not called for fields marked as manual parameter conversion.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processManualConversionFormFields
protected void processManualConversionFormFields()Calls form to process request parameters not handled by other form fields and writes parameters that failed as conversion errors. Does nothing if the form doesn't implement
Form.Can access all InterceptorContext properties.
-
processRejections
protected <T> void processRejections()Presents form field values if any non-conversion validation or conversion failures happened.
Can access all InterceptorContext properties and FieldContext property set 6 and lower.
-
processSetOnlyFormField
Sets string field, string array or string collection form field for set only conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
setFormattedField
Sets the field to receive the unconverted value, if one applies.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
setUnformattedField
Sets the field to receive the converted value, or converted values for collection converters, if one applies.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
startFieldContext
protected <T> void startFieldContext(DefaultAnnotationValidator.FieldContext.ConversionMode conversionMode, FieldParsedParameterList fieldParsedParameterList, InterceptorCommonLibrary.FieldUsage<T> fieldUsage, InterceptorCommonLibrary.PairFieldUsage<T> pairFieldUsage) Called when algorithm is about to start for a field in earnest and sets FieldContext property set 2. -
startInterceptorContext
Called when algorithm is about to start in earnest and sets InterceptorContext property set 2. -
validateInit
protected void validateInit()Initialisation that needs to be done before main logic of validate is run. -
writeFieldError
Writes message to Action's field errors for field. ValidationAware can be null if Action does not implement it. -
writeGeneralError
Writes message to Action's action errors. ValidationAware can be null if Action does not implement it. -
writeInfoMessage
Writes message to Action's action messages. ValidationAware can be null if Action does not implement it. -
writeWarningMessage
Writes message to Action's action warnings. ValidationAware can be null if Action does not implement it. -
getDefaultMessageType
Returns default target for writing or logging conversion and validation failures. Cannot return DEFAULT or null. -
setDefaultMessageType
-
getIgnoreNonAnnotatedFields
public boolean getIgnoreNonAnnotatedFields()Returns whether form fields with no recognised annotations are ignored.. -
setIgnoreNonAnnotatedFields
public void setIgnoreNonAnnotatedFields(boolean ignoreNonAnnotatedFields) -
getParamMaxListSize
public int getParamMaxListSize()Returns maximum number entries of an array or collection field. Defaults to 256. -
setParamMaxListSize
public void setParamMaxListSize(int paramMaxListSize) -
getParamNameMaxLength
public int getParamNameMaxLength()Returns maximum length of parameters that can be accepted. Defaults to 100. -
setParamNameMaxLength
public void setParamNameMaxLength(int paramNameMaxLength) -
getPolicyLookup
Returns policy lookup by annotation helper used in validation. -
setPolicyLookup
-
validate
public void validate()Entry point called byAnnotationValidationInterceptor2.- Specified by:
validatein interfaceAnnotationValidatior
-