private static InitiateMultipartUploadResult parseInitMultipartResponseXML(InputStream in) throws IOException, SAXException, ParserConfigurationException { InitiateMultipartUploadResult result = new InitiateMultipartUploadResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[item] - " + element.getNodeName()); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equalsIgnoreCase("UploadId")) { result.setUploadId(checkChildNotNullAndGetValue(item)); } else if (name.equalsIgnoreCase("Bucket")) { result.setBucketName(checkChildNotNullAndGetValue(item)); } else if (name.equalsIgnoreCase("Key")) { result.setObjectKey(checkChildNotNullAndGetValue(item)); } } return result; }
/** * 解析listObjectInBucket请求的响应体 * * @param in * @return * @throws Exception */ private static ListObjectsResult parseObjectListResponse(InputStream in) throws ParserConfigurationException, IOException, SAXException, ParseException { ListObjectsResult result = new ListObjectsResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[parseObjectListResponse] - " + element.getNodeName()); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("Name")) { result.setBucketName(checkChildNotNullAndGetValue(item)); } else if (name.equals("Prefix")) { result.setPrefix(checkChildNotNullAndGetValue(item)); } else if (name.equals("Marker")) { result.setMarker(checkChildNotNullAndGetValue(item)); } else if (name.equals("Delimiter")) { result.setDelimiter(checkChildNotNullAndGetValue(item)); } else if (name.equals("EncodingType")) { result.setEncodingType(checkChildNotNullAndGetValue(item)); } else if (name.equals("MaxKeys")) { String maxKeys = checkChildNotNullAndGetValue(item); if (maxKeys != null) { result.setMaxKeys(Integer.valueOf(maxKeys)); } } else if (name.equals("NextMarker")) { result.setNextMarker(checkChildNotNullAndGetValue(item)); } else if (name.equals("IsTruncated")) { String isTruncated = checkChildNotNullAndGetValue(item); if (isTruncated != null) { result.setTruncated(Boolean.valueOf(isTruncated)); } } else if (name.equals("Contents")) { if (item.getChildNodes() == null) { continue; } result.getObjectSummaries().add(parseObjectSummaryXML(item.getChildNodes())); } else if (name.equals("CommonPrefixes")) { if (item.getChildNodes() == null) { continue; } String prefix = parseCommonPrefixXML(item.getChildNodes()); if (prefix != null) { result.getCommonPrefixes().add(prefix); } } } return result; }
/** * 解析GetBucketACL请求的响应体 * * @param in * @return * @throws Exception */ private static GetBucketACLResult parseGetBucketACLResponse(InputStream in) throws ParserConfigurationException, IOException, SAXException, ParseException { GetBucketACLResult result = new GetBucketACLResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[parseGetBucketACLResponse - " + element.getNodeName()); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("Owner")) { NodeList ownerList = item.getChildNodes(); for (int j = 0; j < ownerList.getLength(); j++) { Node ownerItem = ownerList.item(j); String ownerName = ownerItem.getNodeName(); if (ownerName == null) { continue; } else if (ownerName.equals("ID")) { result.setBucketOwnerID(checkChildNotNullAndGetValue(ownerItem)); } else if (ownerName.equals("DisplayName")) { result.setBucketOwner(checkChildNotNullAndGetValue(ownerItem)); } } } else if (name.equals("AccessControlList")) { NodeList aclList = item.getChildNodes(); for (int k = 0; k < aclList.getLength(); k++) { Node aclItem = aclList.item(k); String aclName = aclItem.getNodeName(); if (aclName == null) { continue; } else if (aclName.equals("Grant")) { result.setBucketACL(checkChildNotNullAndGetValue(aclItem)); } } } } return result; }
private static CopyObjectResult parseCopyObjectResponseXML(InputStream in) throws ParseException, ParserConfigurationException, IOException, SAXException { CopyObjectResult result = new CopyObjectResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[item] - " + element.getNodeName()); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("LastModified")) { result.setLastModified(DateUtil.parseIso8601Date(checkChildNotNullAndGetValue(item))); } else if (name.equals("ETag")) { result.setEtag(checkChildNotNullAndGetValue(item)); } } return result; }
private static ListPartsResult parseListPartsResponseXML(InputStream in) throws ParserConfigurationException, IOException, SAXException, ParseException { ListPartsResult result = new ListPartsResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[parseObjectListResponse] - " + element.getNodeName()); List<PartSummary> partEtagList = new ArrayList<PartSummary>(); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("Bucket")) { result.setBucketName(checkChildNotNullAndGetValue(item)); } else if (name.equals("Key")) { result.setKey(checkChildNotNullAndGetValue(item)); } else if (name.equals("UploadId")) { result.setUploadId(checkChildNotNullAndGetValue(item)); } else if (name.equals("PartNumberMarker")) { String partNumberMarker = checkChildNotNullAndGetValue(item); if (partNumberMarker != null) { result.setPartNumberMarker(Integer.valueOf(partNumberMarker)); } } else if (name.equals("NextPartNumberMarker")) { String nextPartNumberMarker = checkChildNotNullAndGetValue(item); if (nextPartNumberMarker != null) { result.setNextPartNumberMarker(Integer.valueOf(nextPartNumberMarker)); } } else if (name.equals("MaxParts")) { String maxParts = checkChildNotNullAndGetValue(item); if (maxParts != null) { result.setMaxParts(Integer.valueOf(maxParts)); } } else if (name.equals("IsTruncated")) { String isTruncated = checkChildNotNullAndGetValue(item); if (isTruncated != null) { result.setTruncated(Boolean.valueOf(isTruncated)); } } else if (name.equals("Part")) { NodeList partNodeList = item.getChildNodes(); PartSummary partSummary = new PartSummary(); for (int k = 0; k < partNodeList.getLength(); k++) { Node partItem = partNodeList.item(k); String partItemName = partItem.getNodeName(); if (partItemName == null) { continue; } else if (partItemName.equals("PartNumber")) { String partNumber = checkChildNotNullAndGetValue(partItem); if (partNumber != null) { partSummary.setPartNumber(Integer.valueOf(partNumber)); } } else if (partItemName.equals("LastModified")) { partSummary.setLastModified( DateUtil.parseIso8601Date(checkChildNotNullAndGetValue(partItem))); } else if (partItemName.equals("ETag")) { partSummary.setETag(checkChildNotNullAndGetValue(partItem)); } else if (partItemName.equals("Size")) { String size = checkChildNotNullAndGetValue(partItem); if (size != null) { partSummary.setSize(Integer.valueOf(size)); } } } partEtagList.add(partSummary); } } result.setParts(partEtagList); return result; }