Packageorg.granite.validation
Classpublic class DefaultMessageInterpolator
ImplementsIMessageInterpolator

A default implementation of the IMessageInterpolator interface, that transform a constraint message key into a human readable error message. This implementation follows the JSR-303 specification recommendations (section 4.3.1) for message parameters substitutions.

See also

ValidatorFactory.messageInterpolator
ValidationMessages


Public Methods
 MethodDefined by
  
Constructs a new DefaultMessageInterpolator instance.
DefaultMessageInterpolator
  
[static] Returns the unique instance of the ValidationMessages class (shortcut for ValidationMessages.getInstance()).
DefaultMessageInterpolator
  
interpolate(messageTemplate:String, constraint:IConstraint, value:String, locale:* = null):String
Interpolate the message template based on the contraint validation context and substitute message parameters according to the JSR-303 specification (section 4.3.1).
DefaultMessageInterpolator
  
split(messageTemplate:String):Array
[static] Splits a message template into an array of string literals and parameters.
DefaultMessageInterpolator
  
unescape(message:String):String
[static] Unescape the given string parameter, removing extraneous backslashs.
DefaultMessageInterpolator
Constructor detail
DefaultMessageInterpolator()constructor
public function DefaultMessageInterpolator()

Constructs a new DefaultMessageInterpolator instance.

Method detail
getBundle()method
public static function getBundle():ValidationMessages

Returns the unique instance of the ValidationMessages class (shortcut for ValidationMessages.getInstance()).

Returns
ValidationMessages — the unique instance of the ValidationMessages class.
interpolate()method 
public function interpolate(messageTemplate:String, constraint:IConstraint, value:String, locale:* = null):String

Interpolate the message template based on the contraint validation context and substitute message parameters according to the JSR-303 specification (section 4.3.1). Standard or user specific validation bundles are used for parameters resolution.

Parameters
messageTemplate:String — the message to interpolate.
 
constraint:IConstraint — the constraint related to the interpolation.
 
value:String — the invalid value (according to the current constraint).
 
locale:* (default = null) — an optional locale used for message localization.

Returns
String — the interpolated error message.

See also

split()method 
public static function split(messageTemplate:String):Array

Splits a message template into an array of string literals and parameters. For example, split('Must be in [{min}, {max}]') will return ['Must be in [', '{min}', ', ', '{max}', ']']). See JSR-303 specification section 4.3.1.

Parameters
messageTemplate:String — message template to be split into tokens.

Returns
Array — an array of string literals and parameters.
unescape()method 
public static function unescape(message:String):String

Unescape the given string parameter, removing extraneous backslashs. See JSR-303 specification section 4.3.1.

Parameters
message:String — the message to be unescaped.

Returns
String — the unescaped message.