| 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.domain; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.Date; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | import org.jclouds.io.ContentMetadataBuilder; |
| 26 | import org.jclouds.io.payloads.BaseMutableContentMetadata; |
| 27 | import org.jclouds.s3.domain.ObjectMetadata.StorageClass; |
| 28 | import org.jclouds.s3.domain.internal.MutableObjectMetadataImpl; |
| 29 | |
| 30 | import com.google.common.collect.ImmutableMap; |
| 31 | |
| 32 | /** |
| 33 | * Allows you to create {@link ObjectMetadata} objects. |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | */ |
| 37 | public class ObjectMetadataBuilder { |
| 38 | public static ObjectMetadataBuilder create() { |
| 39 | return new ObjectMetadataBuilder(); |
| 40 | } |
| 41 | |
| 42 | private final ContentMetadataBuilder contentMetadataBuilder = new ContentMetadataBuilder() |
| 43 | .contentType("binary/octet-stream"); |
| 44 | |
| 45 | private String key; |
| 46 | private String bucket; |
| 47 | private URI uri; |
| 48 | private StorageClass storageClass = StorageClass.STANDARD; |
| 49 | private String cacheControl; |
| 50 | private Date lastModified; |
| 51 | private String eTag; |
| 52 | private CanonicalUser owner; |
| 53 | private Map<String, String> userMetadata = ImmutableMap.of(); |
| 54 | |
| 55 | public ObjectMetadataBuilder key(String key) { |
| 56 | this.key = key; |
| 57 | return this; |
| 58 | } |
| 59 | |
| 60 | public ObjectMetadataBuilder bucket(String bucket) { |
| 61 | this.bucket = bucket; |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | public ObjectMetadataBuilder owner(CanonicalUser owner) { |
| 66 | this.owner = owner; |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | public ObjectMetadataBuilder eTag(String eTag) { |
| 71 | this.eTag = eTag; |
| 72 | return this; |
| 73 | } |
| 74 | |
| 75 | public ObjectMetadataBuilder uri(URI uri) { |
| 76 | this.uri = uri; |
| 77 | return this; |
| 78 | } |
| 79 | |
| 80 | public ObjectMetadataBuilder lastModified(Date lastModified) { |
| 81 | this.lastModified = lastModified; |
| 82 | return this; |
| 83 | } |
| 84 | |
| 85 | public ObjectMetadataBuilder storageClass(StorageClass storageClass) { |
| 86 | this.storageClass = storageClass; |
| 87 | return this; |
| 88 | } |
| 89 | |
| 90 | public ObjectMetadataBuilder cacheControl(String cacheControl) { |
| 91 | this.cacheControl = cacheControl; |
| 92 | return this; |
| 93 | } |
| 94 | |
| 95 | public ObjectMetadataBuilder userMetadata(Map<String, String> userMetadata) { |
| 96 | this.userMetadata = ImmutableMap.copyOf(userMetadata); |
| 97 | return this; |
| 98 | } |
| 99 | |
| 100 | public ObjectMetadataBuilder contentDisposition(String contentDisposition) { |
| 101 | contentMetadataBuilder.contentDisposition(contentDisposition); |
| 102 | return this; |
| 103 | } |
| 104 | |
| 105 | public ObjectMetadataBuilder contentEncoding(String contentEncoding) { |
| 106 | contentMetadataBuilder.contentEncoding(contentEncoding); |
| 107 | return this; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | public ObjectMetadataBuilder contentLanguage(String contentLanguage) { |
| 112 | contentMetadataBuilder.contentLanguage(contentLanguage); |
| 113 | return this; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | public ObjectMetadataBuilder contentLength(Long contentLength) { |
| 118 | contentMetadataBuilder.contentLength(contentLength); |
| 119 | return this; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | public ObjectMetadataBuilder contentMD5(byte[] md5) { |
| 124 | contentMetadataBuilder.contentMD5(md5); |
| 125 | return this; |
| 126 | |
| 127 | } |
| 128 | |
| 129 | public ObjectMetadataBuilder contentType(String contentType) { |
| 130 | contentMetadataBuilder.contentType(contentType); |
| 131 | return this; |
| 132 | } |
| 133 | |
| 134 | public ObjectMetadata build() { |
| 135 | MutableObjectMetadataImpl toReturn = new MutableObjectMetadataImpl(); |
| 136 | toReturn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(contentMetadataBuilder.build())); |
| 137 | toReturn.setCacheControl(cacheControl); |
| 138 | toReturn.setKey(key); |
| 139 | toReturn.setBucket(bucket); |
| 140 | toReturn.setUri(uri); |
| 141 | toReturn.setETag(eTag); |
| 142 | toReturn.setOwner(owner); |
| 143 | toReturn.setStorageClass(storageClass); |
| 144 | toReturn.setUserMetadata(userMetadata); |
| 145 | toReturn.setLastModified(lastModified); |
| 146 | return toReturn; |
| 147 | } |
| 148 | |
| 149 | } |