You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
package org.r3pek.guiatv;
|
|
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
|
|
import javax.xml.parsers.SAXParser;
|
|
import javax.xml.parsers.SAXParserFactory;
|
|
|
|
import org.xml.sax.InputSource;
|
|
import org.xml.sax.XMLReader;
|
|
|
|
public class ChannelList {
|
|
private ArrayList<Channel> channelList = null;
|
|
|
|
public ChannelList() {
|
|
try {
|
|
URL url = new URL("http://services.sapo.pt/EPG/GetChannelList?");
|
|
|
|
/* Get a SAXParser from the SAXPArserFactory. */
|
|
SAXParserFactory spf = SAXParserFactory.newInstance();
|
|
SAXParser sp = spf.newSAXParser();
|
|
|
|
/* Get the XMLReader of the SAXParser we created. */
|
|
XMLReader xr = sp.getXMLReader();
|
|
/* Create a new ContentHandler and apply it to the XML-Reader*/
|
|
ChannelListParser handler = new ChannelListParser();
|
|
xr.setContentHandler(handler);
|
|
|
|
/* Parse the xml-data from our URL. */
|
|
xr.parse(new InputSource(url.openStream()));
|
|
/* Parsing has finished. */
|
|
|
|
/* Our XMLParserHandler now provides the parsed data to us. */
|
|
channelList = handler.getChannelList();
|
|
} catch (Exception e) { }
|
|
}
|
|
|
|
public int getChannelCount() {
|
|
return channelList.size();
|
|
}
|
|
|
|
public ArrayList<Channel> getChannels() {
|
|
return channelList;
|
|
}
|
|
|
|
public int namePos(String name) {
|
|
for (int i = 0; i < getChannelCount(); i++) {
|
|
Channel c = channelList.get(i);
|
|
if (c.getName().equals(name))
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|