X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FHTML.java;h=72f0b4b3b514573f650f09701220c0b7b73ec241;hb=511fe72ae8bad61a60f738c01819af58510ae9d3;hp=7b7b1424a692a5dc3ee491419fdf99f85aa87eb3;hpb=0915e687fb41a3543d03b30a3dbe3b3c49103fa3;p=pnews.git diff --git a/war/src/main/java/pnews/servlet/HTML.java b/war/src/main/java/pnews/servlet/HTML.java index 7b7b142..72f0b4b 100644 --- a/war/src/main/java/pnews/servlet/HTML.java +++ b/war/src/main/java/pnews/servlet/HTML.java @@ -1,13 +1,18 @@ package pnews.servlet; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import com.rometools.rome.io.FeedException; + import pnews.Article; import pnews.Category; +import pnews.EntityStat; +import pnews.Language; public class HTML { private static final String CLASS_NAME= HTML.class.getName(); @@ -53,7 +58,7 @@ public class HTML { buf.append("
\n"); buf.append("
\n"); - appendA(buf, a.title, "redirect?url=" + URLEncoder.encode(a.link, "UTF-8"), null); + appendA(buf, a.title, "/redirect?url=" + URLEncoder.encode(a.link, "UTF-8"), null); buf.append("
\n"); buf.append("
" + a.website + " - " + a.publicationDate + "
"); @@ -71,13 +76,16 @@ public class HTML { buf.append("
\n"); } - private static void appendMenu(StringBuffer buf, Category catActive) { + private static void appendMenu(StringBuffer buf, Category catActive, Config cfg) { String cl; buf.append("\n"); } - public static String toHTML(List
articles, Category catActive) { + private static String toURL(Category catActive, String entity) { + try { + return catActive.getURL() + "?entity=" + URLEncoder.encode(entity, "UTF-8"); + } catch (UnsupportedEncodingException e) { + LOG.log(Level.SEVERE, "Failed to generate link to entity " + entity, e); + return catActive.getURL(); + } + } + + public static String toHTML(List
articles, Category catActive, String entityActive, Config cfg, ArticleProvider provider) { StringBuffer buf; int i; + List entities; + String cl; buf = new StringBuffer(); buf.append("\n"); buf.append("\n"); buf.append("\n"); buf.append("\n"); - buf.append("\n"); + buf.append("\n"); buf.append(""); buf.append(catActive.getTitle()); buf.append(" - PNews\n"); buf.append("\n"); buf.append("\n"); - appendMenu(buf, catActive); + appendMenu(buf, catActive, cfg); + + try { + entities = provider.getEntityStats(catActive); + + if (entities.size() > 0) { + buf.append("\n"); + } + } catch (IllegalArgumentException | FeedException | IOException e2) { + LOG.log(Level.SEVERE, "Failed to get entities", e2); + } i = 0; for (Article e: articles) { try { append(buf, e); } catch (UnsupportedEncodingException e1) { - LOG.log(Level.SEVERE, "fail to convert article to HTML", e1); + LOG.log(Level.SEVERE, "Failed to convert article to HTML", e1); } if (i == 100) break;