X-Git-Url: https://git.wpitchoune.net/gitweb/?p=pnews.git;a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FHTML.java;h=ac7a749b3db7e4499ba22c798d1c90427edc79e2;hp=a9ad838222aa7b2128e2ee03d0f0cf42f6f379ba;hb=aff83c8798602b535d13edeaffdb8f4238e2bbf5;hpb=47bc9d3dc6b3cf77957f11bceea1bcda492f8818 diff --git a/war/src/main/java/pnews/servlet/HTML.java b/war/src/main/java/pnews/servlet/HTML.java index a9ad838..ac7a749 100644 --- a/war/src/main/java/pnews/servlet/HTML.java +++ b/war/src/main/java/pnews/servlet/HTML.java @@ -1,14 +1,19 @@ 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 pnews.Article; -import pnews.Category; -import pnews.Language; +import com.rometools.rome.io.FeedException; + +import net.wpitchoune.pnews.Article; +import net.wpitchoune.pnews.Category; +import net.wpitchoune.pnews.Config; +import net.wpitchoune.pnews.EntityStat; +import net.wpitchoune.pnews.Language; public class HTML { private static final String CLASS_NAME= HTML.class.getName(); @@ -44,9 +49,9 @@ public class HTML { buf.append("
\n"); buf.append("
\n"); - if (a.thumbnail != null) { + if (a.getThumbnail() != null) { buf.append("\n"); } buf.append("
\n"); @@ -54,15 +59,20 @@ 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.getTitle(), "/redirect?url=" + URLEncoder.encode(a.getLink(), "UTF-8"), null); buf.append("
\n"); - buf.append(""); + buf.append(""); buf.append("
\n"); - if (a.description != null) { + if (a.getDescription() != null) { buf.append("

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

"); } buf.append("
\n"); @@ -101,10 +111,20 @@ public class HTML { buf.append("\n"); } - public static String toHTML(List
articles, Category catActive, Config cfg) { + 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; - Category[] cats; + List entities; + String cl; buf = new StringBuffer(); buf.append("\n"); @@ -118,10 +138,34 @@ public class HTML { buf.append("\n"); buf.append("\n"); - cats = cfg.getCategories(); - 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 {