All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksoot.common.spring.util.MessageProvider Maven / Gradle / Ivy

The newest version!
package com.ksoot.common.spring.util;

import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.lang.NonNull;

/**
 * @author Rajveer Singh
 */
public class MessageProvider {

  private static MessageSource messageSource;

  public MessageProvider(@NonNull final MessageSource messageSource) {
    MessageProvider.messageSource = messageSource;
  }

  public static String getMessage(final String messageCode, final String defaultMessage) {
    return messageSource.getMessage(messageCode, null, defaultMessage, Locale.getDefault());
  }

  public static String getMessage(
      final String messageCode, final String defaultMessage, final Object... params) {
    return messageSource.getMessage(messageCode, params, defaultMessage, Locale.getDefault());
  }

  public static String getMessage(final MessageResolver messageResolver) {
    return messageSource.getMessage(
        messageResolver.messageCode(), null, messageResolver.defaultMessage(), Locale.getDefault());
  }

  public static String getMessage(final MessageResolver messageResolver, final Object... params) {
    return messageSource.getMessage(
        messageResolver.messageCode(),
        params,
        messageResolver.defaultMessage(),
        Locale.getDefault());
  }

  public static String getMessage(final MessageSourceResolvable resolvable) {
    return messageSource.getMessage(resolvable, Locale.getDefault());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy