multi-language support
[pnews.git] / war / src / main / java / pnews / servlet / HTML.java
index 681c84b..a9ad838 100644 (file)
@@ -8,6 +8,7 @@ import java.util.logging.Logger;
 
 import pnews.Article;
 import pnews.Category;
+import pnews.Language;
 
 public class HTML {
         private static final String CLASS_NAME= HTML.class.getName();
@@ -71,13 +72,16 @@ public class HTML {
                buf.append("</div>\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("<nav>\n");
                buf.append("<ul>\n");
 
-               for (Category cat: cats) {
+               for (Category cat: cfg.getCategories()) {
+                       if (!cat.getLanguage().equals(catActive.getLanguage()))
+                               continue;
+                       
                        buf.append("<li>");
                        
                        if (cat.equals(catActive))
@@ -89,13 +93,18 @@ public class HTML {
                        buf.append("</li>");
                }
                
+               for (Language l: cfg.getLanguages())
+                       buf.append("<li><a href='" + l.toURL() + "'>" + l.getLabel() + "</a></li>");
+                
                buf.append("</ul>\n");
+               
                buf.append("</nav>\n");
        }
        
-       public static String toHTML(List<Article> articles, Category catActive, Category[] cats) {
+       public static String toHTML(List<Article> articles, Category catActive, Config cfg) {
                StringBuffer buf;
                int i;
+               Category[] cats;
                
                buf = new StringBuffer();
                buf.append("<!DOCTYPE html>\n");
@@ -109,14 +118,16 @@ public class HTML {
                buf.append("</head>\n");
                buf.append("<body>\n");
                
-               appendMenu(buf, catActive, cats);
+               cats = cfg.getCategories();
+               
+               appendMenu(buf, catActive, cfg);
                
                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;