use of lucee.runtime.util.Decision in project extension-s3 by lucee.
the class S3 method setMetaData.
public void setMetaData(String bucketName, String objectName, Struct metadata) throws PageException, S3Exception {
Decision dec = CFMLEngineFactory.getInstance().getDecisionUtil();
Cast cas = CFMLEngineFactory.getInstance().getCastUtil();
Iterator<Entry<Key, Object>> it = metadata.entryIterator();
Entry<Key, Object> e;
ObjectMetadata metadataCopy = new ObjectMetadata();
Map<String, String> data = new ConcurrentHashMap<String, String>();
while (it.hasNext()) {
e = it.next();
metadataCopy.addUserMetadata(toMetaDataKey(e.getKey()), cas.toString(e.getValue()));
}
bucketName = improveBucketName(bucketName);
objectName = improveObjectName(objectName);
if (!Util.isEmpty(objectName)) {
AmazonS3Client client = getAmazonS3(bucketName, null);
try {
S3BucketWrapper bw = get(bucketName);
if (bw == null)
throw new S3Exception("there is no bucket [" + bucketName + "]");
Bucket b = bw.getBucket();
CopyObjectRequest request = new CopyObjectRequest(bucketName, objectName, bucketName, objectName).withNewObjectMetadata(metadataCopy);
client.copyObject(request);
flushExists(bucketName, objectName);
} finally {
client.release();
}
} else
// TOOD possible?
throw new S3Exception("cannot set metadata for a bucket");
}
use of lucee.runtime.util.Decision in project extension-s3 by lucee.
the class AccessControlListUtil method toAccessControlList.
public static Object toAccessControlList(Object objACL) throws S3Exception {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Decision dec = engine.getDecisionUtil();
Cast cast = engine.getCastUtil();
// String
if (dec.isSimpleValue(objACL)) {
String str = cast.toString(objACL, "");
CannedAccessControlList acl = S3.toACL(str, null);
if (acl == null)
throw new S3Exception("invalid access control list definition [" + str + "]");
return acl;
}
// Array
if (dec.isCastableToArray(objACL)) {
Array arr = cast.toArray(objACL, null);
if (arr == null || arr.size() == 0)
return null;
AccessControlList acl = new AccessControlList();
acl.grantAllPermissions(toGrantAndPermissions(arr));
return acl;
}
throw new S3Exception("access control list must be an array or a string");
}
Aggregations