Class EntityMessageCodeResolver

java.lang.Object
com.foreach.across.modules.entity.support.EntityMessageCodeResolver
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware, org.springframework.validation.MessageCodesResolver

public class EntityMessageCodeResolver extends Object implements org.springframework.context.MessageSourceAware, org.springframework.validation.MessageCodesResolver
Helper for resolving message codes in the context of an EntityConfiguration. Takes into account the current Locale for resolving the messages.
Author:
Arne Vandamme
  • Constructor Details

    • EntityMessageCodeResolver

      public EntityMessageCodeResolver(EntityMessageCodeResolver original)
    • EntityMessageCodeResolver

      public EntityMessageCodeResolver()
  • Method Details

    • setPrefixes

      public void setPrefixes(@NonNull @NonNull String... prefix)
      Replace all prefixes.
      Parameters:
      prefix - list
    • addPrefixes

      public void addPrefixes(String... prefix)
      Add a new (first) prefix to use for building message codes.
      Parameters:
      prefix - list
    • setFallbackCollections

      public void setFallbackCollections(@NonNull @NonNull String... fallbackCollections)
      Set the prefixes that should be applied only if fallback generation is specified. These prefixes will be ordered after the primary prefixes.
      Parameters:
      fallbackCollections - to try
    • setErrorCodesResolver

      public void setErrorCodesResolver(@NonNull @NonNull org.springframework.validation.MessageCodesResolver errorCodesResolver)
      Set a specific custom resolver that should be used for error code resolving. By default the current resolver is used with a validation prefix.

      The error codes resolver will be used it this resolved is used for resolving error messages.

      Parameters:
      errorCodesResolver - to use
    • setMessageSource

      public void setMessageSource(org.springframework.context.MessageSource messageSource)
      Specified by:
      setMessageSource in interface org.springframework.context.MessageSourceAware
    • setEntityConfiguration

      public void setEntityConfiguration(EntityConfiguration<?> entityConfiguration)
    • getNameSingular

      public String getNameSingular()
    • getNameSingularInline

      public String getNameSingularInline()
    • getNamePlural

      public String getNamePlural()
    • getNamePluralInline

      public String getNamePluralInline()
    • getNameSingular

      public String getNameSingular(Locale locale)
    • getNameSingularInline

      public String getNameSingularInline(Locale locale)
    • getNamePlural

      public String getNamePlural(Locale locale)
    • getNamePluralInline

      public String getNamePluralInline(Locale locale)
    • getPropertyDisplayName

      public String getPropertyDisplayName(EntityPropertyDescriptor descriptor)
    • getPropertyDescription

      public String getPropertyDescription(EntityPropertyDescriptor descriptor)
    • getPropertyMessage

      public String getPropertyMessage(EntityPropertyDescriptor descriptor, String subKey, String defaultValue)
    • getPropertyDisplayName

      public String getPropertyDisplayName(EntityPropertyDescriptor descriptor, Locale locale)
    • getPropertyDescription

      public String getPropertyDescription(EntityPropertyDescriptor descriptor, Locale locale)
    • getPropertyMessage

      public String getPropertyMessage(EntityPropertyDescriptor descriptor, String subKey, String defaultValue, Locale locale)
    • getMessage

      public String getMessage(String code, String defaultValue)
    • getMessage

      public String getMessage(String code, String defaultValue, Locale locale)
    • getMessage

      public String getMessage(String code, Object[] arguments, String defaultValue)
    • getMessage

      public String getMessage(String code, Object[] arguments, String defaultValue, Locale locale)
    • getMessageWithFallback

      public String getMessageWithFallback(String code, String defaultValue)
    • getMessageWithFallback

      public String getMessageWithFallback(String code, String defaultValue, Locale locale)
    • getMessageWithFallback

      public String getMessageWithFallback(String code, Object[] arguments, String defaultValue)
    • getMessageWithFallback

      public String getMessageWithFallback(String code, Object[] arguments, String defaultValue, Locale locale)
    • getMessage

      public String getMessage(org.springframework.context.MessageSourceResolvable messageSourceResolvable)
    • getMessage

      public String getMessage(org.springframework.context.MessageSourceResolvable messageSourceResolvable, Locale locale)
    • resolveMessageCodes

      public String[] resolveMessageCodes(String errorCode, String objectName)
      Specified by:
      resolveMessageCodes in interface org.springframework.validation.MessageCodesResolver
    • resolveMessageCodes

      public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType)
      Specified by:
      resolveMessageCodes in interface org.springframework.validation.MessageCodesResolver
    • addPrefixesToMessageCodes

      @Deprecated public String[] addPrefixesToMessageCodes(String[] codes, boolean includeFallback)
      Deprecated.
    • buildMessageCodes

      public String[] buildMessageCodes(String code)
      Generate the actual codes to lookup based on the registered prefixes.
      Parameters:
      code - requested
      Returns:
      message codes to lookup
    • buildMessageCodes

      public String[] buildMessageCodes(String code, boolean includeFallback)
      Generate the actual codes to lookup based on the registered prefixes. Will not include fallback collections.
      Parameters:
      code - requested
      includeFallback - should fallback collections be included
      Returns:
      message codes to lookup
    • prefixedResolver

      public EntityMessageCodeResolver prefixedResolver(String... additionalPrefixes)
      Create a custom prefixed resolver where the additional prefixes will actually be applied as suffixes for the already registered prefixes. This will generate an exponential number of codes depending on the number of original prefixes and additional prefixes.

      Used to specify scoped code lookups in for example view rendering, where the primary prefixes always stay the same.

      Parameters:
      additionalPrefixes - to add
      Returns:
      code resolver instance