Class InterceptorCommonLibrary
java.lang.Object
name.matthewgreet.strutscommons.util.InterceptorCommonLibrary
Static functions used by validation Interceptors, form formating Interceptors and validators.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSummarises the list of recognised annotations of a form field.static enumstatic classstatic classDescribes a type of form field annotation and an instance of the policy it configures.static classDescribes table entry that finds a default converter for a single value field.static classInterceptorCommonLibrary.DefaultConverterEntry<T,C extends Converter<?, T>> Describes table entry that finds a default converter for a single value field.static classstatic enumstatic classstatic classInterceptorCommonLibrary.PolicyEntry<A extends Annotation,P extends Policy<A>, T> Describes table entry that finds a policy class from the annotation class that configures it. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncategoriseFormFields(Collection<Field> formFields, PolicyLookup policyLookup, boolean ignoreNonAnnotatedField) Sets how each form field should be converted.static <T> booleancheckCollectionRecipientDataType(Field recipientField, Class<T> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type.static booleancheckFieldClass(Class<?> conversionClass, Class<?> fieldClass) Returns whether a converter's target data type can convert to the form field's data type.static booleancheckRecipientDataType(Field recipientField, Class<?> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type.static booleanfieldIsNotForm(Field actionField) Returns whether a viewer Action's member field is definitely not a form.static booleanfieldReceivedStoredForm(Field actionField) Returns whether field of an Action received a stored form.static Collection<Field> filterNonConversionErrorFormFields(Collection<Field> formFields, Map<String, ConversionData> conversionErrors) Returns form member fields that didn't have a conversion error.static Collection<Field> filterPlausibleFormFields(Collection<Field> formFields) Returns form member fields that can plausibly receive form data.static <T> voidformatCollectionFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field.static <T> voidformatFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field.Returns the formatted forms created byFormFormatterInterceptor.static <T> InterceptorCommonLibrary.AnnotationEntries<T> getAnnotationEntries(Field formField, PolicyLookup policyLookup) Returns all recognised annotations and their linked policies.getAnnotationUsageFromPolicyClass(Class<?> policyClass) Returns category of form field policy implementation class or NA if not applicable.Returns built-in single value converters.static List<InterceptorCommonLibrary.DefaultConverterEntry<?, ?>> Returns built-in single value converters.static List<InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> Returns built-in adjusters, converters, and validators.static <T> InterceptorCommonLibrary.ConfiguredPolicy<T> getConfiguredPolicy(Annotation annotation, PolicyLookup policyLookup) Returns configured policy instance that processes an annotated form field, or result of NA type if not recognised.static Class<?> getConverterClassLookupFromFormFieldClass(Class<?> fieldClass) Returns class used in default converter and default collection converter lookup from a form field's type or item class for collection types.static CollectionConverter<?, ?> getDefaultCollectionConverter(Field field, PolicyLookup policyLookup) Returns default collection converter for a collection form field or display field, or null if none available.static Converter<?, ?> getDefaultConverter(Field field, PolicyLookup policyLookup) Returns default converter for a single value form field or display field, or null if none available.static Converter<?, ?> getDefaultConverterFromArray(Field field, PolicyLookup policyLookup) Returns default converter for each item of an array display field, or null if none available.static Converter<?, ?> getDefaultConverterFromCollection(Field field, PolicyLookup policyLookup) Returns default converter for each item of a collection display field, or null if none available.static StringgetDefaultRecipientName(String fieldName) Returns the default field name to receive a converted form field.static ObjectReturns the object expected to receive submitted form data on behalf of an Action.getFormFieldCategory(InterceptorCommonLibrary.FieldUsage<?> fieldUsage) static <T> InterceptorCommonLibrary.FieldUsage<T> getFormFieldUsage(Field formField, PolicyLookup policyLookup) Returns what policies should apply to a form field, such as conversion and validation, or throwsFormFieldAnnotationTypeMismatchExceptionif any annotation does not match the field's type.static Collection<Field> getProperties(Class<?> type) Returns all properties of a class, even private ones, whether directly declared or inherited.static FieldgetProperty(Class<?> type, String name) Returns property of a class, even if private or inherited, or null if not found.Returns a processed form stored in session.static <T> Class<T> getTypeFromArrayField(Field recipientField) Returns element type of a collection-based form field.static <T> Class<T> getTypeFromCollectionField(Field recipientField) Returns element type of a collection-based form field.static <A extends Annotation>
booleanisCustomAnnotationClass(Class<A> annotationClass) Returns whether an annotation class is for custom policies.static <T> Collection<T> makeCollectionForRecipient(Class<?> recipientClass) Returns an empty, modifiable collection from a collection type.
-
Field Details
-
DEFAULT_ACCEPT_CLASSES
- See Also:
-
DEFAULT_ACCEPT_PACKAGES
- See Also:
-
DEFAULT_CLASSPATH_SCANNING_REPLACE_BUILT_IN
- See Also:
-
DEFAULT_ENABLE_CLASSPATH_SCANNING
- See Also:
-
DEFAULT_REJECT_CLASSES
- See Also:
-
DEFAULT_REJECT_PACKAGES
- See Also:
-
STRUTS_CONSTANT_ACCEPT_CLASSES
- See Also:
-
STRUTS_CONSTANT_ACCEPT_PACKAGES
- See Also:
-
STRUTS_CONSTANT_CLASSPATH_SCANNING_REPLACE_BUILT_IN
- See Also:
-
STRUTS_CONSTANT_ENABLE_CLASSPATH_SCANNING
- See Also:
-
STRUTS_CONSTANT_REJECT_CLASSES
- See Also:
-
STRUTS_CONSTANT_REJECT_PACKAGES
- See Also:
-
-
Constructor Details
-
InterceptorCommonLibrary
public InterceptorCommonLibrary()
-
-
Method Details
-
categoriseFormFields
public static <T> InterceptorCommonLibrary.CategoriseFieldResult categoriseFormFields(Collection<Field> formFields, PolicyLookup policyLookup, boolean ignoreNonAnnotatedField) Sets how each form field should be converted. -
checkCollectionRecipientDataType
public static <T> boolean checkCollectionRecipientDataType(Field recipientField, Class<T> recipientClass) Returns whether converting validator can convert form field value to the recipient field's type. -
checkFieldClass
Returns whether a converter's target data type can convert to the form field's data type. -
checkRecipientDataType
Returns whether converting validator can convert form field value to the recipient field's type. -
fieldIsNotForm
Returns whether a viewer Action's member field is definitely not a form. -
fieldReceivedStoredForm
Returns whether field of an Action received a stored form. -
filterNonConversionErrorFormFields
public static Collection<Field> filterNonConversionErrorFormFields(Collection<Field> formFields, Map<String, ConversionData> conversionErrors) Returns form member fields that didn't have a conversion error. -
filterPlausibleFormFields
Returns form member fields that can plausibly receive form data. This excludes static and final fields. -
formatCollectionFormField
public static <T> void formatCollectionFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field. -
formatFormField
public static <T> void formatFormField(Object form, Collection<Field> allFormFields, Field formField, InterceptorCommonLibrary.ConfiguredPolicy<T> configuredPolicy) Sets text for not yet set form field. -
getActionContextFormattedForms
Returns the formatted forms created byFormFormatterInterceptor. As these are only created by a Struts 2 pre-result listener set by the Interceptor, no result is available till then. This is meant for the Interceptor and Actions should useStrutsMiscellaneousLibrary.getFormattedForms()as it's easier to use. -
getAnnotationEntries
public static <T> InterceptorCommonLibrary.AnnotationEntries<T> getAnnotationEntries(Field formField, PolicyLookup policyLookup) Returns all recognised annotations and their linked policies. -
getAnnotationUsageFromPolicyClass
public static InterceptorCommonLibrary.AnnotationUsage getAnnotationUsageFromPolicyClass(Class<?> policyClass) Returns category of form field policy implementation class or NA if not applicable. -
getBuiltInDefaultCollectionConverters
public static List<InterceptorCommonLibrary.DefaultCollectionConverterEntry<?,?>> getBuiltInDefaultCollectionConverters()Returns built-in single value converters. -
getBuiltInDefaultConverters
public static List<InterceptorCommonLibrary.DefaultConverterEntry<?,?>> getBuiltInDefaultConverters()Returns built-in single value converters. -
getBuiltInPolicies
Returns built-in adjusters, converters, and validators. -
getConfiguredPolicy
public static <T> InterceptorCommonLibrary.ConfiguredPolicy<T> getConfiguredPolicy(Annotation annotation, PolicyLookup policyLookup) throws Exception Returns configured policy instance that processes an annotated form field, or result of NA type if not recognised.- Throws:
Exception
-
getConverterClassLookupFromFormFieldClass
Returns class used in default converter and default collection converter lookup from a form field's type or item class for collection types. -
getDefaultCollectionConverter
public static CollectionConverter<?,?> getDefaultCollectionConverter(Field field, PolicyLookup policyLookup) Returns default collection converter for a collection form field or display field, or null if none available. -
getDefaultConverter
Returns default converter for a single value form field or display field, or null if none available. -
getDefaultConverterFromArray
Returns default converter for each item of an array display field, or null if none available. Not used for form fields. -
getDefaultConverterFromCollection
public static Converter<?,?> getDefaultConverterFromCollection(Field field, PolicyLookup policyLookup) Returns default converter for each item of a collection display field, or null if none available. Not used for form fields. -
getDefaultRecipientName
Returns the default field name to receive a converted form field. -
getForm
Returns the object expected to receive submitted form data on behalf of an Action. This can be the model of a ModelDriven Action, or the Action itself. -
getFormFieldCategory
public static InterceptorCommonLibrary.FormFieldCategory getFormFieldCategory(InterceptorCommonLibrary.FieldUsage<?> fieldUsage) -
getFormFieldUsage
public static <T> InterceptorCommonLibrary.FieldUsage<T> getFormFieldUsage(Field formField, PolicyLookup policyLookup) throws FormFieldAnnotationTypeMismatchException Returns what policies should apply to a form field, such as conversion and validation, or throwsFormFieldAnnotationTypeMismatchExceptionif any annotation does not match the field's type. -
getProperties
Returns all properties of a class, even private ones, whether directly declared or inherited. -
getProperty
Returns property of a class, even if private or inherited, or null if not found. -
getStoredForm
Returns a processed form stored in session. -
getTypeFromArrayField
Returns element type of a collection-based form field. -
getTypeFromCollectionField
Returns element type of a collection-based form field. -
isCustomAnnotationClass
Returns whether an annotation class is for custom policies. -
makeCollectionForRecipient
Returns an empty, modifiable collection from a collection type.
-