Class InterceptorCommonLibrary

java.lang.Object
name.matthewgreet.strutscommons.util.InterceptorCommonLibrary

public class InterceptorCommonLibrary extends Object
Static functions used by validation Interceptors, form formating Interceptors and validators.
  • Constructor Details

    • InterceptorCommonLibrary

      public InterceptorCommonLibrary()
  • Method Details

    • categoriseFormFields

      public static <T> InterceptorCommonLibrary.CategoriseFieldResult categoriseFormFields(Collection<Field> formFields)
      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

      public static boolean checkFieldClass(Class<?> conversionClass, Class<?> fieldClass)
      Returns whether a converter's target data type can convert to the form field's data type.
    • checkRecipientDataType

      public static boolean checkRecipientDataType(Field recipientField, Class<?> recipientClass)
      Returns whether converting validator can convert form field value to the recipient field's type.
    • fieldIsNotForm

      public static boolean fieldIsNotForm(Field actionField)
      Returns whether a viewer Action's member field is definitely not a form.
    • fieldReceivedStoredForm

      public static boolean fieldReceivedStoredForm(Field actionField)
      Returns whether field of an Action received a stored form.
    • filterFormFields

      public static Collection<Field> filterFormFields(Collection<Field> allFormFields)
      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

      public static Map<String,Map<String,Object>> getActionContextFormattedForms()
      Returns the formatted forms created by FormFormatterInterceptor. 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 use StrutsMiscellaneousLibrary.getFormattedForms() as it's easier to use.
    • getAnnotationEntries

      public static <T> InterceptorCommonLibrary.AnnotationEntries<T> getAnnotationEntries(Field formField)
      Returns all recognised annotations and their linked policies.
    • getAnnotationUsage

      public static <T> InterceptorCommonLibrary.ConfiguredPolicy<T> getAnnotationUsage(Annotation annotation) throws Exception
      Returns validator (and formatter) that processes an annotated form field, or result of NA type if not recognised.
      Throws:
      Exception
    • getDefaultCollectionConverter

      public static CollectionConverter<?,?> getDefaultCollectionConverter(Field field)
      Returns default collection converter for a collection form field or display field, or null if none available.
    • getDefaultConverter

      public static Converter<?,?> getDefaultConverter(Field field)
      Returns default converter for a single value form field or display field, or null if none available.
    • getDefaultRecognisedConverter

      public static <A extends Annotation, T> Converter<A,T> getDefaultRecognisedConverter(Class<? extends Converter<A,T>> converterClass, Class<? extends A> annotationClass)
    • getDefaultRecipientName

      public static String getDefaultRecipientName(String fieldName)
      Returns the default field name to receive a converted form field.
    • getForm

      public static Object getForm(Object action)
      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)
    • getFormFields

      public static Collection<Field> getFormFields(Collection<Field> allFields)
      Returns form member fields that can plausibly receive form data. This excludes static and final fields.
    • getFormFieldUsage

      public static <T> InterceptorCommonLibrary.FieldUsage<T> getFormFieldUsage(Field formField) throws FormFieldAnnotationTypeMismatchException
      Returns what policies should apply to a form field, such as conversion and validation, or throws FormFieldAnnotationTypeMismatchException if any annotation does not match the field's type.
      Throws:
      FormFieldAnnotationTypeMismatchException
    • getPolicies

      public static List<InterceptorCommonLibrary.PolicyEntry<?,?>> getPolicies()
      Returns list of all built-in adjusters, converters, and validators.
    • getProperties

      public static Collection<Field> getProperties(Class<?> type)
      Returns all properties of a class, even private ones, whether directly declared or inherited.
    • getProperty

      public static Field getProperty(Class<?> type, String name)
      Returns property of a class, even if private or inherited, or null if not found.
    • getStoredForm

      public static FormStoreInterceptor.StoredForm getStoredForm()
      Returns a processed form stored in session.
    • getTypeFromCollectionField

      public static <T> Class<T> getTypeFromCollectionField(Field recipientField)
      Returns element type of a collection-based form field.
    • makeCollectionForRecipient

      public static <T> Collection<T> makeCollectionForRecipient(Class<?> recipientClass)
      Returns an empty, modifiable collection from a collection type.