Class ResourceBundleMessageInterpolator

  • All Implemented Interfaces:
    MessageInterpolator

    public class ResourceBundleMessageInterpolator
    extends java.lang.Object
    implements MessageInterpolator
    This message interpolator will try to convert message templates into I18N messages and then run message property replacement and expression interpolation.

    By default this looks for a resource bundle file called "ValidationMessages.properties" on the class path but you can can override getResourceBundle(java.util.Locale) to provide your own resource bundle

    If it finds no resources then it will use the message template as is and do parameter and expression replacement on it

    This class is heavily inspired by the Hibernate Validator projects ResourceBundleMessageInterpolator implementation and in fact uses that in its implementation and hence the standard facilities such as well known "parameters" like "validatedValue" and "format" are available.

    See the Hibernate Validation documentation for more details

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected graphql.ErrorClassification buildErrorClassification​(java.lang.String messageTemplate, java.util.Map<java.lang.String,​java.lang.Object> messageParams, ValidationEnvironment validationEnvironment)
      Override this method to build your own ErrorClassification
      protected java.util.ResourceBundle getResourceBundle​(java.util.Locale locale)
      You can override this to provide your own resource bundles for a given locale
      graphql.GraphQLError interpolate​(java.lang.String messageTemplate, java.util.Map<java.lang.String,​java.lang.Object> messageParams, ValidationEnvironment validationEnvironment)
      Called to interpolate a message template and arguments into a GraphQLError
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceBundleMessageInterpolator

        public ResourceBundleMessageInterpolator()
    • Method Detail

      • buildErrorClassification

        protected graphql.ErrorClassification buildErrorClassification​(java.lang.String messageTemplate,
                                                                       java.util.Map<java.lang.String,​java.lang.Object> messageParams,
                                                                       ValidationEnvironment validationEnvironment)
        Override this method to build your own ErrorClassification
        Parameters:
        messageTemplate - the message template
        messageParams - the parameters
        validationEnvironment - the rule environment
        Returns:
        an ErrorClassification
      • getResourceBundle

        protected java.util.ResourceBundle getResourceBundle​(java.util.Locale locale)
        You can override this to provide your own resource bundles for a given locale
        Parameters:
        locale - the locale in question
        Returns:
        a resource bundle OR null if you don't have one
      • interpolate

        public graphql.GraphQLError interpolate​(java.lang.String messageTemplate,
                                                java.util.Map<java.lang.String,​java.lang.Object> messageParams,
                                                ValidationEnvironment validationEnvironment)
        Description copied from interface: MessageInterpolator
        Called to interpolate a message template and arguments into a GraphQLError
        Specified by:
        interpolate in interface MessageInterpolator
        Parameters:
        messageTemplate - the message template
        messageParams - the parameters to this error
        validationEnvironment - the validation environment
        Returns:
        a GraphQLError