nyla.solutions.global.patterns.validation.spring.OrREValidation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nyla.solutions.global Show documentation
Show all versions of nyla.solutions.global Show documentation
Nyla Solutions Global Java API provides support for basic application
utilities (application configuration, data encryption, debugger and text
processing).
The newest version!
package nyla.solutions.global.patterns.validation.spring;
import java.util.Iterator;
import java.util.TreeSet;
import nyla.solutions.global.util.Text;
import org.springframework.validation.Errors;
public class OrREValidation extends AbstractValidation implements org.springframework.validation.Validator
{
/**
*
* @param re the regular expression to map
*/
public void addRegularExpresion(String re)
{
regularExpressions.add(re);
}// --------------------------------------------
/**
*
*
* @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
*/
public void validate(Object object, Errors errors)
{
//get value
String value = this.retrieveTextValue(object);
//loop thru re
String re = null;
for (Iterator i = this.regularExpressions.iterator(); i.hasNext();)
{
re = (String) i.next();
if(Text.matches(value, re))
{
return; //found match
}
}
errors.reject(value); //does not match any of the regular expressionsb
}// --------------------------------------------
private java.util.Set regularExpressions = new TreeSet();
}