2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.httpd;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2013-09-03 19:20:28 +00:00
|
|
|
import java.util.Collection;
|
2013-08-27 01:48:04 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
2014-12-21 09:23:50 +00:00
|
|
|
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
|
|
|
public class HTMLGenerationTools
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-08-27 01:48:04 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-09-03 19:20:28 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|