DefaultMessageInterpolator.java :  » GWT » gwt-validation » com » google » gwt » validation » client » Java Open Source

Java Open Source » GWT » gwt validation 
gwt validation » com » google » gwt » validation » client » DefaultMessageInterpolator.java
/**
 * 
 */
package com.google.gwt.validation.client;

import java.util.Map;
import java.util.Map.Entry;

import com.google.gwt.validation.client.interfaces.GWTMessageInterpolator;

/**
 * Message interpolator switching parameters of the constraint in the message
 * for real values.
 * 
 * Example: @Size has "min" and "max" arguments which user would like to see as
 * constraint boundaries. Message interpolator replaces the occurence of \{min\}
 * and \{max\} parameter placeholders in the message string (output of
 * ValidatorMessages) with the real values specified for the field.
 * 
 * @author ladislav.gazo
 */
public class DefaultMessageInterpolator implements GWTMessageInterpolator {
  @Override
  public String interpolate(String template, Map<String, String> validatorArguments) {
    String message = template;
    for (Entry<String, String> entry : validatorArguments.entrySet()) {
      message = message.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue());
    }
    return message;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.