Example usage for org.apache.commons.validator Field getArg

List of usage examples for org.apache.commons.validator Field getArg

Introduction

In this page you can find the example usage for org.apache.commons.validator Field getArg.

Prototype

public Arg getArg(String key, int position) 

Source Link

Document

Gets the Arg object at the given position.

Usage

From source file:org.apache.struts.validator.Resources.java

/**
 * Gets the message arguments based on the current <code>ValidatorAction</code>
 * and <code>Field</code>./*from w  ww .j  a  v a  2  s .  co  m*/
 *
 * @param actionName action name
 * @param messages   message resources
 * @param locale     the locale
 * @param field      the validator field
 */
public static String[] getArgs(String actionName, MessageResources messages, Locale locale, Field field) {
    String[] argMessages = new String[4];

    Arg[] args = new Arg[] { field.getArg(actionName, 0), field.getArg(actionName, 1),
            field.getArg(actionName, 2), field.getArg(actionName, 3) };

    for (int i = 0; i < args.length; i++) {
        if (args[i] == null) {
            continue;
        }

        if (args[i].isResource()) {
            argMessages[i] = getMessage(messages, locale, args[i].getKey());
        } else {
            argMessages[i] = args[i].getKey();
        }
    }

    return argMessages;
}

From source file:org.springmodules.commons.validator.MessageUtils.java

/**
 * <p/>//from w w w  .j  av a 2s .  com
 * Gets the message arguments based on the current
 * <code>ValidatorAction</code> and <code>Field</code>. The array
 * returned here is an array of MessageSourceResolvable's that will be
 * resolved at a later time.
 * </p>
 * <p/>
 * <p/>
 * 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.
 * </p>
 * <p/>
 * -param actionName
 * action name.
 *
 * @param field the validator field.
 * @return array of message keys.
 */
public static Object[] getArgs(ValidatorAction va, Field field) {

    List args = new ArrayList();
    String actionName = va.getName();

    if (field.getArg(actionName, 0) != null) {
        args.add(0, getMessage(field.getArg(actionName, 0)));
    }

    if (field.getArg(actionName, 1) != null) {
        args.add(1, getMessage(field.getArg(actionName, 1)));
    }

    if (field.getArg(actionName, 2) != null) {
        args.add(2, getMessage(field.getArg(actionName, 2)));
    }

    if (field.getArg(actionName, 3) != null) {
        args.add(3, getMessage(field.getArg(actionName, 3)));
    }

    return args.toArray();
}

From source file:org.springmodules.validation.commons.MessageUtils.java

/**
 * <p/>//from   w  w  w.j  av  a2  s.c o  m
 * Gets the message arguments based on the current
 * <code>ValidatorAction</code> and <code>Field</code>. The array
 * returned here is an array of MessageSourceResolvable's that will be
 * resolved at a later time.
 * </p>
 * <p/>
 * <p/>
 * 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.
 * </p>
 * <p/>
 * -param actionName
 * action name.
 *
 * @param field the validator field.
 * @return array of message keys.
 */
public static Object[] getArgs(ValidatorAction va, Field field) {

    List args = new ArrayList();
    String actionName = va.getName();

    if (field.getArg(actionName, 0) != null) {
        args.add(0, MessageUtils.getMessage(field.getArg(actionName, 0)));
    }

    if (field.getArg(actionName, 1) != null) {
        args.add(1, MessageUtils.getMessage(field.getArg(actionName, 1)));
    }

    if (field.getArg(actionName, 2) != null) {
        args.add(2, MessageUtils.getMessage(field.getArg(actionName, 2)));
    }

    if (field.getArg(actionName, 3) != null) {
        args.add(3, MessageUtils.getMessage(field.getArg(actionName, 3)));
    }

    return args.toArray();
}