org.springmodules.validation.commons
Class MessageUtils

java.lang.Object
  extended by org.springmodules.validation.commons.MessageUtils

public abstract class MessageUtils
extends Object

Author:
Daniel Miller, Rob Harrop

Constructor Summary
MessageUtils()
           
 
Method Summary
static MessageSourceResolvable createMessage(Object obj)
          Create a MessageSourceResolvable using the string value of the parameter as a code.
static Object[] getArgs(org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field)
          

Gets the message arguments based on the current ValidatorAction and Field.

static Object getMessage(org.apache.commons.validator.Arg arg)
          Get the message associated with the argument.
static String getMessage(MessageSource messages, Locale locale, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field)
          Get a message for the given validator action and field from the specified message source.
static String getMessageKey(org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field)
          Gets the ActionError based on the ValidatorAction message and the Field's arg objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageUtils

public MessageUtils()
Method Detail

getMessageKey

public static String getMessageKey(org.apache.commons.validator.ValidatorAction va,
                                   org.apache.commons.validator.Field field)
Gets the ActionError based on the ValidatorAction message and the Field's arg objects.


getArgs

public static Object[] getArgs(org.apache.commons.validator.ValidatorAction va,
                               org.apache.commons.validator.Field field)

Gets the message arguments based on the current ValidatorAction and Field. The array returned here is an array of MessageSourceResolvable's that will be resolved at a later time.

Note: this implementation is especially crappy (only four arguments are supported), but it's the best we can do until the next version of validator-validator is out of beta.

-param actionName action name.

Parameters:
field - the validator field.
Returns:
array of message keys.

getMessage

public static Object getMessage(org.apache.commons.validator.Arg arg)
Get the message associated with the argument. If the resource flag is set to false, use the text specified in the argument key directly. Otherwise, create a MessageSourceResolvable with the argument key as its code.


createMessage

public static MessageSourceResolvable createMessage(Object obj)
Create a MessageSourceResolvable using the string value of the parameter as a code.

Note: this implementation uses the key of the Fields message for the given ValidatorAction as the default message.

Parameters:
obj - Object whose string value is the code for this message.
Returns:
MessageSourceResolvable for the given Object.

getMessage

public static String getMessage(MessageSource messages,
                                Locale locale,
                                org.apache.commons.validator.ValidatorAction va,
                                org.apache.commons.validator.Field field)
Get a message for the given validator action and field from the specified message source.

Note: this implementation uses the key of the Fields message for the given ValidatorAction as the default message.

Parameters:
messages - MessageSource from which to get the message.
locale - Locale for for this message.
va - ValidatorAction for this message.
field - Field field for this message.


Copyright © 2009. All Rights Reserved.