play.data.validation.IPv6AddressCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
RePlay is a fork of the Play1 framework, created by Codeborne.
package play.data.validation;
import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;
import net.sf.oval.exception.OValException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IPv6AddressCheck extends AbstractAnnotationCheck {
static final String mes = "validation.ipv6";
@Override
public void configure(IPv6Address phone) {
setMessage(phone.message());
}
@Override
public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator)
throws OValException {
if (value == null || value.toString().length() == 0) {
return true;
}
try {
InetAddress addr = InetAddress.getByName(value.toString());
return addr instanceof Inet6Address;
} catch (UnknownHostException e) {
return false;
}
}
}