return NAME;\r
}\r
\r
+\r
+ private Document fetchXML(URL url) throws Exception {\r
+ Document xml = null;\r
+ boolean done = false;\r
+ for (int count = 0; !done; count++) {\r
+ Thread.sleep(config.niceMilliseconds*(1<<count));\r
+ try {\r
+ xml = DocumentBuilderFactory.newInstance()\r
+ .newDocumentBuilder().parse(url.openStream());\r
+ done = true;\r
+ } catch (Exception e) {\r
+ if (!config.quiet) {\r
+ logger.warn("Error fetching from url " + url + ", count="\r
+ + count);\r
+ }\r
+ if (count >= MAX_FETCH_TRIES) {\r
+ stats.fetchErrors++;\r
+ logger.debug("Error getting data from url", e);\r
+ throw new Exception("Error getting data from url "\r
+ + url, e);\r
+ }\r
+ }\r
+ }\r
+ return xml;\r
+ }\r
+\r
public List<Channel> getChannels() {\r
List<Channel> result = new ArrayList<Channel>(10);\r
\r
}\r
Document xml = null;\r
try {\r
- xml = DocumentBuilderFactory.newInstance().newDocumentBuilder()\r
- .parse(url.openStream());\r
+ xml = fetchXML(url);\r
} catch (Exception e) {\r
- logger.error("Exception reading info from " + url\r
+ logger.error("Exception reading RTL channel listing from " + url\r
+ " and transforming to XML", e);\r
+ return result;\r
}\r
Element root = xml.getDocumentElement();\r
String json = root.getTextContent();\r
private void fetchDetail(Programme prog, DateStatus dateStatus, String id)\r
throws Exception {\r
URL url = detailUrl(id);\r
- Thread.sleep(config.niceMilliseconds);\r
- Document xml = DocumentBuilderFactory.newInstance()\r
- .newDocumentBuilder().parse(url.openStream());\r
+ Document xml = fetchXML(url);\r
Element root = xml.getDocumentElement();\r
if (root.hasAttributes()) {\r
logger.warn("Unknown attributes for RTL detail root node");\r
channelMap.put(c.id, c);\r
}\r
URL url = programmeUrl(day);\r
- // String xmltext = fetchURL(url);\r
- // System.out.println(xmltext);\r
- Thread.sleep(config.niceMilliseconds);\r
- Document xml = DocumentBuilderFactory.newInstance()\r
- .newDocumentBuilder().parse(url.openStream());\r
+ Document xml = fetchXML(url);\r
Element root = xml.getDocumentElement();\r
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(root\r
.getAttribute("date"));\r