Search in sources :

Example 6 with Owner

use of com.aliyun.oss.model.Owner in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetBucketAcl.

/**
 * Unmarshall get bucket acl response body to ACL.
 */
public static AccessControlList parseGetBucketAcl(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        AccessControlList acl = new AccessControlList();
        String id = root.getChild("Owner").getChildText("ID");
        String displayName = root.getChild("Owner").getChildText("DisplayName");
        Owner owner = new Owner(id, displayName);
        acl.setOwner(owner);
        String aclString = root.getChild("AccessControlList").getChildText("Grant");
        CannedAccessControlList cacl = CannedAccessControlList.parse(aclString);
        acl.setCannedACL(cacl);
        switch(cacl) {
            case PublicRead:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
                break;
            case PublicReadWrite:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
                break;
            default:
                break;
        }
        return acl;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) AccessControlList(com.aliyun.oss.model.AccessControlList) JDOMParseException(org.jdom.input.JDOMParseException) Owner(com.aliyun.oss.model.Owner) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

Owner (com.aliyun.oss.model.Owner)6 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)5 ParseException (java.text.ParseException)5 Element (org.jdom.Element)5 JDOMParseException (org.jdom.input.JDOMParseException)5 AccessControlList (com.aliyun.oss.model.AccessControlList)2 Bucket (com.aliyun.oss.model.Bucket)2 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)2 ArrayList (java.util.ArrayList)2 BucketInfo (com.aliyun.oss.model.BucketInfo)1 BucketList (com.aliyun.oss.model.BucketList)1 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)1 ObjectAcl (com.aliyun.oss.model.ObjectAcl)1 ObjectListing (com.aliyun.oss.model.ObjectListing)1 PutObjectResult (com.aliyun.oss.model.PutObjectResult)1 File (java.io.File)1 CurrentTimeMillisSupplier (org.apache.druid.common.utils.CurrentTimeMillisSupplier)1