X-Git-Url: http://git.wpitchoune.net/gitweb/?p=pnews.git;a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FHTML.java;h=d20d415c33c9a5894be6019c3a90b992c0cb09cd;hp=321c5a7822f560548583ba79c3a3255ab2441174;hb=975f59a4767a4fc4f298b87abf2a5b415e988726;hpb=892111b2ecf385bd28bbe93ff6113cbc1e04409e diff --git a/war/src/main/java/pnews/servlet/HTML.java b/war/src/main/java/pnews/servlet/HTML.java index 321c5a7..d20d415 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(); @@ -61,7 +66,12 @@ public class HTML { buf.append("
\n"); if (a.description != null) { buf.append("

"); - buf.append(a.description); + if (a.description.length() < 512) { + buf.append(a.description); + } else { + buf.append(a.description.substring(0, 512)); + buf.append("[..]"); + } buf.append("

"); } buf.append("
\n"); @@ -71,13 +81,16 @@ public class HTML { buf.append("\n"); } - private static void appendMenu(StringBuffer buf, Category catActive, Category[] cats) { + private static void appendMenu(StringBuffer buf, Category catActive, Config cfg) { String cl; buf.append("\n"); } - public static String toHTML(List
articles, Category catActive, Category[] cats) { + 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"); @@ -111,7 +137,33 @@ public class HTML { buf.append("\n"); buf.append("\n"); - appendMenu(buf, catActive, cats); + 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) {