Package io.jmix.core

Class MessageTools

java.lang.Object
io.jmix.core.MessageTools

@Component("core_MessageTools") public class MessageTools extends Object
Utility class to provide common functionality related to localized messages.
Implemented as Spring bean to allow extension in application projects.
  • Field Details

    • MARK

      public static final String MARK
      Prefix defining that the string is actually a key in a localized messages pack.
      See Also:
    • messages

      @Autowired protected Messages messages
    • metadata

      @Autowired protected Metadata metadata
    • metadataTools

      @Autowired protected MetadataTools metadataTools
    • extendedEntities

      @Autowired protected ExtendedEntities extendedEntities
    • properties

      @Autowired protected CoreProperties properties
    • messageResolvers

      @Autowired(required=false) protected List<MessageResolver> messageResolvers
  • Constructor Details

    • MessageTools

      public MessageTools()
  • Method Details

    • loadString

      public String loadString(@Nullable String ref)
      Get localized message by reference provided in the full format.
      Parameters:
      ref - reference to message in the following format: msg://group/message_id
      Returns:
      localized message or input string itself if it doesn't begin with msg://
    • loadString

      public String loadString(String ref, Locale locale)
      Get localized message by reference provided in the full format.
      Parameters:
      ref - reference to message in the following format: msg://group/message_id
      Returns:
      localized message or input string itself if it doesn't begin with msg://
    • loadString

      public String loadString(@Nullable String group, @Nullable String ref)
      Get localized message by reference provided in full or brief format.
      Parameters:
      group - message group to use if the second parameter is in brief format
      ref - reference to message in the following format:
      • Full: msg://group/message_id
      • Brief: msg://message_id, in this case the first parameter is taken into account
      Returns:
      localized message or input string itself if it doesn't begin with msg://
    • loadString

      public String loadString(@Nullable String group, @Nullable String ref, @Nullable Locale locale)
      Get localized message by reference provided in full or brief format.
      Parameters:
      group - message group to use if the second parameter is in brief format
      ref - reference to message in the following format:
      locale - locale
      • Full: msg://group/message_id
      • Brief: msg://message_id, in this case the first parameter is taken into account
      Returns:
      localized message or input string itself if it doesn't begin with msg://
    • getEntityCaption

      public String getEntityCaption(MetaClass metaClass)
      Returns:
      a localized name of an entity. Messages pack must be located in the same package as entity.
    • getEntityCaption

      public String getEntityCaption(MetaClass metaClass, @Nullable Locale locale)
      Returns:
      a localized name of an entity with given locale or default if null
    • getDetailedEntityCaption

      public String getDetailedEntityCaption(MetaClass metaClass)
      Returns:
      a detailed localized name of an entity
    • getDetailedEntityCaption

      public String getDetailedEntityCaption(MetaClass metaClass, @Nullable Locale locale)
      Returns:
      a detailed localized name of an entity with given locale or default if null
    • getPropertyCaption

      public String getPropertyCaption(MetaClass metaClass, String propertyName)
      Get localized name of an entity property.
      Parameters:
      metaClass - MetaClass containing the property
      propertyName - property's name
      Returns:
      localized name
    • getPropertyCaption

      public String getPropertyCaption(MetaClass metaClass, String propertyName, @Nullable Locale locale)
      Get localized name of an entity property.
      Parameters:
      metaClass - MetaClass containing the property
      propertyName - property's name
      locale - locale, if value is null locale of current user is used
      Returns:
      localized name
    • getPropertyCaption

      public String getPropertyCaption(MetaProperty property)
      Get localized name of an entity property.
      Parameters:
      property - MetaProperty
      Returns:
      localized name
    • getPropertyCaption

      public String getPropertyCaption(MetaProperty property, @Nullable Locale locale)
      Get localized name of an entity property. Messages pack must be located in the same package as entity.
      Parameters:
      property - MetaProperty
      locale - locale, if value is null locale of current user is used
      Returns:
      localized name
    • getDefaultRequiredMessage

      public String getDefaultRequiredMessage(MetaClass metaClass, String propertyName)
      Get default required message for specified property of MetaClass.
      Parameters:
      metaClass - MetaClass containing the property
      propertyName - property's name
      Returns:
      default required message for specified property of MetaClass
    • getNotNullMessage

      @Nullable protected String getNotNullMessage(MetaProperty metaProperty)
      Get default required message for specified property of MetaClass if it has NotNull annotation.
      Parameters:
      metaProperty - MetaProperty
      Returns:
      localized not null message
    • getMessageRef

      public String getMessageRef(MetaClass metaClass, String propertyName)
      Get message reference of an entity property. Messages pack part of the reference corresponds to the entity's package.
      Parameters:
      metaClass - MetaClass containing the property
      propertyName - property's name
      Returns:
      message key in the form msg://message_pack/message_id
    • getMessageRef

      public String getMessageRef(MetaProperty property)
      Get message reference of an entity property. Messages pack part of the reference corresponds to the entity's package.
      Parameters:
      property - MetaProperty
      Returns:
      message key in the form msg://message_pack/message_id
    • getDefaultLocale

      public Locale getDefaultLocale()
      Returns the first locale from the list defined in jmix.core.available-locales app property.
    • getLocaleDisplayName

      public String getLocaleDisplayName(Locale locale)
      Returns display name of the given locale set in the message bundle with the localeDisplayName.<code> key. If such message is not defined, returns Locale.getDisplayName().
    • getAvailableLocalesMap

      public Map<String,Locale> getAvailableLocalesMap()
      Returns locales set in the jmix.core.available-locales property as a map of the locale display name to the locale object.
    • getDefaultDateFormat

      public String getDefaultDateFormat(@Nullable javax.persistence.TemporalType temporalType)
      Parameters:
      temporalType - a temporal type
      Returns:
      default date format string for passed temporal type
    • isMessageKey

      public boolean isMessageKey(@Nullable String message)
      Parameters:
      message - a message to check
      Returns:
      whether the given message is a key in a localized messages pack