/** * test Field with only 'default' arguments, no positions specified. */ public void testDefaultPositionImplied() { field.addArg(createArg("default-position-0")); field.addArg(createArg("default-position-1")); field.addArg(createArg("default-position-2")); assertEquals("testDefaultPositionImplied(1) ", 3, field.getArgs("required").length); assertEquals("testDefaultPositionImplied(2) ", "default-position-0", field.getArg("required", 0).getKey()); assertEquals("testDefaultPositionImplied(3) ", "default-position-1", field.getArg("required", 1).getKey()); assertEquals("testDefaultPositionImplied(4) ", "default-position-2", field.getArg("required", 2).getKey()); }
@Override public void begin(String namespace, String name, Attributes attributes) throws Exception { // Create the Arg Arg arg = new Arg(); arg.setKey(attributes.getValue("key")); arg.setName(attributes.getValue("name")); if ("false".equalsIgnoreCase(attributes.getValue("resource"))) { arg.setResource(false); } try { final int length = "arg".length(); // skip the arg prefix arg.setPosition(Integer.parseInt(name.substring(length))); } catch (Exception ex) { getLog().error("Error parsing Arg position: " + name + " " + arg + " " + ex); } // Add the arg to the parent field ((Field)getDigester().peek(0)).addArg(arg); } };
/** * Makes a deep copy of a <code>Map</code> if the values are * <code>Msg</code>, <code>Arg</code>, or <code>Var</code>. Otherwise, * it is a shallow copy. * * @param map The source Map to copy. * * @return A copy of the <code>Map</code> that was passed in. */ public static Map<String, Object> copyMap(Map<String, Object> map) { Map<String, Object> results = new HashMap<String, Object>(); Iterator<Entry<String, Object>> i = map.entrySet().iterator(); while (i.hasNext()) { Entry<String, Object> entry = i.next(); String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Msg) { results.put(key, ((Msg) value).clone()); } else if (value instanceof Arg) { results.put(key, ((Arg) value).clone()); } else if (value instanceof Var) { results.put(key, ((Var) value).clone()); } else { results.put(key, value); } } return results; }
int position = arg.getPosition(); arg.setPosition(0); return; String key = arg.getName() == null ? DEFAULT_ARG : arg.getName(); int lastPosition = -1; int lastDefault = -1; arg.setPosition(++lastPosition);
/** * Add an <code>Arg</code> to the replacement argument list. * @since Validator 1.1 * @param arg Validation message's argument. */ public void addArg(Arg arg) { // TODO this first if check can go away after arg0, etc. are removed from dtd if (arg == null || arg.getKey() == null || arg.getKey().length() == 0) { return; } determineArgPosition(arg); ensureArgsCapacity(arg); Map<String, Arg> argMap = this.args[arg.getPosition()]; if (argMap == null) { argMap = new HashMap<String, Arg>(); this.args[arg.getPosition()] = argMap; } if (arg.getName() == null) { argMap.put(DEFAULT_ARG, arg); } else { argMap.put(arg.getName(), arg); } }
/** * Replace the arg <code>Collection</code> key value with the key/value * pairs passed in. */ private void processArg(String key, String replaceValue) { for (int i = 0; i < this.args.length; i++) { Map<String, Arg> argMap = this.args[i]; if (argMap == null) { continue; } Iterator<Arg> iter = argMap.values().iterator(); while (iter.hasNext()) { Arg arg = iter.next(); if (arg != null) { arg.setKey( ValidatorUtils.replace(arg.getKey(), key, replaceValue)); } } } }
/** * 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. */ public static Object getMessage(Arg arg) { if (arg.isResource()) { return MessageUtils.createMessage(arg.getKey()); } else { return arg.getKey(); } }
public static void bindField(Form form, RuleList rules, String columnName, String displayName, String indexedLIstProperty) { Field newField = rules.createField(columnName); if (indexedLIstProperty != null) { newField.setIndexedListProperty(indexedLIstProperty); } Arg arg = new Arg(); arg.setKey(displayName); arg.setResource(false); newField.addArg(arg); // for(Iterator i=rules.extraArgs.iterator();i.hasNext();){ // newField.addArg((Arg)i.next()); // } form.addField(newField); }
for (int i = 0; i < args.length; i++) { if (args[i] != null) { if (args[i].isResource()) { if (args[i].getBundle() != null) { messages = getMessageResources(application, request, args[i].getBundle()); values[i] = messages.getMessage(locale, args[i].getKey()); values[i] = args[i].getKey();
/** * Convenience Method - create argument (no name, position specified) */ private Arg createArg(String key, int position) { Arg arg = createArg(key); arg.setPosition(position); return arg; }
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArgList{ public static void main(String[] args) { //args1=msg args2=flow args3=content args4=depth args6=within ==> args5=content List<Arg> l = new ArrayList<Arg>(); // hard-coded example instead of more likely parsing l.add(new Arg(1, "msg")); l.add(new Arg(2, "flow")); l.add(new Arg(3, "content")); l.add(new Arg(4, "depth")); l.add(new Arg(5, "flow")); l.add(new Arg(6, "within")); Collections.sort(l, new ArgValComparator()); // take your pick of comparators System.out.println(l); // uses the toString() of Arg. } }
/** * Convenience Method - create argument (name specified, no position) */ private Arg createArg(String key, String name) { Arg arg = createArg(key); arg.setName(name); return arg; }
/** * Replace the arg <code>Collection</code> key value with the key/value * pairs passed in. */ private void processArg(String key, String replaceValue) { for (int i = 0; i < this.args.length; i++) { Map<String, Arg> argMap = this.args[i]; if (argMap == null) { continue; } Iterator<Arg> iter = argMap.values().iterator(); while (iter.hasNext()) { Arg arg = iter.next(); if (arg != null) { arg.setKey( ValidatorUtils.replace(arg.getKey(), key, replaceValue)); } } } }
if (arg != null) if (arg.isResource()) arg.getKey(), null); argMessages[ctr] = arg.getKey();
rules.addVar(var); Arg arg = new Arg(); arg.setKey("" + length); arg.setResource(false); rules.extraArgs.add(arg);
/** * Add an <code>Arg</code> to the replacement argument list. * @since Validator 1.1 * @param arg Validation message's argument. */ public void addArg(Arg arg) { // TODO this first if check can go away after arg0, etc. are removed from dtd if (arg == null || arg.getKey() == null || arg.getKey().length() == 0) { return; } determineArgPosition(arg); ensureArgsCapacity(arg); Map argMap = this.args[arg.getPosition()]; if (argMap == null) { argMap = new HashMap(); this.args[arg.getPosition()] = argMap; } if (arg.getName() == null) { argMap.put(DEFAULT_ARG, arg); } else { argMap.put(arg.getName(), arg); } }
if (args[i].isResource()) { MessageResources messages = defaultMessages; if (args[i].getBundle() != null) { messages = getMessageResources(application, request, args[i].getBundle()); values[i] = messages.getMessage(locale, args[i].getKey()); } else { values[i] = args[i].getKey();
int position = arg.getPosition(); arg.setPosition(0); return; String key = arg.getName() == null ? DEFAULT_ARG : arg.getName(); int lastPosition = -1; int lastDefault = -1; arg.setPosition(++lastPosition);
/** * Convenience Method - create argument (name & position specified) */ private Arg createArg(String key, String name, int position) { Arg arg = createArg(key, name); arg.setPosition(position); return arg; }