return entities;
}
+ public boolean hasEntity(String entity) {
+ for (String e: entities)
+ if (e.equals(entity))
+ return true;
+
+ return false;
+ }
+
public Date getPublicationDate() {
return publicationDate;
}
/**
* Returns a copy.
*/
- public List<Article> getArticles(Category cat)
+ public List<Article> getArticles(Category cat, String entity)
throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
- List<Article> articles;
+ List<Article> articles, result;
synchronized (articlesByCategory) {
articles = getArticlesForUpdate(cat);
}
- synchronized (articles) {
- return new ArrayList<>(articles);
+ synchronized (articles) {
+ if (entity == null)
+ return new ArrayList<>(articles);
+
+ result = new ArrayList<>(articles.size());
+ for (Article a: articles)
+ if (a.hasEntity(entity))
+ result.add(a);
+
+ return result;
}
}
LOG.entering(CLASS_NAME, FUNCTION_NAME, cat);
- articles = getArticles(cat);
+ articles = getArticles(cat, null);
entities = new HashMap<>();
for (Article a: articles)
buf.append("</nav>\n");
}
- public static String toHTML(List<Article> articles, Category catActive, Config cfg, ArticleProvider provider) {
+ 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<Article> articles, Category catActive, String entityActive, Config cfg, ArticleProvider provider) {
StringBuffer buf;
int i;
- Category[] cats;
List<EntityStat> entities;
+ String cl;
buf = new StringBuffer();
buf.append("<!DOCTYPE html>\n");
buf.append("</head>\n");
buf.append("<body>\n");
- cats = cfg.getCategories();
-
appendMenu(buf, catActive, cfg);
try {
i = 0;
for (EntityStat s: entities) {
buf.append("<li>");
- buf.append(s.getEntity());
+ if (entityActive != null && s.getEntity().equals(entityActive))
+ cl = "active";
+ else
+ cl = null;
+ appendA(buf, s.getEntity(), toURL(catActive, s.getEntity()), cl);
buf.append("</li>\n");
i++;
if (i > 10)
for (Category cat: config.getCategories())
try {
- articles = provider.getArticles(cat);
+ articles = provider.getArticles(cat, null);
jcategories.addProperty(cat.getLabel(),
articles.size());
} catch (IllegalArgumentException | FeedException | IOException e) {
}
- 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, provider);
+ 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, provider);
+ html = HTML.toHTML(new ArrayList<Article>(), cat, entity, config, provider);
rp.setContentType("text/html");
rp.getWriter().write(html);
}
for (Category cat: config.getCategories()) {
if (path.equals(cat.getURL())) {
- writeArticles(cat, resp);
+ writeArticles(cat, getQueryParameter(req, "entity"), resp);
return ;
}
}
"http://www.futura-sciences.com/rss/actualites.xml": { "categories": ["technologie"] },
"https://www-03.ibm.com/press/fr/fr/rssfeed.wss?keyword=null&maxFeed=&feedType=RSS&topic=all": { "categories": ["technologie"] },
"https://korben.info/feed": { "categories": ["technologie"]},
+ "https://www.techhive.com/index.rss": { "categories": ["en_technologie"]},
+ "https://www.gnome.org/feed/": { "categories": ["en_technologie"]},
+ "http://www.markshuttleworth.com/feed": { "categories": ["en_technologie"]},
"https://insights.ubuntu.com/feed/": { "categories": ["en_technologie"]},
"https://www-03.ibm.com/press/us/en/rssfeed.wss?keyword=null&maxFeed=&feedType=RSS&topic=all": { "categories": ["en_technologie"]},
"https://www.cnet.com/rss/news/": { "categories": ["en_technologie"]},
"https://www.androidheadlines.com/feed": { "categories": ["en_technologie"]},
"https://www.nasa.gov/rss/dyn/breaking_news.rss": { "categories": ["en_technologie"]},
"http://www.computerweekly.com/rss/RSS-Feed.xml": { "categories": ["en_technologie"]},
- "https://www.debian.org/News/news": { "categories": ["en_technologie"]}
+ "https://www.debian.org/News/news": { "categories": ["en_technologie"]},
+ "https://www.theverge.com/rss/index.xml": { "categories": ["en_technologie"]}
}
}