fixed concurent exception when the list of articles is updated and requested
[pnews.git] / war / src / main / java / pnews / servlet / ArticleProvider.java
index 9095526..55e098a 100644 (file)
@@ -1,7 +1,6 @@
 package pnews.servlet;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -18,13 +17,13 @@ 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;
 import com.rometools.rome.feed.synd.SyndFeed;
 import com.rometools.rome.io.FeedException;
 import com.rometools.rome.io.SyndFeedInput;
+import com.rometools.rome.io.XmlReader;
 
 import pnews.Article;
 import pnews.Category;
@@ -41,11 +40,12 @@ public class ArticleProvider {
         }
         
         private static SyndFeed getSyndFeed(String u) throws IllegalArgumentException, FeedException, MalformedURLException, IOException {
-                InputStream is = new URL(u).openConnection().getInputStream();
-                InputSource source = new InputSource(is);
-                                
-                return new SyndFeedInput().build(source);
+                XmlReader r;
+                
+                r = new XmlReader(new URL(u));
+                XmlReader.setDefaultEncoding("UTF-8");
                 
+                return new SyndFeedInput().build(r);                
         }
         
         private static Map<Category, String[]> getFeeds() {
@@ -56,7 +56,6 @@ public class ArticleProvider {
                 result.put(Category.TOP,
                            new String[] {
                                            "http://www.francetvinfo.fr/titres.rss",
-                                           "http://www.france24.com/fr/actualites/rss",                                           
                                            "http://www.rfi.fr/general/rss",
                                            "http://www.cnews.fr/rss/une",
                                            "http://www.ladepeche.fr/rss/a-la-une.rss",
@@ -74,6 +73,10 @@ public class ArticleProvider {
                 
                 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",
@@ -81,8 +84,7 @@ public class ArticleProvider {
                 
                 result.put(Category.ESSONNE,
                                 new String[] { "http://www.tourisme-essonne.com/rss/actus/",
-                                               "http://www.ville-palaiseau.fr/rss/actualites.htm"
-                                                /*"https://www.essonneinfo.fr/feed/"*/ });
+                                               "http://www.ville-palaiseau.fr/rss/actualites.htm" });
                 
                 result.put(Category.PEOPLE,
                                 new String[] { "http://www.premiere.fr/rss/actu-live",
@@ -121,7 +123,7 @@ public class ArticleProvider {
                         }
                         if (thumbnail == null)
                                 thumbnail = feedImage;
-                                
+                                                        
                         title = entry.getTitle().trim();
                         
                         if (entry.getDescription() != null) {                                      
@@ -195,10 +197,13 @@ public class ArticleProvider {
                         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));
                 }
         }