コード例 #1
0
 /**
  * Merge the given array into the given Collection.
  *
  * @param array the array to merge (may be <code>null</code>)
  * @param collection the target Collection to merge the array into
  */
 public static void mergeArrayIntoCollection(Object array, Collection<Object> collection) {
   if (collection == null) {
     throw new IllegalArgumentException("Collection must not be null");
   }
   Object[] arr = ObjectUtils.toObjectArray(array);
   for (Object elem : arr) {
     collection.add(elem);
   }
 }
コード例 #2
0
 protected void handleResult(Object result) {
   if (result.getClass().isArray()) {
     Object[] events = ObjectUtils.toObjectArray(result);
     for (Object event : events) {
       publishEvent(event);
     }
   } else if (result instanceof Collection<?>) {
     Collection<?> events = (Collection<?>) result;
     for (Object event : events) {
       publishEvent(event);
     }
   } else {
     publishEvent(result);
   }
 }
コード例 #3
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 private Map<String, Object> resolveParameters(Message<?> message) {
   Map<String, Object> map = null;
   if (message.getPayload() instanceof Map) {
     map = (Map<String, Object>) message.getPayload();
   } else if (message.getPayload() instanceof List) {
     map = this.createParameterMapFromList((List) message.getPayload());
   } else if (message.getPayload() != null && message.getPayload().getClass().isArray()) {
     map =
         this.createParameterMapFromList(
             Arrays.asList(ObjectUtils.toObjectArray(message.getPayload())));
   } else if (message.getPayload() != null) {
     map = this.createParameterMapFromList(Collections.singletonList(message.getPayload()));
   } else {
     map = Collections.EMPTY_MAP;
   }
   return map;
 }
コード例 #4
0
  /**
   * Append query properties to the redirect URL. Stringifies, URL-encodes and formats model
   * attributes as query properties.
   *
   * @param targetUrl the StringBuilder to append the properties to
   * @param model Map that contains model attributes
   * @param encodingScheme the encoding scheme to use
   * @throws UnsupportedEncodingException if string encoding failed
   * @see #queryProperties
   */
  protected void appendQueryProperties(
      StringBuilder targetUrl, Map<String, Object> model, String encodingScheme)
      throws UnsupportedEncodingException {

    // Extract anchor fragment, if any.
    String fragment = null;
    int anchorIndex = targetUrl.indexOf("#");
    if (anchorIndex > -1) {
      fragment = targetUrl.substring(anchorIndex);
      targetUrl.delete(anchorIndex, targetUrl.length());
    }

    // If there aren't already some parameters, we need a "?".
    boolean first = (targetUrl.toString().indexOf('?') < 0);
    for (Map.Entry<String, Object> entry : queryProperties(model).entrySet()) {
      Object rawValue = entry.getValue();
      Iterator<Object> valueIter;
      if (rawValue != null && rawValue.getClass().isArray()) {
        valueIter = Arrays.asList(ObjectUtils.toObjectArray(rawValue)).iterator();
      } else if (rawValue instanceof Collection) {
        valueIter = ((Collection) rawValue).iterator();
      } else {
        valueIter = Collections.singleton(rawValue).iterator();
      }
      while (valueIter.hasNext()) {
        Object value = valueIter.next();
        if (first) {
          targetUrl.append('?');
          first = false;
        } else {
          targetUrl.append('&');
        }
        String encodedKey = urlEncode(entry.getKey(), encodingScheme);
        String encodedValue = (value != null ? urlEncode(value.toString(), encodingScheme) : "");
        targetUrl.append(encodedKey).append('=').append(encodedValue);
      }
    }

    // Append anchor fragment, if any, to end of URL.
    if (fragment != null) {
      targetUrl.append(fragment);
    }
  }
コード例 #5
0
 /**
  * Convert the supplied array into a List. A primitive array gets converted into a List of the
  * appropriate wrapper type.
  *
  * <p>A <code>null</code> source value will be converted to an empty List.
  *
  * @param source the (potentially primitive) array
  * @return the converted List result
  * @see ObjectUtils#toObjectArray(Object)
  */
 public static List<?> arrayToList(Object source) {
   return Arrays.asList(ObjectUtils.toObjectArray(source));
 }