navigation with hot topics
[pnews.git] / war / src / main / java / pnews / servlet / Pnews.java
index fc08d13..69ad1bc 100644 (file)
@@ -22,6 +22,7 @@ import com.rometools.rome.io.FeedException;
 
 import pnews.Article;
 import pnews.Category;
+import pnews.Language;
 
 public class Pnews extends HttpServlet {
         private static final String CLASS_NAME = Pnews.class.getName();
@@ -100,24 +101,24 @@ public class Pnews extends HttpServlet {
                 rp.setContentType("application/json;charset=utf-8");
                 rp.setCharacterEncoding("utf-8");
 
-                rp.getWriter().write(JSON.getStats(config.getCategories()));
+                rp.getWriter().write(JSON.getStats(provider, config));
         }
 
         
-        private void writeArticles(Category cat, HttpServletResponse rp) {
+        private void writeArticles(Category cat, String entity, HttpServletResponse rp) {
                 String html;
                 List<Article> articles;
 
                 try {
-                        articles = provider.getArticles(cat);
+                        articles = provider.getArticles(cat, entity);
                         if (articles != null) {
-                                html = HTML.toHTML(articles, cat, config.getCategories());
+                                html = HTML.toHTML(articles, cat, entity, config, provider);
                                 rp.setContentType("text/html;charset=utf-8");
                                 rp.getWriter().write(html);
                                 rp.setCharacterEncoding("utf-8");
                         } else {
                                 LOG.severe("writeArticles cannot retrieve any articles");
-                                html = HTML.toHTML(new ArrayList<Article>(), cat, config.getCategories());
+                                html = HTML.toHTML(new ArrayList<Article>(), cat, entity, config, provider);
                                 rp.setContentType("text/html");
                                 rp.getWriter().write(html);
                         }
@@ -173,7 +174,7 @@ public class Pnews extends HttpServlet {
                 }
 
                 if (path.equals("/")) {
-                        writeArticles(config.getDefaultCategory(), resp);
+                        doTemporaryRedirect(config.getDefaultLanguage().toURL(), resp);
                         return ;
                 }
 
@@ -185,21 +186,21 @@ public class Pnews extends HttpServlet {
                 
                         for (Category cat: config.getCategories()) {
                                 if (path.equals(cat.getURL())) {
-                                        writeArticles(cat, resp);
+                                        writeArticles(cat, getQueryParameter(req, "entity"), resp);
                                         return ;
                                 }
                         }
                         
-                        for (String l: config.getLanguages()) {
-                                if (path.equals("/" + l) || path.equals("/" + l + "/")) {
-                                        doTemporaryRedirect(config.getDefaultCategory().getURL(), resp);
+                        for (Language l: config.getLanguages()) {
+                                if (path.equals(l.toURL())) {
+                                        doTemporaryRedirect(config.getDefaultCategory(l).getURL(), resp);
                                         return ;
                                 }
                         }
                 
                         resp.getWriter().write("Not found " + req.getPathInfo());
                         resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
-                } catch (IOException e) {
+                } catch (IOException | RuntimeException e) {
                         LOG.log(Level.SEVERE, "doGet failure", e);
                         resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 }