@Test public void testDefaultCharset() { final HtmlLayout layout = HtmlLayout.createDefaultLayout(); assertEquals(StandardCharsets.UTF_8, layout.getCharset()); }
@Test public void testContentType() { final HtmlLayout layout = HtmlLayout.newBuilder() .withContentType("text/html; charset=UTF-16") .build(); assertEquals("text/html; charset=UTF-16", layout.getContentType()); // TODO: make sure this following bit works as well // assertEquals(Charset.forName("UTF-16"), layout.getCharset()); }
private void assertFooter(final File file) throws Exception { final HtmlLayout layout = HtmlLayout.createDefaultLayout(); final String footer = new String(layout.getFooter(), Charset.defaultCharset()); final String contents = new String(slurp(file), Charset.defaultCharset()); assertTrue(file.getName(), contents.endsWith(footer)); }
@Test public void testDefaultContentType() { final HtmlLayout layout = HtmlLayout.createDefaultLayout(); assertEquals("text/html; charset=UTF-8", layout.getContentType()); }
private void assertHeader(final File file) throws Exception { final HtmlLayout layout = HtmlLayout.createDefaultLayout(); final String header = new String(layout.getHeader(), Charset.defaultCharset()); final String withoutTimestamp = header.substring(0, 435); final String contents = new String(slurp(file), Charset.defaultCharset()); final String contentsInitialChunk = contents.substring(0, 435); assertEquals(file.getName(), withoutTimestamp, contentsInitialChunk); }
public byte[] getHeader() { final StringBuilder sbuf = new StringBuilder(); append(sbuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "); appendLs(sbuf, "\"http://www.w3.org/TR/html4/loose.dtd\">"); appendLs(sbuf, "<html>"); appendLs(sbuf, "<head>"); append(sbuf, "<meta charset=\""); append(sbuf, getCharset().toString()); appendLs(sbuf, "\"/>"); append(sbuf, "<title>").append(title); appendLs(sbuf, "</title>"); appendLs(sbuf, "<style type=\"text/css\">"); appendLs(sbuf, "<!--"); append(sbuf, "body, table {font-family:").append(font).append("; font-size: "); appendLs(sbuf, headerSize).append(";}"); appendLs(sbuf, "th {background: #336699; color: #FFFFFF; text-align: left;}"); appendLs(sbuf, "-->"); appendLs(sbuf, "</style>"); appendLs(sbuf, "</head>"); appendLs(sbuf, "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">"); appendLs(sbuf, "<hr size=\"1\" noshade=\"noshade\">"); appendLs(sbuf, "Log session start time " + new java.util.Date() + "<br>"); appendLs(sbuf, "<br>"); appendLs(sbuf, "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">"); appendLs(sbuf, "<tr>"); appendLs(sbuf, "<th>Time</th>"); appendLs(sbuf, "<th>Thread</th>"); appendLs(sbuf, "<th>Level</th>");
final HtmlLayout layout = HtmlLayout.newBuilder() .withLocationInfo(includeLocation) .build();
private String addCharsetToContentType(final String contentType) { if (contentType == null) { return DEFAULT_CONTENT_TYPE + "; charset=" + getCharset(); } return contentType.contains("charset") ? contentType : contentType + "; charset=" + getCharset(); }
final StringBuilder sbuf = getStringBuilder(); sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : ").append(fontSize); sbuf.append(";\" colspan=\"6\">"); appendThrowableAsHtml(throwable, sbuf); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR);
layout = HtmlLayout.createDefaultLayout();
@Override public HtmlLayout build() { // TODO: extract charset from content-type if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE + "; charset=" + charset; } return new HtmlLayout(locationInfo, title, contentType, charset, fontName, fontSize.getFontSize(), fontSize.larger().getFontSize()); } }
private HtmlLayout(final boolean locationInfo, final String title, final String contentType, final Charset charset, final String font, final String fontSize, final String headerSize) { super(charset); this.locationInfo = locationInfo; this.title = title; this.contentType = addCharsetToContentType(contentType); this.font = font; this.fontSize = fontSize; this.headerSize = headerSize; }
/** * Creates an HTML Layout using the default settings. * * @return an HTML Layout. */ public static HtmlLayout createDefaultLayout() { return newBuilder().build(); }
/** * Creates an HTML Layout. * @param locationInfo If "true", location information will be included. The default is false. * @param title The title to include in the file header. If none is specified the default title will be used. * @param contentType The content type. Defaults to "text/html". * @param charset The character set to use. If not specified, the default will be used. * @param fontSize The font size of the text. * @param font The font to use for the text. * @return An HTML Layout. */ @PluginFactory public static HtmlLayout createLayout( @PluginAttribute(value = "locationInfo") final boolean locationInfo, @PluginAttribute(value = "title", defaultString = DEFAULT_TITLE) final String title, @PluginAttribute("contentType") String contentType, @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset, @PluginAttribute("fontSize") String fontSize, @PluginAttribute(value = "fontName", defaultString = DEFAULT_FONT_FAMILY) final String font) { final FontSize fs = FontSize.getFontSize(fontSize); fontSize = fs.getFontSize(); final String headerSize = fs.larger().getFontSize(); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE + "; charset=" + charset; } return new HtmlLayout(locationInfo, title, contentType, charset, font, fontSize, headerSize); }