TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java

59 lines
1.4 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.httpd;
2013-08-27 01:48:04 +00:00
import java.util.Collection;
2013-08-27 01:48:04 +00:00
import java.util.Iterator;
import java.util.Map;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
2013-08-27 01:48:04 +00:00
public class HTMLGenerationTools
{
private HTMLGenerationTools()
{
throw new AssertionError();
}
public static String paragraph(String data)
{
return "<p>" + escapeHtml4(data) + "</p>\r\n";
}
2013-08-27 17:49:45 +00:00
public static String heading(String data, int level)
{
return "<h" + level + ">" + escapeHtml4(data) + "</h" + level + ">\r\n";
}
2013-08-27 16:39:28 +00:00
public static <K, V> String list(Map<K, V> map)
2013-08-27 01:48:04 +00:00
{
StringBuilder output = new StringBuilder();
output.append("<ul>\r\n");
2013-08-27 16:39:28 +00:00
Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
2013-08-27 01:48:04 +00:00
while (it.hasNext())
{
2013-08-27 16:39:28 +00:00
Map.Entry<K, V> entry = it.next();
output.append("<li>").append(escapeHtml4(entry.getKey().toString() + " = " + entry.getValue().toString())).append("</li>\r\n");
}
output.append("</ul>\r\n");
return output.toString();
}
public static <T> String list(Collection<T> list)
2013-08-27 16:39:28 +00:00
{
StringBuilder output = new StringBuilder();
output.append("<ul>\r\n");
for (T entry : list)
{
output.append("<li>").append(escapeHtml4(entry.toString())).append("</li>\r\n");
2013-08-27 01:48:04 +00:00
}
output.append("</ul>\r\n");
return output.toString();
}
}