Esempio n. 1
0
 public boolean validate(Problems problems, String compName, String model) {
   Exception e = null;
   try {
     Charset.forName(model);
   } catch (IllegalCharsetNameException badName) {
     problems.add(
         NbBundle.getMessage(
             CharsetValidator.class, "ILLEGAL_CHARSET_NAME", compName, model)); // NOI18N
     e = badName;
   } catch (UnsupportedCharsetException unsup) {
     problems.add(
         NbBundle.getMessage(
             CharsetValidator.class, "UNSUPPORTED_CHARSET_NAME", compName, model)); // NOI18N
     e = unsup;
   }
   return e == null;
 }
 private boolean validate(String realName, String address, Problems problems, String compName) {
   String[] nameAndHost = address.split("@");
   if (nameAndHost.length == 1 && nameAndHost[0].contains("@")) {
     problems.add(
         NbBundle.getMessage(
             EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0]));
     return false;
   }
   if (nameAndHost.length > 2) {
     problems.add(
         NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_HAS_>1_@", compName, address));
     return false;
   }
   String name = nameAndHost[0];
   if (name.length() == 0) {
     problems.add(
         NbBundle.getMessage(EmailAddressValidator.class, "EMAIL_MISSING_NAME", compName, name));
     return false;
   }
   if (name.length() > 64) {
     problems.add(
         new Problem(
             NbBundle.getMessage(
                 EmailAddressValidator.class, "ADDRESS_MAY_BE_TOO_LONG", compName, name),
             Severity.WARNING));
   }
   String host = nameAndHost.length >= 2 ? nameAndHost[1] : null;
   boolean result = host != null;
   if (result) {
     result = hv.validate(problems, compName, host);
     if (result) {
       MayNotContainSpacesValidator v = new MayNotContainSpacesValidator();
       result = v.validate(problems, compName, name);
     }
     Validator<String> v = new EncodableInCharsetValidator("US-ASCII");
     if (result) {
       result = v.validate(problems, compName, address);
     }
   } else {
     problems.add(
         NbBundle.getMessage(
             EmailAddressValidator.class, "EMAIL_MISSING_HOST", compName, nameAndHost[0]));
   }
   return result;
 }
Esempio n. 3
0
 public boolean validate(Problems problems, String compName, String model) {
   boolean result = model.length() >= len;
   if (!result) {
     problems.add(
         NbBundle.getMessage(
             MaximumLength.class, "STRING_TOO_SHORT", compName, model, "" + len)); // NOI18N
   }
   return result;
 }
 @Override
 public void validate(Problems problems, String compName, String model) {
   try {
     fmt.parseObject(model);
   } catch (ParseException ex) {
     problems.add(
         NbBundle.getMessage(
             FormatValidator.class,
             "MSG_DOES_NOT_MATCH_NUMBER_FORMAT",
             compName,
             model)); // NOI18N
   }
 }
Esempio n. 5
0
 @Override
 public boolean validate(Problems problems, String compName, String model) {
   boolean result = true;
   if (panel.regexCheckbox.isSelected()) {
     try {
       Pattern p = Pattern.compile(model);
     } catch (Exception e) {
       result = false;
     }
     if (!result) {
       String message = "Invalid regex";
       problems.add(message);
     }
   }
   return result;
 }
 @Override
 public boolean validate(Problems problems, String compName, String model) {
   boolean result = false;
   try {
     Double d = Double.parseDouble(model);
     result = d >= 0 && d <= 1;
   } catch (Exception e) {
   }
   if (!result) {
     String message =
         NbBundle.getMessage(
             PositiveNumberValidator.class, "PositiveNumberValidator_NOT_POSITIVE", model);
     problems.add(message);
   }
   return result;
 }