5c0c1343a571557362027379e82759e801ef1922
[pnews.git] / war / src / main / java / pnews / servlet / Config.java
1 package pnews.servlet;
2
3 import java.io.IOException;
4 import java.io.InputStreamReader;
5 import java.io.Reader;
6 import java.util.ArrayList;
7 import java.util.HashMap;
8 import java.util.List;
9 import java.util.Map;
10
11 import javax.json.Json;
12 import javax.json.JsonArray;
13 import javax.json.JsonObject;
14
15 import pnews.Category;
16 import pnews.Feed;
17
18 public class Config {
19         public static Feed[] getFeeds() {
20                 Reader r;
21                 List<Feed> feeds;
22                 JsonObject jfeeds;
23                 
24                 r = null;
25                 try {
26                         r = new InputStreamReader(Config.class.getClassLoader().getResourceAsStream("feeds.json"));
27                         jfeeds = Json.createReader(r).readObject();
28                 } finally {
29                         if (r != null)
30                                 try { r.close(); } catch (IOException e) { };
31                 }
32                 
33                 feeds = new ArrayList<Feed>(jfeeds.size());
34
35                 jfeeds.forEach((k, v)-> {
36                         JsonObject jf;
37                         JsonArray jcategories;
38                         
39                         jf = (JsonObject)v;
40                         jcategories = jf.getJsonArray("categories");
41                         feeds.add(new Feed(k, Category.valueOf(jcategories.getString(0))));
42                 });
43                         
44                 return feeds.toArray(new Feed[] {});
45         }
46         
47         public static Map<Category, String[]> getFeedsByCategory() {
48                 Map<Category, String[]> result;
49                 
50                 result = new HashMap<>();
51                 
52                 result.put(Category.ACTUALITE,
53                            new String[] {
54                                            "http://www.europe1.fr/var/export/rss/europe1/actus.xml",
55                                            "http://www.francetvinfo.fr/titres.rss",
56                                            "http://www.rfi.fr/general/rss",
57                                            "http://www.cnews.fr/rss/une",
58                                            "http://www.ladepeche.fr/rss/a-la-une.rss",
59                                            "https://www.franceinter.fr/rss/a-la-une.xml",
60                                            "https://www.francebleu.fr/rss/a-la-une.xml",
61                                            "http://www.bfmtv.com/rss/info/flux-rss/flux-toutes-les-actualites/"
62                            });
63                 
64                 result.put(Category.SPORT,
65                                 new String[] { "http://www.europe1.fr/var/export/rss/europe1/sport.xml",
66                                                "http://www.sportune.fr/feed",
67                                                "http://www.france24.com/fr/sports/rss" });
68                 
69                 result.put(Category.FRANCE,
70                                 new String[] { "http://www.france24.com/fr/france/rss",
71                                                "http://www.francetvinfo.fr/france.rss",
72                                                "http://www.rfi.fr/france/rss"});
73                 
74                 result.put(Category.EUROPE,
75                                 new String[] { "http://www.france24.com/fr/europe/rss" });
76
77                 result.put(Category.MONDE, 
78                            new String[] { "http://www.europe1.fr/var/export/rss/europe1/international.xml",
79                                           "http://www.france24.com/fr/actualites/rss" });                                           
80
81                 
82                 result.put(Category.ECONOMIE,
83                                 new String[] { "http://www.france24.com/fr/economie/rss",
84                                                "http://www.europe1.fr/var/export/rss/europe1/economie.xml",
85                                                "http://www.rfi.fr/economie/rss" });
86                 
87                 result.put(Category.ESSONNE,
88                                 new String[] { "http://www.tourisme-essonne.com/rss/actus/",
89                                                "http://www.ville-palaiseau.fr/rss/actualites.htm" });
90                 
91                 result.put(Category.PEOPLE,
92                                 new String[] { "http://www.premiere.fr/rss/actu-live",
93                                                "http://www.purepeople.com/rss/news_t0.xml"                                               
94                 });
95                 
96                 result.put(Category.TECHNOLOGIE,
97                                 new String[] { "http://www.generation-nt.com/export/rss.xml",
98                                                "http://www.europe1.fr/var/export/rss/europe1/sciences.xml",
99                                                "http://feeds.feedburner.com/lesnumeriques/news",
100                                                "http://www.zdnet.fr/feeds/rss/actualites/",
101                                                "http://www.frandroid.com/feed",
102                                                "http://www.silicon.fr/feed",
103                                                "http://www.fredzone.org/feed",
104                                                "http://www.futura-sciences.com/rss/actualites.xml",
105                                                "https://www-03.ibm.com/press/fr/fr/rssfeed.wss?keyword=null&maxFeed=&feedType=RSS&topic=all"});
106                 
107                 return result;
108         }
109
110         public static void main(String[] args) {
111                 Feed[] feeds;
112                 
113                 feeds = getFeeds();
114                 
115                 System.out.println("Number of feeds: " + feeds.length);
116                 for (Feed f: feeds)
117                         System.out.println(f);
118         }
119 }