+ private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
+ try (XmlReader reader = new XmlReader(new URL(u))) {
+ return new SyndFeedInput().build(reader);
+ }
+ }
+
+ private static Map<Category, String[]> getFeeds() {
+ Map<Category, String[]> result;
+
+ result = new HashMap<>();
+
+ 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.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"
+ });
+
+ result.put(Category.SPORT,
+ new String[] { "http://www.france24.com/fr/sports/rss" });
+
+ result.put(Category.FRANCE,
+ new String[] { "http://www.france24.com/fr/france/rss",
+ "http://www.rfi.fr/france/rss"});
+
+ result.put(Category.EUROPE,
+ new String[] { "http://www.france24.com/fr/europe/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/" });
+
+ result.put(Category.TECHNOLOGIE,
+ new String[] { "http://feeds.feedburner.com/lesnumeriques/news",
+ "http://www.zdnet.fr/feeds/rss/actualites/"});
+
+ return result;
+ }
+
+ private static List<Article> getArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
+ List<Article> articles;
+ String[] feeds;
+ Set<String> links;
+
+ articles = new ArrayList<>();
+
+ feeds = getFeeds().get(cat);
+
+ if (feeds != null)
+ for (String str: feeds)
+ addArticles(cat, getSyndFeed(str), articles);
+ else
+ LOG.severe("No feed for category " + cat);
+
+ links = new HashSet<>(articles.size());
+ for (Article a: articles) {
+ if (links.contains(a.link))
+ LOG.severe(a.link + "is not uniq");
+ else
+ links.add(a.link);
+ }
+
+ articles.sort(new Comparator<Article> () {
+ @Override
+ public int compare(Article o1, Article o2) {
+ return o2.publicationDate.compareTo(o1.publicationDate);
+ }
+ });
+
+ return articles;
+ }
+
+ private static void writeHTMLFile(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
+ List<Article> articles;
+ String html;
+ File f;
+
+ articles = getArticles(cat);
+
+ html = HTML.toHTML(articles, cat);
+
+ f = new File(cat.getId() + ".html");
+
+ try (BufferedWriter writer = Files.newBufferedWriter(f.toPath(), StandardCharsets.UTF_8)) {
+ writer.write(html);
+ }
+ }
+
+ public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {