read categories information from the configuration
[pnews.git] / war / src / main / java / pnews / servlet / JSON.java
index 20afaa6..a36367e 100644 (file)
@@ -1,12 +1,10 @@
 package pnews.servlet;
 
-import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import com.google.gson.Gson;
 import com.google.gson.JsonObject;
-import com.rometools.rome.io.FeedException;
 
 import pnews.Article;
 import pnews.Category;
@@ -14,10 +12,10 @@ import pnews.Category;
 public class JSON {
         private static final Logger LOG = Logger.getLogger(JSON.class.getName());
         
-        public static String getStats() {
+        public static String getStats(Category[] cats) {
                 JsonObject jstats, jreadcounts, jcategories, jmemory;
-                Article[] articles;
                 Runtime runtime;
+                Article[] articles;
                 
                 jstats = new JsonObject();
                                 
@@ -34,10 +32,11 @@ public class JSON {
                 jcategories = new JsonObject();
                 jstats.add("categories", jcategories);
                 
-                for (Category cat: Category.values())
+                for (Category cat: cats)
                         try {
-                                jcategories.addProperty(cat.getId(), ArticleProvider.singleton.getArticles(cat).size());
-                        } catch (IllegalArgumentException | FeedException | IOException e) {
+                                jcategories.addProperty(cat.getLabel(),
+                                                        articles.length);
+                        } catch (IllegalArgumentException e) {
                                 LOG.log(Level.SEVERE, "Fail to retrieve articles", e);
                         }