navigation with hot topics
[pnews.git] / war / src / main / java / pnews / servlet / HTML.java
index 42564e8..72f0b4b 100644 (file)
@@ -105,11 +105,20 @@ public class HTML {
                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");
@@ -123,8 +132,6 @@ public class HTML {
                buf.append("</head>\n");
                buf.append("<body>\n");
                
-               cats = cfg.getCategories();
-               
                appendMenu(buf, catActive, cfg);
                
                try {
@@ -136,7 +143,11 @@ public class HTML {
                                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)