read config from json. Many refactoring to prepare multi language support
[pnews.git] / war / src / main / java / pnews / servlet / JSON.java
index 20afaa6..0a9b8ce 100644 (file)
@@ -14,10 +14,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 +34,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.getName(),
+                                                        articles.length);
+                        } catch (IllegalArgumentException e) {
                                 LOG.log(Level.SEVERE, "Fail to retrieve articles", e);
                         }