1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.access.html;
15
16 import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
17
18 import java.util.Map;
19
20 import ch.qos.logback.access.PatternLayout;
21 import ch.qos.logback.access.spi.IAccessEvent;
22 import ch.qos.logback.core.html.HTMLLayoutBase;
23 import ch.qos.logback.core.pattern.Converter;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class HTMLLayout extends HTMLLayoutBase<IAccessEvent> {
41
42
43
44
45 static final String DEFAULT_CONVERSION_PATTERN = "%h%l%u%t%r%s%b";
46
47
48
49
50
51 public HTMLLayout() {
52 pattern = DEFAULT_CONVERSION_PATTERN;
53 cssBuilder = new DefaultCssBuilder();
54 }
55
56 @Override
57 protected Map<String, String> getDefaultConverterMap() {
58 return PatternLayout.defaultConverterMap;
59 }
60
61 @Override
62 public String doLayout(IAccessEvent event) {
63 StringBuilder buf = new StringBuilder();
64 startNewTableIfLimitReached(buf);
65
66 boolean odd = true;
67 if (((counter++) & 1) == 0) {
68 odd = false;
69 }
70
71 buf.append(LINE_SEPARATOR);
72 buf.append("<tr class=\"");
73 if (odd) {
74 buf.append(" odd\">");
75 } else {
76 buf.append(" even\">");
77 }
78 buf.append(LINE_SEPARATOR);
79
80 Converter<IAccessEvent> c = head;
81 while (c != null) {
82 appendEventToBuffer(buf, c, event);
83 c = c.getNext();
84 }
85 buf.append("</tr>");
86 buf.append(LINE_SEPARATOR);
87
88 return buf.toString();
89 }
90
91 private void appendEventToBuffer(StringBuilder buf, Converter<IAccessEvent> c, IAccessEvent event) {
92 buf.append("<td class=\"");
93 buf.append(computeConverterName(c));
94 buf.append("\">");
95 c.write(buf, event);
96 buf.append("</td>");
97 buf.append(LINE_SEPARATOR);
98 }
99 }