X-Git-Url: https://git.wpitchoune.net/gitweb/?p=pnews.git;a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FPnews.java;h=c51f9468d6de242c4a25d5a774de75448ed0fa63;hp=fc08d136ab112fff271ac878c8d0459e20ccefc4;hb=aff83c8798602b535d13edeaffdb8f4238e2bbf5;hpb=892111b2ecf385bd28bbe93ff6113cbc1e04409e diff --git a/war/src/main/java/pnews/servlet/Pnews.java b/war/src/main/java/pnews/servlet/Pnews.java index fc08d13..c51f946 100644 --- a/war/src/main/java/pnews/servlet/Pnews.java +++ b/war/src/main/java/pnews/servlet/Pnews.java @@ -20,8 +20,11 @@ import javax.servlet.http.HttpServletResponse; import com.rometools.rome.io.FeedException; -import pnews.Article; -import pnews.Category; +import net.wpitchoune.pnews.Article; +import net.wpitchoune.pnews.ArticleStore; +import net.wpitchoune.pnews.Category; +import net.wpitchoune.pnews.Config; +import net.wpitchoune.pnews.Language; public class Pnews extends HttpServlet { private static final String CLASS_NAME = Pnews.class.getName(); @@ -71,7 +74,7 @@ public class Pnews extends HttpServlet { if (redirectURL != null) { a = ArticleStore.singleton.get(redirectURL); if (a != null) - a.readCount.incrementAndGet(); + a.incrementReadCount(); else LOG.severe("Cannot find the article " + redirectURL); @@ -100,24 +103,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
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
(), cat, config.getCategories()); + html = HTML.toHTML(new ArrayList
(), cat, entity, config, provider); rp.setContentType("text/html"); rp.getWriter().write(html); } @@ -173,7 +176,7 @@ public class Pnews extends HttpServlet { } if (path.equals("/")) { - writeArticles(config.getDefaultCategory(), resp); + doTemporaryRedirect(config.getDefaultLanguage().toURL(), resp); return ; } @@ -185,21 +188,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); }