Package graphql.validation.interpolation
Class ResourceBundleMessageInterpolator
- java.lang.Object
-
- graphql.validation.interpolation.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 bundleIf 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
-
-
Constructor Summary
Constructors Constructor Description ResourceBundleMessageInterpolator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected graphql.ErrorClassificationbuildErrorClassification(java.lang.String messageTemplate, java.util.Map<java.lang.String,java.lang.Object> messageParams, ValidationEnvironment validationEnvironment)Override this method to build your own ErrorClassificationprotected java.util.ResourceBundlegetResourceBundle(java.util.Locale locale)You can override this to provide your own resource bundles for a given localegraphql.GraphQLErrorinterpolate(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 aGraphQLError
-
-
-
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 templatemessageParams- the parametersvalidationEnvironment- 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:MessageInterpolatorCalled to interpolate a message template and arguments into aGraphQLError- Specified by:
interpolatein interfaceMessageInterpolator- Parameters:
messageTemplate- the message templatemessageParams- the parameters to this errorvalidationEnvironment- the validation environment- Returns:
- a
GraphQLError
-
-