1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.exceptions.report.generator;
17
18 import java.util.List;
19 import java.util.ResourceBundle;
20
21 import javax.xml.stream.XMLStreamException;
22 import javax.xml.stream.XMLStreamWriter;
23
24 import org.apache.commons.lang.StringUtils;
25
26 import de.smartics.exceptions.core.Code;
27 import de.smartics.exceptions.report.app.ReportException;
28 import de.smartics.exceptions.report.data.ExceptionCodeReportItem;
29 import de.smartics.exceptions.report.data.ProjectConfiguration;
30 import de.smartics.exceptions.report.data.StoredExceptionCodesReport;
31 import de.smartics.exceptions.report.renderer.JavadocRenderer;
32 import de.smartics.exceptions.report.renderer.html.HtmlRendererFactory;
33 import de.smartics.exceptions.report.utils.CopyReader;
34
35
36
37
38 public class HtmlReportGenerator extends AbstractHtmlReportGenerator
39 {
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public HtmlReportGenerator()
56 {
57 super(new JavadocRenderer(new HtmlRendererFactory()));
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 @Override
74 protected void writeTableHeader(final XMLStreamWriter xmlWriter,
75 final ProjectConfiguration<XMLStreamWriter> config)
76 throws XMLStreamException
77 {
78 xmlWriter.writeStartElement("table");
79 xmlWriter.writeStartElement("tr");
80
81 final ResourceBundle bundle = config.getBundle();
82 final String codeLabel =
83 StringFunction.getMessage(bundle,
84 "report.exceptioncode.item.reportElement", "Code");
85 xmlWriter.writeStartElement("th");
86 xmlWriter.writeCharacters(codeLabel);
87 xmlWriter.writeEndElement();
88
89 final String propertyNameLabel =
90 StringFunction.getMessage(bundle,
91 "report.exceptioncode.item.propertyName", "Property Name");
92 xmlWriter.writeStartElement("th");
93 xmlWriter.writeCharacters(propertyNameLabel);
94 xmlWriter.writeEndElement();
95
96 final String descriptionLabel =
97 StringFunction.getMessage(bundle,
98 "report.exceptioncode.item.description", "Description");
99 xmlWriter.writeStartElement("th");
100 xmlWriter.writeCharacters(descriptionLabel);
101 xmlWriter.writeEndElement();
102
103 xmlWriter.writeEndElement();
104 }
105
106
107
108
109 @Override
110 protected void writeReportElementInfo(final XMLStreamWriter xmlWriter,
111 final ProjectConfiguration<XMLStreamWriter> config,
112 final ExceptionCodeReportItem item) throws Exception
113 {
114 xmlWriter.writeStartElement("tr");
115
116 final Code instance = item.getCode();
117
118 xmlWriter.writeStartElement("td");
119 xmlWriter.writeAttribute("style", "white-space: nowrap;");
120 xmlWriter.writeCharacters(String.valueOf(instance));
121 xmlWriter.writeEndElement();
122
123 xmlWriter.writeStartElement("td");
124 xmlWriter.writeAttribute("style", "white-space: nowrap;");
125 xmlWriter.writeCharacters(item.getName());
126 xmlWriter.writeEndElement();
127
128 xmlWriter.writeStartElement("td");
129 final String javadoc = this.renderer.render(item.getJavadoc());
130 if (StringUtils.isNotBlank(javadoc))
131 {
132
133 final CopyReader copy = new CopyReader(xmlWriter);
134 copy.copy(javadoc);
135 }
136 xmlWriter.writeEndElement();
137 xmlWriter.writeEndElement();
138 }
139
140 @Override
141 public void writeReport(final ProjectConfiguration<XMLStreamWriter> config,
142 final StoredExceptionCodesReport report) throws ReportException
143 {
144
145 }
146
147 @Override
148 protected List<ExceptionCodeReportItem> getItems(
149 final StoredExceptionCodesReport report)
150 {
151 return report.getItems();
152 }
153
154 @Override
155 protected boolean hasSectionChanged(final String currentSection,
156 final ExceptionCodeReportItem item)
157 {
158 return !item.getDeclaringTypeName().equals(currentSection);
159 }
160
161 @Override
162 protected String getCurrentSelection(final ExceptionCodeReportItem item)
163 {
164 return item.getDeclaringTypeName();
165 }
166
167 @Override
168 protected String getCodeTitle(final String headLine,
169 final ExceptionCodeReportItem item)
170 {
171 final String title;
172 if (headLine != null)
173 {
174 title = headLine;
175 }
176 else
177 {
178 final String componentId = item.getCode().getComponentId();
179 if (StringUtils.isNotBlank(componentId))
180 {
181 title = componentId;
182 }
183 else
184 {
185 final String className = item.getDeclaringTypeName();
186 title = className;
187 }
188 }
189
190 return title;
191 }
192
193
194
195 }