1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package org.jclouds.blobstore.functions;
39
40 import static com.google.common.base.Preconditions.checkNotNull;
41
42 import java.util.Date;
43
44 import javax.inject.Inject;
45 import javax.inject.Singleton;
46
47 import org.jclouds.blobstore.options.GetOptions;
48 import org.jclouds.date.DateService;
49 import org.jclouds.util.Strings2;
50
51 import com.google.common.base.Function;
52
53
54
55
56
57 @Singleton
58 public class HttpGetOptionsListToGetOptions implements
59 Function<org.jclouds.http.options.GetOptions[], org.jclouds.blobstore.options.GetOptions> {
60 private final DateService dateService;
61
62 @Inject
63 HttpGetOptionsListToGetOptions(DateService dateService) {
64 this.dateService = checkNotNull(dateService, "dateService");
65 }
66
67 public GetOptions apply(org.jclouds.http.options.GetOptions[] from) {
68 checkNotNull(from, "options");
69
70 org.jclouds.blobstore.options.GetOptions to = new org.jclouds.blobstore.options.GetOptions();
71 if (from.length != 0) {
72 if (from[0].getIfMatch() != null) {
73 to.ifETagMatches(Strings2.replaceAll(from[0].getIfMatch(), '"', ""));
74 }
75 if (from[0].getIfModifiedSince() != null) {
76 Date time = dateService.rfc822DateParse(from[0].getIfModifiedSince());
77 to.ifModifiedSince(time);
78 }
79 if (from[0].getIfNoneMatch() != null) {
80 to.ifETagDoesntMatch(Strings2.replaceAll(from[0].getIfNoneMatch(), '"', ""));
81 }
82 if (from[0].getIfUnmodifiedSince() != null) {
83 Date time = dateService.rfc822DateParse(from[0].getIfUnmodifiedSince());
84 to.ifUnmodifiedSince(time);
85 }
86 for (String range : from[0].getRanges()) {
87 String[] firstLast = range.split("\\-");
88 to.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1]));
89 }
90 }
91 return to;
92 }
93
94 }