예제 #1
0
 /**
  * Convert the error arguments.
  *
  * @param arguments The arguments to convert.
  * @return The converted arguments.
  */
 private List<Object> convertErrorArguments(Object[] arguments) {
   List<Object> converted = new ArrayList<>(arguments.length);
   for (Object arg : arguments) {
     if (!(arg instanceof org.springframework.context.support.DefaultMessageSourceResolvable)) {
       converted.add(arg);
     }
   }
   return Collections.unmodifiableList(converted);
 }
예제 #2
0
    /** Return the indexes available for this field (for repeated fields ad List) */
    @SuppressWarnings("rawtypes")
    public List<Integer> indexes() {
      if (form.value().isPresent()) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(form.value().get());
        beanWrapper.setAutoGrowNestedPaths(true);
        String objectKey = name;
        if (form.name() != null && name.startsWith(form.name() + ".")) {
          objectKey = name.substring(form.name().length() + 1);
        }

        List<Integer> result = new ArrayList<>();
        if (beanWrapper.isReadableProperty(objectKey)) {
          Object value = beanWrapper.getPropertyValue(objectKey);
          if (value instanceof Collection) {
            for (int i = 0; i < ((Collection) value).size(); i++) {
              result.add(i);
            }
          }
        }

        return result;

      } else {
        Set<Integer> result = new HashSet<>();
        Pattern pattern = Pattern.compile("^" + Pattern.quote(name) + "\\[(\\d+)\\].*$");

        for (String key : form.data().keySet()) {
          java.util.regex.Matcher matcher = pattern.matcher(key);
          if (matcher.matches()) {
            result.add(Integer.parseInt(matcher.group(1)));
          }
        }

        List<Integer> sortedResult = new ArrayList<>(result);
        Collections.sort(sortedResult);
        return sortedResult;
      }
    }