Search in sources :

Example 11 with SimpleXMLParserDocumentNode

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));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) ArrayList(java.util.ArrayList) UPnPMSException(com.biglybt.net.upnpms.UPnPMSException) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) URL(java.net.URL)

Aggregations

SimpleXMLParserDocumentNode (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)11 URL (java.net.URL)5 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 SimpleXMLParserDocument (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument)3 SimpleXMLParserDocumentAttribute (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentAttribute)3 ArrayList (java.util.ArrayList)3 UPnPException (com.biglybt.net.upnp.UPnPException)2 WebResult (com.biglybt.core.metasearch.impl.web.WebResult)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 UPnPActionArgument (com.biglybt.net.upnp.UPnPActionArgument)1 UPnPService (com.biglybt.net.upnp.UPnPService)1 UPnPDeviceImpl (com.biglybt.net.upnp.impl.device.UPnPDeviceImpl)1 UPnPMSException (com.biglybt.net.upnpms.UPnPMSException)1 RSSChannel (com.biglybt.pif.utils.xml.rss.RSSChannel)1 RSSFeed (com.biglybt.pif.utils.xml.rss.RSSFeed)1 RSSItem (com.biglybt.pif.utils.xml.rss.RSSItem)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 Matcher (java.util.regex.Matcher)1