various fixes
authorJean-Philippe Orsini <orsinije@fr.ibm.com>
Thu, 12 Oct 2017 23:09:01 +0000 (01:09 +0200)
committerJean-Philippe Orsini <orsinije@fr.ibm.com>
Thu, 12 Oct 2017 23:09:01 +0000 (01:09 +0200)
pnews/src/main/java/pnews/Category.java
war/src/main/java/pnews/servlet/ArticleProvider.java
war/src/main/java/pnews/servlet/Pnews.java

index efabe5e..7a8106f 100644 (file)
@@ -7,7 +7,8 @@ public enum Category {
         EUROPE("europe"),
         ECO("eco"),
         ESSONNE("essonne"),
-        TECHNOLOGIE("technologie");
+        TECHNOLOGIE("technologie"),
+        PEOPLE("people");
         
         private final String id;
                 
index d09cb0c..11689e5 100644 (file)
@@ -1,6 +1,7 @@
 package pnews.servlet;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -17,6 +18,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.jsoup.Jsoup;
+import org.xml.sax.InputSource;
 
 import com.rometools.rome.feed.synd.SyndEnclosure;
 import com.rometools.rome.feed.synd.SyndEntry;
@@ -40,9 +42,11 @@ public class ArticleProvider {
         }
         
         private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
-                try (XmlReader reader = new XmlReader(new URL(u))) {
-                        return new SyndFeedInput().build(reader);
-                }
+                InputStream is = new URL(u).openConnection().getInputStream();
+                InputSource source = new InputSource(is);
+                                
+                return new SyndFeedInput().build(source);
+                
         }
         
         private static Map<Category, String[]> getFeeds() {
@@ -75,7 +79,14 @@ public class ArticleProvider {
                                                "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"
+                                                /*"https://www.essonneinfo.fr/feed/"*/ });
+                
+                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",
@@ -86,9 +97,10 @@ public class ArticleProvider {
         
         private void addArticles(Category cat, SyndFeed feed) {
                 String thumbnail;
-                String desc;
+                String desc, link, title;
                 Date date;
                 List<Article> articles;
+                boolean exist;
                 
                 LOG.info("addArticles" + cat.getId());
                 
@@ -100,7 +112,7 @@ public class ArticleProvider {
                                 break;
                         }
                                 
-                        if (entry.getDescription() != null) {                             
+                        if (entry.getDescription() != null) {                                      
                                 desc = Jsoup.parse(entry.getDescription().getValue()).text();
                         } else {       
                                 desc = null;
@@ -112,32 +124,35 @@ public class ArticleProvider {
                                 date = entry.getUpdatedDate();
                         
                         synchronized(articlesByCategory) {
+                                link = entry.getLink().trim();
+                                title = entry.getTitle().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.info(link + " already present");
+                                                        exist = true;
+                                                }
                                 }
                                 
-                                articles.add(new Article(entry.getLink(),
-                                                         cat,
-                                                         entry.getTitle(),
-                                                         desc,
-                                                         thumbnail,
-                                                         date,
-                                                         feed.getTitle()));
-
+                                if (!exist) {
+                                        LOG.info("add " + cat.getId() + " " + feed.getTitle() + " " + 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);
+                                                }
+
+                                        });
+                                }
                         }
                 }               
         }
@@ -149,7 +164,11 @@ public class ArticleProvider {
                 
                 if (feeds != null)
                         for (String str: feeds)
-                                addArticles(cat, getSyndFeed(str));
+                                try {
+                                        addArticles(cat, getSyndFeed(str));
+                                } catch (IOException e) {
+                                        LOG.log(Level.SEVERE, "retrieveArticles failure " + cat.getId(), e);
+                                }
                 else
                         LOG.severe("No feed for category " + cat);
         }
index 01489f8..4edfb7a 100644 (file)
@@ -141,6 +141,10 @@ public class Pnews extends HttpServlet {
                         }
                 }
                 
+                if (path.equals("/")) {
+                        writeArticles(Category.TOP, resp);
+                        return ;
+                }
                 for (Category cat: Category.values()) {
                         if (path.equals('/' + cat.getId())) {
                                 writeArticles(cat, resp);