use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode in project BiglyBT by BiglySoftware.
the class UPNPMSBrowserImpl method getContainerContents.
protected List<SimpleXMLParserDocumentNode> getContainerContents(String id) throws UPnPMSException {
try {
List<SimpleXMLParserDocumentNode> results = new ArrayList<>();
int starting_index = 0;
while (true) {
String NL = "\r\n";
String soap_action = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse";
String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + NL + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + NL + "<s:Body>" + NL + "<u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\">" + NL + "<ObjectID>" + id + "</ObjectID>" + NL + "<BrowseFlag>BrowseDirectChildren</BrowseFlag>" + NL + "<Filter>dc:date,res@protocolInfo,res@size</Filter>" + NL + "<StartingIndex>" + starting_index + "</StartingIndex>" + NL + "<RequestedCount>256</RequestedCount>" + NL + "<SortCriteria></SortCriteria>" + NL + "</u:Browse>" + NL + "</s:Body>" + NL + "</s:Envelope>";
SimpleXMLParserDocument doc = null;
UPnPMSException last_error = null;
for (URL endpoint : new ArrayList<>(endpoints)) {
try {
doc = getXML(endpoint, soap_action, request);
setPreferredEndpoint(endpoint);
break;
} catch (UPnPMSException e) {
last_error = e;
}
}
if (doc == null) {
throw (last_error);
}
SimpleXMLParserDocumentNode body = doc.getChild("Body");
SimpleXMLParserDocumentNode response = body.getChild("BrowseResponse");
SimpleXMLParserDocumentNode didl_result = response.getChild("Result");
String didl_str = didl_result.getValue();
SimpleXMLParserDocument didle_doc = SimpleXMLParserDocumentFactory.create(didl_str);
results.add(didle_doc);
int num_returned = Integer.parseInt(response.getChild("NumberReturned").getValue());
if (num_returned <= 0) {
break;
}
starting_index += num_returned;
int total_matches = Integer.parseInt(response.getChild("TotalMatches").getValue());
if (starting_index >= total_matches) {
break;
}
}
return (results);
} catch (UPnPMSException e) {
throw (e);
} catch (Throwable e) {
throw (new UPnPMSException("Failed to read container", e));
}
}
Aggregations