TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java
JeromSar a0058869c9 Added checkstyle plugin
Moved resources to correct folder
Fixed and improved build information, no longer tracking build.properties
2015-11-22 19:28:32 +01:00

60 lines
1.4 KiB
Java

package me.totalfreedom.totalfreedommod.httpd;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
public class HTMLGenerationTools
{
private HTMLGenerationTools()
{
throw new AssertionError();
}
public static String paragraph(String data)
{
return "<p>" + escapeHtml4(data) + "</p>\r\n";
}
public static String heading(String data, int level)
{
return "<h" + level + ">" + escapeHtml4(data) + "</h" + level + ">\r\n";
}
public static <K, V> String list(Map<K, V> map)
{
StringBuilder output = new StringBuilder();
output.append("<ul>\r\n");
Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
while (it.hasNext())
{
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)
{
StringBuilder output = new StringBuilder();
output.append("<ul>\r\n");
for (T entry : list)
{
output.append("<li>").append(escapeHtml4(entry.toString())).append("</li>\r\n");
}
output.append("</ul>\r\n");
return output.toString();
}
}