All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.data.validation.MatchCheck Maven / Gradle / Ivy

There is a newer version: 2.6.2
Show newest version
package play.data.validation;

import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

@SuppressWarnings("serial")
public class MatchCheck extends AbstractAnnotationCheck {

    static final String mes = "validation.match";
    Pattern pattern = null;

    @Override
    public void configure(Match match) {
        setMessage(match.message());
        pattern = Pattern.compile(match.value());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        requireMessageVariablesRecreation();
        if (value == null || value.toString().length() == 0) {
            return true;
        }
        return pattern.matcher(value.toString()).matches();
    }

    @Override
    public Map createMessageVariables() {
        Map messageVariables = new HashMap<>();
        messageVariables.put("pattern", pattern.toString());
        return messageVariables;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy