Document document = builder.parse(response.getEntity().getContent());
NodeList nodes = document.getChildNodes();
Node accountNode = nodes.item(0);
if(!"account".equals(accountNode.getNodeName())) {
throw new GenericException("Unexpected node name", response.getAllHeaders(), response.getStatusLine());
}
List<ContainerInfo> list = new ArrayList<ContainerInfo>();
NodeList containerNodes = accountNode.getChildNodes();
for(int i = 0; i < containerNodes.getLength(); ++i) {
Node containerNode = containerNodes.item(i);
if(!"container".equals(containerNode.getNodeName())) {
continue;
}
String name = null;
int count = -1;
long size = -1;
NodeList objectData = containerNode.getChildNodes();
for(int j = 0; j < objectData.getLength(); ++j) {
Node data = objectData.item(j);
if("name".equals(data.getNodeName())) {
name = data.getTextContent();
}
else if("bytes".equals(data.getNodeName())) {
size = Long.parseLong(data.getTextContent());
}
else if("count".equals(data.getNodeName())) {
count = Integer.parseInt(data.getTextContent());
}
else {
logger.warn(String.format("Unexpected node name %s", data.getNodeName()));
}
}
if(name != null) {
ContainerInfo info = new ContainerInfo(region, name, count, size);
list.add(info);
}
}
return list;
}
catch(ParserConfigurationException e) {
throw new GenericException("Parser configuration failure", e);
}
catch(SAXException e) {
throw new GenericException("Error parsing XML server response", e);
}
}
else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
return Collections.emptyList();
}
else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
throw new ContainerNotFoundException(new Response(response));
}
else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
throw new AuthorizationException(new Response(response));
}
throw new GenericException(new Response(response));
}