public static <R extends HttpRequest> R indexMapOfIterableToFormValuesWithPrefix( R request, String prefix, String keySuffix, String valueSuffix, Object input) { checkArgument( checkNotNull(input, "input") instanceof Map<?, ?>, "this binder is only valid for Map<?,Iterable<?>>: " + input.getClass()); Map<Object, Iterable<Object>> map = (Map<Object, Iterable<Object>>) input; Builder<String, String> builder = ImmutableMultimap.builder(); int i = 1; for (Map.Entry<Object, Iterable<Object>> entry : map.entrySet()) { builder.put( prefix + "." + i + "." + keySuffix, checkNotNull(entry.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]")); Iterable<Object> iterable = entry.getValue(); if (!Iterables.isEmpty(iterable)) { int j = 1; for (Object v : iterable) { builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString()); j++; } } i++; } ImmutableMultimap<String, String> forms = builder.build(); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
public static <R extends HttpRequest> R indexMapToFormValuesWithPrefix( R request, String prefix, String keySuffix, String valueSuffix, Object input) { checkArgument( checkNotNull(input, "input") instanceof Map<?, ?>, "this binder is only valid for Map<?,?>: " + input.getClass()); Map<?, ?> map = (Map<?, ?>) input; Builder<String, String> builder = ImmutableMultimap.builder(); int i = 1; for (Map.Entry<?, ?> e : map.entrySet()) { builder.put( prefix + "." + i + "." + keySuffix, checkNotNull(e.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]")); if (e.getValue() != null) { builder.put(prefix + "." + i + "." + valueSuffix, e.getValue().toString()); } i++; } ImmutableMultimap<String, String> forms = builder.build(); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument( checkNotNull(input, "input") instanceof UserIdGroupPair, "this binder is only valid for UserIdGroupPair!"); UserIdGroupPair pair = (UserIdGroupPair) input; Builder<String, String> builder = ImmutableMultimap.builder(); builder.put("SourceSecurityGroupOwnerId", pair.getUserId()); builder.put("SourceSecurityGroupName", pair.getGroupName()); return (R) request.toBuilder().replaceFormParams(builder.build()).build(); }
public static <R extends HttpRequest> R indexStringArrayToFormValuesWithPrefix( R request, String prefix, Object input) { checkArgument( checkNotNull(input, "input") instanceof String[], "this binder is only valid for String[] : " + input.getClass()); String[] values = (String[]) input; Builder<String, String> builder = ImmutableMultimap.builder(); for (int i = 0; i < values.length; i++) { builder.put( prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() + "s[" + i + "]")); } ImmutableMultimap<String, String> forms = builder.build(); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
public static <R extends HttpRequest> R indexIterableToFormValuesWithPrefix( R request, String prefix, Object input) { checkArgument( checkNotNull(input, "input") instanceof Iterable<?>, "this binder is only valid for Iterable<?>: " + input.getClass()); Iterable<?> values = (Iterable<?>) input; Builder<String, String> builder = ImmutableMultimap.builder(); int i = 0; for (Object o : values) { builder.put( prefix + "." + (i++ + 1), checkNotNull(o.toString(), prefix.toLowerCase() + "s[" + i + "]")); } ImmutableMultimap<String, String> forms = builder.build(); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument( checkNotNull(input, "input") instanceof ObjectMetadata, "this binder is only valid for ObjectMetadata!"); checkNotNull(request, "request"); ObjectMetadata md = ObjectMetadata.class.cast(input); checkArgument(md.getKey() != null, "objectMetadata.getKey() must be set!"); request = metadataPrefixer.bindToRequest(request, md.getUserMetadata()); Builder<String, String> headers = ImmutableMultimap.builder(); if (md.getCacheControl() != null) { headers.put(HttpHeaders.CACHE_CONTROL, md.getCacheControl()); } if (md.getContentMetadata().getContentDisposition() != null) { headers.put("Content-Disposition", md.getContentMetadata().getContentDisposition()); } if (md.getContentMetadata().getContentEncoding() != null) { headers.put("Content-Encoding", md.getContentMetadata().getContentEncoding()); } String contentLanguage = md.getContentMetadata().getContentLanguage(); if (contentLanguage != null) { headers.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage); } if (md.getContentMetadata().getContentType() != null) { headers.put(HttpHeaders.CONTENT_TYPE, md.getContentMetadata().getContentType()); } else { headers.put(HttpHeaders.CONTENT_TYPE, "binary/octet-stream"); } if (md.getContentMetadata().getContentMD5() != null) { headers.put("Content-MD5", base64().encode(md.getContentMetadata().getContentMD5())); } return (R) request.toBuilder().replaceHeaders(headers.build()).build(); }