Java Code Examples for javax.validation.MessageInterpolator#interpolate()

The following examples show how to use javax.validation.MessageInterpolator#interpolate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OsgiMessageInterpolator.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
protected String resolve ( final String key, final Context context, final Locale locale )
{
    for ( final Resolver resolver : this.tracker.getTracked ().values () )
    {
        final String result = resolver.resolve ( key, context, locale );
        if ( result != null )
        {
            return result;
        }
    }

    final MessageInterpolator fallback = this.fallback;

    if ( fallback == null )
    {
        return null;
    }
    return fallback.interpolate ( String.format ( "{%s}", key ), context, locale );
}
 
Example 2
Source File: ConstraintViolationTranslator.java    From krazo with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the human readable error message for a given {@link ConstraintViolation}.
 *
 * @param violation The violation to get the message for
 * @param locale    The desired target locale
 * @return the localized message
 */
public String translate(ConstraintViolation<?> violation, Locale locale) {

    SimpleMessageInterpolatorContext context = new SimpleMessageInterpolatorContext(violation);

    MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();

    return interpolator.interpolate(violation.getMessageTemplate(), context, locale);

}
 
Example 3
Source File: ConstraintViolationTranslator.java    From ozark with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the human readable error message for a given {@link ConstraintViolation}.
 *
 * @param violation The violation to get the message for
 * @param locale    The desired target locale
 * @return the localized message
 */
public String translate(ConstraintViolation<?> violation, Locale locale) {

    SimpleMessageInterpolatorContext context = new SimpleMessageInterpolatorContext(violation);

    MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();

    return interpolator.interpolate(violation.getMessageTemplate(), context, locale);

}