package pnews;
public enum Category {
- TOP("actualite", "Les actualités à la une"),
- FRANCE("france", "France"),
- SPORT("sport", "Sport"),
- EUROPE("europe", "Europe"),
- MONDE("monde", "Monde"),
- ECO("economie", "Economie"),
- ESSONNE("essonne", "Essonne"),
- TECHNOLOGIE("technologie", "Technologie"),
- PEOPLE("people", "People");
+ ACTUALITE("Les actualités à la une"),
+ FRANCE("France"),
+ SPORT("Sport"),
+ EUROPE("Europe"),
+ MONDE("Monde"),
+ ECONOMIE("Economie"),
+ ESSONNE("Essonne"),
+ TECHNOLOGIE("Technologie"),
+ PEOPLE("People");
- private final String id;
private final String title;
- private Category(String id, String title) {
- this.id = id;
+ private Category(String title) {
this.title = title;
}
public String getId() {
- return id;
+ return name();
}
public String getTitle() {
--- /dev/null
+package pnews;
+
+public class Feed {
+ private final String URL;
+ private final Category category;
+
+ public Feed(String URL, Category category) {
+ this.URL = URL;
+ this.category = category;
+ }
+
+ public String getURL() {
+ return URL;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ @Override
+ public String toString() {
+ return getURL() + "[" + category + "]";
+ }
+}
return new SyndFeedInput().build(r);
}
- private static Map<Category, String[]> getFeeds() {
- Map<Category, String[]> result;
-
- result = new HashMap<>();
-
- result.put(Category.TOP,
- new String[] {
- "http://www.europe1.fr/var/export/rss/europe1/actus.xml",
- "http://www.francetvinfo.fr/titres.rss",
- "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.SPORT,
- new String[] { "http://www.europe1.fr/var/export/rss/europe1/sport.xml",
- "http://www.sportune.fr/feed",
- "http://www.france24.com/fr/sports/rss" });
-
- result.put(Category.FRANCE,
- new String[] { "http://www.france24.com/fr/france/rss",
- "http://www.francetvinfo.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.MONDE,
- new String[] { "http://www.europe1.fr/var/export/rss/europe1/international.xml",
- "http://www.france24.com/fr/actualites/rss" });
-
-
- result.put(Category.ECO,
- new String[] { "http://www.france24.com/fr/economie/rss",
- "http://www.europe1.fr/var/export/rss/europe1/economie.xml",
- "http://www.rfi.fr/economie/rss" });
-
- result.put(Category.ESSONNE,
- 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://www.generation-nt.com/export/rss.xml",
- "http://www.europe1.fr/var/export/rss/europe1/sciences.xml",
- "http://feeds.feedburner.com/lesnumeriques/news",
- "http://www.zdnet.fr/feeds/rss/actualites/",
- "http://www.frandroid.com/feed",
- "http://www.silicon.fr/feed",
- "http://www.fredzone.org/feed",
- "http://www.futura-sciences.com/rss/actualites.xml",
- "https://www-03.ibm.com/press/fr/fr/rssfeed.wss?keyword=null&maxFeed=&feedType=RSS&topic=all"});
-
- return result;
- }
+
private List<Article> getArticlesForUpdate(Category cat) {
List<Article> result;
private void retrieveArticles(Category cat) throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
String[] feeds;
- feeds = getFeeds().get(cat);
+ feeds = Config.getFeedsByCategory().get(cat);
if (feeds != null)
for (String str: feeds)
--- /dev/null
+package pnews.servlet;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+
+import pnews.Category;
+import pnews.Feed;
+
+public class Config {
+ public static Feed[] getFeeds() {
+ Reader r;
+ List<Feed> feeds;
+ JsonObject jfeeds;
+
+ r = null;
+ try {
+ r = new InputStreamReader(Config.class.getClassLoader().getResourceAsStream("feeds.json"));
+ jfeeds = Json.createReader(r).readObject();
+ } finally {
+ if (r != null)
+ try { r.close(); } catch (IOException e) { };
+ }
+
+ feeds = new ArrayList<Feed>(jfeeds.size());
+
+ jfeeds.forEach((k, v)-> {
+ JsonObject jf;
+ JsonArray jcategories;
+
+ jf = (JsonObject)v;
+ jcategories = jf.getJsonArray("categories");
+ feeds.add(new Feed(k, Category.valueOf(jcategories.getString(0))));
+ });
+
+ return feeds.toArray(new Feed[] {});
+ }
+
+ public static Map<Category, String[]> getFeedsByCategory() {
+ Map<Category, String[]> result;
+
+ result = new HashMap<>();
+
+ result.put(Category.ACTUALITE,
+ new String[] {
+ "http://www.europe1.fr/var/export/rss/europe1/actus.xml",
+ "http://www.francetvinfo.fr/titres.rss",
+ "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.SPORT,
+ new String[] { "http://www.europe1.fr/var/export/rss/europe1/sport.xml",
+ "http://www.sportune.fr/feed",
+ "http://www.france24.com/fr/sports/rss" });
+
+ result.put(Category.FRANCE,
+ new String[] { "http://www.france24.com/fr/france/rss",
+ "http://www.francetvinfo.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.MONDE,
+ new String[] { "http://www.europe1.fr/var/export/rss/europe1/international.xml",
+ "http://www.france24.com/fr/actualites/rss" });
+
+
+ result.put(Category.ECONOMIE,
+ new String[] { "http://www.france24.com/fr/economie/rss",
+ "http://www.europe1.fr/var/export/rss/europe1/economie.xml",
+ "http://www.rfi.fr/economie/rss" });
+
+ result.put(Category.ESSONNE,
+ 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://www.generation-nt.com/export/rss.xml",
+ "http://www.europe1.fr/var/export/rss/europe1/sciences.xml",
+ "http://feeds.feedburner.com/lesnumeriques/news",
+ "http://www.zdnet.fr/feeds/rss/actualites/",
+ "http://www.frandroid.com/feed",
+ "http://www.silicon.fr/feed",
+ "http://www.fredzone.org/feed",
+ "http://www.futura-sciences.com/rss/actualites.xml",
+ "https://www-03.ibm.com/press/fr/fr/rssfeed.wss?keyword=null&maxFeed=&feedType=RSS&topic=all"});
+
+ return result;
+ }
+
+ public static void main(String[] args) {
+ Feed[] feeds;
+
+ feeds = getFeeds();
+
+ System.out.println("Number of feeds: " + feeds.length);
+ for (Feed f: feeds)
+ System.out.println(f);
+ }
+}
}
if (path.equals("/")) {
- writeArticles(Category.TOP, resp);
+ writeArticles(Category.ACTUALITE, resp);
return ;
}
--- /dev/null
+{
+ "http://www.europe1.fr/var/export/rss/europe1/actus.xml": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "http://www.francetvinfo.fr/titres.rss": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "http://www.rfi.fr/general/rss": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "http://www.cnews.fr/rss/une": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "http://www.ladepeche.fr/rss/a-la-une.rss": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "https://www.franceinter.fr/rss/a-la-une.xml": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "https://www.francebleu.fr/rss/a-la-une.xml": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ },
+ "http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/": {
+ "categories": ["ACTUALITE"],
+ "language": "fr"
+ }
+}