private ArticleProvider() {
for (Category cat:Category.values())
- scheduler.scheduleAtFixedRate(new Refresher(cat), 2, 120, TimeUnit.SECONDS);
+ scheduler.scheduleAtFixedRate(new Refresher(cat), 2, 600, TimeUnit.SECONDS);
}
private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
- try (XmlReader reader = new XmlReader(new URL(u))) {
- return new SyndFeedInput().build(reader);
- }
+ XmlReader r;
+
+ r = new XmlReader(new URL(u));
+ XmlReader.setDefaultEncoding("UTF-8");
+
+ return new SyndFeedInput().build(r);
}
private static Map<Category, String[]> getFeeds() {
result.put(Category.TOP,
new String[] {
"http://www.francetvinfo.fr/titres.rss",
- "http://www.france24.com/fr/actualites/rss",
- //"https://www.franceinter.fr/rss/a-la-une.xml",
"http://www.rfi.fr/general/rss",
"http://www.cnews.fr/rss/une",
+ "http://www.ladepeche.fr/rss/a-la-une.rss",
+ "https://www.franceinter.fr/rss/a-la-une.xml",
+ "https://www.francebleu.fr/rss/a-la-une.xml",
"http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"
});
result.put(Category.EUROPE,
new String[] { "http://www.france24.com/fr/europe/rss" });
+
+ result.put(Category.MONDE,
+ new String[] { "http://www.france24.com/fr/actualites/rss" });
+
result.put(Category.ECO,
new String[] { "http://www.france24.com/fr/economie/rss",
"http://www.rfi.fr/economie/rss" });
result.put(Category.ESSONNE,
- new String[] { /*"https://www.essonneinfo.fr/feed/"*/ });
+ new String[] { "http://www.tourisme-essonne.com/rss/actus/",
+ "http://www.ville-palaiseau.fr/rss/actualites.htm" });
+
+ result.put(Category.PEOPLE,
+ new String[] { "http://www.premiere.fr/rss/actu-live",
+ "http://www.purepeople.com/rss/news_t0.xml"
+ });
result.put(Category.TECHNOLOGIE,
new String[] { "http://feeds.feedburner.com/lesnumeriques/news",
private void addArticles(Category cat, SyndFeed feed) {
String thumbnail;
- String desc;
+ String desc, link, title, feedTitle, feedImage;
Date date;
List<Article> articles;
+ boolean exist;
+
+ feedTitle = feed.getTitle().trim();
- LOG.info("addArticles" + cat.getId());
+ if (feed.getImage() != null)
+ feedImage = feed.getImage().getUrl();
+ else
+ feedImage = null;
+
+ LOG.info("addArticles " + cat.getId() + " " + feedTitle + " number of articles: " + feed.getEntries().size());
for (SyndEntry entry: feed.getEntries()) {
thumbnail = null;
thumbnail = e.getUrl();
break;
}
-
- if (entry.getDescription() != null) {
+ if (thumbnail == null)
+ thumbnail = feedImage;
+
+ title = entry.getTitle().trim();
+
+ if (entry.getDescription() != null) {
desc = Jsoup.parse(entry.getDescription().getValue()).text();
} else {
desc = null;
- LOG.severe("No description for " + feed.getTitle() + " - " + entry.getTitle());
+ LOG.severe("No description for " + feedTitle + " - " + title);
}
date = entry.getPublishedDate();
if (date == null)
date = entry.getUpdatedDate();
+ if (date == null) {
+ LOG.severe("The article " + feedTitle + " - " + title + " does not have a date");
+ continue;
+ }
synchronized(articlesByCategory) {
+ link = entry.getLink().trim();
+
articles = articlesByCategory.get(cat);
+ exist = false;
if (articles == null) {
articles = new ArrayList<>();
articlesByCategory.put(cat, articles);
} else {
for (Article a: articles)
- if (a.link.equals(entry.getLink()))
- return ;
+ if (a.link.equals(link)) {
+ LOG.fine("addArticles " + link + " is already present");
+ exist = true;
+ }
}
- articles.add(new Article(entry.getLink(),
- cat,
- entry.getTitle(),
- desc,
- thumbnail,
- date,
- feed.getTitle()));
-
+ if (!exist) {
+ LOG.fine("add " + cat.getId() + " " + feedTitle + " " + title);
- Collections.sort(articles, new Comparator<Article>() {
- @Override
- public int compare(Article o1, Article o2) {
- return o2.publicationDate.compareTo(o1.publicationDate);
- }
-
- });
+ articles.add(new Article(link, cat, title, desc, thumbnail, date,
+ feed.getTitle()));
+
+ Collections.sort(articles, new Comparator<Article>() {
+ @Override
+ public int compare(Article o1, Article o2) {
+ return o2.publicationDate.compareTo(o1.publicationDate);
+ }
+
+ });
+ } else {
+ LOG.finest("addArticles already exist: " + title);
+ }
}
- }
+ }
+
+ LOG.info("addArticles done " + cat.getId());
}
private void retrieveArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
if (feeds != null)
for (String str: feeds)
- addArticles(cat, getSyndFeed(str));
+ try {
+ addArticles(cat, getSyndFeed(str));
+ } catch (Throwable e) {
+ LOG.log(Level.SEVERE,
+ "retrieveArticles failure " + cat.getId() + " " + str,
+ e);
+ }
else
LOG.severe("No feed for category " + cat);
}
+ /**
+ * Returns a copy.
+ */
public List<Article> getArticles(Category cat)
throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
synchronized (articlesByCategory) {
- return articlesByCategory.get(cat);
+ return new ArrayList<>(articlesByCategory.get(cat));
}
}
articles.subList(0, 100));
}
+ LOG.info("refresher " + category.getId() + " number of articles: " + articles.size());
}
} catch (IllegalArgumentException | FeedException | IOException e) {
LOG.log(Level.SEVERE, "refresher failure", e);