Esempio n. 1
0
 public void validate(IValidatable<List<FileUpload>> pValidatables) {
   for (FileUpload image : pValidatables.getValue()) {
     String extension = FilenameUtils.getExtension(image.getClientFileName());
     if (extension != null && !extensions.contains(extension.toLowerCase())) {
       ValidationError error = new ValidationError();
       error.addKey("WrongExtensionValidator");
       error.setVariable("extensions", extensions.toString());
       pValidatables.error(error);
     }
   }
 }
Esempio n. 2
0
    @Override
    public void validate(IValidatable<List<Grid>> validatable) {
      ValidationError error = new ValidationError();

      List<Grid> grids = validatable.getValue();
      if (grids == null || grids.size() == 0) {
        error.setMessage(new ResourceModel("TileMatrixSetEditor.validation.empty").getObject());
        validatable.error(error);
        return;
      }

      for (int i = 1; i < grids.size(); i++) {
        Grid prev = grids.get(i - 1);
        Grid curr = grids.get(i);

        if (curr.getResolution() >= prev.getResolution()) {
          String message =
              "Each resolution should be lower than it's prior one. Res["
                  + i
                  + "] == "
                  + curr.getResolution()
                  + ", Res["
                  + (i - 1)
                  + "] == "
                  + prev.getResolution()
                  + ".";
          error.setMessage(message);
          validatable.error(error);
          return;
        }

        if (curr.getScaleDenominator() >= prev.getScaleDenominator()) {
          String message =
              "Each scale denominator should be lower "
                  + "than it's prior one. Scale["
                  + i
                  + "] == "
                  + curr.getScaleDenominator()
                  + ", Scale["
                  + (i - 1)
                  + "] == "
                  + prev.getScaleDenominator()
                  + ".";
          error.setMessage(message);
          validatable.error(error);
          return;
        }
      }
    }
Esempio n. 3
0
    private void error(
        IValidatable<Set<XMLGridSubset>> validatable,
        final String resourceKey,
        final String... params) {

      ValidationError error = new ValidationError();
      String message;
      if (params == null) {
        message = new ResourceModel(resourceKey).getObject();
      } else {
        message =
            new ParamResourceModel(resourceKey, GridSubsetsEditor.this, (Object[]) params)
                .getObject();
      }
      error.setMessage(message);
      validatable.error(error);
    }
 public void validate(final IValidatable<Z> validatable) {
   final Z value = validatable.getValue();
   final Z min = this.getMinimum();
   final Z max = this.getMaximum();
   if ((min != null && ((Comparable) value).compareTo(min) < 0)
       || (max != null && ((Comparable) value).compareTo(max) > 0)) {
     final ValidationError error = new ValidationError();
     error.addMessageKey(this.resourceKey());
     if (min != null) {
       error.setVariable("minimum", min);
     }
     if (max != null) {
       error.setVariable("maximum", max);
     }
     validatable.error(error);
   }
 }
Esempio n. 5
0
  /**
   * Robbed from {@link FormComponent}
   *
   * @param e
   * @param error
   */
  private void reportValidationError(ConversionException e, ValidationError error) {
    final Locale locale = e.getLocale();
    if (locale != null) {
      error.setVariable("locale", locale);
    }
    error.setVariable("exception", e);
    Format format = e.getFormat();
    if (format instanceof SimpleDateFormat) {
      error.setVariable("format", ((SimpleDateFormat) format).toLocalizedPattern());
    }

    Map<String, Object> variables = e.getVariables();
    if (variables != null) {
      error.getVariables().putAll(variables);
    }

    error((IValidationError) error);
  }
Esempio n. 6
0
 @SuppressWarnings("unchecked")
 private Collection<T> convertInput(String[] inputs) {
   if (getType() == null) {
     try {
       return convertValue(inputs);
     } catch (ConversionException e) {
       ValidationError error = new ValidationError();
       if (e.getResourceKey() != null) {
         error.addMessageKey(e.getResourceKey());
       }
       if (e.getTargetType() != null) {
         error.addMessageKey("ConversionError." + Classes.simpleName(e.getTargetType()));
       }
       error.addMessageKey("ConversionError");
       reportValidationError(e, error);
     }
   } else {
     final IConverter converter = getConverter(getType());
     String curInput = "";
     try {
       Collection<T> convertedInput = new ArrayList<T>();
       if (inputs != null) {
         for (String input : inputs) {
           curInput = input;
           convertedInput.add(((T) converter.convertToObject(curInput, getLocale())));
         }
       }
       return convertedInput;
     } catch (ConversionException e) {
       ValidationError error = new ValidationError();
       if (e.getResourceKey() != null) {
         error.addMessageKey(e.getResourceKey());
       }
       String simpleName = Classes.simpleName(getType());
       error.addMessageKey("IConverter." + simpleName);
       error.addMessageKey("IConverter");
       error.setVariable("type", simpleName);
       error.setVariable("input", curInput);
       reportValidationError(e, error);
     }
   }
   return null;
 }
Esempio n. 7
0
  @Override
  protected ValidationError decorate(ValidationError error, IValidatable<Date> validatable) {
    error = super.decorate(error, validatable);

    error.setVariable("inputdate", validatable.getValue());

    // format variables if format has been specified
    if (format != null) {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      if (getMinimum() != null) {
        error.setVariable("minimum", sdf.format(getMinimum()));
      }
      if (getMaximum() != null) {
        error.setVariable("maximum", sdf.format(getMaximum()));
      }
      error.setVariable("inputdate", sdf.format(validatable.getValue()));
    }

    return error;
  }
Esempio n. 8
0
  @Override
  protected void convertInput() {
    Integer lower = this.lower.getConvertedInput();
    Integer upper = this.upper.getConvertedInput();

    if (lower != null && upper != null) {
      RangeValue value = new RangeValue(lower, upper);

      if (value.getLower() <= value.getUpper()) {
        this.setConvertedInput(value);
      } else {
        ValidationError error = new ValidationError();
        error.addKey("RangeSlider.ConversionError"); // wicket6
        error.setVariable("lower", value.getLower());
        error.setVariable("upper", value.getUpper());

        this.error(error);
      }
    }
  }
  // Methods //
  @Override
  protected void convertInput() {
    final IConverter<Date> converter = this.getConverter(Date.class);

    String dateInput = this.datePicker.getInput();
    String timeInput = this.timePicker.getInput();

    try {
      Date date =
          converter.convertToObject(this.formatInput(dateInput, timeInput), this.getLocale());
      this.setConvertedInput(date);
    } catch (ConversionException e) {
      ValidationError error = new ValidationError();
      error.addKey("DateTimePicker.ConversionError"); // wicket6
      error.setVariable("date", dateInput);
      error.setVariable("time", timeInput);

      this.error(error);
    }
  }
 private void error(IValidatable<String> validatable, String errorKey) {
   ValidationError error = new ValidationError();
   error.addKey(getClass().getSimpleName() + "." + errorKey);
   error.setMessage(errorKey);
   validatable.error(error);
 }
 private ValidationError decorate(ValidationError validationError) {
   validationError.addKey(errorKey);
   return validationError;
 }