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 Summary
ConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPrefixes
(String... prefix) Add a new (first) prefix to use for building message codes.String[]
addPrefixesToMessageCodes
(String[] codes, boolean includeFallback) Deprecated.String[]
buildMessageCodes
(String code) Generate the actual codes to lookup based on the registered prefixes.String[]
buildMessageCodes
(String code, boolean includeFallback) Generate the actual codes to lookup based on the registered prefixes.getMessage
(String code, Object[] arguments, String defaultValue) getMessage
(String code, Object[] arguments, String defaultValue, Locale locale) getMessage
(String code, String defaultValue) getMessage
(String code, String defaultValue, Locale locale) getMessage
(org.springframework.context.MessageSourceResolvable messageSourceResolvable) getMessage
(org.springframework.context.MessageSourceResolvable messageSourceResolvable, Locale locale) getMessageWithFallback
(String code, Object[] arguments, String defaultValue) getMessageWithFallback
(String code, Object[] arguments, String defaultValue, Locale locale) getMessageWithFallback
(String code, String defaultValue) getMessageWithFallback
(String code, String defaultValue, Locale locale) getNamePlural
(Locale locale) getNamePluralInline
(Locale locale) getNameSingular
(Locale locale) getNameSingularInline
(Locale locale) getPropertyDescription
(EntityPropertyDescriptor descriptor) getPropertyDescription
(EntityPropertyDescriptor descriptor, Locale locale) getPropertyDisplayName
(EntityPropertyDescriptor descriptor) getPropertyDisplayName
(EntityPropertyDescriptor descriptor, Locale locale) getPropertyMessage
(EntityPropertyDescriptor descriptor, String subKey, String defaultValue) getPropertyMessage
(EntityPropertyDescriptor descriptor, String subKey, String defaultValue, Locale locale) prefixedResolver
(String... additionalPrefixes) Create a custom prefixed resolver where the additional prefixes will actually be applied as suffixes for the already registered prefixes.String[]
resolveMessageCodes
(String errorCode, String objectName) String[]
resolveMessageCodes
(String errorCode, String objectName, String field, Class<?> fieldType) void
setEntityConfiguration
(EntityConfiguration<?> entityConfiguration) void
setErrorCodesResolver
(@NonNull org.springframework.validation.MessageCodesResolver errorCodesResolver) Set a specific custom resolver that should be used for error code resolving.void
setFallbackCollections
(@NonNull String... fallbackCollections) Set the prefixes that should be applied only if fallback generation is specified.void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setPrefixes
(@NonNull String... prefix) Replace all prefixes.
-
Constructor Details
-
EntityMessageCodeResolver
-
EntityMessageCodeResolver
public EntityMessageCodeResolver()
-
-
Method Details
-
setPrefixes
Replace all prefixes.- Parameters:
prefix
- list
-
addPrefixes
Add a new (first) prefix to use for building message codes.- Parameters:
prefix
- list
-
setFallbackCollections
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 interfaceorg.springframework.context.MessageSourceAware
-
setEntityConfiguration
-
getNameSingular
-
getNameSingularInline
-
getNamePlural
-
getNamePluralInline
-
getNameSingular
-
getNameSingularInline
-
getNamePlural
-
getNamePluralInline
-
getPropertyDisplayName
-
getPropertyDescription
-
getPropertyMessage
public String getPropertyMessage(EntityPropertyDescriptor descriptor, String subKey, String defaultValue) -
getPropertyDisplayName
-
getPropertyDescription
-
getPropertyMessage
public String getPropertyMessage(EntityPropertyDescriptor descriptor, String subKey, String defaultValue, Locale locale) -
getMessage
-
getMessage
-
getMessage
-
getMessage
-
getMessageWithFallback
-
getMessageWithFallback
-
getMessageWithFallback
-
getMessageWithFallback
-
getMessage
public String getMessage(org.springframework.context.MessageSourceResolvable messageSourceResolvable) -
getMessage
-
resolveMessageCodes
- Specified by:
resolveMessageCodes
in interfaceorg.springframework.validation.MessageCodesResolver
-
resolveMessageCodes
public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType) - Specified by:
resolveMessageCodes
in interfaceorg.springframework.validation.MessageCodesResolver
-
addPrefixesToMessageCodes
Deprecated. -
buildMessageCodes
Generate the actual codes to lookup based on the registered prefixes.- Parameters:
code
- requested- Returns:
- message codes to lookup
-
buildMessageCodes
Generate the actual codes to lookup based on the registered prefixes. Will not include fallback collections.- Parameters:
code
- requestedincludeFallback
- should fallback collections be included- Returns:
- message codes to lookup
-
prefixedResolver
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
-