Exemplo n.º 1
0
 @Override
 public boolean isValid(String tld, ConstraintValidatorContext context) {
   if (tld == null) {
     return true;
   }
   if (types.contains(TLDType.COUNTRY)) {
     if (DomainValidator.getInstance().isValidCountryCodeTld(tld)) {
       return true;
     }
   }
   if (types.contains(TLDType.GENERIC)) {
     if (DomainValidator.getInstance().isValidGenericTld(tld)) {
       return true;
     }
   }
   if (types.contains(TLDType.INFRASTRUCTURE)) {
     if (DomainValidator.getInstance().isValidInfrastructureTld(tld)) {
       return true;
     }
   }
   if (types.contains(TLDType.LOCAL)) {
     if (DomainValidator.getInstance().isValidLocalTld(tld)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 2
0
 @Override
 public IStatus validate(Object value) {
   if (InetAddressValidator.getInstance().isValid(value.toString())
       || DomainValidator.getInstance(true).isValid(value.toString())) {
     return ValidationStatus.ok();
   }
   return ValidationStatus.error("Invalid host name or IP address"); // $NON-NLS-1$
 }
  @Override
  public boolean isValid(String value, ConstraintValidatorContext context) {
    if (value == null) {
      return false;
    }

    if (!InetAddressValidator.getInstance().isValid(value)
        && !DomainValidator.getInstance().isValid(value)) {
      context.disableDefaultConstraintViolation();
      context
          .buildConstraintViolationWithTemplate(
              String.format("%s is invalid IP or Domain Address", value))
          .addConstraintViolation();
      return false;
    }

    return true;
  }