| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.s3.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | import static com.google.common.base.Preconditions.checkState; |
| 23 | |
| 24 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 25 | |
| 26 | /** |
| 27 | * Contains options supported in the REST API for the GET bucket operation. <h2> |
| 28 | * Usage</h2> The recommended way to instantiate a GetBucketOptions object is to statically import |
| 29 | * GetBucketOptions.Builder.* and invoke a static creation method followed by an instance mutator |
| 30 | * (if needed): |
| 31 | * <p/> |
| 32 | * <code> |
| 33 | * import static org.jclouds.s3.commands.options.GetBucketOptions.Builder.* |
| 34 | * <p/> |
| 35 | * S3Client connection = // get connection |
| 36 | * Future<S3Bucket> bucket = connection.listBucket("bucketName",withPrefix("home/users").maxKeys(1000)); |
| 37 | * <code> |
| 38 | * |
| 39 | * @author Adrian Cole |
| 40 | * @see <a |
| 41 | * href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketGET.html?" |
| 42 | * /> |
| 43 | */ |
| 44 | public class ListBucketOptions extends BaseHttpRequestOptions { |
| 45 | public static final ListBucketOptions NONE = new ListBucketOptions(); |
| 46 | |
| 47 | /** |
| 48 | * Limits the response to keys which begin with the indicated prefix. You can use prefixes to |
| 49 | * separate a bucket into different sets of keys in a way similar to how a file system uses |
| 50 | * folders. |
| 51 | * |
| 52 | */ |
| 53 | public ListBucketOptions withPrefix(String prefix) { |
| 54 | queryParameters.put("prefix", checkNotNull(prefix, "prefix")); |
| 55 | return this; |
| 56 | } |
| 57 | |
| 58 | public String getPrefix() { |
| 59 | return getFirstQueryOrNull("prefix"); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Indicates where in the bucket to begin listing. The list will only include keys that occur |
| 64 | * lexicographically after marker. This is convenient for pagination: To get the next page of |
| 65 | * results use the last key of the current page as the marker. |
| 66 | */ |
| 67 | public ListBucketOptions afterMarker(String marker) { |
| 68 | queryParameters.put("marker", checkNotNull(marker, "marker")); |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | public String getMarker() { |
| 73 | return getFirstQueryOrNull("marker"); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * The maximum number of keys you'd like to see in the response body. The server might return |
| 78 | * fewer than this many keys, but will not return more. |
| 79 | */ |
| 80 | public ListBucketOptions maxResults(int maxKeys) { |
| 81 | checkState(maxKeys >= 0, "maxKeys must be >= 0"); |
| 82 | queryParameters.put("max-keys", Long.toString(maxKeys)); |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public Integer getMaxResults() { |
| 87 | String returnVal = getFirstQueryOrNull("max-keys"); |
| 88 | return (returnVal != null) ? new Integer(returnVal) : null; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Causes keys that contain the same string between the prefix and the first occurrence of the |
| 93 | * delimiter to be rolled up into a single result element in the CommonPrefixes collection. These |
| 94 | * rolled-up keys are not returned elsewhere in the response. |
| 95 | * |
| 96 | */ |
| 97 | public ListBucketOptions delimiter(String delimiter) { |
| 98 | queryParameters.put("delimiter", checkNotNull(delimiter, "delimiter")); |
| 99 | return this; |
| 100 | } |
| 101 | |
| 102 | public String getDelimiter() { |
| 103 | return getFirstQueryOrNull("delimiter"); |
| 104 | } |
| 105 | |
| 106 | public static class Builder { |
| 107 | |
| 108 | /** |
| 109 | * @see ListBucketOptions#withPrefix(String) |
| 110 | */ |
| 111 | public static ListBucketOptions withPrefix(String prefix) { |
| 112 | ListBucketOptions options = new ListBucketOptions(); |
| 113 | return options.withPrefix(prefix); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @see ListBucketOptions#afterMarker(String) |
| 118 | */ |
| 119 | public static ListBucketOptions afterMarker(String marker) { |
| 120 | ListBucketOptions options = new ListBucketOptions(); |
| 121 | return options.afterMarker(marker); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @see ListBucketOptions#maxResults(int) |
| 126 | */ |
| 127 | public static ListBucketOptions maxResults(int maxKeys) { |
| 128 | ListBucketOptions options = new ListBucketOptions(); |
| 129 | return options.maxResults(maxKeys); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @see ListBucketOptions#delimiter(String) |
| 134 | */ |
| 135 | public static ListBucketOptions delimiter(String delimiter) { |
| 136 | ListBucketOptions options = new ListBucketOptions(); |
| 137 | return options.delimiter(delimiter); |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | } |