コード例 #1
1
  public ValidationResult validate() {
    PropertyValidationSupport infoSupport = new PropertyValidationSupport(model, "Info");

    if (ValidationUtils.isBlank(model.getAppName())) {
      infoSupport.addError("application name", "is mandatory");
    }

    if (ValidationUtils.isBlank(model.getVersion())) {
      infoSupport.addError("application version", "is mandatory");
    }

    // A simple way to check if a homepage URL is valid
    try {
      if (model.getHomepage() != null && model.getHomepage().length() != 0)
        new URL(model.getHomepage());
    } catch (MalformedURLException murle) {
      infoSupport.addError("homepage", "is not a valid URL: " + murle.getLocalizedMessage());
    }

    PropertyValidationSupport localeSupport = new PropertyValidationSupport(model, "Locale");

    if (model.getLangCodes().size() == 0) {
      localeSupport.addError("langpacks", "must have at least one language added");
    }

    PropertyValidationSupport guiPrefsSupport = new PropertyValidationSupport(model, "GUIPrefs");

    // Check for 0 sizes
    // Warn for small sizes
    // TODO find good values for these
    if (model.getWidth() == 0) {
      guiPrefsSupport.addError("width", "must not be 0");
    } else if (model.getWidth() < 400) {
      guiPrefsSupport.addWarning("width", "may be too small to display correctly");
    }

    if (model.getHeight() == 0) {
      guiPrefsSupport.addError("height", "must not be 0");
    } else if (model.getHeight() < 400) {
      guiPrefsSupport.addWarning("height", "may be too small to display correctly");
    }

    ValidationResult vr = new ValidationResult();

    vr.addAllFrom(infoSupport.getResult());
    vr.addAllFrom(localeSupport.getResult());
    vr.addAllFrom(guiPrefsSupport.getResult());

    return vr;
  }
コード例 #2
0
  /**
   * Validates this Validator's Order and returns the result as an instance of {@link
   * com.jgoodies.validation.ValidationResult}.
   *
   * @return the ValidationResult of the accession validation
   */
  public ValidationResult validate() {

    ArchDescriptionPhysicalDescriptions modelToValidate =
        (ArchDescriptionPhysicalDescriptions) objectToValidate;

    ATPropertyValidationSupport support =
        new ATPropertyValidationSupport(modelToValidate, "Physical Description");

    if (ValidationUtils.isBlank(modelToValidate.getExtentType()))
      support.addError("Extent Type", "is mandatory");

    if (modelToValidate.getExtentNumber() == null || modelToValidate.getExtentNumber() == 0)
      support.addError("Extent", "is mandatory");

    checkForStringLengths(modelToValidate, support);

    return support.getResult();
  }
コード例 #3
0
 /**
  * Returns a String representation of the Object <code>value</code>. This invokes <code>format
  * </code> on the current <code>Format</code>.
  *
  * <p>Unlike its superclass, this class converts the empty value to the empty string.
  *
  * @param value the value to convert
  * @return a String representation of value
  * @throws ParseException if there is an error in the conversion
  */
 @Override
 public String valueToString(Object value) throws ParseException {
   return ValidationUtils.equals(value, emptyValue) ? "" : super.valueToString(value);
 }
コード例 #4
0
 /**
  * Returns the <code>Object</code> representation of the <code>String</code> <code>text</code>.
  *
  * <p>Unlike its superclass, this class converts blank strings to the empty value.
  *
  * @param text <code>String</code> to convert
  * @return <code>Object</code> representation of text
  * @throws ParseException if there is an error in the conversion
  */
 @Override
 public Object stringToValue(String text) throws ParseException {
   return ValidationUtils.isBlank(text) ? emptyValue : super.stringToValue(text);
 }