use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseListBucket.
/**
* Unmarshall list bucket response body to bucket list.
*/
@SuppressWarnings("unchecked")
public static BucketList parseListBucket(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
BucketList bucketList = new BucketList();
if (root.getChild("Prefix") != null) {
bucketList.setPrefix(root.getChildText("Prefix"));
}
if (root.getChild("Marker") != null) {
bucketList.setMarker(root.getChildText("Marker"));
}
if (root.getChild("MaxKeys") != null) {
String value = root.getChildText("MaxKeys");
bucketList.setMaxKeys(isNullOrEmpty(value) ? null : Integer.valueOf(value));
}
if (root.getChild("IsTruncated") != null) {
String value = root.getChildText("IsTruncated");
bucketList.setTruncated(isNullOrEmpty(value) ? false : Boolean.valueOf(value));
}
if (root.getChild("NextMarker") != null) {
bucketList.setNextMarker(root.getChildText("NextMarker"));
}
Element ownerElem = root.getChild("Owner");
String id = ownerElem.getChildText("ID");
String displayName = ownerElem.getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
List<Bucket> buckets = new ArrayList<Bucket>();
if (root.getChild("Buckets") != null) {
List<Element> bucketElems = root.getChild("Buckets").getChildren("Bucket");
for (Element e : bucketElems) {
Bucket bucket = new Bucket();
bucket.setOwner(owner);
bucket.setName(e.getChildText("Name"));
bucket.setLocation(e.getChildText("Location"));
bucket.setCreationDate(DateUtil.parseIso8601Date(e.getChildText("CreationDate")));
if (e.getChild("StorageClass") != null) {
bucket.setStorageClass(StorageClass.parse(e.getChildText("StorageClass")));
}
bucket.setExtranetEndpoint(e.getChildText("ExtranetEndpoint"));
bucket.setIntranetEndpoint(e.getChildText("IntranetEndpoint"));
buckets.add(bucket);
}
}
bucketList.setBucketList(buckets);
return bucketList;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations