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

jodd.vtor.constraint.WildcardMatchConstraint Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.vtor.constraint;

import jodd.util.Wildcard;
import jodd.vtor.ValidationConstraint;
import jodd.vtor.ValidationConstraintContext;

public class WildcardMatchConstraint implements ValidationConstraint {

	public WildcardMatchConstraint() {
	}

	public WildcardMatchConstraint(String pattern) {
		this.pattern = pattern;
	}

	// ---------------------------------------------------------------- properties

	protected String pattern;

	public String getPattern() {
		return pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	// ---------------------------------------------------------------- configure
	
	public void configure(WildcardMatch annotation) {
		pattern = annotation.value();
	}

	// ---------------------------------------------------------------- valid

	public boolean isValid(ValidationConstraintContext vcc, Object value) {
		return validate(value, pattern);
	}

	public static boolean validate(Object value, String pattern) {
		if (value == null) {
			return true;
		}
		return Wildcard.match(value.toString(), pattern);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy